From 9dcc30874194382a25c66baf359b863c6e013caf Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Tue, 23 Apr 2019 16:49:55 +0200 Subject: Refactor modules to avoid duplicated code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It also increases number of lines to warm about duplicated codes. Change-Id: I3914da8a90cbfe8fd024e9944c3adc8a617330d3 Signed-off-by: Cédric Ollivier --- functest/core/cloudify.py | 43 ++++++++++++++++++++++++++++++++++++++++++ functest/core/tenantnetwork.py | 15 +++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'functest/core') diff --git a/functest/core/cloudify.py b/functest/core/cloudify.py index c5613cab5..21bfc937e 100644 --- a/functest/core/cloudify.py +++ b/functest/core/cloudify.py @@ -114,6 +114,49 @@ class Cloudify(singlevm.SingleVm2): self.__logger.info("Cloudify Manager is up and running") return 0 + def put_private_key(self): + """Put private keypair in manager""" + self.__logger.info("Put private keypair in manager") + scpc = scp.SCPClient(self.ssh.get_transport()) + scpc.put(self.key_filename, remote_path='~/cloudify_ims.pem') + (_, stdout, stderr) = self.ssh.exec_command( + "sudo docker cp ~/cloudify_ims.pem " + "cfy_manager_local:/etc/cloudify/ && " + "sudo docker exec cfy_manager_local " + "chmod 444 /etc/cloudify/cloudify_ims.pem") + self.__logger.debug("output:\n%s", stdout.read()) + self.__logger.debug("error:\n%s", stderr.read()) + + def upload_cfy_plugins(self, yaml, wgn): + """Upload Cloudify plugins""" + (_, stdout, stderr) = self.ssh.exec_command( + "sudo docker exec cfy_manager_local " + "cfy plugins upload -y {} {} && " + "sudo docker exec cfy_manager_local cfy status".format(yaml, wgn)) + self.__logger.debug("output:\n%s", stdout.read()) + self.__logger.debug("error:\n%s", stderr.read()) + + def kill_existing_execution(self, dep_name): + """kill existing execution""" + try: + self.__logger.info('Deleting the current deployment') + exec_list = self.cfy_client.executions.list() + for execution in exec_list: + if execution['status'] == "started": + try: + self.cfy_client.executions.cancel( + execution['id'], force=True) + except Exception: # pylint: disable=broad-except + self.__logger.warn("Can't cancel the current exec") + execution = self.cfy_client.executions.start( + dep_name, 'uninstall', parameters=dict(ignore_failure=True)) + wait_for_execution(self.cfy_client, execution, self.__logger) + self.cfy_client.deployments.delete(dep_name) + time.sleep(10) + self.cfy_client.blueprints.delete(dep_name) + except Exception: # pylint: disable=broad-except + self.__logger.exception("Some issue during the undeployment ..") + def wait_for_execution(client, execution, logger, timeout=3600, ): """Wait for a workflow execution on Cloudify Manager.""" diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py index 1b2eb9414..7b2bf8799 100644 --- a/functest/core/tenantnetwork.py +++ b/functest/core/tenantnetwork.py @@ -98,6 +98,21 @@ class NewProject(object): cloud_config=osconfig.get_one_cloud()) self.__logger.debug("new cloud %s", self.cloud.auth) + def get_environ(self): + "Get new environ" + environ = dict( + os.environ, + OS_USERNAME=self.user.name, + OS_PROJECT_NAME=self.project.name, + OS_PROJECT_ID=self.project.id, + OS_PASSWORD=self.password) + try: + del environ['OS_TENANT_NAME'] + del environ['OS_TENANT_ID'] + except Exception: # pylint: disable=broad-except + pass + return environ + def clean(self): """Remove projects/users""" try: -- cgit 1.2.3-korg