Merge "Fix role processing in Patrole"
[functest.git] / functest / opnfv_tests / vnf / router / cloudify_vrouter.py
index ad8f761..9f6327b 100644 (file)
@@ -23,7 +23,8 @@ from scp import SCPClient
 from functest.opnfv_tests.openstack.snaps import snaps_utils
 import functest.opnfv_tests.vnf.router.vrouter_base as vrouter_base
 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
-from functest.utils.constants import CONST
+from functest.utils import config
+from functest.utils import env
 from functest.utils import functest_utils
 
 from git import Repo
@@ -69,12 +70,11 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
         # Retrieve the configuration
         try:
             self.config = getattr(
-                CONST, 'vnf_{}_config'.format(self.case_name))
+                config.CONF, 'vnf_{}_config'.format(self.case_name))
         except Exception:
             raise Exception("VNF config file not found")
 
         self.cfy_manager_ip = ''
-        self.util_info = {}
         self.deployment_name = ''
 
         config_file = os.path.join(self.case_dir, self.config)
@@ -121,6 +121,17 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
             "tenant_images", config_file)
         self.__logger.info("Images needed for vrouter: %s", self.images)
 
+    @staticmethod
+    def run_blocking_ssh_command(ssh, cmd,
+                                 error_msg="Unable to run this command"):
+        """Command to run ssh command with the exit status."""
+        (_, stdout, stderr) = ssh.exec_command(cmd)
+        CloudifyVrouter.__logger.debug("SSH %s stdout: %s", cmd, stdout.read())
+        if stdout.channel.recv_exit_status() != 0:
+            CloudifyVrouter.__logger.error(
+                "SSH %s stderr: %s", cmd, stderr.read())
+            raise Exception(error_msg)
+
     def prepare(self):
         super(CloudifyVrouter, self).prepare()
         self.__logger.info("Additional pre-configuration steps")
@@ -157,7 +168,8 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
         self.__logger.info("Creating full network ...")
         subnet_settings = SubnetConfig(
             name='cloudify_vrouter_subnet-{}'.format(self.uuid),
-            cidr='10.67.79.0/24')
+            cidr='10.67.79.0/24',
+            dns_nameservers=[env.get('NAMESERVER')])
         network_settings = NetworkConfig(
             name='cloudify_vrouter_network-{}'.format(self.uuid),
             subnet_settings=[subnet_settings])
@@ -250,10 +262,10 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
         while str(cfy_status) != 'running' and retry:
             try:
                 cfy_status = cfy_client.manager.get_status()['status']
-                self.__logger.debug("The current manager status is %s",
-                                    cfy_status)
+                self.__logger.info(
+                    "The current manager status is %s", cfy_status)
             except Exception:  # pylint: disable=broad-except
-                self.__logger.exception(
+                self.__logger.info(
                     "Cloudify Manager isn't up and running. Retrying ...")
             retry = retry - 1
             time.sleep(30)
@@ -271,11 +283,11 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
             scp = SCPClient(ssh.get_transport(), socket_timeout=15.0)
             scp.put(kp_file, '~/')
             cmd = "sudo cp ~/cloudify_vrouter.pem /etc/cloudify/"
-            run_blocking_ssh_command(ssh, cmd)
+            self.run_blocking_ssh_command(ssh, cmd)
             cmd = "sudo chmod 444 /etc/cloudify/cloudify_vrouter.pem"
-            run_blocking_ssh_command(ssh, cmd)
+            self.run_blocking_ssh_command(ssh, cmd)
             cmd = "sudo yum install -y gcc python-devel"
-            run_blocking_ssh_command(
+            self.run_blocking_ssh_command(
                 ssh, cmd, "Unable to install packages on manager")
 
         self.details['orchestrator'].update(status='PASS', duration=duration)
@@ -321,10 +333,13 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
             UserConfig(
                 name='cloudify_network_bug-{}'.format(self.uuid),
                 password=str(uuid.uuid4()),
+                project_name=self.tenant_name,
+                domain=self.snaps_creds.user_domain_name,
                 roles={'_member_': self.tenant_name}))
         user_creator.create()
         self.created_object.append(user_creator)
         snaps_creds = user_creator.get_os_creds(self.snaps_creds.project_name)
+        self.__logger.debug("snaps creds: %s", snaps_creds)
 
         self.vnf['inputs'].update(dict(target_vnf_image_id=image.id))
         self.vnf['inputs'].update(dict(reference_vnf_image_id=image.id))
@@ -336,6 +351,10 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
             keystone_password=snaps_creds.password))
         self.vnf['inputs'].update(dict(
             keystone_tenant_name=snaps_creds.project_name))
+        self.vnf['inputs'].update(dict(
+            keystone_user_domain_name=snaps_creds.user_domain_name))
+        self.vnf['inputs'].update(dict(
+            keystone_project_domain_name=snaps_creds.project_domain_name))
         self.vnf['inputs'].update(dict(
             region=snaps_creds.region_name))
         self.vnf['inputs'].update(dict(
@@ -370,11 +389,7 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
 
     def test_vnf(self):
         cfy_client = self.orchestrator['object']
-        credentials = {"snaps_creds": self.snaps_creds,
-                       "username": self.snaps_creds.username,
-                       "password": self.snaps_creds.password,
-                       "auth_url": self.snaps_creds.auth_url,
-                       "tenant_name": self.snaps_creds.project_name}
+        credentials = {"snaps_creds": self.snaps_creds}
 
         self.util_info = {"credentials": credentials,
                           "cfy": cfy_client,
@@ -419,8 +434,8 @@ class CloudifyVrouter(vrouter_base.VrouterOnBoardingBase):
             cfy_client.deployments.delete(self.vnf['descriptor'].get('name'))
             cfy_client.blueprints.delete(self.vnf['descriptor'].get('name'))
         except Exception:  # pylint: disable=broad-except
-            self.__logger.warn("Some issue during the undeployment ..")
-            self.__logger.warn("Tenant clean continue ..")
+            self.__logger.exception("Some issue during the undeployment ..")
+
         super(CloudifyVrouter, self).clean()
 
     def get_vnf_info_list(self, target_vnf_name):
@@ -486,10 +501,3 @@ def get_execution_id(client, deployment_id):
     raise RuntimeError('Failed to get create_deployment_environment '
                        'workflow execution.'
                        'Available executions: {0}'.format(executions))
-
-
-def run_blocking_ssh_command(ssh, cmd, error_msg="Unable to run this command"):
-    """Command to run ssh command with the exit status."""
-    (_, stdout, _) = ssh.exec_command(cmd)
-    if stdout.channel.recv_exit_status() != 0:
-        raise Exception(error_msg)