From f9a6e37b970ff3974ad9e3f0027354d04bbf3ce7 Mon Sep 17 00:00:00 2001 From: George Paraskevopoulos Date: Tue, 14 Feb 2017 13:44:42 +0200 Subject: Refactor utils using installer adapters JIRA: SFC-65 JIRA: SFC-71 Use the new library in releng to talk to fuel. This allows for correct configuration of the compute hosts to resolve SFC-71 Also since https://gerrit.opnfv.org/gerrit/#/c/28281/ was merged it allows to run in multienv deployments so it resolves SFC-65 Change-Id: I5e6beb90d9c5108c21acb8d898f07cd2f4ae34f3 Signed-off-by: George Paraskevopoulos --- sfc/tests/functest/config.yaml | 10 +++--- sfc/tests/functest/run_tests.py | 43 ++++++++++++----------- sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py | 28 +++++++++++---- 3 files changed, 50 insertions(+), 31 deletions(-) (limited to 'sfc/tests') diff --git a/sfc/tests/functest/config.yaml b/sfc/tests/functest/config.yaml index b6f9c138..9cc4c5f4 100644 --- a/sfc/tests/functest/config.yaml +++ b/sfc/tests/functest/config.yaml @@ -6,10 +6,12 @@ defaults: vcpu_count: 1 image_name: sfc_nsh_danube image_file_name: sfc_nsh_danube.qcow2 - fuel_master_ip: 10.20.0.2 - fuel_master_uname: root - fuel_master_passwd: r00tme - fuel_environment: # Change this to the id of the desired fuel env (1, 2, 3...) + installer: + type: fuel + ip: 10.20.0.2 + user: root + password: r00tme + cluster: 1 # Change this to the id of the desired fuel env (1, 2, 3...) image_format: qcow2 url: "http://artifacts.opnfv.org/sfc/images" vnfd-dir: "vnfd-templates" diff --git a/sfc/tests/functest/run_tests.py b/sfc/tests/functest/run_tests.py index d0ed35f4..7214dd94 100644 --- a/sfc/tests/functest/run_tests.py +++ b/sfc/tests/functest/run_tests.py @@ -17,10 +17,10 @@ import yaml import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.openstack_utils as os_utils import opnfv.utils.ovs_logger as ovs_log -import opnfv.utils.SSHUtils as ssh_utils import sfc.lib.config as sfc_config -import sfc.lib.utils as utils +from opnfv.deployment.factory import Factory as DeploymentFactory parser = argparse.ArgumentParser() @@ -43,33 +43,34 @@ def push_results(testname, start_time, end_time, criteria, details): details) -def get_tackerc_file(): +def fetch_tackerc_file(controller_node): rc_file = os.path.join(COMMON_CONFIG.sfc_test_dir, 'tackerc') if not os.path.exists(rc_file): - logger.info("tackerc file not found, getting it from controller") - ip = utils.get_openstack_node_ips("controller") - ssh_conn = ssh_utils.get_ssh_client(ip[0], 'root', - proxy=COMMON_CONFIG.fuel_proxy) - ssh_utils.get_file(ssh_conn, "tackerc", rc_file) + logger.info("tackerc file not found, fetching it from controller") + controller_node.get_file("~/tackerc", rc_file) else: logger.info("found tackerc file") - return rc_file -def set_tacker_rc_file_env(): - rc_file = get_tackerc_file() - with open(rc_file) as f: - for line in f.readlines(): - if not (line.startswith('#') or len(line) == 1): - filtered = line.strip().split(' ') - kv = filtered[1].split('=') - logger.info("Set shell env %s=%s" % (kv[0], kv[1])) - os.environ[kv[0]] = kv[1].strip("'") - - def main(): - set_tacker_rc_file_env() + deploymentHandler = DeploymentFactory.get_handler( + COMMON_CONFIG.installer_type, + COMMON_CONFIG.installer_ip, + COMMON_CONFIG.installer_user, + installer_pwd=COMMON_CONFIG.installer_password) + + cluster = COMMON_CONFIG.installer_cluster + nodes = (deploymentHandler.get_nodes({'cluster': cluster}) + if cluster is not None + else deploymentHandler.get_nodes()) + + a_controller = [node for node in nodes + if node.is_controller()][0] + rc_file = fetch_tackerc_file(a_controller) + + creds = os_utils.source_credentials(rc_file) + logger.info("Updating env with {0}".format(creds)) ovs_logger = ovs_log.OVSLogger( os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'), COMMON_CONFIG.functest_results_dir) diff --git a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py index e112e07b..58959530 100644 --- a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py +++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py @@ -20,6 +20,7 @@ import opnfv.utils.ovs_logger as ovs_log import sfc.lib.config as sfc_config import sfc.lib.utils as test_utils from sfc.lib.results import Results +from opnfv.deployment.factory import Factory as DeploymentFactory """ logging configuration """ @@ -32,6 +33,22 @@ TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc_two_chains_SSH_and_HTTP') def main(): + deploymentHandler = DeploymentFactory.get_handler( + COMMON_CONFIG.installer_type, + COMMON_CONFIG.installer_ip, + COMMON_CONFIG.installer_user, + installer_pwd=COMMON_CONFIG.installer_password) + + cluster = COMMON_CONFIG.installer_cluster + openstack_nodes = (deploymentHandler.get_nodes({'cluster': cluster}) + if cluster is not None + else deploymentHandler.get_nodes()) + + controller_nodes = [node for node in openstack_nodes + if node.is_controller()] + compute_nodes = [node for node in openstack_nodes + if node.is_compute()] + results = Results(COMMON_CONFIG.line_length) results.add_to_summary(0, "=") results.add_to_summary(2, "STATUS", "SUBTEST") @@ -51,8 +68,9 @@ def main(): '\033[91mexport INSTALLER_IP=\033[0m') sys.exit(1) - test_utils.setup_compute_node(TESTCASE_CONFIG.subnet_cidr) - test_utils.configure_iptables() + test_utils.setup_compute_node(TESTCASE_CONFIG.subnet_cidr, compute_nodes) + test_utils.configure_iptables(controller_nodes) + test_utils.download_image(COMMON_CONFIG.url, COMMON_CONFIG.image_path) _, custom_flv_id = os_utils.get_or_create_flavor( @@ -69,10 +87,8 @@ def main(): nova_client = os_utils.get_nova_client() tacker_client = os_tacker.get_tacker_client() - controller_clients = test_utils.get_ssh_clients("controller", - COMMON_CONFIG.fuel_proxy) - compute_clients = test_utils.get_ssh_clients("compute", - COMMON_CONFIG.fuel_proxy) + controller_clients = test_utils.get_ssh_clients(controller_nodes) + compute_clients = test_utils.get_ssh_clients(compute_nodes) ovs_logger = ovs_log.OVSLogger( os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'), -- cgit 1.2.3-korg