summaryrefslogtreecommitdiffstats
path: root/sfc/lib
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 /sfc/lib
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>
Diffstat (limited to 'sfc/lib')
-rw-r--r--sfc/lib/config.py37
-rw-r--r--sfc/lib/utils.py76
2 files changed, 36 insertions, 77 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)