summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/core/singlevm.py138
-rw-r--r--functest/opnfv_tests/openstack/shaker/shaker.py16
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py27
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py180
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py109
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py33
6 files changed, 131 insertions, 372 deletions
diff --git a/functest/core/singlevm.py b/functest/core/singlevm.py
index 65743e37f..e6cf01835 100644
--- a/functest/core/singlevm.py
+++ b/functest/core/singlevm.py
@@ -25,7 +25,7 @@ from functest.utils import config
class VmReady1(tenantnetwork.TenantNetwork1):
- """Deploy a single VM reachable via ssh (scenario1)
+ """Prepare a single VM (scenario1)
It inherits from TenantNetwork1 which creates all network resources and
prepares a future VM attached to that network.
@@ -51,10 +51,19 @@ class VmReady1(tenantnetwork.TenantNetwork1):
self.image = None
self.flavor = None
- def _publish_image(self):
+ def publish_image(self, name=None):
+ """Publish image
+
+ It allows publishing multiple images for the child testcases. It forces
+ the same configuration for all subtestcases.
+
+ Returns: image
+
+ Raises: expection on error
+ """
assert self.cloud
- self.image = self.cloud.create_image(
- '{}-img_{}'.format(self.case_name, self.guid),
+ image = self.cloud.create_image(
+ name if name else '{}-img_{}'.format(self.case_name, self.guid),
filename=getattr(
config.CONF, '{}_image'.format(self.case_name),
self.filename),
@@ -64,21 +73,53 @@ class VmReady1(tenantnetwork.TenantNetwork1):
visibility=getattr(
config.CONF, '{}_visibility'.format(self.case_name),
self.visibility))
- self.__logger.debug("image: %s", self.image)
+ self.__logger.debug("image: %s", image)
+ return image
- def _create_flavor(self):
+ def create_flavor(self, name=None):
+ """Create flavor
+
+ It allows creating multiple flavors for the child testcases. It forces
+ the same configuration for all subtestcases.
+
+ Returns: flavor
+
+ Raises: expection on error
+ """
assert self.orig_cloud
- self.flavor = self.orig_cloud.create_flavor(
- '{}-flavor_{}'.format(self.case_name, self.guid),
+ flavor = self.orig_cloud.create_flavor(
+ name if name else '{}-flavor_{}'.format(self.case_name, self.guid),
getattr(config.CONF, '{}_flavor_ram'.format(self.case_name),
self.flavor_ram),
getattr(config.CONF, '{}_flavor_vcpus'.format(self.case_name),
self.flavor_vcpus),
getattr(config.CONF, '{}_flavor_disk'.format(self.case_name),
self.flavor_disk))
- self.__logger.debug("flavor: %s", self.flavor)
+ self.__logger.debug("flavor: %s", flavor)
self.orig_cloud.set_flavor_specs(
- self.flavor.id, getattr(config.CONF, 'flavor_extra_specs', {}))
+ flavor.id, getattr(config.CONF, 'flavor_extra_specs', {}))
+ return flavor
+
+ def boot_vm(self, name=None, **kwargs):
+ """Boot the virtual machine
+
+ It allows booting multiple machines for the child testcases. It forces
+ the same configuration for all subtestcases.
+
+ Returns: vm
+
+ Raises: expection on error
+ """
+ assert self.cloud
+ vm1 = self.cloud.create_server(
+ name if name else '{}-vm_{}'.format(self.case_name, self.guid),
+ image=self.image.id, flavor=self.flavor.id,
+ auto_ip=False, wait=True,
+ network=self.network.id,
+ **kwargs)
+ vm1 = self.cloud.wait_for_server(vm1, auto_ip=False)
+ self.__logger.debug("vm: %s", vm1)
+ return vm1
def run(self, **kwargs):
"""Boot the new VM
@@ -95,8 +136,8 @@ class VmReady1(tenantnetwork.TenantNetwork1):
try:
assert self.cloud
super(VmReady1, self).run(**kwargs)
- self._publish_image()
- self._create_flavor()
+ self.image = self.publish_image()
+ self.flavor = self.create_flavor()
self.result = 100
status = testcase.TestCase.EX_OK
except Exception: # pylint: disable=broad-except
@@ -175,11 +216,11 @@ class SingleVm1(VmReady1):
self.sec = None
self.fip = None
self.keypair = None
- self.ssh = paramiko.SSHClient()
+ self.ssh = None
(_, self.key_filename) = tempfile.mkstemp()
- def create_sg_rules(self):
- """Create the security group
+ def prepare(self):
+ """Create the security group and the keypair
It can be overriden to set other rules according to the services
running in the VM
@@ -187,6 +228,12 @@ class SingleVm1(VmReady1):
Raises: Exception on error
"""
assert self.cloud
+ self.keypair = self.cloud.create_keypair(
+ '{}-kp_{}'.format(self.case_name, self.guid))
+ self.__logger.debug("keypair: %s", self.keypair)
+ self.__logger.debug("private_key: %s", self.keypair.private_key)
+ with open(self.key_filename, 'w') as private_key_file:
+ private_key_file.write(self.keypair.private_key)
self.sec = self.cloud.create_security_group(
'{}-sg_{}'.format(self.case_name, self.guid),
'created by OPNFV Functest ({})'.format(self.case_name))
@@ -196,37 +243,28 @@ class SingleVm1(VmReady1):
self.cloud.create_security_group_rule(
self.sec.id, protocol='icmp', direction='ingress')
- def _boot_vm(self):
- assert self.cloud
- self.keypair = self.cloud.create_keypair(
- '{}-kp_{}'.format(self.case_name, self.guid))
- self.__logger.debug("keypair: %s", self.keypair)
- self.__logger.debug("private_key: %s", self.keypair.private_key)
- with open(self.key_filename, 'w') as private_key_file:
- private_key_file.write(self.keypair.private_key)
+ def connect(self, vm1):
+ """Connect to a virtual machine via ssh
- self.sshvm = self.cloud.create_server(
- '{}-vm_{}'.format(self.case_name, self.guid),
- image=self.image.id, flavor=self.flavor.id,
- key_name=self.keypair.id,
- auto_ip=False, wait=True,
- network=self.network.id,
- security_groups=[self.sec.id])
- self.__logger.debug("vm: %s", self.sshvm)
- self.fip = self.cloud.create_floating_ip(
- network=self.ext_net.id, server=self.sshvm)
- self.__logger.debug("floating_ip: %s", self.fip)
- self.sshvm = self.cloud.wait_for_server(self.sshvm, auto_ip=False)
-
- def _connect(self):
- assert self.cloud
- p_console = self.cloud.get_server_console(self.sshvm.id)
+ It first adds a floating ip to the virtual machine and then establishes
+ the ssh connection.
+
+ Returns:
+ - (fip, ssh)
+ - None on error
+ """
+ assert vm1
+ fip = self.cloud.create_floating_ip(
+ network=self.ext_net.id, server=vm1)
+ self.__logger.debug("floating_ip: %s", fip)
+ p_console = self.cloud.get_server_console(vm1)
self.__logger.debug("vm console: \n%s", p_console)
- self.ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
+ ssh = paramiko.SSHClient()
+ ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
for loop in range(6):
try:
- self.ssh.connect(
- self.sshvm.public_v4,
+ ssh.connect(
+ fip.floating_ip_address,
username=getattr(
config.CONF,
'{}_image_user'.format(self.case_name), self.username),
@@ -239,12 +277,13 @@ class SingleVm1(VmReady1):
except Exception: # pylint: disable=broad-except
self.__logger.debug(
"try %s: cannot connect to %s", loop + 1,
- self.sshvm.public_v4)
+ fip.floating_ip_address)
time.sleep(10)
else:
- self.__logger.error("cannot connect to %s", self.sshvm.public_v4)
- return False
- return True
+ self.__logger.error(
+ "cannot connect to %s", fip.floating_ip_address)
+ return None
+ return (fip, ssh)
def execute(self):
"""Say hello world via ssh
@@ -275,9 +314,10 @@ class SingleVm1(VmReady1):
assert self.cloud
super(SingleVm1, self).run(**kwargs)
self.result = 0
- self.create_sg_rules()
- self._boot_vm()
- assert self._connect()
+ self.prepare()
+ self.sshvm = self.boot_vm(
+ key_name=self.keypair.id, security_groups=[self.sec.id])
+ (self.fip, self.ssh) = self.connect(self.sshvm)
if not self.execute():
self.result = 100
status = testcase.TestCase.EX_OK
diff --git a/functest/opnfv_tests/openstack/shaker/shaker.py b/functest/opnfv_tests/openstack/shaker/shaker.py
index c664eb066..ba93ba5b5 100644
--- a/functest/opnfv_tests/openstack/shaker/shaker.py
+++ b/functest/opnfv_tests/openstack/shaker/shaker.py
@@ -37,15 +37,9 @@ class Shaker(singlevm.SingleVm2):
username = 'ubuntu'
port = 9000
- def create_sg_rules(self):
- """
- It adds one security group rule allowing ingress 9000/tcp
-
- Raises: Exception on error.
- """
- assert self.orig_cloud
- super(Shaker, self).create_sg_rules()
- self.orig_cloud.create_security_group_rule(
+ def prepare(self):
+ super(Shaker, self).prepare()
+ self.cloud.create_security_group_rule(
self.sec.id, port_range_min=self.port, port_range_max=self.port,
protocol='tcp', direction='ingress')
@@ -57,14 +51,14 @@ class Shaker(singlevm.SingleVm2):
"""
assert self.ssh
scpc = scp.SCPClient(self.ssh.get_transport())
- scpc.put('/home/opnfv/functest/conf/env_file', '~/')
+ scpc.put('/home/opnfv/functest/conf/env_file', '~/env_file')
(_, stdout, stderr) = self.ssh.exec_command(
'source ~/env_file && export OS_INTERFACE=public &&'
'shaker --server-endpoint {}:9000 --scenario '
'openstack/full_l2,openstack/full_l3_east_west,'
'openstack/full_l3_north_south,openstack/perf_l2,'
'openstack/perf_l3_east_west,openstack/perf_l3_north_south '
- '--report report.html --output report.json ; echo $?'.format(
+ '--report report.html --output report.json'.format(
self.sshvm.public_v4))
self.__logger.info("output:\n%s", stdout.read())
self.__logger.info("error:\n%s", stderr.read())
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 2fa3bd609..baa7e14fc 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -266,31 +266,12 @@ class TempestCommon(singlevm.VmReady1):
compute_cnt = len(self.cloud.list_hypervisors())
LOGGER.info("Creating two images for Tempest suite")
-
- self.image_alt = self.cloud.create_image(
- '{}-img_alt_{}'.format(self.case_name, self.guid),
- filename=getattr(
- config.CONF, '{}_image'.format(self.case_name),
- self.filename),
- meta=getattr(
- config.CONF, '{}_extra_properties'.format(self.case_name),
- self.extra_properties),
- visibility=getattr(
- config.CONF, '{}_visibility'.format(self.case_name),
- self.visibility))
+ self.image_alt = self.publish_image(
+ '{}-img_alt_{}'.format(self.case_name, self.guid))
LOGGER.debug("image_alt: %s", self.image_alt)
-
- self.flavor_alt = self.orig_cloud.create_flavor(
- '{}-flavor_alt_{}'.format(self.case_name, self.guid),
- getattr(config.CONF, '{}_flavor_ram'.format(self.case_name),
- self.flavor_ram),
- getattr(config.CONF, '{}_flavor_vcpus'.format(self.case_name),
- self.flavor_vcpus),
- getattr(config.CONF, '{}_flavor_disk'.format(self.case_name),
- self.flavor_disk))
+ self.flavor_alt = self.create_flavor(
+ '{}-flavor_alt_{}'.format(self.case_name, self.guid))
LOGGER.debug("flavor: %s", self.flavor_alt)
- self.orig_cloud.set_flavor_specs(
- self.flavor_alt.id, getattr(config.CONF, 'flavor_extra_specs', {}))
self.conf_file = conf_utils.configure_verifier(self.deployment_dir)
conf_utils.configure_tempest_update_params(
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
deleted file mode 100644
index 2451c2de4..000000000
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
-#
-# This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-
-"""Define the parent class of vping_ssh and vping_userdata testcases."""
-
-from datetime import datetime
-import logging
-import time
-import uuid
-
-import os_client_config
-from xtesting.core import testcase
-
-from functest.utils import config
-from functest.utils import env
-from functest.utils import functest_utils
-
-
-class VPingBase(testcase.TestCase):
-
- """
- Base class for vPing tests that check connectivity between two VMs shared
- internal network.
- This class is responsible for creating the image, internal network.
- """
- # pylint: disable=too-many-instance-attributes
-
- def __init__(self, **kwargs):
- super(VPingBase, self).__init__(**kwargs)
- self.logger = logging.getLogger(__name__)
- self.cloud = os_client_config.make_shade()
- self.ext_net = functest_utils.get_external_network(self.cloud)
- self.logger.debug("ext_net: %s", self.ext_net)
- self.guid = '-' + str(uuid.uuid4())
- self.network = None
- self.subnet = None
- self.router = None
- self.image = None
- self.flavor = None
- self.vm1 = None
- self.sec1 = None
-
- def run(self, **kwargs): # pylint: disable=too-many-locals
- """
- Begins the test execution which should originate from the subclass
- """
- assert self.cloud
- assert self.ext_net
- self.logger.info('Begin virtual environment setup')
-
- self.start_time = time.time()
- self.logger.info(
- "vPing Start Time:'%s'",
- datetime.fromtimestamp(self.start_time).strftime(
- '%Y-%m-%d %H:%M:%S'))
-
- image_base_name = '{}-{}'.format(
- getattr(config.CONF, 'vping_image_name'), self.guid)
- self.logger.info("Creating image with name: '%s'", image_base_name)
- meta = getattr(config.CONF, 'openstack_extra_properties', None)
- self.logger.info("Image metadata: %s", meta)
- self.image = self.cloud.create_image(
- image_base_name,
- filename=getattr(config.CONF, 'openstack_image_url'),
- meta=meta)
- self.logger.debug("image: %s", self.image)
-
- private_net_name = getattr(
- config.CONF, 'vping_private_net_name') + self.guid
- private_subnet_name = str(getattr(
- config.CONF, 'vping_private_subnet_name') + self.guid)
- private_subnet_cidr = getattr(config.CONF, 'vping_private_subnet_cidr')
-
- provider = {}
- if hasattr(config.CONF, 'vping_network_type'):
- provider["network_type"] = getattr(
- config.CONF, 'vping_network_type')
- if hasattr(config.CONF, 'vping_physical_network'):
- provider["physical_network"] = getattr(
- config.CONF, 'vping_physical_network')
- if hasattr(config.CONF, 'vping_segmentation_id'):
- provider["segmentation_id"] = getattr(
- config.CONF, 'vping_segmentation_id')
- self.logger.info(
- "Creating network with name: '%s'", private_net_name)
- self.network = self.cloud.create_network(
- private_net_name,
- provider=provider)
- self.logger.debug("network: %s", self.network)
-
- self.subnet = self.cloud.create_subnet(
- self.network.id,
- subnet_name=private_subnet_name,
- cidr=private_subnet_cidr,
- enable_dhcp=True,
- dns_nameservers=[env.get('NAMESERVER')])
- self.logger.debug("subnet: %s", self.subnet)
-
- router_name = getattr(config.CONF, 'vping_router_name') + self.guid
- self.logger.info("Creating router with name: '%s'", router_name)
- self.router = self.cloud.create_router(
- name=router_name,
- ext_gateway_net_id=self.ext_net.id)
- self.logger.debug("router: %s", self.router)
- self.cloud.add_router_interface(self.router, subnet_id=self.subnet.id)
-
- flavor_name = 'vping-flavor' + self.guid
- self.logger.info(
- "Creating flavor with name: '%s'", flavor_name)
- self.flavor = self.cloud.create_flavor(
- flavor_name, getattr(config.CONF, 'openstack_flavor_ram'),
- getattr(config.CONF, 'openstack_flavor_vcpus'),
- getattr(config.CONF, 'openstack_flavor_disk'))
- self.logger.debug("flavor: %s", self.flavor)
- self.cloud.set_flavor_specs(
- self.flavor.id, getattr(config.CONF, 'flavor_extra_specs', {}))
-
- self.sec1 = self.cloud.create_security_group(
- getattr(config.CONF, 'vping_sg_name') + self.guid,
- getattr(config.CONF, 'vping_sg_desc'))
- self.cloud.create_security_group_rule(
- self.sec1.id, protocol='icmp', direction='ingress')
-
- vm1_name = getattr(config.CONF, 'vping_vm_name_1') + self.guid
- self.logger.info(
- "Creating VM 1 instance with name: '%s'", vm1_name)
- self.vm1 = self.cloud.create_server(
- vm1_name, image=self.image.id,
- flavor=self.flavor.id,
- auto_ip=False, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_boot_timeout'),
- network=self.network.id,
- security_groups=[self.sec1.id])
- self.logger.debug("vm1: %s", self.vm1)
- self.vm1 = self.cloud.wait_for_server(self.vm1, auto_ip=False)
- p_console = self.cloud.get_server_console(self.vm1.id)
- self.logger.debug("vm1 console: \n%s", p_console)
-
- def _execute(self):
- """
- Method called by subclasses after environment has been setup
- :return: the exit code
- """
- self.logger.info('Begin test execution')
- result = self._do_vping()
- self.stop_time = time.time()
- if result != testcase.TestCase.EX_OK:
- self.result = 0
- return testcase.TestCase.EX_RUN_ERROR
- self.result = 100
- return testcase.TestCase.EX_OK
-
- def clean(self):
- """
- Cleanup all OpenStack objects. Should be called on completion
- :return:
- """
- assert self.cloud
- self.cloud.delete_server(self.vm1, wait=True)
- self.cloud.delete_security_group(self.sec1.id)
- self.cloud.delete_image(self.image)
- self.cloud.remove_router_interface(self.router, self.subnet.id)
- self.cloud.delete_router(self.router.id)
- self.cloud.delete_network(self.network.id)
- self.cloud.delete_flavor(self.flavor.id)
-
- def _do_vping(self):
- """
- Method to be implemented by subclasses
- Begins the real test after the OpenStack environment has been setup
- :return: T/F
- """
- raise NotImplementedError('vping execution is not implemented')
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 1dfca89a3..e3453e4c2 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -10,19 +10,12 @@
"""vPingSSH testcase."""
import logging
-import os
-import tempfile
-import time
-import paramiko
-from xtesting.core import testcase
-from xtesting.energy import energy
-
-from functest.opnfv_tests.openstack.vping import vping_base
+from functest.core import singlevm
from functest.utils import config
-class VPingSSH(vping_base.VPingBase):
+class VPingSSH(singlevm.SingleVm2):
"""
VPingSSH testcase implementation.
@@ -30,105 +23,37 @@ class VPingSSH(vping_base.VPingBase):
to issue the ping command to the second
"""
+ __logger = logging.getLogger(__name__)
+
def __init__(self, **kwargs):
"""Initialize testcase."""
if "case_name" not in kwargs:
kwargs["case_name"] = "vping_ssh"
super(VPingSSH, self).__init__(**kwargs)
- self.logger = logging.getLogger(__name__)
self.vm2 = None
- self.sec2 = None
- self.fip = None
- self.keypair = None
- self.ssh = paramiko.SSHClient()
- (_, self.key_filename) = tempfile.mkstemp()
-
- @energy.enable_recording
- def run(self, **kwargs):
- """
- Excecute VPingSSH testcase.
- Sets up the OpenStack keypair, router, security group, and VM instance
- objects then validates the ping.
- :return: the exit code from the super.execute() method
- """
- try:
- assert self.cloud
- super(VPingSSH, self).run()
-
- kp_name = getattr(config.CONF, 'vping_keypair_name') + self.guid
- self.logger.info("Creating keypair with name: '%s'", kp_name)
- self.keypair = self.cloud.create_keypair(kp_name)
- self.logger.debug("keypair: %s", self.keypair)
- self.logger.debug("private_key: %s", self.keypair.private_key)
- with open(self.key_filename, 'w') as private_key_file:
- private_key_file.write(self.keypair.private_key)
+ def prepare(self):
+ super(VPingSSH, self).prepare()
+ self.vm2 = self.boot_vm(
+ '{}-vm2_{}'.format(self.case_name, self.guid),
+ security_groups=[self.sec.id])
- self.sec2 = self.cloud.create_security_group(
- getattr(config.CONF, 'vping_sg_name') + self.guid,
- getattr(config.CONF, 'vping_sg_desc'))
- self.cloud.create_security_group_rule(
- self.sec2.id, port_range_min='22', port_range_max='22',
- protocol='tcp', direction='ingress')
- self.cloud.create_security_group_rule(
- self.sec2.id, protocol='icmp', direction='ingress')
+ def execute(self):
+ """Ping the second VM
- vm2_name = "{}-{}-{}".format(
- getattr(config.CONF, 'vping_vm_name_2'), "ssh", self.guid)
- self.logger.info(
- "Creating VM 2 instance with name: '%s'", vm2_name)
- self.vm2 = self.cloud.create_server(
- vm2_name, image=self.image.id, flavor=self.flavor.id,
- key_name=self.keypair.id,
- auto_ip=False, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_boot_timeout'),
- network=self.network.id,
- security_groups=[self.sec2.id])
- self.logger.debug("vm2: %s", self.vm2)
- self.fip = self.cloud.create_floating_ip(
- network=self.ext_net.id, server=self.vm2)
- self.logger.debug("floating_ip2: %s", self.fip)
- self.vm2 = self.cloud.wait_for_server(self.vm2, auto_ip=False)
- p_console = self.cloud.get_server_console(self.vm2.id)
- self.logger.debug("vm2 console: \n%s", p_console)
- return self._execute()
- except Exception: # pylint: disable=broad-except
- self.logger.exception('Unexpected error running vping_ssh')
- return testcase.TestCase.EX_RUN_ERROR
+ It can be overriden to execute any command.
- def _do_vping(self):
- self.ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
- for loop in range(6):
- try:
- self.ssh.connect(
- self.vm2.public_v4,
- username=getattr(config.CONF, 'openstack_image_user'),
- key_filename=self.key_filename,
- timeout=getattr(
- config.CONF, 'vping_vm_ssh_connect_timeout'))
- break
- except Exception: # pylint: disable=broad-except
- self.logger.info(
- "try %s: cannot connect to %s", loop + 1,
- self.vm2.public_v4)
- time.sleep(10)
- else:
- self.logger.error("cannot connect to %s", self.vm2.public_v4)
- return testcase.TestCase.EX_RUN_ERROR
-
- self.logger.debug("ssh: %s", self.ssh)
+ Returns: ping exit codes
+ """
+ assert self.ssh
(_, stdout, _) = self.ssh.exec_command(
- 'ping -c 1 ' + self.vm1.private_v4)
- self.logger.debug("ping output:\n%s", stdout.read())
+ 'ping -c 1 ' + self.vm2.private_v4)
+ self.__logger.debug("output:\n%s", stdout.read())
return stdout.channel.recv_exit_status()
def clean(self):
assert self.cloud
- os.remove(self.key_filename)
self.cloud.delete_server(
self.vm2, wait=True,
timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
- self.cloud.delete_security_group(self.sec2.id)
- self.cloud.delete_keypair(self.keypair.id)
- self.cloud.delete_floating_ip(self.fip.id)
super(VPingSSH, self).clean()
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index 4f9f635c3..c3de0b8b6 100644
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -14,11 +14,11 @@ import time
from xtesting.core import testcase
-from functest.opnfv_tests.openstack.vping import vping_base
+from functest.core import singlevm
from functest.utils import config
-class VPingUserdata(vping_base.VPingBase):
+class VPingUserdata(singlevm.VmReady2):
"""
Class to execute the vPing test using userdata and the VM's console
"""
@@ -28,6 +28,7 @@ class VPingUserdata(vping_base.VPingBase):
kwargs["case_name"] = "vping_userdata"
super(VPingUserdata, self).__init__(**kwargs)
self.logger = logging.getLogger(__name__)
+ self.vm1 = None
self.vm2 = None
def run(self, **kwargs):
@@ -39,23 +40,19 @@ class VPingUserdata(vping_base.VPingBase):
try:
assert self.cloud
super(VPingUserdata, self).run()
-
- vm2_name = "{}-{}-{}".format(
- getattr(config.CONF, 'vping_vm_name_2'), "userdata", self.guid)
- self.logger.info(
- "Creating VM 2 instance with name: '%s'", vm2_name)
- self.vm2 = self.cloud.create_server(
- vm2_name, image=self.image.id, flavor=self.flavor.id,
- auto_ip=False, wait=True,
- timeout=getattr(config.CONF, 'vping_vm_boot_timeout'),
- network=self.network.id,
+ self.result = 0
+ self.vm1 = self.boot_vm()
+ self.vm2 = self.boot_vm(
+ '{}-vm2_{}'.format(self.case_name, self.guid),
userdata=self._get_userdata())
- self.logger.debug("vm2: %s", self.vm2)
self.vm2 = self.cloud.wait_for_server(self.vm2, auto_ip=False)
- p_console = self.cloud.get_server_console(self.vm1.id)
- self.logger.debug("vm2 console: \n%s", p_console)
- return self._execute()
+ result = self._do_vping()
+ self.stop_time = time.time()
+ if result != testcase.TestCase.EX_OK:
+ return testcase.TestCase.EX_RUN_ERROR
+ self.result = 100
+ return testcase.TestCase.EX_OK
except Exception: # pylint: disable=broad-except
self.logger.exception('Unexpected error running vping_userdata')
return testcase.TestCase.EX_RUN_ERROR
@@ -125,7 +122,9 @@ class VPingUserdata(vping_base.VPingBase):
def clean(self):
assert self.cloud
self.cloud.delete_server(
+ self.vm1, wait=True,
+ timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
+ self.cloud.delete_server(
self.vm2, wait=True,
timeout=getattr(config.CONF, 'vping_vm_delete_timeout'))
- self.cloud.delete_server(self.vm2, wait=True)
super(VPingUserdata, self).clean()