diff options
author | Cristina Pauna <cristina.pauna@enea.com> | 2017-03-02 14:53:17 +0000 |
---|---|---|
committer | Cristina Pauna <cristina.pauna@enea.com> | 2017-03-06 20:20:43 +0200 |
commit | ebf6b1653e731c757f56a26a67096fa8bed38557 (patch) | |
tree | c1b41b7a8e2dc714bb322f2742dd5339d140a659 | |
parent | 06e3b9ca9abd8bc3d96707bbb2de0c460a196f2f (diff) |
Adapt simple health check to use 3-part image
This fix adds the possibility to pass custom imformation about the
image via image_metadata variable. In SimpleHealthcheck it checks
for this info and creates a 3-part image if the kernel_url and
ramdisk_url are set. The fix also allows the default url to be
overriden as well as passing extra-properties. All the metadata info
comes from the app.
The part in functest where the custom config is set for creating
a 3-part image is https://gerrit.opnfv.org/gerrit/#/c/29851/
JIRA: ARMBAND-222
Change-Id: I11435d8bab4cf097b4079b6984741869f83aee2b
Signed-off-by: Cristina Pauna <cristina.pauna@enea.com>
-rw-r--r-- | snaps/openstack/tests/create_instance_tests.py | 44 | ||||
-rw-r--r-- | snaps/openstack/tests/os_source_file_test.py | 8 | ||||
-rw-r--r-- | snaps/test_suite_builder.py | 10 |
3 files changed, 43 insertions, 19 deletions
diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index 40fb779..9a02765 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -243,7 +243,7 @@ class SimpleHealthCheck(OSIntegrationTestCase): self.floating_ip_name = guid + 'fip1' # Initialize for tearDown() - self.image_creator = None + self.image_creators = list() self.network_creator = None self.flavor_creator = None self.inst_creator = None @@ -253,12 +253,34 @@ class SimpleHealthCheck(OSIntegrationTestCase): self.port_settings = PortSettings( name=self.port_1_name, network_name=self.priv_net_config.network_settings.name) + # set the default image settings, then set any custom parameters sent from the app self.os_image_settings = openstack_tests.cirros_url_image(name=guid + '-image') + if self.image_metadata: + if self.image_metadata['disk_url']: + self.os_image_settings.url = self.image_metadata['disk_url'] + if self.image_metadata['extra_properties']: + self.os_image_settings.extra_properties = self.image_metadata['extra_properties'] + try: - # Create Image - self.image_creator = OpenStackImage(self.os_creds, self.os_image_settings) - self.image_creator.create() + # Create Image; if this is a 3-part image create the kernel and ramdisk images first + if self.image_metadata: + if 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']: + 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)) + ramdisk_image = self.image_creators[-1].create() + self.os_image_settings.extra_properties['ramdisk_id'] = ramdisk_image.id + + self.image_creators.append(OpenStackImage(self.os_creds, self.os_image_settings)) + self.image_creators[-1].create() # Create Network self.network_creator = OpenStackNetwork(self.os_creds, self.priv_net_config.network_settings) @@ -293,17 +315,13 @@ class SimpleHealthCheck(OSIntegrationTestCase): try: self.flavor_creator.clean() except Exception as e: - logger.error('Unexpected exception cleaning flavor with message - ' + e.message) - - if self.network_creator: - try: - self.network_creator.clean() - except Exception as e: logger.error('Unexpected exception cleaning network with message - ' + e.message) - if self.image_creator: + if self.image_creators: try: - self.image_creator.clean() + while self.image_creators: + self.image_creators[-1].clean() + self.image_creators.pop() except Exception as e: logger.error('Unexpected exception cleaning image with message - ' + e.message) @@ -317,7 +335,7 @@ class SimpleHealthCheck(OSIntegrationTestCase): instance_settings = VmInstanceSettings( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) - self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings) + self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creators[-1].image_settings) vm = self.inst_creator.create() ip = self.inst_creator.get_port_ip(self.port_settings.name) diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index 20a8d80..bd37eef 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -69,17 +69,19 @@ class OSIntegrationTestCase(OSComponentTestCase): Super for test classes requiring a connection to OpenStack """ def __init__(self, method_name='runTest', os_env_file=None, ext_net_name=None, http_proxy_str=None, - ssh_proxy_cmd=None, use_keystone=False, flavor_metadata=None, log_level=logging.DEBUG): + ssh_proxy_cmd=None, use_keystone=False, flavor_metadata=None, image_metadata=None, + log_level=logging.DEBUG): super(OSIntegrationTestCase, self).__init__(method_name=method_name, os_env_file=os_env_file, ext_net_name=ext_net_name, http_proxy_str=http_proxy_str, ssh_proxy_cmd=ssh_proxy_cmd, log_level=log_level) self.use_keystone = use_keystone self.keystone = None self.flavor_metadata = flavor_metadata + self.image_metadata = image_metadata @staticmethod def parameterize(testcase_klass, os_env_file, ext_net_name, http_proxy_str=None, ssh_proxy_cmd=None, - use_keystone=False, flavor_metadata=None, log_level=logging.DEBUG): + use_keystone=False, flavor_metadata=None, image_metadata=None, log_level=logging.DEBUG): """ Create a suite containing all tests taken from the given subclass, passing them the parameter 'param'. """ @@ -88,7 +90,7 @@ class OSIntegrationTestCase(OSComponentTestCase): suite = unittest.TestSuite() for name in test_names: suite.addTest(testcase_klass(name, os_env_file, ext_net_name, http_proxy_str, ssh_proxy_cmd, use_keystone, - flavor_metadata, log_level)) + flavor_metadata, image_metadata, log_level)) return suite """ diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py index 1768921..2800d04 100644 --- a/snaps/test_suite_builder.py +++ b/snaps/test_suite_builder.py @@ -134,8 +134,8 @@ def add_openstack_api_tests(suite, source_filename, ext_net_name, http_proxy_str def add_openstack_integration_tests(suite, source_filename, ext_net_name, proxy_settings=None, ssh_proxy_cmd=None, - use_keystone=True, flavor_metadata=None, use_floating_ips=True, - log_level=logging.INFO): + use_keystone=True, flavor_metadata=None, image_metadata=None, + use_floating_ips=True, log_level=logging.INFO): """ Adds tests written to exercise all long-running OpenStack integration tests meaning they will be creating VM instances and potentially performing some SSH functions through floating IPs @@ -146,6 +146,9 @@ def add_openstack_integration_tests(suite, source_filename, ext_net_name, proxy_ :param ssh_proxy_cmd: the command your environment requires for creating ssh connections through a proxy :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on a host that has access to the cloud's private network + :param image_metadata: dict() object containing metadata for creating an image with custom config: + (i.e. {'hw_video_model' : 'vga'}). It can be used to override the default url and + create 3-part images by passing kerner_url and ramdisk_url info :param flavor_metadata: dict() object containing the metadata required by your flavor based on your configuration: (i.e. {'hw:mem_page_size': 'large'}) :param use_floating_ips: when true, all tests requiring Floating IPs will be added to the suite @@ -184,7 +187,8 @@ def add_openstack_integration_tests(suite, source_filename, ext_net_name, proxy_ # VM Instances suite.addTest(OSIntegrationTestCase.parameterize(SimpleHealthCheck, source_filename, ext_net_name, http_proxy_str=proxy_settings, use_keystone=use_keystone, - flavor_metadata=flavor_metadata, log_level=log_level)) + flavor_metadata=flavor_metadata, image_metadata=image_metadata, + log_level=log_level)) suite.addTest(OSIntegrationTestCase.parameterize(CreateInstanceSimpleTests, source_filename, ext_net_name, http_proxy_str=proxy_settings, use_keystone=use_keystone, flavor_metadata=flavor_metadata, log_level=log_level)) |