Improvments in Makefile and Amulets
This commit is contained in:
14
Makefile
14
Makefile
@@ -1,14 +1,18 @@
|
|||||||
#!/usr/bin/make
|
#!/usr/bin/make
|
||||||
PYTHON := /usr/bin/env python
|
PYTHON := /usr/bin/env python
|
||||||
|
|
||||||
lint:
|
virtualenv:
|
||||||
@flake8 --exclude hooks/charmhelpers hooks
|
virtualenv .venv
|
||||||
@flake8 --exclude hooks/charmhelpers unit_tests
|
.venv/bin/pip install flake8 nose coverage mock pyyaml netifaces \
|
||||||
|
netaddr jinja2
|
||||||
|
|
||||||
|
lint: virtualenv
|
||||||
|
.venv/bin/flake8 --exclude hooks/charmhelpers hooks unit_tests tests
|
||||||
@charm proof
|
@charm proof
|
||||||
|
|
||||||
unit_test:
|
unit_test: virtualenv
|
||||||
@echo Starting tests...
|
@echo Starting tests...
|
||||||
@$(PYTHON) /usr/bin/nosetests --nologcapture unit_tests
|
@.venv/bin/nosetests --nologcapture --with-coverage unit_tests
|
||||||
|
|
||||||
bin/charm_helpers_sync.py:
|
bin/charm_helpers_sync.py:
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Once deployed this charm performs the configurations required for a PLUMgrid Dir
|
|||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
Step by step instructions on using the charm:
|
Instructions on using the charm:
|
||||||
|
|
||||||
juju deploy neutron-api
|
juju deploy neutron-api
|
||||||
juju deploy neutron-api-plumgrid
|
juju deploy neutron-api-plumgrid
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
|
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
|
||||||
|
|
||||||
# This file contains the class that generates context for PLUMgrid template files.
|
# This file contains the class that generates context
|
||||||
|
# for PLUMgrid template files.
|
||||||
|
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
config,
|
config,
|
||||||
@@ -21,7 +22,8 @@ from socket import gethostname as get_unit_hostname
|
|||||||
|
|
||||||
def _pg_dir_ips():
|
def _pg_dir_ips():
|
||||||
'''
|
'''
|
||||||
Inspects plumgrid-director peer relation and returns the ips of the peer directors
|
Inspects plumgrid-director peer relation and returns the
|
||||||
|
ips of the peer directors
|
||||||
'''
|
'''
|
||||||
pg_dir_ips = []
|
pg_dir_ips = []
|
||||||
for rid in relation_ids('director'):
|
for rid in relation_ids('director'):
|
||||||
@@ -58,7 +60,8 @@ class PGDirContext(context.NeutronContext):
|
|||||||
|
|
||||||
def pg_ctxt(self):
|
def pg_ctxt(self):
|
||||||
'''
|
'''
|
||||||
Generated Config for all PLUMgrid templates inside the templates folder.
|
Generated Config for all PLUMgrid templates inside the templates
|
||||||
|
folder.
|
||||||
'''
|
'''
|
||||||
pg_ctxt = super(PGDirContext, self).pg_ctxt()
|
pg_ctxt = super(PGDirContext, self).pg_ctxt()
|
||||||
if not pg_ctxt:
|
if not pg_ctxt:
|
||||||
@@ -66,7 +69,8 @@ class PGDirContext(context.NeutronContext):
|
|||||||
|
|
||||||
conf = config()
|
conf = config()
|
||||||
pg_dir_ips = _pg_dir_ips()
|
pg_dir_ips = _pg_dir_ips()
|
||||||
pg_dir_ips.append(str(get_address_in_network(network=None, fallback=get_host_ip(unit_get('private-address')))))
|
pg_dir_ips.append(str(get_address_in_network(network=None,
|
||||||
|
fallback=get_host_ip(unit_get('private-address')))))
|
||||||
pg_ctxt['director_ips'] = pg_dir_ips
|
pg_ctxt['director_ips'] = pg_dir_ips
|
||||||
pg_dir_ips_string = ''
|
pg_dir_ips_string = ''
|
||||||
single_ip = True
|
single_ip = True
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
# in this file.
|
# in this file.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
Hooks,
|
Hooks,
|
||||||
UnregisteredHookError,
|
UnregisteredHookError,
|
||||||
log,
|
log,
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
@@ -46,7 +47,6 @@ def install():
|
|||||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||||
load_iovisor()
|
load_iovisor()
|
||||||
ensure_mtu()
|
ensure_mtu()
|
||||||
post_pg_license()
|
|
||||||
add_lcm_key()
|
add_lcm_key()
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +83,20 @@ def config_changed():
|
|||||||
restart_pg()
|
restart_pg()
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('start')
|
||||||
|
def start():
|
||||||
|
'''
|
||||||
|
This hook is run when the charm is started.
|
||||||
|
'''
|
||||||
|
if config('plumgrid-license-key') is not None:
|
||||||
|
count = 0
|
||||||
|
while (count < 10):
|
||||||
|
if post_pg_license():
|
||||||
|
break
|
||||||
|
count = count + 1
|
||||||
|
time.sleep(15)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('stop')
|
@hooks.hook('stop')
|
||||||
def stop():
|
def stop():
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ def remove_iovisor():
|
|||||||
'''
|
'''
|
||||||
Removes iovisor kernel module.
|
Removes iovisor kernel module.
|
||||||
'''
|
'''
|
||||||
_exec_cmd(cmd=['rmmod', 'iovisor'], error_msg='Error Loading IOVisor Kernel Module')
|
_exec_cmd(cmd=['rmmod', 'iovisor'],
|
||||||
|
error_msg='Error Loading IOVisor Kernel Module')
|
||||||
|
|
||||||
|
|
||||||
def check_interface_type():
|
def check_interface_type():
|
||||||
@@ -232,16 +233,24 @@ def post_pg_license():
|
|||||||
LICENSE_GET_PATH = 'https://%s/0/tenant_manager/licenses' % PG_VIP
|
LICENSE_GET_PATH = 'https://%s/0/tenant_manager/licenses' % PG_VIP
|
||||||
PG_CURL = '%s/opt/pg/scripts/pg_curl.sh' % PG_LXC_PATH
|
PG_CURL = '%s/opt/pg/scripts/pg_curl.sh' % PG_LXC_PATH
|
||||||
license = {"key1": {"license": key}}
|
license = {"key1": {"license": key}}
|
||||||
licence_post_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_POST_PATH, '-d', json.dumps(license)]
|
licence_post_cmd = [
|
||||||
|
PG_CURL,
|
||||||
|
'-u',
|
||||||
|
'plumgrid:plumgrid',
|
||||||
|
LICENSE_POST_PATH,
|
||||||
|
'-d',
|
||||||
|
json.dumps(license)
|
||||||
|
]
|
||||||
licence_get_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_GET_PATH]
|
licence_get_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_GET_PATH]
|
||||||
try:
|
try:
|
||||||
old_license = subprocess.check_output(licence_get_cmd)
|
old_license = subprocess.check_output(licence_get_cmd)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
log('Virtual IP Changed')
|
log('No response from specified virtual IP')
|
||||||
return 0
|
return 0
|
||||||
_exec_cmd(cmd=licence_post_cmd, error_msg='Unable to post License', fatal=False)
|
_exec_cmd(cmd=licence_post_cmd,
|
||||||
|
error_msg='Unable to post License', fatal=False)
|
||||||
new_license = subprocess.check_output(licence_get_cmd)
|
new_license = subprocess.check_output(licence_get_cmd)
|
||||||
if old_license == new_license:
|
if old_license == new_license:
|
||||||
log('PLUMgrid License already posted')
|
log('No change in PLUMgrid License')
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
1
hooks/start
Symbolic link
1
hooks/start
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
pg_dir_hooks.py
|
||||||
@@ -10,7 +10,7 @@ class TestDeployment(unittest.TestCase):
|
|||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
cls.deployment = amulet.Deployment(series='trusty')
|
cls.deployment = amulet.Deployment(series='trusty')
|
||||||
cls.deployment.load_bundle_file(
|
cls.deployment.load_bundle_file(
|
||||||
bundle_file='files/plumgrid-director.yaml',
|
bundle_file='tests/files/plumgrid-director.yaml',
|
||||||
deployment_name='test')
|
deployment_name='test')
|
||||||
try:
|
try:
|
||||||
cls.deployment.setup(timeout=2000)
|
cls.deployment.setup(timeout=2000)
|
||||||
@@ -46,9 +46,11 @@ class PGDirContextTest(CharmTestCase):
|
|||||||
@patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip')
|
@patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip')
|
||||||
@patch.object(context, '_pg_dir_ips')
|
@patch.object(context, '_pg_dir_ips')
|
||||||
@patch.object(utils, 'check_interface_type')
|
@patch.object(utils, 'check_interface_type')
|
||||||
def test_neutroncc_context_api_rel(self, _int_type, _pg_dir_ips, _unit_priv_ip, _npa, _ens_pkgs,
|
def test_neutroncc_context_api_rel(self, _int_type, _pg_dir_ips,
|
||||||
_save_ff, _https, _is_clus, _unit_get,
|
_unit_priv_ip, _npa, _ens_pkgs,
|
||||||
_config, _runits, _rids, _rget):
|
_save_ff, _https, _is_clus,
|
||||||
|
_unit_get, _config, _runits, _rids,
|
||||||
|
_rget):
|
||||||
def mock_npa(plugin, section, manager):
|
def mock_npa(plugin, section, manager):
|
||||||
if section == "driver":
|
if section == "driver":
|
||||||
return "neutron.randomdriver"
|
return "neutron.randomdriver"
|
||||||
@@ -87,7 +89,9 @@ class PGDirContextTest(CharmTestCase):
|
|||||||
'label': 'node0',
|
'label': 'node0',
|
||||||
'fabric_mode': 'host',
|
'fabric_mode': 'host',
|
||||||
'virtual_router_id': '250',
|
'virtual_router_id': '250',
|
||||||
'director_ips': ['192.168.100.202', '192.168.100.203', '192.168.100.201'],
|
'director_ips': ['192.168.100.202', '192.168.100.203',
|
||||||
'director_ips_string': '192.168.100.202,192.168.100.203,192.168.100.201',
|
'192.168.100.201'],
|
||||||
|
'director_ips_string':
|
||||||
|
'192.168.100.202,192.168.100.203,192.168.100.201',
|
||||||
}
|
}
|
||||||
self.assertEquals(expect, napi_ctxt())
|
self.assertEquals(expect, napi_ctxt())
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ TO_PATCH = [
|
|||||||
'ensure_mtu',
|
'ensure_mtu',
|
||||||
'add_lcm_key',
|
'add_lcm_key',
|
||||||
'determine_packages',
|
'determine_packages',
|
||||||
'post_pg_license'
|
'post_pg_license',
|
||||||
|
'config'
|
||||||
]
|
]
|
||||||
NEUTRON_CONF_DIR = "/etc/neutron"
|
NEUTRON_CONF_DIR = "/etc/neutron"
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ class PGDirHooksTests(CharmTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(PGDirHooksTests, self).setUp(hooks, TO_PATCH)
|
super(PGDirHooksTests, self).setUp(hooks, TO_PATCH)
|
||||||
|
self.config.side_effect = self.test_config.get
|
||||||
hooks.hooks._config_save = False
|
hooks.hooks._config_save = False
|
||||||
|
|
||||||
def _call_hook(self, hookname):
|
def _call_hook(self, hookname):
|
||||||
@@ -56,7 +58,6 @@ class PGDirHooksTests(CharmTestCase):
|
|||||||
])
|
])
|
||||||
self.load_iovisor.assert_called_with()
|
self.load_iovisor.assert_called_with()
|
||||||
self.ensure_mtu.assert_called_with()
|
self.ensure_mtu.assert_called_with()
|
||||||
self.post_pg_license.assert_called_with()
|
|
||||||
self.add_lcm_key.assert_called_with()
|
self.add_lcm_key.assert_called_with()
|
||||||
|
|
||||||
def test_config_changed_hook(self):
|
def test_config_changed_hook(self):
|
||||||
@@ -77,6 +78,10 @@ class PGDirHooksTests(CharmTestCase):
|
|||||||
self.CONFIGS.write_all.assert_called_with()
|
self.CONFIGS.write_all.assert_called_with()
|
||||||
self.restart_pg.assert_called_with()
|
self.restart_pg.assert_called_with()
|
||||||
|
|
||||||
|
def test_start(self):
|
||||||
|
self._call_hook('start')
|
||||||
|
self.test_config.set('plumgrid-license-key', None)
|
||||||
|
|
||||||
def test_stop(self):
|
def test_stop(self):
|
||||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||||
self._call_hook('stop')
|
self._call_hook('stop')
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class TestPGDirUtils(CharmTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPGDirUtils, self).setUp(nutils, TO_PATCH)
|
super(TestPGDirUtils, self).setUp(nutils, TO_PATCH)
|
||||||
#self.config.side_effect = self.test_config.get
|
# self.config.side_effect = self.test_config.get
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Reset cached cache
|
# Reset cached cache
|
||||||
@@ -50,12 +50,12 @@ class TestPGDirUtils(CharmTestCase):
|
|||||||
self.os_release.return_value = 'trusty'
|
self.os_release.return_value = 'trusty'
|
||||||
templating.OSConfigRenderer.side_effect = _mock_OSConfigRenderer
|
templating.OSConfigRenderer.side_effect = _mock_OSConfigRenderer
|
||||||
_regconfs = nutils.register_configs()
|
_regconfs = nutils.register_configs()
|
||||||
confs = ['/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/keepalived.conf',
|
confs = [nutils.PG_KA_CONF,
|
||||||
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/plumgrid.conf',
|
nutils.PG_CONF,
|
||||||
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/nginx.conf',
|
nutils.PG_DEF_CONF,
|
||||||
'/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hostname',
|
nutils.PG_HN_CONF,
|
||||||
'/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hosts',
|
nutils.PG_HS_CONF,
|
||||||
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/ifcs.conf']
|
nutils.PG_IFCS_CONF]
|
||||||
self.assertItemsEqual(_regconfs.configs, confs)
|
self.assertItemsEqual(_regconfs.configs, confs)
|
||||||
|
|
||||||
def test_resource_map(self):
|
def test_resource_map(self):
|
||||||
@@ -67,10 +67,9 @@ class TestPGDirUtils(CharmTestCase):
|
|||||||
|
|
||||||
def test_restart_map(self):
|
def test_restart_map(self):
|
||||||
_restart_map = nutils.restart_map()
|
_restart_map = nutils.restart_map()
|
||||||
PG_KA_CONF = '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/keepalived.conf'
|
|
||||||
expect = OrderedDict([
|
expect = OrderedDict([
|
||||||
(nutils.PG_CONF, ['plumgrid']),
|
(nutils.PG_CONF, ['plumgrid']),
|
||||||
(PG_KA_CONF, ['plumgrid']),
|
(nutils.PG_KA_CONF, ['plumgrid']),
|
||||||
(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']),
|
||||||
|
|||||||
Reference in New Issue
Block a user