diff options
author | 2018-03-08 10:39:37 -0700 | |
---|---|---|
committer | 2018-03-13 08:02:02 -0600 | |
commit | 47d2625f5ae2ade601f0e4181ed94684a763cb0a (patch) | |
tree | e4b25353654d8802c5b040b15a3274a2d2e7ff1b | |
parent | 95e5df0e17e947901b6360323006636d17312aa8 (diff) |
Added test to ensure VM instances spawned by an admin user can
have an external network used on a port.
JIRA: SNAPS-282
Change-Id: I3ee2fef65d1751880e576dc8f6a797260d1028ee
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r-- | docs/how-to-use/IntegrationTests.rst | 10 | ||||
-rw-r--r-- | snaps/openstack/tests/create_instance_tests.py | 99 | ||||
-rw-r--r-- | snaps/test_suite_builder.py | 9 |
3 files changed, 116 insertions, 2 deletions
diff --git a/docs/how-to-use/IntegrationTests.rst b/docs/how-to-use/IntegrationTests.rst index 23b3e5c..853d2db 100644 --- a/docs/how-to-use/IntegrationTests.rst +++ b/docs/how-to-use/IntegrationTests.rst @@ -622,6 +622,16 @@ create_instance_tests.py - CreateInstanceSimpleTests | | Neutron 2 | and compute_host return a value | +---------------------------------------+---------------+-----------------------------------------------------------+ +create_instance_tests.py - CreateInstanceExternalNetTests +--------------------------------------------------------- + ++---------------------------------------+---------------+-----------------------------------------------------------+ +| Test Name | API Versions | Description | ++=======================================+===============+===========================================================+ +| test_create_instance_public_net | Nova 2 | Ensures that an OpenStackVmInstance initialized as a user | +| | Neutron 2 | of type 'admin' can create a VM against an external net | ++---------------------------------------+---------------+-----------------------------------------------------------+ + create_instance_tests.py - SimpleHealthCheck -------------------------------------------- diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index 6005f98..8ff98fc 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -580,6 +580,105 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase): self.assertIsNotNone(self.inst_creator.get_vm_inst().compute_host) +class CreateInstanceExternalNetTests(OSIntegrationTestCase): + """ + Simple instance creation tests where the network is external + """ + + def setUp(self): + """ + Instantiates the CreateImage object that is responsible for downloading + and creating an OS image file + within OpenStack + """ + super(self.__class__, self).__start__() + + guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) + self.vm_inst_name = guid + '-inst' + self.nova = nova_utils.nova_client(self.admin_os_creds) + self.neutron = neutron_utils.neutron_client(self.admin_os_creds) + os_image_settings = openstack_tests.cirros_image_settings( + name=guid + '-image', image_metadata=self.image_metadata) + + # Initialize for tearDown() + self.image_creator = None + self.flavor_creator = None + self.inst_creator = None + + try: + # Create Image + self.image_creator = OpenStackImage(self.os_creds, + os_image_settings) + self.image_creator.create() + + # Create Flavor + self.flavor_creator = OpenStackFlavor( + self.admin_os_creds, + FlavorConfig(name=guid + '-flavor-name', ram=256, disk=10, + vcpus=2, metadata=self.flavor_metadata)) + self.flavor_creator.create() + + self.port_settings = PortConfig( + name=guid + '-port', + network_name=self.ext_net_name) + + except Exception as e: + self.tearDown() + raise e + + def tearDown(self): + """ + Cleans the created object + """ + if self.inst_creator: + try: + self.inst_creator.clean() + except Exception as e: + logger.error( + 'Unexpected exception cleaning VM instance with message ' + '- %s', e) + + if self.flavor_creator: + try: + self.flavor_creator.clean() + except Exception as e: + logger.error( + 'Unexpected exception cleaning flavor with message - %s', + e) + + if self.image_creator and not self.image_creator.image_settings.exists: + try: + self.image_creator.clean() + except Exception as e: + logger.error( + 'Unexpected exception cleaning image with message - %s', e) + + super(self.__class__, self).__clean__() + + def test_create_instance_public_net(self): + """ + Tests the creation of an OpenStack instance with a single port to + the external network. + """ + instance_settings = VmInstanceConfig( + name=self.vm_inst_name, + flavor=self.flavor_creator.flavor_settings.name, + port_settings=[self.port_settings]) + + self.inst_creator = OpenStackVmInstance( + self.admin_os_creds, instance_settings, + self.image_creator.image_settings) + + vm_inst = self.inst_creator.create(block=True) + vm_inst_get = nova_utils.get_server( + self.nova, self.neutron, self.keystone, + vm_inst_settings=instance_settings) + self.assertEqual(vm_inst, vm_inst_get) + ip = self.inst_creator.get_port_ip(self.port_settings.name) + + check_dhcp_lease(self.inst_creator, ip) + + class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): """ Test for the CreateInstance class with a single NIC/Port with Floating IPs diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py index 7933277..e47becd 100644 --- a/snaps/test_suite_builder.py +++ b/snaps/test_suite_builder.py @@ -65,13 +65,13 @@ from snaps.openstack.tests.create_image_tests import ( CreateImageSuccessTests, CreateImageNegativeTests, CreateMultiPartImageTests) from snaps.openstack.tests.create_instance_tests import ( - CreateInstanceSingleNetworkTests, CreateInstanceOnComputeHost, + CreateInstanceSingleNetworkTests, CreateInstanceOnComputeHost, CreateInstanceSimpleTests, FloatingIpSettingsUnitTests, InstanceSecurityGroupTests, VmInstanceSettingsUnitTests, CreateInstancePortManipulationTests, SimpleHealthCheck, CreateInstanceFromThreePartImage, CreateInstanceMockOfflineTests, CreateInstanceTwoNetTests, CreateInstanceVolumeTests, - CreateInstanceIPv6NetworkTests) + CreateInstanceIPv6NetworkTests, CreateInstanceExternalNetTests) from snaps.openstack.tests.create_keypairs_tests import ( CreateKeypairsTests, KeypairSettingsUnitTests, CreateKeypairsCleanupTests) from snaps.openstack.tests.create_network_tests import ( @@ -598,6 +598,11 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name, flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level)) suite.addTest(OSIntegrationTestCase.parameterize( + CreateInstanceExternalNetTests, os_creds=os_creds, + ext_net_name=ext_net_name, use_keystone=use_keystone, + flavor_metadata=flavor_metadata, image_metadata=image_metadata, + log_level=log_level)) + suite.addTest(OSIntegrationTestCase.parameterize( CreateInstancePortManipulationTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone, flavor_metadata=flavor_metadata, image_metadata=image_metadata, |