From c997fcd6a2b7202987e9677988b681cbd12ad421 Mon Sep 17 00:00:00 2001 From: Victor Ryzhenkin Date: Sun, 27 Sep 2015 22:16:53 +0300 Subject: [PATCH] Add test for resources deallocation - Add test for resources deallocation after application removed from instance Change-Id: I2ea25b4fd8fb180624259fe4078ac5ddaa4c9bf3 Related-Bug: #1499563 --- murano/tests/functional/common/utils.py | 55 +++++++++++++++++-- murano/tests/functional/engine/manager.py | 19 +++++++ .../functional/engine/test_deployment.py | 50 ++++++++++------- 3 files changed, 97 insertions(+), 27 deletions(-) diff --git a/murano/tests/functional/common/utils.py b/murano/tests/functional/common/utils.py index 3d979544..e85b24eb 100644 --- a/murano/tests/functional/common/utils.py +++ b/murano/tests/functional/common/utils.py @@ -209,16 +209,26 @@ class DeployTestMixin(zip_utils.ZipUtilsMixin): return service @classmethod - def get_service_as_json(cls, environment, service_name): - """Get a service with specific name from environment in JSON format. + def services_list(cls, environment): + """Get a list of environment services. :param environment: Murano environment - :param service_name: Service name - :return: + :return: List of objects """ - for service in cls.murano_client().services.list(environment.id): + return cls.murano_client().services.list(environment.id) + + @classmethod + def get_service(cls, environment, service_name, to_dict=True): + """Get a service with specific name from environment. + + :param to_dict: Convert service to JSON or not to convert + :param environment: Murano environment + :param service_name: Service name + :return: JSON or object + """ + for service in cls.services_list(environment): if service.name == service_name: - return cls._convert_service(service) + return cls._convert_service(service) if to_dict else service @classmethod def _convert_service(cls, service): @@ -231,6 +241,35 @@ class DeployTestMixin(zip_utils.ZipUtilsMixin): component = json.dumps(component) return yaml.load(component) + @classmethod + def get_service_id(cls, service): + """Gets id on object. + + :param service: object + :return: ID of the Service + """ + serv = cls._convert_service(service) + serv_id = serv['?']['id'] + return serv_id + + @classmethod + def delete_service(cls, environment, session, service): + """This function removes a specific service from environment. + + :param environment: Murano environment + :param session: Session fir urano environment + :param service: object + :return: Updated murano environment + """ + cls.murano_client().services.delete( + environment.id, path='/{0}'.format(cls.get_service_id(service)), + session_id=session.id) + LOG.debug('Service with name {0} from environment {1} successfully ' + 'removed'.format(environment.name, service.name)) + updated_env = cls.get_environment(environment) + return updated_env + + # -----------------------------Packages methods-------------------------------- @classmethod @@ -472,3 +511,7 @@ class DeployTestMixin(zip_utils.ZipUtilsMixin): for stack in cls.heat_client().stacks.list(): if environment_id in stack.description: return stack + + @classmethod + def get_stack_template(cls, stack): + return cls.heat_client().stacks.template(stack.stack_name) diff --git a/murano/tests/functional/engine/manager.py b/murano/tests/functional/engine/manager.py index 87e3b1dc..d9fc16cc 100644 --- a/murano/tests/functional/engine/manager.py +++ b/murano/tests/functional/engine/manager.py @@ -206,6 +206,25 @@ class MuranoTestsCore(testtools.TestCase, testtools.testcase.WithAttributes, } } + def get_test_app(self): + return { + "instance": { + "flavor": self.flavor, + "image": self.linux, + "assignFloatingIp": True, + "?": { + "type": "io.murano.resources.LinuxMuranoInstance", + "id": str(uuid.uuid4()) + }, + "name": self.rand_name('mrntest') + }, + "name": self.rand_name('dummy'), + "?": { + "type": "io.murano.apps.test.UpdateExecutor", + "id": str(uuid.uuid4()) + } + } + @classmethod def upload_app(cls, app_dir, name, tags): """Zip and upload application to Murano diff --git a/murano/tests/functional/engine/test_deployment.py b/murano/tests/functional/engine/test_deployment.py index 185254a0..7c7e88e5 100644 --- a/murano/tests/functional/engine/test_deployment.py +++ b/murano/tests/functional/engine/test_deployment.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from nose.plugins.attrib import attr as tag import murano.tests.functional.engine.manager as core @@ -41,27 +39,37 @@ class MuranoDeploymentTest(core.MuranoTestsCore): @tag('gate', 'all', 'coverage') def test_app_deployment(self): - post_body = { - "instance": { - "flavor": self.flavor, - "image": self.linux, - "assignFloatingIp": True, - "?": { - "type": "io.murano.resources.LinuxMuranoInstance", - "id": str(uuid.uuid4()) - }, - "name": "testMurano" - }, - "name": "teMurano", - "?": { - "type": "io.murano.apps.test.UpdateExecutor", - "id": str(uuid.uuid4()) - } - } - + post_body = self.get_test_app() environment_name = self.rand_name('dummyMurano') environment = self.create_environment(name=environment_name) session = self.create_session(environment) self.add_service(environment, post_body, session) self.deploy_environment(environment, session) - self.wait_for_environment_deploy(environment) + + @tag('gate', 'all', 'coverage') + def test_resources_deallocation(self): + app_1 = self.get_test_app() + app_2 = self.get_test_app() + environment_name = self.rand_name('dummyMurano') + environment = self.create_environment(name=environment_name) + session = self.create_session(environment) + self.add_service(environment, app_1, session) + self.add_service(environment, app_2, session) + self.deploy_environment(environment, session) + + environment = self.get_environment(environment) + app_for_remove = self.get_service(environment, app_1['name'], + to_dict=False) + session = self.create_session(environment) + environment = self.delete_service(environment, session, app_for_remove) + self.deploy_environment(environment, session) + + instance_name = app_1['instance']['name'] + stack = self._get_stack(environment.id) + template = self.get_stack_template(stack) + ip_addresses = '{0}-assigned-ip'.format(instance_name) + floating_ip = '{0}-FloatingIPaddress'.format(instance_name) + + self.assertNotIn(ip_addresses, template['outputs']) + self.assertNotIn(floating_ip, template['outputs']) + self.assertNotIn(instance_name, template['resources'])