summaryrefslogtreecommitdiffstats
path: root/odl-pipeline/lib/utils
diff options
context:
space:
mode:
authorNikolas Hermanns <nikolas.hermanns@ericsson.com>2017-01-31 14:45:54 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-01-31 14:45:54 +0000
commit192e6af198cf94a678edece8ad4bb123132e9ce2 (patch)
treec9ed8b238a1b4d5c82dcf8dc26f597cc92a6adaa /odl-pipeline/lib/utils
parent4182a4715e55969868f17b11e5e3ac79fc3c7555 (diff)
parentc7cbf47421382ef5db5ad8a2f470def52640b21f (diff)
Merge "Updates ODL Pipeline scripts for CSIT"
Diffstat (limited to 'odl-pipeline/lib/utils')
-rwxr-xr-xodl-pipeline/lib/utils/node_manager.py10
-rwxr-xr-xodl-pipeline/lib/utils/processutils.py2
-rwxr-xr-xodl-pipeline/lib/utils/service.py6
-rwxr-xr-xodl-pipeline/lib/utils/shutil.py2
-rwxr-xr-xodl-pipeline/lib/utils/ssh_util.py2
-rw-r--r--odl-pipeline/lib/utils/tripleo_helper.py53
-rwxr-xr-xodl-pipeline/lib/utils/utils_log.py6
-rwxr-xr-xodl-pipeline/lib/utils/utils_yaml.py4
8 files changed, 77 insertions, 8 deletions
diff --git a/odl-pipeline/lib/utils/node_manager.py b/odl-pipeline/lib/utils/node_manager.py
index d11065f..8a320ed 100755
--- a/odl-pipeline/lib/utils/node_manager.py
+++ b/odl-pipeline/lib/utils/node_manager.py
@@ -17,14 +17,15 @@ class NodeManager(object):
primary_controller = None
def __init__(self, config=None):
- if config:
+ if config is not None:
for (node_name, node_config) in config.iteritems():
self.add_node(node_name, node_config)
def add_node(self, node_name, node_config):
from node import Node
if not node_config.get('address'):
- node_config['address'] = self.get_address_of_node(node_name)
+ raise NodeManagerException("IP address missing from node_config:"
+ " {}".format(node_config))
node = Node(node_name, dict=node_config)
self.env_nodes.append(node)
self.env_node_dict[node_name] = node
@@ -41,3 +42,8 @@ class NodeManager(object):
if node not in cls.env_nodes:
cls.env_nodes.append(node)
SshUtil.gen_ssh_config(cls.env_nodes)
+
+
+class NodeManagerException(Exception):
+ def __init__(self, value):
+ self.value = value
diff --git a/odl-pipeline/lib/utils/processutils.py b/odl-pipeline/lib/utils/processutils.py
index b5aecb3..2abb88a 100755
--- a/odl-pipeline/lib/utils/processutils.py
+++ b/odl-pipeline/lib/utils/processutils.py
@@ -226,7 +226,7 @@ def execute(cmd, **kwargs):
stderr=sanitized_stderr,
cmd=(' '.join(cmd)) if isinstance(cmd, list) else cmd)
(stdout, stderr) = result
- return (stdout, (stderr, _returncode))
+ return stdout, (stderr, _returncode)
except ProcessExecutionError:
raise
finally:
diff --git a/odl-pipeline/lib/utils/service.py b/odl-pipeline/lib/utils/service.py
index 39cdce5..cf46872 100755
--- a/odl-pipeline/lib/utils/service.py
+++ b/odl-pipeline/lib/utils/service.py
@@ -13,6 +13,7 @@ import argparse
import traceback
from utils_log import LOG, LOG_PATH
from abc import abstractmethod
+from ssh_util import SSH_CONFIG
class Service(object):
@@ -31,6 +32,8 @@ class Service(object):
parser = self._create_cli_parser()
sys_args = parser.parse_args()
config = self.read_config(sys_args)
+ if sys_args.ssh_key_file:
+ SSH_CONFIG['ID_RSA_PATH'] = sys_args.ssh_key_file
self.run(sys_args, config)
@abstractmethod
@@ -49,6 +52,9 @@ class Service(object):
# required=False)
# parser.add_argument('--boolean', help="",
# required=False, action='store_true')
+ parser.add_argument('--ssh-key-file',
+ help="SSH private key file to use",
+ required=False)
return self.create_cli_parser(parser)
def read_config(self, sys_args):
diff --git a/odl-pipeline/lib/utils/shutil.py b/odl-pipeline/lib/utils/shutil.py
index 40e2aba..5f6d482 100755
--- a/odl-pipeline/lib/utils/shutil.py
+++ b/odl-pipeline/lib/utils/shutil.py
@@ -17,7 +17,7 @@ class shutil():
classdocs
'''
@staticmethod
- def mkdir_if_not_exsist(path):
+ def mkdir_if_not_exist(path):
if not path:
raise Exception('Path should not be empty.')
putils.execute(["mkdir", "-p", path])
diff --git a/odl-pipeline/lib/utils/ssh_util.py b/odl-pipeline/lib/utils/ssh_util.py
index e70aed3..635a718 100755
--- a/odl-pipeline/lib/utils/ssh_util.py
+++ b/odl-pipeline/lib/utils/ssh_util.py
@@ -33,4 +33,4 @@ class SshUtil(object):
@staticmethod
def get_id_rsa():
- return (SSH_CONFIG['ID_RSA_PATH'])
+ return SSH_CONFIG['ID_RSA_PATH']
diff --git a/odl-pipeline/lib/utils/tripleo_helper.py b/odl-pipeline/lib/utils/tripleo_helper.py
new file mode 100644
index 0000000..702e811
--- /dev/null
+++ b/odl-pipeline/lib/utils/tripleo_helper.py
@@ -0,0 +1,53 @@
+import re
+import processutils
+from processutils import execute
+from utils.node import Node
+
+
+class TripleoHelper():
+
+ @staticmethod
+ def find_overcloud_ips():
+ try:
+ res, _ = TripleoHelper.get_undercloud().execute(
+ "'source /home/stack/stackrc; nova list'",
+ shell=True)
+ except processutils.ProcessExecutionError as e:
+ raise TripleOHelperException(
+ "Error unable to issue nova list "
+ "on undercloud. Please verify "
+ "undercloud is up. Full error: {"
+ "}".format(e.message))
+ return re.findall('ctlplane=([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)', res)
+
+ @staticmethod
+ def get_virtual_node_name_from_mac(mac):
+ vnode_names, _ = execute('virsh list|awk \'{print '
+ '$2}\'', shell=True)
+ for node in vnode_names.split('\n'):
+ if 'baremetal' in node:
+ admin_net_mac, _ = execute(
+ 'virsh domiflist %s |grep admin |awk \'{print $5}\''
+ % node, shell=True)
+ if admin_net_mac.replace('\n', '') == mac:
+ return node
+ raise Exception('Could not find corresponding virtual node for MAC: %s'
+ % mac)
+
+ @staticmethod
+ def get_undercloud_ip():
+ out, _ = execute('virsh domifaddr undercloud', shell=True)
+ return re.findall('([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)', out)[0]
+
+ @staticmethod
+ def get_undercloud():
+ return Node('undercloud', address=TripleoHelper.get_undercloud_ip(),
+ user='stack')
+
+
+class TripleOHelperException(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return self.value
diff --git a/odl-pipeline/lib/utils/utils_log.py b/odl-pipeline/lib/utils/utils_log.py
index e49434c..9d7648f 100755
--- a/odl-pipeline/lib/utils/utils_log.py
+++ b/odl-pipeline/lib/utils/utils_log.py
@@ -11,6 +11,7 @@ import logging
import datetime
import os
import sys
+import types
LOG = logging.getLogger(__name__)
LOG_LEVEL = logging.DEBUG
@@ -35,7 +36,10 @@ def log_enter_exit(func):
'args': args,
'kwargs': kwargs})
start = datetime.datetime.now()
- ret = func(self, *args, **kwargs)
+ if isinstance(func, types.FunctionType):
+ ret = func(*args, **kwargs)
+ else:
+ ret = func(self, *args, **kwargs)
end = datetime.datetime.now()
LOG.debug(("Exiting %(cls)s.%(method)s. "
"Spent %(duration)s sec. "
diff --git a/odl-pipeline/lib/utils/utils_yaml.py b/odl-pipeline/lib/utils/utils_yaml.py
index f9513b8..b9357f6 100755
--- a/odl-pipeline/lib/utils/utils_yaml.py
+++ b/odl-pipeline/lib/utils/utils_yaml.py
@@ -12,9 +12,9 @@ import yaml
def write_dict_to_yaml(config, path):
with open(path, 'w+') as f:
- yaml.dump(config, f, default_flow_style=False)
+ yaml.safe_dump(config, f, default_flow_style=False)
def read_dict_from_yaml(path):
with open(path, 'r') as f:
- return yaml.load(f)
+ return yaml.safe_load(f)