aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-14 13:44:42 +0200
committerGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-15 12:28:11 +0200
commitf9a6e37b970ff3974ad9e3f0027354d04bbf3ce7 (patch)
treedb1af81b1c7c40e5535159a30e821ef254d78a7f
parent306daf5219a2ba7975c2cc22096e41fd39f91918 (diff)
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 <geopar@intracom-telecom.com>
-rw-r--r--sfc/lib/config.py37
-rw-r--r--sfc/lib/utils.py76
-rw-r--r--sfc/tests/functest/config.yaml10
-rw-r--r--sfc/tests/functest/run_tests.py43
-rw-r--r--sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py28
5 files changed, 86 insertions, 108 deletions
diff --git a/sfc/lib/config.py b/sfc/lib/config.py
index e9fcd582..f5a07013 100644
--- a/sfc/lib/config.py
+++ b/sfc/lib/config.py
@@ -34,22 +34,31 @@ class CommonConfig(object):
self.functest_results_dir = os.path.join(
CONST.dir_results, "odl-sfc")
self.config_file = os.path.join(self.sfc_test_dir, "config.yaml")
- self.fuel_master_ip = ft_utils.get_parameter_from_yaml(
- "defaults.fuel_master_ip", self.config_file)
- self.fuel_master_uname = ft_utils.get_parameter_from_yaml(
- "defaults.fuel_master_uname", self.config_file)
- self.fuel_master_passwd = ft_utils.get_parameter_from_yaml(
- "defaults.fuel_master_passwd", self.config_file)
- self.fuel_proxy = {
- 'ip': self.fuel_master_ip,
- 'username': self.fuel_master_uname,
- 'password': self.fuel_master_passwd
- }
+ self.installer_type = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.type", self.config_file)
+ self.installer_ip = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.ip", self.config_file)
+ self.installer_user = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.user", self.config_file)
+
+ try:
+ self.installer_password = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.password", self.config_file)
+ except:
+ self.installer_password = None
+
try:
- self.fuel_environment = ft_utils.get_parameter_from_yaml(
- "defaults.fuel_environment", self.config_file)
+ self.installer_key_file = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.key_file", self.config_file)
except:
- self.fuel_environment = None
+ self.installer_key_file = None
+
+ try:
+ self.installer_cluster = ft_utils.get_parameter_from_yaml(
+ "defaults.installer.cluster", self.config_file)
+ except:
+ self.installer_cluster = None
+
self.flavor = ft_utils.get_parameter_from_yaml(
"defaults.flavor", self.config_file)
self.ram_size_in_mb = ft_utils.get_parameter_from_yaml(
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index 02782765..9c191462 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -8,7 +8,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
-import json
import os
import re
import subprocess
@@ -17,8 +16,6 @@ import time
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.SSHUtils as ssh_utils
-import sfc.lib.config as sfc_config
logger = ft_logger.Logger("sfc_test_utils").getLogger()
@@ -46,30 +43,6 @@ def run_cmd(cmd):
return output
-def run_cmd_on_controller(cmd):
- """run given command on OpenStack controller"""
- ip_controllers = get_openstack_node_ips("controller")
- if not ip_controllers:
- return None
-
- ssh_cmd = "ssh %s %s %s" % (SSH_OPTIONS, ip_controllers[0], cmd)
- return run_cmd_on_fm(ssh_cmd)
-
-
-def run_cmd_on_compute(cmd, ip_compute):
- """run given command on OpenStack Compute node"""
- ssh_cmd = "ssh %s %s %s" % (SSH_OPTIONS, ip_compute, cmd)
- return run_cmd_on_fm(ssh_cmd)
-
-
-def run_cmd_on_fm(cmd, username="root", passwd="r00tme"):
- """run given command on Fuel Master"""
- ip = os.environ.get("INSTALLER_IP")
- ssh_cmd = "sshpass -p %s ssh %s %s@%s %s" % (
- passwd, SSH_OPTIONS, username, ip, cmd)
- return run_cmd(ssh_cmd)
-
-
def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"):
"""run given command on Remote Machine, Can be VM"""
ssh_opt_append = "%s -o ConnectTimeout=50 " % SSH_OPTIONS
@@ -78,25 +51,7 @@ def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"):
return run_cmd(ssh_cmd)
-def get_openstack_node_ips(role):
- """Get OpenStack Nodes IP Address"""
- fuel_env = sfc_config.CommonConfig().fuel_environment
- if fuel_env is not None:
- cmd = "fuel2 node list -f json -e %s" % fuel_env
- else:
- cmd = "fuel2 node list -f json"
-
- nodes = run_cmd_on_fm(cmd)
- ips = []
- nodes = json.loads(nodes)
- for node in nodes:
- if role in node["roles"]:
- ips.append(node["ip"])
-
- return ips
-
-
-def configure_iptables():
+def configure_iptables(controller_nodes):
"""Configures IPTABLES on OpenStack Controller"""
iptable_cmds = ["iptables -P INPUT ACCEPT",
"iptables -t nat -P INPUT ACCEPT",
@@ -105,7 +60,8 @@ def configure_iptables():
for cmd in iptable_cmds:
logger.info("Configuring %s on contoller" % cmd)
- run_cmd_on_controller(cmd)
+ for controller in controller_nodes:
+ controller.run_cmd(cmd)
def download_image(url, image_path):
@@ -317,13 +273,8 @@ def capture_ovs_logs(ovs_logger, controller_clients, compute_clients, error):
timestamp=timestamp)
-def get_ssh_clients(role, proxy):
- clients = []
- for ip in get_openstack_node_ips(role):
- s_client = ssh_utils.get_ssh_client(ip, 'root', proxy=proxy)
- clients.append(s_client)
-
- return clients
+def get_ssh_clients(nodes):
+ return [n.ssh_client for n in nodes]
def check_ssh(ips, retries=100):
@@ -396,15 +347,14 @@ def wait_for_classification_rules(ovs_logger, compute_clients, timeout=200):
logger.info("classification rules updated")
-def setup_compute_node(cidr):
+def setup_compute_node(cidr, compute_nodes):
logger.info("bringing up br-int iface")
- # TODO: Get only the compute nodes which belong to the env.
- ip_computes = get_openstack_node_ips("compute")
- for ip_compute in ip_computes:
- run_cmd_on_compute("ifconfig br-int up", ip_compute)
- if not run_cmd_on_compute(
- "ip route|grep -o %s || true" % cidr, ip_compute):
- logger.info("adding route %s in %s" % (cidr, ip_compute))
- run_cmd_on_compute("ip route add %s dev br-int" % cidr, ip_compute)
+ grep_cidr_routes = ("ip route|grep -o {0} || true".format(cidr)).strip()
+ add_cidr = "ip route add {0} br-int".format(cidr)
+ for compute in compute_nodes:
+ compute.run_cmd("ifconfig br-int up")
+ if not compute.run_cmd(grep_cidr_routes):
+ logger.info("adding route %s in %s" % (cidr, compute.ip))
+ compute.run_cmd(add_cidr)
else:
logger.info("route %s exists" % cidr)
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=<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'),