diff options
author | 2018-03-07 16:58:42 -0700 | |
---|---|---|
committer | 2018-03-13 07:45:22 -0600 | |
commit | 95e5df0e17e947901b6360323006636d17312aa8 (patch) | |
tree | 84394641b3b840cc3ef490eeee8c862496d86ff4 | |
parent | 6c60d13052ca1196333782edd4bf118ba25e0bda (diff) |
Reverse engineer OpenStackHeatStack
Added support for obtaining an initialized
OpenStackHeatStack object from an existing Stack object
JIRA: SNAPS-278
Change-Id: I68cb0c85179868e4e3899b5516316dda3321e9f6
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r-- | docs/how-to-use/IntegrationTests.rst | 6 | ||||
-rw-r--r-- | snaps/openstack/create_stack.py | 16 | ||||
-rw-r--r-- | snaps/openstack/tests/create_stack_tests.py | 40 | ||||
-rw-r--r-- | snaps/openstack/utils/heat_utils.py | 4 |
4 files changed, 64 insertions, 2 deletions
diff --git a/docs/how-to-use/IntegrationTests.rst b/docs/how-to-use/IntegrationTests.rst index deee6c7..23b3e5c 100644 --- a/docs/how-to-use/IntegrationTests.rst +++ b/docs/how-to-use/IntegrationTests.rst @@ -511,6 +511,12 @@ create_stack_tests.py - CreateStackFloatingIpTests | | | VM with a floating IP that can be accessed via | | | | OpenStackVmInstance | +---------------------------------------+---------------+-----------------------------------------------------------+ +| test_connect_via_ssh_heat_vm_derived | 1 | Ensures that an OpenStackHeatStack instance can create a | +| | | VM with a floating IP where a generated initialized | +| | | OpenStackHeatStack can return an initialized | +| | | OpenStackVmInstance object that will be used to access the| +| | | VM via SSH | ++---------------------------------------+---------------+-----------------------------------------------------------+ create_stack_tests.py - CreateStackNestedResourceTests ------------------------------------------------------ diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py index 12ce602..43ac307 100644 --- a/snaps/openstack/create_stack.py +++ b/snaps/openstack/create_stack.py @@ -498,6 +498,22 @@ class OpenStackHeatStack(OpenStackCloudObject, object): return status == expected_status_code +def generate_creator(os_creds, stack_inst, image_settings): + """ + Initializes an OpenStackHeatStack object + :param os_creds: the OpenStack credentials + :param stack_inst: the SNAPS-OO VmInst domain object + :param image_settings: list of SNAPS-OO ImageConfig objects + :return: an initialized OpenStackHeatStack object + """ + + heat_config = StackConfig( + name=stack_inst.name, template={'place': 'holder'}) + heat_creator = OpenStackHeatStack(os_creds, heat_config, image_settings) + heat_creator.initialize() + return heat_creator + + class StackSettings(StackConfig): """ Class to hold the configuration settings required for creating OpenStack diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index f728211..6325b7a 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -35,6 +35,7 @@ import logging import unittest import uuid +from snaps.openstack import create_stack from snaps.openstack.create_stack import ( StackSettings, StackCreationError, StackError, OpenStackHeatStack) from snaps.openstack.tests import openstack_tests, create_instance_tests @@ -216,6 +217,12 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.assertEqual(created_stack.id, retrieved_stack.id) self.assertEqual(0, len(self.stack_creator.get_outputs())) + derived_creator = create_stack.generate_creator( + self.os_creds, retrieved_stack, + [self.image_creator.image_settings]) + derived_stack = derived_creator.get_stack() + self.assertEqual(retrieved_stack, derived_stack) + def test_create_stack_short_timeout(self): """ Tests the creation of an OpenStack stack from Heat template file. @@ -510,6 +517,39 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): vm_settings = vm_inst_creator.instance_settings self.assertEqual(0, len(vm_settings.floating_ip_settings)) + def test_connect_via_ssh_heat_vm_derived(self): + """ + Tests the the retrieval of two VM instance creators from a derived + OpenStackHeatStack object and attempt to connect via + SSH to the first one with a floating IP. + """ + stack_settings = StackConfig( + name=self.__class__.__name__ + '-' + str(self.guid) + '-stack', + template_path=self.heat_tmplt_path, + env_values=self.env_values) + self.stack_creator = OpenStackHeatStack( + self.os_creds, stack_settings, + [self.image_creator.image_settings]) + created_stack = self.stack_creator.create() + self.assertIsNotNone(created_stack) + + derived_stack = create_stack.generate_creator( + self.os_creds, created_stack, + [self.image_creator.image_settings]) + + self.vm_inst_creators = derived_stack.get_vm_inst_creators( + heat_keypair_option='private_key') + self.assertIsNotNone(self.vm_inst_creators) + self.assertEqual(2, len(self.vm_inst_creators)) + + for vm_inst_creator in self.vm_inst_creators: + if vm_inst_creator.get_vm_inst().name == self.vm_inst1_name: + self.assertTrue( + create_instance_tests.validate_ssh_client(vm_inst_creator)) + else: + vm_settings = vm_inst_creator.instance_settings + self.assertEqual(0, len(vm_settings.floating_ip_settings)) + class CreateStackNestedResourceTests(OSIntegrationTestCase): """ diff --git a/snaps/openstack/utils/heat_utils.py b/snaps/openstack/utils/heat_utils.py index 3d62fdf..b38a7b9 100644 --- a/snaps/openstack/utils/heat_utils.py +++ b/snaps/openstack/utils/heat_utils.py @@ -68,7 +68,7 @@ def get_stack(heat_cli, stack_settings=None, stack_name=None): stacks = heat_cli.stacks.list(**stack_filter) for stack in stacks: return Stack( - name=stack.identifier, stack_id=stack.id, + name=stack.stack_name, stack_id=stack.id, stack_project_id=stack.stack_user_project_id, status=stack.stack_status, status_reason=stack.stack_status_reason) @@ -83,7 +83,7 @@ def get_stack_by_id(heat_cli, stack_id): """ stack = heat_cli.stacks.get(stack_id) return Stack( - name=stack.identifier, stack_id=stack.id, + name=stack.stack_name, stack_id=stack.id, stack_project_id=stack.stack_user_project_id, status=stack.stack_status, status_reason=stack.stack_status_reason) |