From c859ba4e97b0edbf307cc9947fce2b5edcda1f12 Mon Sep 17 00:00:00 2001 From: Catalina Focsa Date: Wed, 22 Mar 2017 17:07:30 +0100 Subject: Check for kernel_url and ramdisk_url keys in dict Need to check if the above keys exist in image_metadata before checking for their assigned values in case they are not declared (e.g. obsolete when creating a one part image) Change-Id: I22fa259b320a425d6ad030eeb9bf68b4c06b667f Signed-off-by: Catalina Focsa --- snaps/openstack/tests/create_image_tests.py | 81 ++++++++++++++----------- snaps/openstack/tests/create_instance_tests.py | 77 ++++++++++++----------- snaps/provisioning/tests/ansible_utils_tests.py | 8 +-- 3 files changed, 90 insertions(+), 76 deletions(-) diff --git a/snaps/openstack/tests/create_image_tests.py b/snaps/openstack/tests/create_image_tests.py index c74846c..502b815 100644 --- a/snaps/openstack/tests/create_image_tests.py +++ b/snaps/openstack/tests/create_image_tests.py @@ -225,21 +225,21 @@ class CreateImageSuccessTests(OSIntegrationTestCase): # Set the default image settings, then set any custom parameters sent from the app os_image_settings = openstack_tests.cirros_url_image(name=self.image_name) if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -267,22 +267,22 @@ class CreateImageSuccessTests(OSIntegrationTestCase): os_image_settings.extra_properties = {'hw_video_model' : 'vga'} if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: os_image_settings.extra_properties = dict(os_image_settings.extra_properties.items() + self.image_metadata['extra_properties'].items()) # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -309,7 +309,7 @@ class CreateImageSuccessTests(OSIntegrationTestCase): # Set the default image settings, then set any custom parameters sent from the app url_image_settings = openstack_tests.cirros_url_image('foo') if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: url_image_settings.url = self.image_metadata['disk_url'] # Download the file of the image @@ -318,12 +318,12 @@ class CreateImageSuccessTests(OSIntegrationTestCase): # Set extra properties sent from the app (if any) if self.image_metadata: - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: file_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_file = file_utils.download(self.image_metadata['kernel_url'], self.tmp_dir) kernel_image_settings = openstack_tests.file_image_test_settings( name=self.image_name+'_kernel', file_path=kernel_image_file.name) @@ -331,7 +331,7 @@ class CreateImageSuccessTests(OSIntegrationTestCase): kernel_image = self.image_creators[-1].create() file_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_file = file_utils.download(self.image_metadata['ramdisk_url'], self.tmp_dir) ramdisk_image_settings = openstack_tests.file_image_test_settings( name=self.image_name+'_ramdisk', file_path=ramdisk_image_file.name) @@ -358,21 +358,21 @@ class CreateImageSuccessTests(OSIntegrationTestCase): # Set the default image settings, then set any custom parameters sent from the app os_image_settings = openstack_tests.cirros_url_image(name=self.image_name) if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -401,21 +401,21 @@ class CreateImageSuccessTests(OSIntegrationTestCase): # Set the default image settings, then set any custom parameters sent from the app os_image_settings = openstack_tests.cirros_url_image(name=self.image_name) if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -573,14 +573,17 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): """ # Set properties properties = {} - if self.image_metadata and self.image_metadata['extra_properties']: - properties = self.image_metadata['extra_properties'] + if self.image_metadata: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: + properties = self.image_metadata['extra_properties'] # Create the kernel image kernel_image_settings = openstack_tests.cirros_url_image(name=self.image_name+'_kernel', url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel') - if self.image_metadata and self.image_metadata['kernel_url']: - kernel_image_settings.url = self.image_metadata['kernel_url'] + + if self.image_metadata: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: + kernel_image_settings.url = self.image_metadata['kernel_url'] self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.assertIsNotNone(kernel_image) @@ -588,8 +591,9 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): # Create the ramdisk image ramdisk_image_settings = openstack_tests.cirros_url_image(name=self.image_name+'_ramdisk', url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs') - if self.image_metadata and self.image_metadata['ramdisk_url']: - ramdisk_image_settings.url = self.image_metadata['ramdisk_url'] + if self.image_metadata: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: + ramdisk_image_settings.url = self.image_metadata['ramdisk_url'] self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) ramdisk_image = self.image_creators[-1].create() self.assertIsNotNone(ramdisk_image) @@ -597,8 +601,9 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): # Create the main image os_image_settings = openstack_tests.cirros_url_image(name=self.image_name, url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img') - if self.image_metadata and self.image_metadata['disk_url']: - os_image_settings.url = self.image_metadata['disk_url'] + if self.image_metadata: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: + os_image_settings.url = self.image_metadata['disk_url'] properties['kernel_id'] = kernel_image.id properties['ramdisk_id'] = ramdisk_image.id @@ -622,12 +627,14 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): """ # Set properties properties = {} - if self.image_metadata and self.image_metadata['extra_properties']: - properties = self.image_metadata['extra_properties'] + if self.image_metadata: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: + properties = self.image_metadata['extra_properties'] # Create the kernel image kernel_url = 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel' - if self.image_metadata and self.image_metadata['kernel_url']: - kernel_url = self.image_metadata['kernel_url'] + if self.image_metadata: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: + kernel_url = self.image_metadata['kernel_url'] kernel_image_file = file_utils.download(kernel_url, self.tmp_dir) kernel_file_image_settings = openstack_tests.file_image_test_settings( name=self.image_name+'_kernel', file_path=kernel_image_file.name) @@ -637,8 +644,9 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): # Create the ramdisk image ramdisk_url = 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs' - if self.image_metadata and self.image_metadata['ramdisk_url']: - ramdisk_url = self.image_metadata['ramdisk_url'] + if self.image_metadata: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: + ramdisk_url = self.image_metadata['ramdisk_url'] ramdisk_image_file = file_utils.download(ramdisk_url, self.tmp_dir) ramdisk_file_image_settings = openstack_tests.file_image_test_settings( name=self.image_name+'_ramdisk', file_path=ramdisk_image_file.name) @@ -648,8 +656,9 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): # Create the main image image_url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img' - if self.image_metadata and self.image_metadata['disk_url']: - umage_url = self.image_metadata['disk_url'] + if self.image_metadata: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: + umage_url = self.image_metadata['disk_url'] image_file = file_utils.download(image_url, self.tmp_dir) file_image_settings = openstack_tests.file_image_test_settings(name=self.image_name, file_path=image_file.name) properties['kernel_id'] = kernel_image.id diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index 5e7fbf1..2cb1cdc 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -258,22 +258,22 @@ class SimpleHealthCheck(OSIntegrationTestCase): self.os_image_settings = openstack_tests.cirros_url_image(name=guid + '-image') if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] try: # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -403,21 +403,21 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -537,21 +537,21 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -830,21 +830,21 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -1098,21 +1098,21 @@ class CreateInstanceOnComputeHost(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -1236,21 +1236,21 @@ class CreateInstancePubPrivNetTests(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -1425,21 +1425,21 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): # Create Image # Set any custom parameters sent from the app if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: self.os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() self.os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) @@ -1715,16 +1715,18 @@ class CreateInstanceFromThreePartImage(OSIntegrationTestCase): # Create Images # Set properties properties = {} - if self.image_metadata and self.image_metadata['extra_properties']: - properties = self.image_metadata['extra_properties'] + if self.image_metadata: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: + properties = self.image_metadata['extra_properties'] # Create the kernel image kernel_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_kernel', url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel') - if self.image_metadata and self.image_metadata['kernel_url']: - kernel_image_settings.url = self.image_metadata['kernel_url'] + if self.image_metadata: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: + kernel_image_settings.url = self.image_metadata['kernel_url'] self.image_creators.append(OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() @@ -1733,8 +1735,10 @@ class CreateInstanceFromThreePartImage(OSIntegrationTestCase): ramdisk_image_settings = openstack_tests.cirros_url_image( name=self.image_name+'_ramdisk', url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs') - if self.image_metadata and self.image_metadata['ramdisk_url']: - ramdisk_image_settings.url = self.image_metadata['ramdisk_url'] + + if self.image_metadata: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: + ramdisk_image_settings.url = self.image_metadata['ramdisk_url'] self.image_creators.append(OpenStackImage(self.os_creds, ramdisk_image_settings)) ramdisk_image = self.image_creators[-1].create() @@ -1744,8 +1748,9 @@ class CreateInstanceFromThreePartImage(OSIntegrationTestCase): os_image_settings = openstack_tests.cirros_url_image( name=self.image_name, url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img') - if self.image_metadata and self.image_metadata['disk_url']: - os_image_settings.url = self.image_metadata['disk_url'] + if self.image_metadata: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: + os_image_settings.url = self.image_metadata['disk_url'] properties['kernel_id'] = kernel_image.id properties['ramdisk_id'] = ramdisk_image.id diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py index 92a56dc..a26c497 100644 --- a/snaps/provisioning/tests/ansible_utils_tests.py +++ b/snaps/provisioning/tests/ansible_utils_tests.py @@ -68,21 +68,21 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): # Create Image os_image_settings = openstack_tests.ubuntu_url_image(name=guid + '-' + '-image') if self.image_metadata: - if self.image_metadata['disk_url']: + if 'disk_url' in self.image_metadata and self.image_metadata['disk_url']: os_image_settings.url = self.image_metadata['disk_url'] - if self.image_metadata['extra_properties']: + if 'extra_properties' in self.image_metadata and self.image_metadata['extra_properties']: os_image_settings.extra_properties = self.image_metadata['extra_properties'] # If this is a 3-part image create the kernel and ramdisk images first if self.image_metadata: - if self.image_metadata['kernel_url']: + if 'kernel_url' in self.image_metadata and self.image_metadata['kernel_url']: kernel_image_settings = openstack_tests.cirros_url_image( name=os_image_settings.name+'_kernel', url=self.image_metadata['kernel_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, kernel_image_settings)) kernel_image = self.image_creators[-1].create() os_image_settings.extra_properties['kernel_id'] = kernel_image.id - if self.image_metadata['ramdisk_url']: + if 'ramdisk_url' in self.image_metadata and self.image_metadata['ramdisk_url']: ramdisk_image_settings = openstack_tests.cirros_url_image( name=os_image_settings.name+'_ramdisk', url=self.image_metadata['ramdisk_url']) self.image_creators.append(create_image.OpenStackImage(self.os_creds, ramdisk_image_settings)) -- cgit 1.2.3-korg