[gnuoy,r=james-page] Add NSX support to neutron-api.

This commit is contained in:
James Page 2014-10-14 17:12:41 +01:00
commit a4e66e3217
6 changed files with 97 additions and 11 deletions

View File

@ -55,7 +55,7 @@ options:
Neutron plugin to use for network management; supports
.
ovs - OpenvSwitch Plugin
nvp - Nicira Network Virtualization Platform
nsx - VMWare NSX
.
overlay-network-type:
default: gre
@ -165,4 +165,29 @@ options:
The CPU core multiplier to use when configuring worker processes for
Neutron. By default, the number of workers for each daemon is set to
twice the number of CPU cores a service unit has.
# VMware NSX plugin configuration
nsx-controllers:
type: string
default:
description: Space delimited addresses of NSX controllers
nsx-username:
type: string
default: admin
description: Username to connect to NSX controllers with
nsx-password:
type: string
default: admin
description: Password to connect to NSX controllers with
nsx-tz-uuid:
type: string
default:
description: |
This is uuid of the default NSX Transport zone that will be used for
creating tunneled isolated Quantum networks. It needs to be created
in NSX before starting Quantum with the nsx plugin.
nsx-l3-uuid:
type: string
default:
description: |
This is uuid of the default NSX L3 Gateway Service.
# end of NSX configuration

View File

@ -80,6 +80,16 @@ class NeutronCCContext(context.NeutronContext):
def __call__(self):
from neutron_api_utils import api_port
ctxt = super(NeutronCCContext, self).__call__()
if config('neutron-plugin') == 'nsx':
ctxt['nsx_username'] = config('nsx-username')
ctxt['nsx_password'] = config('nsx-password')
ctxt['nsx_tz_uuid'] = config('nsx-tz-uuid')
ctxt['nsx_l3_uuid'] = config('nsx-l3-uuid')
if 'nsx-controllers' in config():
ctxt['nsx_controllers'] = \
','.join(config('nsx-controllers').split())
ctxt['nsx_controllers_list'] = \
config('nsx-controllers').split()
ctxt['l2_population'] = self.neutron_l2_population
ctxt['overlay_network_type'] = self.neutron_overlay_network_type
ctxt['external_network'] = config('neutron-external-network')

View File

@ -24,7 +24,9 @@ from charmhelpers.core.host import (
)
from charmhelpers.fetch import (
apt_install, apt_update
apt_install,
apt_update,
filter_installed_packages,
)
from charmhelpers.contrib.openstack.utils import (
@ -112,6 +114,8 @@ def install():
@hooks.hook('config-changed')
@restart_on_change(restart_map(), stopstart=True)
def config_changed():
apt_install(filter_installed_packages(determine_packages()),
fatal=True)
if config('prefer-ipv6'):
setup_ipv6()
sync_db_with_multi_ipv6_addresses(config('database'),
@ -295,11 +299,21 @@ def neutron_api_relation_changed():
@hooks.hook('neutron-plugin-api-relation-joined')
def neutron_plugin_api_relation_joined(rid=None):
relation_data = {
'neutron-security-groups': config('neutron-security-groups'),
'l2-population': get_l2population(),
'overlay-network-type': get_overlay_network_type(),
}
if config('neutron-plugin') == 'nsx':
relation_data = {
'nsx-username': config('nsx-username'),
'nsx-password': config('nsx-password'),
'nsx-cluster-name': config('nsx-cluster-name'),
'nsx-tz-uuid': config('nsx-tz-uuid'),
'nsx-l3-uuid': config('nsx-l3-uuid'),
'nsx-controllers': config('nsx-controllers'),
}
else:
relation_data = {
'neutron-security-groups': config('neutron-security-groups'),
'l2-population': get_l2population(),
'overlay-network-type': get_overlay_network_type(),
}
relation_set(relation_id=rid, **relation_data)

View File

@ -0,0 +1,11 @@
# icehouse
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
###############################################################################
[DEFAULT]
nsx_user = {{ nsx_username }}
nsx_password = {{ nsx_password }}
nsx_controllers = {{ nsx_controllers }}
default_tz_uuid = {{ nsx_tz_uuid }}
default_l3_gw_service_uuid = {{ nsx_l3_uuid }}

View File

@ -122,10 +122,10 @@ class HAProxyContextTest(CharmTestCase):
_open.assert_called_with('/etc/default/haproxy', 'w')
class NeutronAPIContextsTest(CharmTestCase):
class NeutronCCContextTest(CharmTestCase):
def setUp(self):
super(NeutronAPIContextsTest, self).setUp(context, TO_PATCH)
super(NeutronCCContextTest, self).setUp(context, TO_PATCH)
self.relation_get.side_effect = self.test_relation.get
self.config.side_effect = self.test_config.get
self.api_port = 9696
@ -135,9 +135,14 @@ class NeutronAPIContextsTest(CharmTestCase):
self.test_config.set('debug', True)
self.test_config.set('verbose', True)
self.test_config.set('neutron-external-network', 'bob')
self.test_config.set('nsx-username', 'bob')
self.test_config.set('nsx-password', 'hardpass')
self.test_config.set('nsx-tz-uuid', 'tzuuid')
self.test_config.set('nsx-l3-uuid', 'l3uuid')
self.test_config.set('nsx-controllers', 'ctrl1 ctrl2')
def tearDown(self):
super(NeutronAPIContextsTest, self).tearDown()
super(NeutronCCContextTest, self).tearDown()
@patch.object(context.NeutronCCContext, 'network_manager')
@patch.object(context.NeutronCCContext, 'plugin')
@ -209,3 +214,22 @@ class NeutronAPIContextsTest(CharmTestCase):
with patch.object(napi_ctxt, '_ensure_packages') as ep:
napi_ctxt._ensure_packages()
ep.assert_has_calls([])
@patch.object(context.NeutronCCContext, 'network_manager')
@patch.object(context.NeutronCCContext, 'plugin')
@patch('__builtin__.__import__')
def test_neutroncc_context_nsx(self, _import, plugin, nm):
plugin.return_value = 'nsx'
self.related_units.return_value = []
self.test_config.set('neutron-plugin', 'nsx')
napi_ctxt = context.NeutronCCContext()()
expect = {
'nsx_controllers': 'ctrl1,ctrl2',
'nsx_controllers_list': ['ctrl1', 'ctrl2'],
'nsx_l3_uuid': 'l3uuid',
'nsx_password': 'hardpass',
'nsx_tz_uuid': 'tzuuid',
'nsx_username': 'bob',
}
for key in expect.iterkeys():
self.assertEquals(napi_ctxt[key], expect[key])

View File

@ -33,6 +33,7 @@ TO_PATCH = [
'determine_ports',
'do_openstack_upgrade',
'execd_preinstall',
'filter_installed_packages',
'get_l2population',
'get_overlay_network_type',
'is_relation_made',
@ -111,6 +112,7 @@ class NeutronAPIHooksTests(CharmTestCase):
self.assertTrue(_id_cluster_joined.called)
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.do_openstack_upgrade.called)
self.assertTrue(self.apt_install.called)
def test_amqp_joined(self):
self._call_hook('amqp-relation-joined')