aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/openstack/vping/vping_userdata.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2016-12-01 12:10:48 -0700
committerCédric Ollivier <cedric.ollivier@orange.com>2017-05-16 18:15:06 +0200
commit1b940dcafb40c28e519700cf23e4d0f880f962d1 (patch)
treef1250ebe47d3ea86a3f46b342be106bb475029d7 /functest/opnfv_tests/openstack/vping/vping_userdata.py
parent10ed30e26e9510dcdc9563a0eda3b94c0ccb16ad (diff)
Converted vPing to leverage the object-oriented SNAPS library.
JIRA: FUNCTEST-577 1. Replaced procedural openstack_utils with the object-oriented SNAPS library 2. Tests now clean themselves up. 3. Improved code documentation. 4. Removed dependency on file-based Cirros image and now leveraging the download URL. 5. Removed hardcoded location to the testcases.yaml file to leverage the value in config_functest.yaml 6. Included optional flavor metadata based on the scenario being tested 7. Included support for multi-part images. 8. Added enhanced support for configurable images. see SNAPS-76 Fixed line length verification problem with the previous submission Fixed retrieval of external network name to be dynamic. Changed external network name retrieval to leverage the newly merged snap_util.get_ext_net_name() function Added the creation and deletion of flavors. SNAPS now has the ability to add/remove security groups from running instances. Changed VMInstance constructor by moving userdata to configuration object. Change-Id: I0ef5e268eb153d696bb4d9a7533f780e5c603d26 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'functest/opnfv_tests/openstack/vping/vping_userdata.py')
-rwxr-xr-xfunctest/opnfv_tests/openstack/vping/vping_userdata.py134
1 files changed, 102 insertions, 32 deletions
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index 05dda9dea..8ea9be84b 100755
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -7,74 +7,144 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
-import logging
+import argparse
import sys
import time
-import argparse
+from functest.core.testcase import TestCase
+
+from snaps.openstack.utils import deploy_utils
+from snaps.openstack.create_instance import VmInstanceSettings
+from snaps.openstack.create_network import PortSettings
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)
- self.logger = logging.getLogger(__name__)
-
- def boot_vm_preparation(self, config, vmname, test_ip):
- config['config_drive'] = True
- if vmname == self.vm2_name:
- u = ("#!/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" % test_ip)
- config['userdata'] = u
-
- def do_vping(self, vm, test_ip):
+
+ def run(self):
+ """
+ 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 = PortSettings(
+ name=self.vm1_name + '-vPingPort',
+ network_name=self.network_creator.network_settings.name)
+ instance1_settings = VmInstanceSettings(
+ 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 = PortSettings(
+ name=self.vm2_name + '-vPingPort',
+ network_name=self.network_creator.network_settings.name)
+ instance2_settings = VmInstanceSettings(
+ 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 = -1
+ exit_code = -1
sec = 0
tries = 0
while True:
time.sleep(1)
- p_console = vm.get_console_output()
+ p_console = vm_creator.get_vm_inst().get_console_output()
if "vPing OK" in p_console:
self.logger.info("vPing detected!")
- EXIT_CODE = 0
+ exit_code = TestCase.EX_OK
break
elif "failed to read iid from metadata" in p_console or tries > 5:
- EXIT_CODE = -2
+ exit_code = TestCase.EX_TESTCASE_FAILED
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...")
+ 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)
+ self.logger.debug(
+ "Pinging %s. Waiting for response..." % test_ip)
sec += 1
- return EXIT_CODE
+ 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" % test_ip)
+ return None
if __name__ == '__main__':
- logging.basicConfig()
args_parser = argparse.ArgumentParser()
args_parser.add_argument("-r", "--report",
help="Create json result file",