OPSVM Changes - Ticket: [SOL-830]
- Getting OPSVM IP from charm configs - Making OPSVM specific changes - Setting OPSVM IP in relation with edge/gw - Cleaned code in various functions - Added restart_on_change decorater function that restarts plumgrid service only when there has been any change in the configuration files - Removed restart of plumgrid service when only two directors are available - Fixed unit tests accordingly
This commit is contained in:
commit
2b71d6592c
@ -55,3 +55,7 @@ options:
|
|||||||
default: null
|
default: null
|
||||||
type: string
|
type: string
|
||||||
description: Provide the PLUMgrid ONS License key.
|
description: Provide the PLUMgrid ONS License key.
|
||||||
|
opsvm-ip:
|
||||||
|
default: 127.0.0.1
|
||||||
|
type: string
|
||||||
|
description: IP address of the PLUMgrid Operations VM Management interface.
|
||||||
|
@ -31,12 +31,11 @@ def _pg_dir_ips():
|
|||||||
Inspects plumgrid-director peer relation and returns the
|
Inspects plumgrid-director peer relation and returns the
|
||||||
ips of the peer directors
|
ips of the peer directors
|
||||||
'''
|
'''
|
||||||
pg_dir_ips = []
|
return [get_host_ip(rdata['private-address'])
|
||||||
for rid in relation_ids('director'):
|
for rid in relation_ids("director")
|
||||||
for unit in related_units(rid):
|
for rdata in
|
||||||
rdata = relation_get(rid=rid, unit=unit)
|
(relation_get(rid=rid, unit=unit) for unit in related_units(rid))
|
||||||
pg_dir_ips.append(get_host_ip(rdata['private-address']))
|
if rdata]
|
||||||
return pg_dir_ips
|
|
||||||
|
|
||||||
|
|
||||||
class PGDirContext(context.NeutronContext):
|
class PGDirContext(context.NeutronContext):
|
||||||
@ -79,18 +78,15 @@ class PGDirContext(context.NeutronContext):
|
|||||||
fallback=get_host_ip(unit_get('private-address')))))
|
fallback=get_host_ip(unit_get('private-address')))))
|
||||||
pg_dir_ips = sorted(pg_dir_ips)
|
pg_dir_ips = sorted(pg_dir_ips)
|
||||||
pg_ctxt['director_ips'] = pg_dir_ips
|
pg_ctxt['director_ips'] = pg_dir_ips
|
||||||
pg_dir_ips_string = ''
|
dir_count = len(pg_dir_ips)
|
||||||
single_ip = True
|
pg_ctxt['director_ips_string'] = (str(pg_dir_ips[0]) + ',' +
|
||||||
for ip in pg_dir_ips:
|
str(pg_dir_ips[1]) + ',' +
|
||||||
if single_ip:
|
str(pg_dir_ips[2])
|
||||||
pg_dir_ips_string = str(ip)
|
if dir_count == 3 else
|
||||||
single_ip = False
|
str(pg_dir_ips[0]))
|
||||||
else:
|
PG_VIP = conf['plumgrid-virtual-ip']
|
||||||
pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip)
|
|
||||||
pg_ctxt['director_ips_string'] = pg_dir_ips_string
|
|
||||||
PG_VIP = config('plumgrid-virtual-ip')
|
|
||||||
if is_ip(PG_VIP):
|
if is_ip(PG_VIP):
|
||||||
pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']
|
pg_ctxt['virtual_ip'] = PG_VIP
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid PLUMgrid Virtual IP Provided')
|
raise ValueError('Invalid PLUMgrid Virtual IP Provided')
|
||||||
unit_hostname = gethostname()
|
unit_hostname = gethostname()
|
||||||
@ -103,5 +99,6 @@ class PGDirContext(context.NeutronContext):
|
|||||||
pg_ctxt['fabric_mode'] = 'host'
|
pg_ctxt['fabric_mode'] = 'host'
|
||||||
virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip'])
|
virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip'])
|
||||||
pg_ctxt['virtual_router_id'] = virtual_ip_array[3]
|
pg_ctxt['virtual_router_id'] = virtual_ip_array[3]
|
||||||
|
pg_ctxt['opsvm_ip'] = conf['opsvm-ip']
|
||||||
|
|
||||||
return pg_ctxt
|
return pg_ctxt
|
||||||
|
@ -8,23 +8,26 @@
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from charmhelpers.core.host import service_running
|
from charmhelpers.core.host import service_running
|
||||||
|
from charmhelpers.contrib.network.ip import is_ip
|
||||||
|
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
Hooks,
|
Hooks,
|
||||||
UnregisteredHookError,
|
UnregisteredHookError,
|
||||||
log,
|
log,
|
||||||
config,
|
config,
|
||||||
|
relation_set,
|
||||||
|
relation_ids
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
apt_install,
|
apt_install,
|
||||||
apt_purge,
|
|
||||||
configure_sources,
|
configure_sources,
|
||||||
)
|
)
|
||||||
|
|
||||||
from pg_dir_utils import (
|
from pg_dir_utils import (
|
||||||
register_configs,
|
register_configs,
|
||||||
restart_pg,
|
restart_pg,
|
||||||
|
restart_map,
|
||||||
stop_pg,
|
stop_pg,
|
||||||
determine_packages,
|
determine_packages,
|
||||||
load_iovisor,
|
load_iovisor,
|
||||||
@ -33,7 +36,9 @@ from pg_dir_utils import (
|
|||||||
add_lcm_key,
|
add_lcm_key,
|
||||||
post_pg_license,
|
post_pg_license,
|
||||||
fabric_interface_changed,
|
fabric_interface_changed,
|
||||||
load_iptables
|
load_iptables,
|
||||||
|
restart_on_change,
|
||||||
|
director_cluster_ready
|
||||||
)
|
)
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
@ -56,12 +61,26 @@ def install():
|
|||||||
|
|
||||||
|
|
||||||
@hooks.hook('director-relation-joined')
|
@hooks.hook('director-relation-joined')
|
||||||
|
@restart_on_change(restart_map())
|
||||||
def dir_joined():
|
def dir_joined():
|
||||||
'''
|
'''
|
||||||
This hook is run when a unit of director is added.
|
This hook is run when a unit of director is added.
|
||||||
'''
|
'''
|
||||||
|
if director_cluster_ready():
|
||||||
|
ensure_mtu()
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
restart_pg()
|
|
||||||
|
|
||||||
|
@hooks.hook('plumgrid-relation-joined')
|
||||||
|
def plumgrid_joined(relation_id=None):
|
||||||
|
'''
|
||||||
|
This hook is run when relation with edge or gateway is created.
|
||||||
|
'''
|
||||||
|
opsvm_ip = config('opsvm-ip')
|
||||||
|
if not is_ip(opsvm_ip):
|
||||||
|
raise ValueError('Incorrect OPSVM IP specified')
|
||||||
|
else:
|
||||||
|
relation_set(relation_id=relation_id, opsvm_ip=opsvm_ip)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('config-changed')
|
@hooks.hook('config-changed')
|
||||||
@ -96,6 +115,10 @@ def config_changed():
|
|||||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||||
remove_iovisor()
|
remove_iovisor()
|
||||||
load_iovisor()
|
load_iovisor()
|
||||||
|
if charm_config.changed('opsvm-ip'):
|
||||||
|
for rid in relation_ids('plumgrid'):
|
||||||
|
plumgrid_joined(rid)
|
||||||
|
stop_pg()
|
||||||
ensure_mtu()
|
ensure_mtu()
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
if not service_running('plumgrid'):
|
if not service_running('plumgrid'):
|
||||||
@ -112,16 +135,17 @@ def start():
|
|||||||
while (count < 10):
|
while (count < 10):
|
||||||
if post_pg_license():
|
if post_pg_license():
|
||||||
break
|
break
|
||||||
count = count + 1
|
count += 1
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('upgrade-charm')
|
@hooks.hook('upgrade-charm')
|
||||||
|
@restart_on_change(restart_map())
|
||||||
def upgrade_charm():
|
def upgrade_charm():
|
||||||
'''
|
'''
|
||||||
This hook is run when the charm is upgraded
|
This hook is run when the charm is upgraded
|
||||||
'''
|
'''
|
||||||
load_iptables()
|
ensure_mtu()
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
|
|
||||||
|
|
||||||
@ -131,10 +155,6 @@ def stop():
|
|||||||
This hook is run when the charm is destroyed.
|
This hook is run when the charm is destroyed.
|
||||||
'''
|
'''
|
||||||
stop_pg()
|
stop_pg()
|
||||||
remove_iovisor()
|
|
||||||
pkgs = determine_packages()
|
|
||||||
for pkg in pkgs:
|
|
||||||
apt_purge(pkg, fatal=False)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -12,7 +12,6 @@ from socket import gethostname as get_unit_hostname
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
|
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
|
||||||
from charmhelpers.contrib.openstack import templating
|
from charmhelpers.contrib.openstack import templating
|
||||||
from charmhelpers.core.host import set_nic_mtu
|
|
||||||
from charmhelpers.contrib.storage.linux.ceph import modprobe
|
from charmhelpers.contrib.storage.linux.ceph import modprobe
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
log,
|
log,
|
||||||
@ -30,7 +29,9 @@ from charmhelpers.contrib.network.ip import (
|
|||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
service_start,
|
service_start,
|
||||||
service_stop,
|
service_stop,
|
||||||
service_running
|
service_running,
|
||||||
|
path_hash,
|
||||||
|
set_nic_mtu
|
||||||
)
|
)
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
apt_cache,
|
apt_cache,
|
||||||
@ -50,6 +51,7 @@ PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH
|
|||||||
PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
|
PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
|
||||||
PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
|
PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
|
||||||
PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
|
PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
|
||||||
|
OPS_CONF = '%s/conf/etc/00-pg.conf' % PG_LXC_DATA_PATH
|
||||||
AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
|
AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
|
||||||
TEMP_LICENSE_FILE = '/tmp/license'
|
TEMP_LICENSE_FILE = '/tmp/license'
|
||||||
|
|
||||||
@ -74,6 +76,10 @@ BASE_RESOURCE_MAP = OrderedDict([
|
|||||||
'services': ['plumgrid'],
|
'services': ['plumgrid'],
|
||||||
'contexts': [pg_dir_context.PGDirContext()],
|
'contexts': [pg_dir_context.PGDirContext()],
|
||||||
}),
|
}),
|
||||||
|
(OPS_CONF, {
|
||||||
|
'services': ['plumgrid'],
|
||||||
|
'contexts': [pg_dir_context.PGDirContext()],
|
||||||
|
}),
|
||||||
(PG_IFCS_CONF, {
|
(PG_IFCS_CONF, {
|
||||||
'services': [],
|
'services': [],
|
||||||
'contexts': [pg_dir_context.PGDirContext()],
|
'contexts': [pg_dir_context.PGDirContext()],
|
||||||
@ -401,3 +407,24 @@ def get_cidr_from_iface(interface):
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def director_cluster_ready():
|
||||||
|
dirs_count = len(pg_dir_context._pg_dir_ips())
|
||||||
|
return True if dirs_count == 2 else False
|
||||||
|
|
||||||
|
|
||||||
|
def restart_on_change(restart_map):
|
||||||
|
"""
|
||||||
|
Restart services based on configuration files changing
|
||||||
|
"""
|
||||||
|
def wrap(f):
|
||||||
|
def wrapped_f(*args, **kwargs):
|
||||||
|
checksums = {path: path_hash(path) for path in restart_map}
|
||||||
|
f(*args, **kwargs)
|
||||||
|
for path in restart_map:
|
||||||
|
if path_hash(path) != checksums[path]:
|
||||||
|
restart_pg()
|
||||||
|
break
|
||||||
|
return wrapped_f
|
||||||
|
return wrap
|
||||||
|
1
hooks/plumgrid-relation-joined
Symbolic link
1
hooks/plumgrid-relation-joined
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
pg_dir_hooks.py
|
1
templates/kilo/00-pg.conf
Normal file
1
templates/kilo/00-pg.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}":syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json
|
@ -13,7 +13,7 @@ upstream pgCli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upstream pgMW {
|
upstream pgMW {
|
||||||
server 127.0.0.1:4000;
|
server {{ opsvm_ip }}:4000;
|
||||||
}
|
}
|
||||||
|
|
||||||
map $http_upgrade $connection_upgrade {
|
map $http_upgrade $connection_upgrade {
|
||||||
|
@ -59,7 +59,8 @@ class PGDirContextTest(CharmTestCase):
|
|||||||
if section == "config":
|
if section == "config":
|
||||||
return "neutron.randomconfig"
|
return "neutron.randomconfig"
|
||||||
|
|
||||||
config = {'plumgrid-virtual-ip': "192.168.100.250"}
|
config = {'plumgrid-virtual-ip': "192.168.100.250",
|
||||||
|
'opsvm-ip': '127.0.0.1'}
|
||||||
|
|
||||||
def mock_config(key=None):
|
def mock_config(key=None):
|
||||||
if key:
|
if key:
|
||||||
@ -99,5 +100,6 @@ class PGDirContextTest(CharmTestCase):
|
|||||||
'192.168.100.203'],
|
'192.168.100.203'],
|
||||||
'director_ips_string':
|
'director_ips_string':
|
||||||
'192.168.100.201,192.168.100.202,192.168.100.203',
|
'192.168.100.201,192.168.100.202,192.168.100.203',
|
||||||
|
'opsvm_ip': '127.0.0.1',
|
||||||
}
|
}
|
||||||
self.assertEquals(expect, napi_ctxt())
|
self.assertEquals(expect, napi_ctxt())
|
||||||
|
@ -20,7 +20,6 @@ utils.restart_map = _map
|
|||||||
TO_PATCH = [
|
TO_PATCH = [
|
||||||
'remove_iovisor',
|
'remove_iovisor',
|
||||||
'apt_install',
|
'apt_install',
|
||||||
'apt_purge',
|
|
||||||
'CONFIGS',
|
'CONFIGS',
|
||||||
'log',
|
'log',
|
||||||
'configure_sources',
|
'configure_sources',
|
||||||
@ -67,8 +66,5 @@ class PGDirHooksTests(CharmTestCase):
|
|||||||
self.test_config.set('plumgrid-license-key', None)
|
self.test_config.set('plumgrid-license-key', None)
|
||||||
|
|
||||||
def test_stop(self):
|
def test_stop(self):
|
||||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
|
||||||
self._call_hook('stop')
|
self._call_hook('stop')
|
||||||
self.stop_pg.assert_called_with()
|
self.stop_pg.assert_called_with()
|
||||||
self.remove_iovisor.assert_called_with()
|
|
||||||
self.determine_packages.return_value = _pkgs
|
|
||||||
|
@ -55,7 +55,8 @@ class TestPGDirUtils(CharmTestCase):
|
|||||||
nutils.PG_DEF_CONF,
|
nutils.PG_DEF_CONF,
|
||||||
nutils.PG_HN_CONF,
|
nutils.PG_HN_CONF,
|
||||||
nutils.PG_HS_CONF,
|
nutils.PG_HS_CONF,
|
||||||
nutils.PG_IFCS_CONF]
|
nutils.PG_IFCS_CONF,
|
||||||
|
nutils.OPS_CONF]
|
||||||
self.assertItemsEqual(_regconfs.configs, confs)
|
self.assertItemsEqual(_regconfs.configs, confs)
|
||||||
|
|
||||||
def test_resource_map(self):
|
def test_resource_map(self):
|
||||||
@ -73,6 +74,7 @@ class TestPGDirUtils(CharmTestCase):
|
|||||||
(nutils.PG_DEF_CONF, ['plumgrid']),
|
(nutils.PG_DEF_CONF, ['plumgrid']),
|
||||||
(nutils.PG_HN_CONF, ['plumgrid']),
|
(nutils.PG_HN_CONF, ['plumgrid']),
|
||||||
(nutils.PG_HS_CONF, ['plumgrid']),
|
(nutils.PG_HS_CONF, ['plumgrid']),
|
||||||
|
(nutils.OPS_CONF, ['plumgrid']),
|
||||||
(nutils.PG_IFCS_CONF, []),
|
(nutils.PG_IFCS_CONF, []),
|
||||||
])
|
])
|
||||||
self.assertEqual(expect, _restart_map)
|
self.assertEqual(expect, _restart_map)
|
||||||
|
Loading…
Reference in New Issue
Block a user