summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Ollivier <cedric.ollivier@orange.com>2018-04-24 12:05:02 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-04-24 12:05:02 +0000
commit0911abc82403066af66d285db739cff03772b06c (patch)
tree1b17bff1a3db07a7c57b6bcf108160467422404e
parent7bfdcd4b7d5ad67004f9f7467148089016c45ba5 (diff)
parentfd18d52e94cc293c32bb7f69a00ec4604bdace0e (diff)
Merge "Switch from deploy utils to the right objects"
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py37
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py7
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py2
-rw-r--r--functest/tests/unit/openstack/vping/test_vping.py38
4 files changed, 49 insertions, 35 deletions
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
index 13e0efbc8..4b6e4e97f 100644
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ b/functest/opnfv_tests/openstack/vping/vping_base.py
@@ -16,11 +16,14 @@ import time
import uuid
from snaps.config.flavor import FlavorConfig
-from snaps.config.network import NetworkConfig, SubnetConfig
+from snaps.config.network import NetworkConfig
+from snaps.config.network import SubnetConfig
from snaps.config.router import RouterConfig
from snaps.openstack.create_flavor import OpenStackFlavor
+from snaps.openstack.create_image import OpenStackImage
+from snaps.openstack.create_network import OpenStackNetwork
+from snaps.openstack.create_router import OpenStackRouter
from snaps.openstack.tests import openstack_tests
-from snaps.openstack.utils import deploy_utils
from xtesting.core import testcase
from functest.opnfv_tests.openstack.snaps import snaps_utils
@@ -85,14 +88,14 @@ class VPingBase(testcase.TestCase):
'%Y-%m-%d %H:%M:%S'))
image_base_name = '{}-{}'.format(
- getattr(config.CONF, 'vping_image_name'),
- str(self.guid))
+ getattr(config.CONF, 'vping_image_name'), self.guid)
os_image_settings = openstack_tests.cirros_image_settings(
image_base_name, image_metadata=self.cirros_image_config)
self.logger.info("Creating image with name: '%s'", image_base_name)
- self.image_creator = deploy_utils.create_image(
+ self.image_creator = OpenStackImage(
self.os_creds, os_image_settings)
+ self.image_creator.create()
self.creators.append(self.image_creator)
private_net_name = getattr(
@@ -116,29 +119,31 @@ class VPingBase(testcase.TestCase):
self.logger.info(
"Creating network with name: '%s'", private_net_name)
- self.network_creator = deploy_utils.create_network(
+ subnet_settings = SubnetConfig(
+ name=private_subnet_name,
+ cidr=private_subnet_cidr,
+ dns_nameservers=[env.get('NAMESERVER')])
+ self.network_creator = OpenStackNetwork(
self.os_creds,
NetworkConfig(
name=private_net_name,
network_type=vping_network_type,
physical_network=vping_physical_network,
segmentation_id=vping_segmentation_id,
- subnet_settings=[SubnetConfig(
- name=private_subnet_name,
- cidr=private_subnet_cidr,
- dns_nameservers=[env.get('NAMESERVER')])]))
+ subnet_settings=[subnet_settings]))
+ self.network_creator.create()
self.creators.append(self.network_creator)
# Creating router to external network
- log = "Creating router with name: '%s'" % self.router_name
- self.logger.info(log)
+ self.logger.info("Creating router with name: '%s'", self.router_name)
ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
- self.router_creator = deploy_utils.create_router(
+ self.router_creator = OpenStackRouter(
self.os_creds,
RouterConfig(
name=self.router_name,
external_gateway=ext_net_name,
- internal_subnets=[private_subnet_name]))
+ internal_subnets=[subnet_settings.name]))
+ self.router_creator.create()
self.creators.append(self.router_creator)
self.logger.info(
@@ -187,8 +192,8 @@ class VPingBase(testcase.TestCase):
for creator in reversed(self.creators):
try:
creator.clean()
- except Exception as error: # pylint: disable=broad-except
- self.logger.error('Unexpected error cleaning - %s', error)
+ except Exception: # pylint: disable=broad-except
+ self.logger.exception('Unexpected error cleaning')
def _do_vping(self, vm_creator, test_ip):
"""
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 7cdcd2576..93c9c0976 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -9,6 +9,7 @@
"""vPingSSH testcase."""
+import logging
import time
from scp import SCPClient
@@ -29,6 +30,7 @@ from functest.utils import config
class VPingSSH(vping_base.VPingBase):
+ # pylint: disable=too-many-instance-attributes
"""
VPingSSH testcase implementation.
@@ -41,6 +43,7 @@ class VPingSSH(vping_base.VPingBase):
if "case_name" not in kwargs:
kwargs["case_name"] = "vping_ssh"
super(VPingSSH, self).__init__(**kwargs)
+ self.logger = logging.getLogger(__name__)
self.kp_name = getattr(config.CONF, 'vping_keypair_name') + self.guid
self.kp_priv_file = getattr(config.CONF, 'vping_keypair_priv_file')
@@ -120,8 +123,8 @@ class VPingSSH(vping_base.VPingBase):
self.creators.append(self.vm2_creator)
return self._execute()
- except Exception as exc: # pylint: disable=broad-except
- self.logger.error('Unexpected error running test - ' + exc.message)
+ except Exception: # pylint: disable=broad-except
+ self.logger.exception('Unexpected error running test')
return testcase.TestCase.EX_RUN_ERROR
def _do_vping(self, vm_creator, test_ip):
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index 7d9a57c93..c2ff75150 100644
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -9,6 +9,7 @@
"""vping_userdata testcase."""
+import logging
import time
from snaps.config.network import PortConfig
@@ -28,6 +29,7 @@ class VPingUserdata(vping_base.VPingBase):
if "case_name" not in kwargs:
kwargs["case_name"] = "vping_userdata"
super(VPingUserdata, self).__init__(**kwargs)
+ self.logger = logging.getLogger(__name__)
def run(self, **kwargs):
"""
diff --git a/functest/tests/unit/openstack/vping/test_vping.py b/functest/tests/unit/openstack/vping/test_vping.py
index 3aaa4594a..adc0f69a6 100644
--- a/functest/tests/unit/openstack/vping/test_vping.py
+++ b/functest/tests/unit/openstack/vping/test_vping.py
@@ -60,14 +60,16 @@ class VPingUserdataTesting(unittest.TestCase):
'get_ext_net_name', return_value='foo')
def test_vping_userdata(self, *args):
# pylint: disable=unused-argument
- with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
+ with mock.patch('snaps.openstack.create_image.OpenStackImage.create',
return_value=OpenStackImage(self.os_creds, None)), \
- mock.patch('snaps.openstack.utils.deploy_utils.create_network',
- return_value=OpenStackNetwork(
- self.os_creds, NetworkConfig(name='foo'))), \
- mock.patch('snaps.openstack.utils.deploy_utils.create_router',
- return_value=OpenStackRouter(
- self.os_creds, RouterConfig(name='foo'))), \
+ mock.patch(
+ 'snaps.openstack.create_network.OpenStackNetwork.create',
+ return_value=OpenStackNetwork(
+ self.os_creds, NetworkConfig(name='foo'))), \
+ mock.patch(
+ 'snaps.openstack.create_router.OpenStackRouter.create',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterConfig(name='foo'))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_vm_instance',
return_value=OpenStackVmInstance(
@@ -133,14 +135,15 @@ class VPingSSHTesting(unittest.TestCase):
cidr='10.0.0.1/24',
dns_nameservers=[env.get('NAMESERVER')])
- with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
+ with mock.patch('snaps.openstack.create_image.OpenStackImage.create',
return_value=OpenStackImage(self.os_creds, None)), \
- mock.patch('snaps.openstack.utils.deploy_utils.create_network',
- return_value=OpenStackNetwork(
- self.os_creds,
- NetworkConfig(
- name='foo',
- subnet_settings=[subnet_config]))), \
+ mock.patch(
+ 'snaps.openstack.create_network.OpenStackNetwork.create',
+ return_value=OpenStackNetwork(
+ self.os_creds,
+ NetworkConfig(
+ name='foo',
+ subnet_settings=[subnet_config]))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_vm_instance',
return_value=OpenStackVmInstance(
@@ -153,9 +156,10 @@ class VPingSSHTesting(unittest.TestCase):
mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
return_value=OpenStackKeypair(
self.os_creds, KeypairConfig(name='foo'))), \
- mock.patch('snaps.openstack.utils.deploy_utils.create_router',
- return_value=OpenStackRouter(
- self.os_creds, RouterConfig(name='foo'))), \
+ mock.patch(
+ 'snaps.openstack.create_router.OpenStackRouter.create',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterConfig(name='foo'))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_security_group',
return_value=OpenStackSecurityGroup(