aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/openstack/vping
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-02-27 14:25:49 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-02-27 14:27:57 +0100
commitbaa8f2d5f67d45e5761f92cb93fe22050f08d0fe (patch)
tree05ddb33dc893cad35369b3286db944eac79ffe4d /functest/opnfv_tests/openstack/vping
parent53cd7f8176c996014decb7311d9f546f6b8f2497 (diff)
Clean all OpenStack related modules
Xtesting is only focused on the framework and entry points. Change-Id: I1a4146ed8519438b13810a20ddf1140c35bb6ecd Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/opnfv_tests/openstack/vping')
-rw-r--r--functest/opnfv_tests/openstack/vping/__init__.py0
-rw-r--r--functest/opnfv_tests/openstack/vping/ping.sh10
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py204
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py235
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py143
5 files changed, 0 insertions, 592 deletions
diff --git a/functest/opnfv_tests/openstack/vping/__init__.py b/functest/opnfv_tests/openstack/vping/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/functest/opnfv_tests/openstack/vping/__init__.py
+++ /dev/null
diff --git a/functest/opnfv_tests/openstack/vping/ping.sh b/functest/opnfv_tests/openstack/vping/ping.sh
deleted file mode 100644
index 15f5e84e..00000000
--- a/functest/opnfv_tests/openstack/vping/ping.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-
-ping -c 1 $1 2>&1 >/dev/null
-RES=$?
-if [ "Z$RES" = "Z0" ] ; then
- echo 'vPing OK'
-else
- echo 'vPing KO'
-fi
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 586b8d65..00000000
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ /dev/null
@@ -1,204 +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
-
-from functest.core import testcase
-from functest.opnfv_tests.openstack.snaps import snaps_utils
-from functest.utils import config
-from functest.utils import env
-
-from snaps.config.flavor import FlavorConfig
-from snaps.config.network import NetworkConfig, SubnetConfig
-from snaps.config.router import RouterConfig
-from snaps.openstack import create_flavor
-from snaps.openstack.create_flavor import OpenStackFlavor
-from snaps.openstack.tests import openstack_tests
-from snaps.openstack.utils import deploy_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.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
- self.creators = list()
- self.image_creator = None
- self.network_creator = None
- self.vm1_creator = None
- self.vm2_creator = None
- self.router_creator = None
-
- # Shared metadata
- self.guid = '-' + str(uuid.uuid4())
-
- self.router_name = getattr(
- config.CONF, 'vping_router_name') + self.guid
- self.vm1_name = getattr(
- config.CONF, 'vping_vm_name_1') + self.guid
- self.vm2_name = getattr(config.CONF, 'vping_vm_name_2') + self.guid
-
- self.vm_boot_timeout = getattr(config.CONF, 'vping_vm_boot_timeout')
- self.vm_delete_timeout = getattr(
- config.CONF, 'vping_vm_delete_timeout')
- self.vm_ssh_connect_timeout = getattr(
- config.CONF, 'vping_vm_ssh_connect_timeout')
- self.ping_timeout = getattr(config.CONF, 'vping_ping_timeout')
- self.flavor_name = 'vping-flavor' + self.guid
-
- # Move this configuration option up for all tests to leverage
- if hasattr(config.CONF, 'snaps_images_cirros'):
- self.cirros_image_config = getattr(
- config.CONF, 'snaps_images_cirros')
- else:
- self.cirros_image_config = None
-
- def run(self, **kwargs): # pylint: disable=too-many-locals
- """
- Begins the test execution which should originate from the subclass
- """
- 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'),
- str(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.os_creds, os_image_settings)
- self.creators.append(self.image_creator)
-
- private_net_name = getattr(
- config.CONF, 'vping_private_net_name') + self.guid
- private_subnet_name = getattr(
- config.CONF, 'vping_private_subnet_name') + self.guid
- private_subnet_cidr = getattr(config.CONF, 'vping_private_subnet_cidr')
-
- vping_network_type = None
- vping_physical_network = None
- vping_segmentation_id = None
-
- if hasattr(config.CONF, 'vping_network_type'):
- vping_network_type = getattr(config.CONF, 'vping_network_type')
- if hasattr(config.CONF, 'vping_physical_network'):
- vping_physical_network = getattr(
- config.CONF, 'vping_physical_network')
- if hasattr(config.CONF, 'vping_segmentation_id'):
- vping_segmentation_id = getattr(
- config.CONF, 'vping_segmentation_id')
-
- self.logger.info(
- "Creating network with name: '%s'", private_net_name)
- self.network_creator = deploy_utils.create_network(
- 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)]))
- self.creators.append(self.network_creator)
-
- # Creating router to external network
- log = "Creating router with name: '%s'" % self.router_name
- self.logger.info(log)
- ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
- self.router_creator = deploy_utils.create_router(
- self.os_creds,
- RouterConfig(
- name=self.router_name,
- external_gateway=ext_net_name,
- internal_subnets=[private_subnet_name]))
- self.creators.append(self.router_creator)
-
- self.logger.info(
- "Creating flavor with name: '%s'", self.flavor_name)
- scenario = env.get('DEPLOY_SCENARIO')
- flavor_metadata = None
- flavor_ram = 512
- if 'ovs' in scenario or 'fdio' in scenario:
- flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
- flavor_ram = 1024
- flavor_creator = OpenStackFlavor(
- self.os_creds,
- FlavorConfig(name=self.flavor_name, ram=flavor_ram, disk=1,
- vcpus=1, metadata=flavor_metadata))
- flavor_creator.create()
- self.creators.append(flavor_creator)
-
- def _execute(self):
- """
- Method called by subclasses after environment has been setup
- :return: the exit code
- """
- self.logger.info('Begin test execution')
-
- test_ip = self.vm1_creator.get_port_ip(
- self.vm1_creator.instance_settings.port_settings[0].name)
-
- if self.vm1_creator.vm_active(
- block=True) and self.vm2_creator.vm_active(block=True):
- result = self._do_vping(self.vm2_creator, test_ip)
- else:
- raise Exception('VMs never became active')
-
- 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 _cleanup(self):
- """
- Cleanup all OpenStack objects. Should be called on completion
- :return:
- """
- if getattr(config.CONF, 'vping_cleanup_objects') == 'True':
- 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)
-
- def _do_vping(self, vm_creator, test_ip):
- """
- Method to be implemented by subclasses
- Begins the real test after the OpenStack environment has been setup
- :param vm_creator: the SNAPS VM instance creator object
- :param test_ip: the IP to which the VM needs to issue the ping
- :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
deleted file mode 100644
index e6c6bf35..00000000
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ /dev/null
@@ -1,235 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2015 All rights reserved
-# 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
-
-"""vPingSSH testcase."""
-
-import time
-
-from scp import SCPClient
-import pkg_resources
-
-from functest.core.testcase import TestCase
-from functest.energy import energy
-from functest.opnfv_tests.openstack.vping import vping_base
-from functest.utils import config
-
-from snaps.config.keypair import KeypairConfig
-from snaps.config.network import PortConfig
-from snaps.config.security_group import (
- Direction, Protocol, SecurityGroupConfig, SecurityGroupRuleConfig)
-from snaps.config.vm_inst import FloatingIpConfig, VmInstanceConfig
-
-from snaps.openstack.utils import deploy_utils
-
-
-class VPingSSH(vping_base.VPingBase):
- """
- VPingSSH testcase implementation.
-
- Class to execute the vPing test using a Floating IP to connect to one VM
- to issue the ping command to the second
- """
-
- def __init__(self, **kwargs):
- """Initialize testcase."""
- if "case_name" not in kwargs:
- kwargs["case_name"] = "vping_ssh"
- super(VPingSSH, self).__init__(**kwargs)
-
- self.kp_name = getattr(config.CONF, 'vping_keypair_name') + self.guid
- self.kp_priv_file = getattr(config.CONF, 'vping_keypair_priv_file')
- self.kp_pub_file = getattr(config.CONF, 'vping_keypair_pub_file')
- self.sg_name = getattr(config.CONF, 'vping_sg_name') + self.guid
- self.sg_desc = getattr(config.CONF, 'vping_sg_desc')
-
- @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:
- super(VPingSSH, self).run()
-
- log = "Creating keypair with name: '%s'" % self.kp_name
- self.logger.info(log)
- kp_creator = deploy_utils.create_keypair(
- self.os_creds,
- KeypairConfig(
- name=self.kp_name, private_filepath=self.kp_priv_file,
- public_filepath=self.kp_pub_file))
- self.creators.append(kp_creator)
-
- # Creating Instance 1
- port1_settings = PortConfig(
- name=self.vm1_name + '-vPingPort',
- network_name=self.network_creator.network_settings.name)
- instance1_settings = VmInstanceConfig(
- name=self.vm1_name, flavor=self.flavor_name,
- vm_boot_timeout=self.vm_boot_timeout,
- vm_delete_timeout=self.vm_delete_timeout,
- ssh_connect_timeout=self.vm_ssh_connect_timeout,
- port_settings=[port1_settings])
-
- log = ("Creating VM 1 instance with name: '%s'"
- % instance1_settings.name)
- self.logger.info(log)
- self.vm1_creator = deploy_utils.create_vm_instance(
- self.os_creds,
- instance1_settings,
- self.image_creator.image_settings,
- keypair_creator=kp_creator)
- self.creators.append(self.vm1_creator)
-
- # Creating Instance 2
- sg_creator = self.__create_security_group()
- self.creators.append(sg_creator)
-
- port2_settings = PortConfig(
- name=self.vm2_name + '-vPingPort',
- network_name=self.network_creator.network_settings.name)
- instance2_settings = VmInstanceConfig(
- name=self.vm2_name, flavor=self.flavor_name,
- vm_boot_timeout=self.vm_boot_timeout,
- vm_delete_timeout=self.vm_delete_timeout,
- ssh_connect_timeout=self.vm_ssh_connect_timeout,
- port_settings=[port2_settings],
- security_group_names=[sg_creator.sec_grp_settings.name],
- floating_ip_settings=[FloatingIpConfig(
- name=self.vm2_name + '-FIPName',
- port_name=port2_settings.name,
- router_name=self.router_creator.router_settings.name)])
-
- log = ("Creating VM 2 instance with name: '%s'"
- % instance2_settings.name)
- self.logger.info(log)
- self.vm2_creator = deploy_utils.create_vm_instance(
- self.os_creds,
- instance2_settings,
- self.image_creator.image_settings,
- keypair_creator=kp_creator)
- 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)
- return TestCase.EX_RUN_ERROR
- finally:
- self._cleanup()
-
- def _do_vping(self, vm_creator, test_ip):
- """
- Execute ping command.
-
- Override from super
- """
- if vm_creator.vm_ssh_active(block=True):
- ssh = vm_creator.ssh_client()
- if not self._transfer_ping_script(ssh):
- return TestCase.EX_RUN_ERROR
- return self._do_vping_ssh(ssh, test_ip)
- else:
- return TestCase.EX_RUN_ERROR
-
- def _transfer_ping_script(self, ssh):
- """
- Transfert vping script to VM.
-
- Uses SCP to copy the ping script via the SSH client
- :param ssh: the SSH client
- :return:
- """
- self.logger.info("Trying to transfer ping.sh")
- scp = SCPClient(ssh.get_transport())
- ping_script = pkg_resources.resource_filename(
- 'functest.opnfv_tests.openstack.vping', 'ping.sh')
- try:
- scp.put(ping_script, "~/")
- except Exception: # pylint: disable=broad-except
- self.logger.error("Cannot SCP the file '%s'", ping_script)
- return False
-
- cmd = 'chmod 755 ~/ping.sh'
- # pylint: disable=unused-variable
- (stdin, stdout, stderr) = ssh.exec_command(cmd)
- for line in stdout.readlines():
- print line
-
- return True
-
- def _do_vping_ssh(self, ssh, test_ip):
- """
- Execute ping command via SSH.
-
- Pings the test_ip via the SSH client
- :param ssh: the SSH client used to issue the ping command
- :param test_ip: the IP for the ping command to use
- :return: exit_code (int)
- """
- exit_code = TestCase.EX_TESTCASE_FAILED
- self.logger.info("Waiting for ping...")
-
- sec = 0
- cmd = '~/ping.sh ' + test_ip
- flag = False
-
- while True:
- time.sleep(1)
- (_, stdout, _) = ssh.exec_command(cmd)
- output = stdout.readlines()
-
- for line in output:
- if "vPing OK" in line:
- self.logger.info("vPing detected!")
- exit_code = TestCase.EX_OK
- flag = True
- break
-
- elif sec == self.ping_timeout:
- self.logger.info("Timeout reached.")
- flag = True
- break
- if flag:
- break
- log = "Pinging %s. Waiting for response..." % test_ip
- self.logger.debug(log)
- sec += 1
- return exit_code
-
- def __create_security_group(self):
- """
- Configure OpenStack security groups.
-
- Configures and deploys an OpenStack security group object
- :return: the creator object
- """
- sg_rules = list()
- sg_rules.append(
- SecurityGroupRuleConfig(
- sec_grp_name=self.sg_name, direction=Direction.ingress,
- protocol=Protocol.icmp))
- sg_rules.append(
- SecurityGroupRuleConfig(
- sec_grp_name=self.sg_name, direction=Direction.ingress,
- protocol=Protocol.tcp, port_range_min=22, port_range_max=22))
- sg_rules.append(
- SecurityGroupRuleConfig(
- sec_grp_name=self.sg_name, direction=Direction.egress,
- protocol=Protocol.tcp, port_range_min=22, port_range_max=22))
-
- log = "Security group with name: '%s'" % self.sg_name
- self.logger.info(log)
- return deploy_utils.create_security_group(self.os_creds,
- SecurityGroupConfig(
- name=self.sg_name,
- description=self.sg_desc,
- rule_settings=sg_rules))
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
deleted file mode 100644
index 76cdcf83..00000000
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ /dev/null
@@ -1,143 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2015 All rights reserved
-# 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
-
-"""vping_userdata testcase."""
-
-import time
-
-from snaps.config.network import PortConfig
-from snaps.config.vm_inst import VmInstanceConfig
-from snaps.openstack.utils import deploy_utils
-
-from functest.core.testcase import TestCase
-from functest.opnfv_tests.openstack.vping import vping_base
-
-
-class VPingUserdata(vping_base.VPingBase):
- """
- Class to execute the vPing test using userdata and the VM's console
- """
-
- def __init__(self, **kwargs):
- if "case_name" not in kwargs:
- kwargs["case_name"] = "vping_userdata"
- super(VPingUserdata, self).__init__(**kwargs)
-
- def run(self, **kwargs):
- """
- Sets up the OpenStack VM instance objects then executes the ping and
- validates.
- :return: the exit code from the super.execute() method
- """
- try:
- super(VPingUserdata, self).run()
-
- # Creating Instance 1
- port1_settings = PortConfig(
- name=self.vm1_name + '-vPingPort',
- network_name=self.network_creator.network_settings.name)
- instance1_settings = VmInstanceConfig(
- name=self.vm1_name,
- flavor=self.flavor_name,
- vm_boot_timeout=self.vm_boot_timeout,
- port_settings=[port1_settings])
-
- self.logger.info(
- "Creating VM 1 instance with name: '%s'",
- instance1_settings.name)
- self.vm1_creator = deploy_utils.create_vm_instance(
- self.os_creds, instance1_settings,
- self.image_creator.image_settings)
- self.creators.append(self.vm1_creator)
-
- userdata = _get_userdata(
- self.vm1_creator.get_port_ip(port1_settings.name))
- if userdata:
- # Creating Instance 2
- port2_settings = PortConfig(
- name=self.vm2_name + '-vPingPort',
- network_name=self.network_creator.network_settings.name)
- instance2_settings = VmInstanceConfig(
- name=self.vm2_name,
- flavor=self.flavor_name,
- vm_boot_timeout=self.vm_boot_timeout,
- port_settings=[port2_settings],
- userdata=userdata)
-
- self.logger.info(
- "Creating VM 2 instance with name: '%s'",
- instance2_settings.name)
- self.vm2_creator = deploy_utils.create_vm_instance(
- self.os_creds, instance2_settings,
- self.image_creator.image_settings)
- self.creators.append(self.vm2_creator)
- else:
- raise Exception('Userdata is None')
-
- return self._execute()
-
- finally:
- self._cleanup()
-
- def _do_vping(self, vm_creator, test_ip):
- """
- Override from super
- """
- self.logger.info("Waiting for ping...")
- exit_code = TestCase.EX_TESTCASE_FAILED
- sec = 0
- tries = 0
-
- while True:
- time.sleep(1)
- p_console = vm_creator.get_console_output()
- if "vPing OK" in p_console:
- self.logger.info("vPing detected!")
- exit_code = TestCase.EX_OK
- break
- elif "failed to read iid from metadata" in p_console or tries > 5:
- self.logger.info("Failed to read iid from metadata")
- break
- elif sec == self.ping_timeout:
- self.logger.info("Timeout reached.")
- break
- elif sec % 10 == 0:
- if "request failed" in p_console:
- self.logger.debug(
- "It seems userdata is not supported in nova boot. " +
- "Waiting a bit...")
- tries += 1
- else:
- self.logger.debug(
- "Pinging %s. Waiting for response...", test_ip)
- sec += 1
-
- return exit_code
-
-
-def _get_userdata(test_ip):
- """
- Returns the post VM creation script to be added into the VM's userdata
- :param test_ip: the IP value to substitute into the script
- :return: the bash script contents
- """
- if test_ip:
- return ("#!/bin/sh\n\n"
- "while true; do\n"
- " ping -c 1 %s 2>&1 >/dev/null\n"
- " RES=$?\n"
- " if [ \"Z$RES\" = \"Z0\" ] ; then\n"
- " echo 'vPing OK'\n"
- " break\n"
- " else\n"
- " echo 'vPing KO'\n"
- " fi\n"
- " sleep 1\n"
- "done\n" % str(test_ip))
- return None