Updated unit tests for HA
This commit is contained in:
@@ -11,7 +11,6 @@ Step by step instructions on using the charm:
|
||||
juju deploy plumgrid-director
|
||||
|
||||
juju add-relation neutron-api neutron-api-plumgrid
|
||||
juju add-relation neutron-api-plumgrid plumgrid-director
|
||||
|
||||
For plumgrid-director to work make the configuration in the neutron-api and neutron-api-plumgrid charms as specified in the configuration section below.
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from charmhelpers.contrib.network.ip import get_address_in_network
|
||||
import re
|
||||
from socket import gethostname as get_unit_hostname
|
||||
|
||||
|
||||
def _pg_dir_ips():
|
||||
'''
|
||||
Inspects plumgrid-director peer relation and returns the ips of the peer directors
|
||||
@@ -29,6 +30,7 @@ def _pg_dir_ips():
|
||||
pg_dir_ips.append(rdata['private-address'])
|
||||
return pg_dir_ips
|
||||
|
||||
|
||||
class PGDirContext(context.NeutronContext):
|
||||
|
||||
@property
|
||||
@@ -64,8 +66,7 @@ class PGDirContext(context.NeutronContext):
|
||||
|
||||
conf = config()
|
||||
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_dir_ips_string = ''
|
||||
single_ip = True
|
||||
|
||||
@@ -21,7 +21,6 @@ from charmhelpers.fetch import (
|
||||
|
||||
from pg_dir_utils import (
|
||||
register_configs,
|
||||
ensure_files,
|
||||
restart_pg,
|
||||
stop_pg,
|
||||
determine_packages,
|
||||
@@ -46,28 +45,18 @@ def install():
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
|
||||
|
||||
@hooks.hook('plumgrid-plugin-relation-joined')
|
||||
def plumgrid_dir():
|
||||
'''
|
||||
This hook is run when relation between neutron-api-plumgrid
|
||||
and plumgrid-director is made.
|
||||
'''
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
@hooks.hook('director-relation-joined')
|
||||
def dir_joined():
|
||||
ensure_files()
|
||||
'''
|
||||
This hook is run when a unit of director is added.
|
||||
'''
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('config-changed')
|
||||
def config_changed():
|
||||
'''
|
||||
@@ -81,7 +70,6 @@ def config_changed():
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
@@ -103,15 +103,6 @@ def restart_map():
|
||||
return {cfg: rscs['services'] for cfg, rscs in resource_map().iteritems()}
|
||||
|
||||
|
||||
def ensure_files():
|
||||
'''
|
||||
Ensures PLUMgrid specific files exist before templates are written.
|
||||
'''
|
||||
#_exec_cmd(cmd=['mkdir', '/etc/nova'])
|
||||
#_exec_cmd(cmd=['touch', 'neutron_plugin.conf'])
|
||||
pass
|
||||
|
||||
|
||||
def restart_pg():
|
||||
'''
|
||||
Stops and Starts PLUMgrid service after flushing iptables.
|
||||
@@ -144,6 +135,7 @@ def remove_iovisor():
|
||||
'''
|
||||
_exec_cmd(cmd=['rmmod', 'iovisor'], error_msg='Error Loading IOVisor Kernel Module')
|
||||
|
||||
|
||||
def check_interface_type():
|
||||
'''
|
||||
Checks the interface. Support added for AWS deployments. There are 2
|
||||
@@ -159,6 +151,7 @@ def check_interface_type():
|
||||
else:
|
||||
return default_interface
|
||||
|
||||
|
||||
def ensure_mtu():
|
||||
'''
|
||||
Ensures required MTU of the underlying networking of the node.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from test_utils import CharmTestCase
|
||||
from mock import patch
|
||||
import pg_dir_context as context
|
||||
import pg_dir_utils as utils
|
||||
import charmhelpers
|
||||
|
||||
TO_PATCH = [
|
||||
#'resolve_address',
|
||||
'config',
|
||||
'unit_get',
|
||||
'get_host_ip',
|
||||
@@ -44,7 +44,9 @@ class PGDirContextTest(CharmTestCase):
|
||||
@patch.object(charmhelpers.contrib.openstack.context,
|
||||
'neutron_plugin_attribute')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip')
|
||||
def test_neutroncc_context_api_rel(self, _unit_priv_ip, _npa, _ens_pkgs,
|
||||
@patch.object(context, '_pg_dir_ips')
|
||||
@patch.object(utils, 'check_interface_type')
|
||||
def test_neutroncc_context_api_rel(self, _int_type, _pg_dir_ips, _unit_priv_ip, _npa, _ens_pkgs,
|
||||
_save_ff, _https, _is_clus, _unit_get,
|
||||
_config, _runits, _rids, _rget):
|
||||
def mock_npa(plugin, section, manager):
|
||||
@@ -68,6 +70,8 @@ class PGDirContextTest(CharmTestCase):
|
||||
_unit_priv_ip.return_value = '192.168.100.201'
|
||||
self.get_unit_hostname.return_value = 'node0'
|
||||
self.get_host_ip.return_value = '192.168.100.201'
|
||||
_pg_dir_ips.return_value = ['192.168.100.202', '192.168.100.203']
|
||||
_int_type.return_value = 'juju-br0'
|
||||
napi_ctxt = context.PGDirContext()
|
||||
expect = {
|
||||
'config': 'neutron.randomconfig',
|
||||
@@ -83,5 +87,7 @@ class PGDirContextTest(CharmTestCase):
|
||||
'label': 'node0',
|
||||
'fabric_mode': 'host',
|
||||
'virtual_router_id': '250',
|
||||
'director_ips': ['192.168.100.202', '192.168.100.203', '192.168.100.201'],
|
||||
'director_ips_string': '192.168.100.202,192.168.100.203,192.168.100.201',
|
||||
}
|
||||
self.assertEquals(expect, napi_ctxt())
|
||||
|
||||
@@ -22,7 +22,6 @@ TO_PATCH = [
|
||||
'CONFIGS',
|
||||
'log',
|
||||
'configure_sources',
|
||||
'ensure_files',
|
||||
'stop_pg',
|
||||
'restart_pg',
|
||||
'load_iovisor',
|
||||
@@ -56,7 +55,6 @@ class PGDirHooksTests(CharmTestCase):
|
||||
])
|
||||
self.load_iovisor.assert_called_with()
|
||||
self.ensure_mtu.assert_called_with()
|
||||
self.ensure_files.assert_called_with()
|
||||
self.add_lcm_key.assert_called_with()
|
||||
|
||||
def test_config_changed_hook(self):
|
||||
@@ -71,7 +69,6 @@ class PGDirHooksTests(CharmTestCase):
|
||||
])
|
||||
self.load_iovisor.assert_called_with()
|
||||
self.ensure_mtu.assert_called_with()
|
||||
self.ensure_files.assert_called_with()
|
||||
self.add_lcm_key.assert_called_with()
|
||||
self.CONFIGS.write_all.assert_called_with()
|
||||
self.restart_pg.assert_called_with()
|
||||
|
||||
Reference in New Issue
Block a user