It also prints the full exceptions and removes useless casts.
Change-Id: I19ff1ae90670833f998c0d17592da82207235229
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
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
'%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(
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(
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):
"""
"""vPingSSH testcase."""
+import logging
import time
from scp import SCPClient
class VPingSSH(vping_base.VPingBase):
+ # pylint: disable=too-many-instance-attributes
"""
VPingSSH testcase implementation.
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')
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):
"""vping_userdata testcase."""
+import logging
import time
from snaps.config.network import PortConfig
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):
"""
'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(
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(
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(