From 3541c7bdcae9227c302ce0cb5c06015d4ecb46d8 Mon Sep 17 00:00:00 2001 From: Jared Hoag Date: Tue, 6 Sep 2016 11:31:43 -0500 Subject: [PATCH 1/4] Fixed metadata disk exclusion issue in vs capture command. (#723) --- .gitignore | 2 ++ SoftLayer/managers/vs.py | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 411709398..438f1d703 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ docs/_build/* build/* dist/* *.egg-info +.cache + diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 25090e078..4bc68c0e3 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -714,19 +714,21 @@ def capture(self, instance_id, name, additional_disks=False, notes=None): notes = "Some notes about this image" result = mgr.capture(instance_id=12345, name=name, notes=notes) """ + disks = self.client.call('Virtual_Guest', 'getObject', id=instance_id, mask="id,blockDevices[id,diskImage[id,metadataFlag]]") + metadata_disks = [element.get('id') for element in disks.get('blockDevices') if element.get('diskImage').get('metadataFlag') == True] vsi = self.get_instance(instance_id) disk_filter = lambda x: x['device'] == '0' - # Skip disk 1 (swap partition) and CD mounts + # Skip disk 1 (swap partition), CD mounts, and metadata disks if additional_disks: disk_filter = lambda x: (str(x['device']) != '1' and - x['mountType'] != 'CD') - - disks = [block_device for block_device in vsi['blockDevices'] + x['mountType'] != 'CD' and + x['id'] not in metadata_disks) + non_metadata_disks = [block_device for block_device in vsi['blockDevices'] if disk_filter(block_device)] return self.guest.createArchiveTransaction( - name, disks, notes, id=instance_id) + name, non_metadata_disks, notes, id=instance_id) def upgrade(self, instance_id, cpus=None, memory=None, nic_speed=None, public=True): From b83fbd29e4b8b897a0dad480defb39cae251bf45 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 6 Sep 2016 12:09:01 -0500 Subject: [PATCH 2/4] Always excludes metadata disks from image capturing (fixes #723) --- SoftLayer/fixtures/SoftLayer_Virtual_Guest.py | 4 +- SoftLayer/managers/vs.py | 42 +++++++++++++------ setup.cfg | 2 +- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py index 104406681..8def96035 100644 --- a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py +++ b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py @@ -36,7 +36,9 @@ 'blockDevices': [{"device": 0, 'mountType': 'Disk', "uuid": 1}, {"device": 1, 'mountType': 'Disk'}, {"device": 2, 'mountType': 'CD'}, - {"device": 3, 'mountType': 'Disk', "uuid": 3}], + {"device": 3, 'mountType': 'Disk', "uuid": 3}, + {"device": 4, 'mountType': 'Disk', "uuid": 4, + 'diskImage': {'metadataFlag': True}}], 'notes': 'notes', 'networkVlans': [{'networkSpace': 'PUBLIC', 'vlanNumber': 23, diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 0ad9ceceb..26c60b8a8 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -721,21 +721,37 @@ def capture(self, instance_id, name, additional_disks=False, notes=None): notes = "Some notes about this image" result = mgr.capture(instance_id=12345, name=name, notes=notes) """ - disks = self.client.call('Virtual_Guest', 'getObject', id=instance_id, mask="id,blockDevices[id,diskImage[id,metadataFlag]]") - metadata_disks = [element.get('id') for element in disks.get('blockDevices') if element.get('diskImage').get('metadataFlag') == True] - vsi = self.get_instance(instance_id) - - disk_filter = lambda x: x['device'] == '0' - # Skip disk 1 (swap partition), CD mounts, and metadata disks - if additional_disks: - disk_filter = lambda x: (str(x['device']) != '1' and - x['mountType'] != 'CD' and - x['id'] not in metadata_disks) - non_metadata_disks = [block_device for block_device in vsi['blockDevices'] - if disk_filter(block_device)] + + vsi = self.client.call( + 'Virtual_Guest', + 'getObject', + id=instance_id, + mask="""id, + blockDevices[id,device,mountType,diskImage[id,metadataFlag]]""") + + disks_to_capture = [] + for block_device in vsi['blockDevices']: + + # We never want metadata disks + if utils.lookup(block_device, 'diskImage', 'metadataFlag'): + continue + + # We never want device 1 (swap) + if str(block_device['device']) == '1': + continue + + # We never want CD images + if block_device['mountType'] == 'CD': + continue + + # Only use the first block device if we don't want additional disks + if not additional_disks and block_device['device'] != '0': + continue + + disks_to_capture.append(block_device) return self.guest.createArchiveTransaction( - name, non_metadata_disks, notes, id=instance_id) + name, disks_to_capture, notes, id=instance_id) def upgrade(self, instance_id, cpus=None, memory=None, nic_speed=None, public=True): diff --git a/setup.cfg b/setup.cfg index 20520b557..ba4e6f120 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ -[pytest] +[tool:pytest] python_files = *_tests.py [wheel] From 31d0632cb66bf742aa851430d974797d99c906dd Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 6 Sep 2016 12:12:11 -0500 Subject: [PATCH 3/4] Fix a test issue where the types might not match in reality --- SoftLayer/managers/vs.py | 2 +- tests/managers/vs_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 26c60b8a8..54fabdc95 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -745,7 +745,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None): continue # Only use the first block device if we don't want additional disks - if not additional_disks and block_device['device'] != '0': + if not additional_disks and str(block_device['device']) != '0': continue disks_to_capture.append(block_device) diff --git a/tests/managers/vs_tests.py b/tests/managers/vs_tests.py index a0cecb205..fb1a2c2aa 100644 --- a/tests/managers/vs_tests.py +++ b/tests/managers/vs_tests.py @@ -615,7 +615,7 @@ def test_captures(self): expected = fixtures.SoftLayer_Virtual_Guest.createArchiveTransaction self.assertEqual(result, expected) - args = ('a', [], None) + args = ('a', [{'device': 0, 'uuid': 1, 'mountType': 'Disk'}], None) self.assert_called_with('SoftLayer_Virtual_Guest', 'createArchiveTransaction', args=args, From e2a87a1a71b66d31d07275d0059ed7351f283005 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Wed, 12 Oct 2016 12:01:32 -0500 Subject: [PATCH 4/4] Filter caputer images by type being SWAP --- SoftLayer/fixtures/SoftLayer_Virtual_Guest.py | 11 ++++++----- SoftLayer/managers/vs.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py index 8def96035..966e8a405 100644 --- a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py +++ b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py @@ -33,11 +33,12 @@ "primaryNetworkComponent": {"speed": 10, "maxSpeed": 100}, 'hourlyBillingFlag': False, 'createDate': '2013-08-01 15:23:45', - 'blockDevices': [{"device": 0, 'mountType': 'Disk', "uuid": 1}, - {"device": 1, 'mountType': 'Disk'}, - {"device": 2, 'mountType': 'CD'}, - {"device": 3, 'mountType': 'Disk', "uuid": 3}, - {"device": 4, 'mountType': 'Disk', "uuid": 4, + 'blockDevices': [{'device': 0, 'mountType': 'Disk', "uuid": 1}, + {'device': 1, 'mountType': 'Disk', + 'diskImage': {'type': {'keyName': 'SWAP'}}}, + {'device': 2, 'mountType': 'CD'}, + {'device': 3, 'mountType': 'Disk', 'uuid': 3}, + {'device': 4, 'mountType': 'Disk', 'uuid': 4, 'diskImage': {'metadataFlag': True}}], 'notes': 'notes', 'networkVlans': [{'networkSpace': 'PUBLIC', diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 54fabdc95..9d0741c05 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -727,7 +727,8 @@ def capture(self, instance_id, name, additional_disks=False, notes=None): 'getObject', id=instance_id, mask="""id, - blockDevices[id,device,mountType,diskImage[id,metadataFlag]]""") + blockDevices[id,device,mountType, + diskImage[id,metadataFlag,type[keyName]]]""") disks_to_capture = [] for block_device in vsi['blockDevices']: @@ -736,8 +737,12 @@ def capture(self, instance_id, name, additional_disks=False, notes=None): if utils.lookup(block_device, 'diskImage', 'metadataFlag'): continue - # We never want device 1 (swap) - if str(block_device['device']) == '1': + # We never want swap devices + type_name = utils.lookup(block_device, + 'diskImage', + 'type', + 'keyName') + if type_name == 'SWAP': continue # We never want CD images