From f6377042fcf61e48c52c814aee70733701739dbf Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 24 Jun 2015 16:47:45 +0200 Subject: [PATCH] rename util get_block_device_list into get_block_devices_dict and clean up its usage --- source/steps/ChainBootNode.py | 2 +- source/steps/CheckForNewDisks.py | 6 +++--- source/steps/CheckHardwareRequirements.py | 26 ++++++++++++----------- source/steps/InstallBootstrapFS.py | 7 ++++++ source/steps/ValidateNodeInstall.py | 2 +- source/systeminfo.py | 4 ++-- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/source/steps/ChainBootNode.py b/source/steps/ChainBootNode.py index f21a2ff..820aa7d 100644 --- a/source/steps/ChainBootNode.py +++ b/source/steps/ChainBootNode.py @@ -78,7 +78,7 @@ def Run(vars, log): # simply creating an instance of this class and listing the system # block devices will make them show up so vgscan can find the planetlab # volume group - systeminfo.get_block_device_list(vars, log) + systeminfo.get_block_devices_dict(vars, log) utils.sysexec("vgscan", log) utils.sysexec("vgchange -ay planetlab", log) diff --git a/source/steps/CheckForNewDisks.py b/source/steps/CheckForNewDisks.py index 60ae952..223c3ae 100644 --- a/source/steps/CheckForNewDisks.py +++ b/source/steps/CheckForNewDisks.py @@ -50,7 +50,7 @@ def Run(vars, log): except ValueError as var: raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var)) - all_devices = systeminfo.get_block_device_list(vars, log) + devices_dict = systeminfo.get_block_devices_dict(vars, log) # will contain the new devices to add to the volume group new_devices = [] @@ -58,9 +58,9 @@ def Run(vars, log): # total amount of new space in gb extended_gb_size = 0 - for device in all_devices.keys(): + for device, details in devices_dict.items(): - (major, minor, blocks, gb_size, readonly) = all_devices[device] + (major, minor, blocks, gb_size, readonly) = details if device[:14] == "/dev/planetlab": log.write("Skipping device {} in volume group.\n".format(device)) diff --git a/source/steps/CheckHardwareRequirements.py b/source/steps/CheckHardwareRequirements.py index a3f8677..1e10362 100644 --- a/source/steps/CheckHardwareRequirements.py +++ b/source/steps/CheckHardwareRequirements.py @@ -110,7 +110,7 @@ def Run(vars, log): # get a list of block devices to attempt to install on # (may include cdrom devices) - install_devices = systeminfo.get_block_device_list(vars, log) + install_devices = systeminfo.get_block_devices_dict(vars, log) # save the list of block devices in the log log.write("Detected block devices:\n") @@ -147,37 +147,39 @@ def Run(vars, log): # also, keep track of the total size for all devices that appear usable total_size = 0 - for device in install_devices.keys(): + # do not modify subject of current loop + ignored_devices = [] + for device, details in install_devices.items(): - major, minor, blocks, gb_size, readonly = install_devices[device] + major, minor, blocks, gb_size, readonly = details # if the device string starts with # planetlab or dm- (device mapper), ignore it (could be old lvm setup) if device[:14] == "/dev/planetlab" or device[:8] == "/dev/dm-": - del install_devices[device] + ignored_devices.append(device) continue if gb_size < MINIMUM_DISK_SIZE: log.write("Device is too small to use: {} \n" "(appears to be {:4.2f} Gb)\n".format(device, gb_size)) - try: - del install_devices[device] - except KeyError as e: - pass + ignored_devices.append(device) continue if readonly: log.write("Device is readonly, not using: {}\n".format(device)) - try: - del install_devices[device] - except KeyError as e: - pass + ignored_devices.append(device) continue # add this sector count to the total count of usable # sectors we've found. total_size = total_size + gb_size + # delayed erasure + for device in ignored_devices: + try: + del install_devices[device] + except KeyError as e: + pass if len(install_devices) == 0: log.write("No suitable block devices found for install.\n") diff --git a/source/steps/InstallBootstrapFS.py b/source/steps/InstallBootstrapFS.py index 24ea4bf..70d22a5 100644 --- a/source/steps/InstallBootstrapFS.py +++ b/source/steps/InstallBootstrapFS.py @@ -78,6 +78,13 @@ def Run(vars, upgrade, log): bs_request = BootServerRequest.BootServerRequest(vars) + # in upgrade mode, since we skip InstallPartitionDisks + # we need to run this + if upgrade: + log.write("Running vgscan for devices (upgrade mode)\n") + systeminfo.get_block_devices_dict(vars, log) + utils.sysexec_noerr("vgscan", log) + log.write("turning on swap space\n") utils.sysexec("swapon {}".format(PARTITIONS["swap"]), log) diff --git a/source/steps/ValidateNodeInstall.py b/source/steps/ValidateNodeInstall.py index 529400d..becb675 100644 --- a/source/steps/ValidateNodeInstall.py +++ b/source/steps/ValidateNodeInstall.py @@ -71,7 +71,7 @@ def Run(vars, log): # simply creating an instance of this class and listing the system # block devices will make them show up so vgscan can find the planetlab # volume group - systeminfo.get_block_device_list(vars, log) + systeminfo.get_block_devices_dict(vars, log) try: utils.sysexec("vgscan", log) diff --git a/source/systeminfo.py b/source/systeminfo.py index 4536294..3140755 100755 --- a/source/systeminfo.py +++ b/source/systeminfo.py @@ -103,7 +103,7 @@ def get_total_phsyical_mem(vars = {}, log = sys.stderr): meminfo_file.close() return total_memory -def get_block_device_list(vars = {}, log = sys.stderr): +def get_block_devices_dict(vars = {}, log = sys.stderr): """ get a list of block devices from this system. return an associative array, where the device name @@ -348,7 +348,7 @@ def getKernelVersion(vars = {}, log = sys.stderr): if __name__ == "__main__": - devices = get_block_device_list() + devices = get_block_devices_dict() print("block devices detected:") if not devices: print("no devices found!") -- 2.43.0