From 77a25e2225013a622677499a7f019bdf91f15da3 Mon Sep 17 00:00:00 2001 From: plumgrid Date: Sun, 7 Aug 2016 14:46:12 -0400 Subject: [PATCH] Configuring analyst for OPSVM Ticket: [SOL-1144] Signed-off-by: Junaid Ali --- hooks/pg_gw_hooks.py | 4 +++- hooks/pg_gw_utils.py | 26 ++++++++++++++++++++++++++ unit_tests/test_pg_gw_hooks.py | 3 ++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 5818cea..5e74500 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -35,7 +35,8 @@ from pg_gw_utils import ( restart_on_change, restart_on_stop, director_cluster_ready, - configure_pg_sources + configure_pg_sources, + configure_analyst_opsvm ) hooks = Hooks() @@ -69,6 +70,7 @@ def plumgrid_changed(): ''' if director_cluster_ready(): ensure_mtu() + configure_analyst_opsvm() CONFIGS.write_all() diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index ebd5899..ad62133 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -93,6 +93,32 @@ def configure_pg_sources(): log('Unable to update /etc/apt/sources.list') +def configure_analyst_opsvm(): + ''' + Configures Anaylyst for OPSVM + ''' + opsvm_ip = pg_gw_context._pg_dir_context()['opsvm_ip'] + if not service_running('plumgrid'): + restart_pg() + NS_ENTER = ('/opt/local/bin/nsenter -t $(ps ho pid --ppid $(cat ' + '/var/run/libvirt/lxc/plumgrid.pid)) -m -n -u -i -p ') + sigmund_stop = NS_ENTER + '/usr/bin/service plumgrid-sigmund stop' + sigmund_status = NS_ENTER \ + + '/usr/bin/service plumgrid-sigmund status' + sigmund_autoboot = NS_ENTER \ + + '/usr/bin/sigmund-configure --ip {0} --start --autoboot' \ + .format(opsvm_ip) + try: + status = subprocess.check_output(sigmund_status, shell=True) + if 'start/running' in status: + if subprocess.call(sigmund_stop, shell=True): + log('plumgrid-sigmund couldn\'t be stopped!') + return + subprocess.check_call(sigmund_autoboot, shell=True) + except: + log('plumgrid-sigmund couldn\'t be started!') + + def determine_packages(): ''' Returns list of packages required by PLUMgrid Gateway as specified diff --git a/unit_tests/test_pg_gw_hooks.py b/unit_tests/test_pg_gw_hooks.py index 194d0c0..101ea49 100644 --- a/unit_tests/test_pg_gw_hooks.py +++ b/unit_tests/test_pg_gw_hooks.py @@ -30,7 +30,8 @@ TO_PATCH = [ 'determine_packages', 'load_iptables', 'director_cluster_ready', - 'status_set' + 'status_set', + 'configure_analyst_opsvm' ] NEUTRON_CONF_DIR = "/etc/neutron"