Skip to content

Commit 864b2fe

Browse files
author
Kurt Biery
committed
Incremental changes in resource_validation.py
1 parent 9457515 commit 864b2fe

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/integrationtest/resource_validation.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
# resval = resource_validation.ResourceValidator()
1919
# resval.require_cpu_count(64)
2020
# resval.require_free_memory_gb(28)
21-
# # set other minimum values, if needed
21+
# # set other minimum values, if desired
2222
# resval_debug_string = resval.get_debug_string()
2323
# print(f"{resval_debug_string}")
24-
# # skip to one of the pytest "tests"
24+
# # then, in one of the pytest "tests"
2525
# if not resval.this_computer_has_sufficient_resources:
2626
# resval_full_report = resval.get_insufficient_resources_report()
2727
# print(f"{resval_full_report}")
@@ -35,25 +35,24 @@
3535
class ResourceValidator:
3636
def __init__(self):
3737
self.this_computer_has_sufficient_resources = True
38-
self.debug_string = ""
39-
self.report_string = ""
38+
4039
hostname = os.uname().nodename
4140
self.report_header = f"This computer ({hostname}) does not have enough resources to run this test."
41+
self.report_indentation = " *"
4242

43-
def get_report_header(self):
44-
return self.report_header
43+
self.debug_string = ""
44+
self.report_string = ""
4545

46-
def get_report_indentation(self):
47-
return " *"
46+
self.free_disk_space_gb = -1
4847

4948
def require_cpu_count(self, minimum_cpu_count):
5049
cpu_count = os.cpu_count()
5150
self.debug_string += f"\nDEBUG: CPU count is {cpu_count}, minimum required number is {minimum_cpu_count}."
5251
if cpu_count < minimum_cpu_count:
5352
self.this_computer_has_sufficient_resources = False
5453
if len(self.report_string) == 0:
55-
self.report_string = self.get_report_header()
56-
self.report_string += f"\n{self.get_report_indentation()} CPU count is {cpu_count}, Minimum CPU count is {minimum_cpu_count}."
54+
self.report_string = self.report_header
55+
self.report_string += f"\n{self.report_indentation} CPU count is {cpu_count}, minimum CPU count is {minimum_cpu_count}."
5756

5857
def require_free_memory_gb(self, minimum_free_memory):
5958
mem_obj = psutil.virtual_memory()
@@ -62,8 +61,8 @@ def require_free_memory_gb(self, minimum_free_memory):
6261
if free_mem < minimum_free_memory:
6362
self.this_computer_has_sufficient_resources = False
6463
if len(self.report_string) == 0:
65-
self.report_string = self.get_report_header()
66-
self.report_string += f"\n{self.get_report_indentation()} Free memory is {free_mem} GB, minimum amount is {minimum_free_memory}."
64+
self.report_string = self.report_header
65+
self.report_string += f"\n{self.report_indentation} Free memory is {free_mem} GB, minimum amount is {minimum_free_memory}."
6766

6867
def require_total_memory_gb(self, minimum_total_memory):
6968
mem_obj = psutil.virtual_memory()
@@ -72,28 +71,28 @@ def require_total_memory_gb(self, minimum_total_memory):
7271
if total_mem < minimum_total_memory:
7372
self.this_computer_has_sufficient_resources = False
7473
if len(self.report_string) == 0:
75-
self.report_string = self.get_report_header()
76-
self.report_string += f"\n{self.get_report_indentation()} Total memory is {total_mem} GB, minimum amount is {minimum_total_memory}."
74+
self.report_string = self.report_header
75+
self.report_string += f"\n{self.report_indentation} Total memory is {total_mem} GB, minimum amount is {minimum_total_memory}."
7776

7877
def require_free_disk_space_gb(self, path_of_interest, minimum_free_disk_space):
7978
disk_space = shutil.disk_usage(path_of_interest)
80-
free_disk_space = disk_space.free / (1024 * 1024 * 1024)
81-
self.debug_string += f"\nDEBUG: Free disk space is {free_disk_space} GB, minimum required amount is {minimum_free_disk_space}."
82-
if free_disk_space < minimum_free_disk_space:
79+
self.free_disk_space_gb = disk_space.free / (1024 * 1024 * 1024)
80+
self.debug_string += f"\nDEBUG: Free disk space on \"{path_of_interest}\" is {self.free_disk_space_gb} GB, minimum required amount is {minimum_free_disk_space}."
81+
if self.free_disk_space_gb < minimum_free_disk_space:
8382
self.this_computer_has_sufficient_resources = False
8483
if len(self.report_string) == 0:
85-
self.report_string = self.get_report_header()
86-
self.report_string += f"\n{self.get_report_indentation()} Free disk space is {free_disk_space} GB, minimum amount is {minimum_free_disk_space}."
84+
self.report_string = self.report_header
85+
self.report_string += f"\n{self.report_indentation} Free disk space on \"{path_of_interest}\" is {self.free_disk_space_gb} GB, minimum amount is {minimum_free_disk_space}."
8786

8887
def require_total_disk_space_gb(self, path_of_interest, minimum_total_disk_space):
8988
disk_space = shutil.disk_usage(path_of_interest)
9089
total_disk_space = disk_space.total / (1024 * 1024 * 1024)
91-
self.debug_string += f"\nDEBUG: Total disk space is {total_disk_space} GB, minimum required amount is {minimum_total_disk_space}."
90+
self.debug_string += f"\nDEBUG: Total disk space on \"{path_of_interest}\" is {total_disk_space} GB, minimum required amount is {minimum_total_disk_space}."
9291
if total_disk_space < minimum_total_disk_space:
9392
self.this_computer_has_sufficient_resources = False
9493
if len(self.report_string) == 0:
95-
self.report_string = self.get_report_header()
96-
self.report_string += f"\n{self.get_report_indentation()} Total disk space is {total_disk_space} GB, minimum amount is {minimum_total_disk_space}."
94+
self.report_string = self.report_header
95+
self.report_string += f"\n{self.report_indentation} Total disk space on \"{path_of_interest}\" is {total_disk_space} GB, minimum amount is {minimum_total_disk_space}."
9796

9897
def get_debug_string(self):
9998
return self.debug_string
@@ -102,4 +101,4 @@ def get_insufficient_resources_report(self):
102101
return self.report_string
103102

104103
def get_insufficient_resources_summary(self):
105-
return self.get_report_header()
104+
return self.report_header

0 commit comments

Comments
 (0)