diff options
-rw-r--r-- | docker/smoke/Dockerfile | 2 | ||||
-rw-r--r-- | functest/core/tenantnetwork.py | 11 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/vmtp/vmtp.py | 49 | ||||
-rw-r--r-- | functest/tests/unit/openstack/vmtp/test_vmtp.py | 1 |
4 files changed, 53 insertions, 10 deletions
diff --git a/docker/smoke/Dockerfile b/docker/smoke/Dockerfile index 695bee5f4..ff905e31b 100644 --- a/docker/smoke/Dockerfile +++ b/docker/smoke/Dockerfile @@ -4,7 +4,7 @@ ARG BRANCH=master ARG OPENSTACK_TAG=stable/queens ARG REFSTACK_TARGET=2017.09 ARG PATROLE_TAG=0.3.0 -ARG VMTP_TAG=9c016e3f9683ae557e8271ef358d9c1b59126cdf +ARG VMTP_TAG=refs/changes/59/588459/1 RUN apk --no-cache add --update libxml2 libxslt && \ apk --no-cache add --virtual .build-deps --update \ diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py index b118893de..760dc30e9 100644 --- a/functest/core/tenantnetwork.py +++ b/functest/core/tenantnetwork.py @@ -184,7 +184,14 @@ class TenantNetwork1(testcase.TestCase): 'service_id': keystone_id})[0].url return endpoint - def _create_network_ressources(self): + def create_network_resources(self): + """Create all tenant network resources + + It creates a router which gateway is the external network detected. + The new subnet is attached to that router. + + Raises: expection on error + """ assert self.cloud assert self.ext_net provider = {} @@ -224,7 +231,7 @@ class TenantNetwork1(testcase.TestCase): try: assert self.cloud self.start_time = time.time() - self._create_network_ressources() + self.create_network_resources() self.result = 100 status = testcase.TestCase.EX_OK except Exception: # pylint: disable=broad-except diff --git a/functest/opnfv_tests/openstack/vmtp/vmtp.py b/functest/opnfv_tests/openstack/vmtp/vmtp.py index 326a4f383..aada034da 100644 --- a/functest/opnfv_tests/openstack/vmtp/vmtp.py +++ b/functest/opnfv_tests/openstack/vmtp/vmtp.py @@ -35,7 +35,7 @@ from functest.core import singlevm from functest.utils import env -class Vmtp(singlevm.VmReady1): +class Vmtp(singlevm.VmReady2): """Class to run Vmtp_ as an OPNFV Functest testcase .. _Vmtp: http://vmtp.readthedocs.io/en/latest/ @@ -58,6 +58,20 @@ class Vmtp(singlevm.VmReady1): (_, self.privkey_filename) = tempfile.mkstemp() (_, self.pubkey_filename) = tempfile.mkstemp() + def create_network_ressources(self): + """Create router + + It creates a router which gateway is the external network detected. + + Raises: expection on error + """ + assert self.cloud + assert self.ext_net + self.router = self.cloud.create_router( + name='{}-router_{}'.format(self.case_name, self.guid), + ext_gateway_net_id=self.ext_net.id) + self.__logger.debug("router: %s", self.router) + def generate_keys(self): """Generate Keys @@ -90,7 +104,7 @@ class Vmtp(singlevm.VmReady1): vmtp_conf["private_key_file"] = self.privkey_filename vmtp_conf["public_key_file"] = self.pubkey_filename vmtp_conf["image_name"] = str(self.image.name) - vmtp_conf["router_name"] = "pns_router_{}".format(self.guid) + vmtp_conf["router_name"] = str(self.router.name) vmtp_conf["flavor_type"] = str(self.flavor.name) vmtp_conf["internal_network_name"] = [ "pns-internal-net_{}".format(self.guid), @@ -108,9 +122,21 @@ class Vmtp(singlevm.VmReady1): Raises: Exception on error """ assert self.cloud + new_env = dict( + os.environ, + OS_USERNAME=self.project.user.name, + OS_PROJECT_NAME=self.project.project.name, + OS_PROJECT_ID=self.project.project.id, + OS_PASSWORD=self.project.password) + try: + del new_env['OS_TENANT_NAME'] + del new_env['OS_TENANT_ID'] + except Exception: # pylint: disable=broad-except + pass cmd = ['vmtp', '-d', '--json', '{}/vmtp.json'.format(self.res_dir), '-c', self.config] - output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + output = subprocess.check_output( + cmd, stderr=subprocess.STDOUT, env=new_env) self.__logger.info("%s\n%s", " ".join(cmd), output) cmd = ['vmtp_genchart', '-c', '{}/vmtp.html'.format(self.res_dir), '{}/vmtp.json'.format(self.res_dir)] @@ -124,8 +150,18 @@ class Vmtp(singlevm.VmReady1): status = testcase.TestCase.EX_RUN_ERROR try: assert self.cloud - self.image = self.publish_image() - self.flavor = self.create_flavor() + assert super(Vmtp, self).run(**kwargs) == self.EX_OK + status = testcase.TestCase.EX_RUN_ERROR + if self.orig_cloud.get_role("admin"): + role_name = "admin" + elif self.orig_cloud.get_role("Admin"): + role_name = "Admin" + else: + raise Exception("Cannot detect neither admin nor Admin") + self.orig_cloud.grant_role( + role_name, user=self.project.user.id, + project=self.project.project.id, + domain=self.project.domain.id) self.generate_keys() self.write_config() self.run_vmtp() @@ -144,10 +180,9 @@ class Vmtp(singlevm.VmReady1): def clean(self): try: assert self.cloud + super(Vmtp, self).clean() os.remove(self.privkey_filename) os.remove(self.pubkey_filename) - if self.image: - self.cloud.delete_image(self.image) self.cloud.delete_network("pns-internal-net_{}".format(self.guid)) self.cloud.delete_network("pns-internal-net2_{}".format(self.guid)) except Exception: # pylint: disable=broad-except diff --git a/functest/tests/unit/openstack/vmtp/test_vmtp.py b/functest/tests/unit/openstack/vmtp/test_vmtp.py index 7f8cf40c7..fcbb0c46b 100644 --- a/functest/tests/unit/openstack/vmtp/test_vmtp.py +++ b/functest/tests/unit/openstack/vmtp/test_vmtp.py @@ -83,6 +83,7 @@ class VmtpTesting(unittest.TestCase): mock_obj.assert_called_once_with('vmtp_{}'.format(self.testcase.guid)) args[0].assert_not_called() + if __name__ == "__main__": logging.disable(logging.CRITICAL) unittest.main(verbosity=2) |