Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions data/templates/secure_erase.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
PATH = os.getcwd()


class Progress:
class Progress(object):
"""
Secure erase job progress class.
"""
Expand Down Expand Up @@ -109,9 +109,10 @@ def scrub_parser(self, drive):
log = open(self.path + drive + '.log', 'r')
MAX_DOT_COUNT = 50
# Scrub pass counts for different scrub methods, default pass count is 1
pass_count_key = self.parameters["option"] or "nnsa"
pass_counts = {"nnsa": 4, "dod": 4, "gutmann": 35, "schneier":7, "pfitzner7":7,
"pfitzner33": 33, "usarmy": 3, "random2": 2, "old": 6, "fastold": 5}
pass_count = pass_counts[self.parameters["option"]]
pass_count = pass_counts.get(pass_count_key, 1)
line_count = 0
dot_count = 0
patterna = re.compile("^scrub: \w{4,6}\s*\|\.+\|$")
Expand Down Expand Up @@ -151,6 +152,7 @@ def hdparm_parser(self, drive):
:param drive: drive name
:return: a float digital of percentage
"""
self.parameters["option"] = self.parameters["option"] or "security-erase"
log = open(self.path + drive + '.log', 'r')
percent = 0.0
if not self.duration.has_key(drive) or self.duration[drive] == 0:
Expand Down Expand Up @@ -218,15 +220,14 @@ def __run(self):
erase_start_flags = [False]*disk_count
payload = {
"taskId": self.parameters["taskId"],
"progress": {
"value": 0,
"maximum": 100
}
"value": 0,
"maximum": 100
}
counter = 0
total_percent = 0.00
if not self.parameters["address"]:
self.parameters["address"] = "http://172.31.128.1:9080/api/current/notification/progress"
self.parameters["address"] = \
"http://172.31.128.1:9080/api/current/notification/progress"
while True:
for (index, value) in enumerate(self.disk_list):
value = value.split("/")[-1]
Expand All @@ -244,12 +245,12 @@ def __run(self):
erase_start_flags[index] = os.path.exists(self.path + value + '.log')
total_percent = sum(percentage_list)/disk_count
if total_percent == float('+inf'):
payload["progress"]["percentage"] = "Not Available"
payload["percentage"] = "Not Available"
else:
payload["progress"]["percentage"] = str("%.2f" % total_percent) + "%"
payload["progress"]["value"] = int(total_percent)
payload["percentage"] = str("%.2f" % total_percent) + "%"
payload["value"] = int(total_percent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In latest progress design, the property percentage will be ignored, any progress need be split into value and maximum. In your case, you could set a constant maximum as 100.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maximum is 100, percentage was already there, I just sent in case progress can save calculation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, make sense

counter += 1
payload["progress"]["description"] = "This is the {}th polling with {}s interval" \
payload["description"] = "This is the {}th polling with {}s interval" \
.format(str(counter), str(self.interval))
cmd = 'curl -X POST -H "Content-Type:application/json" ' \
'-d \'{}\' {}'.format(json.dumps(payload), self.parameters["address"])
Expand Down Expand Up @@ -755,7 +756,7 @@ def progress_wrapper(obj):
pool.join()

if progress_result["exitcode"]:
print progress_result["Message"]
print progress_result["message"]

print erase_result_list
for erase_result in erase_result_list:
Expand Down