summaryrefslogtreecommitdiffstats
path: root/odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2017-01-12 12:27:41 -0500
committerTim Rozet <trozet@redhat.com>2017-01-30 14:36:24 -0500
commitc7cbf47421382ef5db5ad8a2f470def52640b21f (patch)
tree78474dd4298b163b7816e038533f50a586df9e8c /odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py
parentced7ceab968ee2542b5d4d4255195d971aa61fea (diff)
Updates ODL Pipeline scripts for CSIT
Changes Include: - Change to TripleOInspector which only introspect a current Apex deployment and dump yaml config to be bundled with snapshots. - Add TripleOHelper which consists of all tripleO helper functions. Many this are done to virsh so the idea is to have at. Some point in time a libvirtHelper, or use another libvirt python lib. Thatsway it is a class so that we can inherit later on. - New argument for passing the SSH private key to use to connect to nodes is added to the service utils. - Some general clean up and consolidation of logic JIRA: APEX-363 Change-Id: I792db0fac3f4e81969fe85c05fc298fe5af02537 Signed-off-by: Tim Rozet <trozet@redhat.com>
Diffstat (limited to 'odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py')
-rwxr-xr-xodl-pipeline/lib/tripleo_introspector/tripleo_introspector.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py b/odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py
new file mode 100755
index 0000000..dd378ed
--- /dev/null
+++ b/odl-pipeline/lib/tripleo_introspector/tripleo_introspector.py
@@ -0,0 +1,116 @@
+import os
+import re
+
+from utils import processutils
+from utils.node import Node
+from utils.utils_log import log_enter_exit, for_all_methods, LOG
+from utils.service import Service
+from utils.shutil import shutil
+from common import constants
+from utils import utils_yaml
+from utils.tripleo_helper import TripleoHelper
+
+
+@for_all_methods(log_enter_exit)
+class TripleOIntrospector(Service):
+
+ def __init__(self):
+ self.overcloud_user = 'heat-admin'
+ self.node_info = {'servers': {}}
+
+ def create_cli_parser(self, parser):
+ parser.add_argument('--out-file',
+ help="File where pod config will be written to. "
+ "Defaults to ./node.yaml",
+ default=constants.NODE_YAML_PATH,
+ dest="out_file",
+ required=False)
+ return parser
+
+ def run(self, sys_args, config):
+ self.gen_node_info()
+ shutil.mkdir_if_not_exist(os.path.dirname(sys_args.out_file))
+ utils_yaml.write_dict_to_yaml(self.node_info, sys_args.out_file)
+
+ def gen_node_info(self):
+ overcloud_ip_list = TripleoHelper.find_overcloud_ips()
+
+ for node_ip in overcloud_ip_list:
+ LOG.info('Introspecting node %s' % node_ip)
+ node = Node('intro-%s' % node_ip, address=node_ip,
+ user=self.overcloud_user)
+ node_mac = None
+ virsh_domain = None
+ server_name, _ = node.execute('hostname')
+ server_name = server_name.rstrip()
+ if 'overcloud-controller' in server_name:
+ node_type = 'controller'
+ elif 'overcloud-novacompute' in server_name:
+ node_type = 'compute'
+ else:
+ raise TripleOInspectorException('Unknown type '
+ '(controller/compute) %s '
+ % server_name)
+ try:
+ processutils.execute('ping -c 1 %s' % node_ip)
+ res, _ = processutils.execute('/usr/sbin/arp -a '
+ '%s' % node_ip)
+ node_mac = \
+ re.search('([0-9a-z]+:){5}[0-9a-z]+', res).group(0)
+ virsh_domain = \
+ TripleoHelper.get_virtual_node_name_from_mac(node_mac)
+ except AttributeError:
+ LOG.warning("Unable to find MAC address for node {"
+ "}".format(node_ip))
+
+ # find ovs controller and manager
+ ovs_controller = self.get_ovs_controller(node)
+ out, _ = node.execute('ovs-vsctl get-manager', as_root=True)
+ ovs_managers = out.rstrip().split("\n")
+ if all(ovs_manager == '' for ovs_manager in ovs_managers):
+ LOG.warning("OVS managers for node {} is empty!".format(
+ node_ip))
+ self.node_info['servers'][server_name] = {
+ 'address': node_ip,
+ 'user': self.overcloud_user,
+ 'type': node_type,
+ 'orig-ctl-mac': node_mac,
+ 'vNode-name': virsh_domain,
+ 'ovs-controller': ovs_controller,
+ 'ovs-managers': ovs_managers}
+
+ @staticmethod
+ def copy_ssh_id_and_overcloudrc(dest):
+ undercloud = TripleoHelper.get_undercloud()
+ # copy overcloudrc
+ undercloud.copy('from', dest, './overcloudrc')
+
+ # copy ssh id
+ undercloud.copy('from', dest, '.ssh/id_rsa')
+
+ @staticmethod
+ def get_ovs_controller(node):
+ # find ovs controller and manager
+ ovs_controller, _ = node.execute('ovs-vsctl get-controller '
+ 'br-int', as_root=True)
+ ovs_controller = ovs_controller.rstrip()
+ if ovs_controller == '':
+ LOG.warning("OVS controller for node {} is empty!".format(
+ node.address))
+ else:
+ return ovs_controller
+
+
+class TripleOInspectorException(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return self.value
+
+
+def main():
+ TripleOIntrospector().start()
+
+if __name__ == '__main__':
+ main()