From 34623d35ba81b5d8290b87e469af784be746f78f Mon Sep 17 00:00:00 2001 From: spisarski Date: Mon, 17 Jul 2017 10:14:23 -0600 Subject: Added proper assertion config NIC test. The test that exercises the OpenStackVmInstance class config_nic() now checks the Ansible return code. JIRA: SNAPS-124 Change-Id: I7840cd53eea2eacf7952d14be30870c8fa3aeab8 Signed-off-by: spisarski --- snaps/openstack/create_instance.py | 5 ++- snaps/openstack/tests/create_instance_tests.py | 56 +++++++++++--------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py index 9aaf127..b034c5f 100644 --- a/snaps/openstack/create_instance.py +++ b/snaps/openstack/create_instance.py @@ -398,7 +398,7 @@ class OpenStackVmInstance: """ Responsible for configuring NICs on RPM systems where the instance has more than one configured port - :return: None + :return: the value returned by ansible_utils.apply_ansible_playbook() """ if len(self.__ports) > 1 and len(self.__floating_ips) > 0: if self.vm_active(block=True) and self.vm_ssh_active(block=True): @@ -406,11 +406,12 @@ class OpenStackVmInstance: port_index = self.__ports.index((key, port)) if port_index > 0: nic_name = 'eth' + repr(port_index) - self.__config_nic( + retval = self.__config_nic( nic_name, port, self.__get_first_provisioning_floating_ip().ip) logger.info('Configured NIC - %s on VM - %s', nic_name, self.instance_settings.name) + return retval def __get_first_provisioning_floating_ip(self): """ diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index a13a38c..6b2307e 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -1276,9 +1276,9 @@ class CreateInstancePubPrivNetTests(OSIntegrationTestCase): SecurityGroupSettings(name=sec_grp_name, rule_settings=[rule1, rule2])) self.sec_grp_creator.create() - except Exception as e: + except: self.tearDown() - raise Exception(str(e)) + raise def tearDown(self): """ @@ -1400,15 +1400,7 @@ class CreateInstancePubPrivNetTests(OSIntegrationTestCase): # Effectively blocks until VM's ssh port has been opened self.assertTrue(self.inst_creator.vm_ssh_active(block=True)) - # TODO - Refactor config_nics() to return a status that can be - # validated here. - self.inst_creator.config_nics() - - # TODO - *** ADD VALIDATION HERE *** - # TODO - Add validation that both floating IPs work - # TODO - Add tests where only one NIC has a floating IP - # TODO - Add tests where one attempts to place a floating IP on a - # network/router without an external gateway + self.assertEqual(0, self.inst_creator.config_nics()) class InstanceSecurityGroupTests(OSIntegrationTestCase): @@ -2084,11 +2076,11 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.image_creator.create() metadata = { - 'cirros': - {'config': - {'name': os_image_settings.name, - 'image_user': os_image_settings.image_user, - 'exists': True}}} + 'cirros': { + 'config': { + 'name': os_image_settings.name, + 'image_user': os_image_settings.image_user, + 'exists': True}}} test_image_settings = openstack_tests.cirros_image_settings( image_metadata=metadata) test_image = OpenStackImage(self.os_creds, test_image_settings) @@ -2119,22 +2111,22 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): openstack_tests.CIRROS_DEFAULT_RAMDISK_IMAGE_URL, self.tmpDir) metadata = { - 'cirros': - {'config': - {'name': self.image_name, - 'image_user': openstack_tests.CIRROS_USER, - 'image_file': self.image_file.name, - 'format': openstack_tests.DEFAULT_IMAGE_FORMAT, - 'kernel_image_settings': - {'name': self.image_name + '-kernel', - 'image_user': openstack_tests.CIRROS_USER, - 'image_file': kernel_file.name, - 'format': openstack_tests.DEFAULT_IMAGE_FORMAT}, - 'ramdisk_image_settings': - {'name': self.image_name + '-ramdisk', - 'image_user': openstack_tests.CIRROS_USER, - 'image_file': ramdisk_file.name, - 'format': openstack_tests.DEFAULT_IMAGE_FORMAT}}}} + 'cirros': { + 'config': { + 'name': self.image_name, + 'image_user': openstack_tests.CIRROS_USER, + 'image_file': self.image_file.name, + 'format': openstack_tests.DEFAULT_IMAGE_FORMAT, + 'kernel_image_settings': { + 'name': self.image_name + '-kernel', + 'image_user': openstack_tests.CIRROS_USER, + 'image_file': kernel_file.name, + 'format': openstack_tests.DEFAULT_IMAGE_FORMAT}, + 'ramdisk_image_settings': { + 'name': self.image_name + '-ramdisk', + 'image_user': openstack_tests.CIRROS_USER, + 'image_file': ramdisk_file.name, + 'format': openstack_tests.DEFAULT_IMAGE_FORMAT}}}} os_image_settings = openstack_tests.cirros_image_settings( name=self.image_name, image_metadata=metadata) -- cgit 1.2.3-korg