Browse Source

Make it a proper neutron-api plugin

This removes the need for a special neutron-api fork. Validated that the
content of /etc/neutron/ remained equivalent after this change.

Func-Test-PR: https://github.com/openstack-charmers/zaza-openstack-tests/pull/371
Change-Id: If17aeca06ef71310b1b918a1fa9a555a636b03f8
changes/60/742460/3
Aurelien Lourot 1 year ago
parent
commit
9fa03e8a64
  1. 4
      .zuul.yaml
  2. 4
      src/config.yaml
  3. 40
      src/lib/charm/openstack/neutron_arista.py
  4. 70
      src/reactive/neutron_arista_handlers.py
  5. 11
      src/templates/ml2_conf_arista.ini
  6. 7
      src/tests/bundles/bionic-queens.yaml
  7. 7
      src/tests/bundles/bionic-rocky.yaml
  8. 7
      src/tests/bundles/xenial-queens.yaml
  9. 3
      src/tests/tests.yaml
  10. 47
      unit_tests/test_neutron_arista_handlers.py

4
.zuul.yaml

@ -1,6 +1,4 @@
- project:
# NOTE(lourot): templates are defined in
# https://opendev.org/openstack/openstack-zuul-jobs
templates:
- openstack-python3-ussuri-jobs
- openstack-python3-charm-jobs
- openstack-cover-jobs

4
src/config.yaml

@ -38,7 +38,3 @@ options:
type: string
description: |
Name of the OpenStack region.
service-plugins:
default: router,firewall,metering,neutron_lbaas.services.loadbalancer.plugin.LoadBalancerPluginv2
type: string
description: Override of Neutron-API service plugins setting.

40
src/lib/charm/openstack/neutron_arista.py

@ -1,26 +1,16 @@
#!/usr/bin/env python
from collections import OrderedDict
from charmhelpers.core.hookenv import (
config,
log
)
import charms_openstack.charm
from charmhelpers.contrib.openstack import (
context,
templating,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
filter_installed_packages,
add_source,
)
from charmhelpers.contrib.openstack.utils import os_release
ML2_CONFIG = '/etc/neutron/plugins/ml2/ml2_conf_arista.ini'
TEMPLATES = 'templates/'
class NeutronAristaCharm(charms_openstack.charm.OpenStackCharm):
@ -41,33 +31,3 @@ class NeutronAristaCharm(charms_openstack.charm.OpenStackCharm):
add_source(config('source'))
apt_update(fatal=True)
apt_install(self.packages[0], fatal=True)
def write_config(self):
configs = self.register_configs()
configs.write_all()
def register_configs(release=None):
resources = OrderedDict([
(ML2_CONFIG, {
'services': ['neutron-server'],
'contexts': [AristaMl2Context(), ]
}),
])
release = os_release('neutron-common')
configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
openstack_release=release)
for cfg, rscs in resources.items():
configs.register(cfg, rscs['contexts'])
return configs
class AristaMl2Context(context.OSContextGenerator):
def __call__(self):
ctxt = {'eapi_host': config('eapi-host'),
'eapi_username': config('eapi-username'),
'eapi_password': config('eapi-password'),
'region_name': config('region-name'),
'api_type': config('api-type'),
'arista_version': config('arista-version')}
return ctxt

70
src/reactive/neutron_arista_handlers.py

@ -16,17 +16,13 @@ import charms.reactive as reactive
from charmhelpers.core.hookenv import (
config,
)
from charmhelpers.core.host import (
service_restart,
log,
)
from charms_openstack.charm import (
provide_charm_instance,
use_defaults,
)
import charm.openstack.neutron_arista as arista # noqa
use_defaults('update-status')
@ -40,33 +36,45 @@ def install_arista():
reactive.set_state('arista-package.installed')
@reactive.when('neutron-plugin-api-subordinate.connected')
def configure_principle(api_principle):
inject_config = {
'neutron-api': {
'/etc/neutron/neutron.conf': {
'sections': {
'DEFAULT': [
],
}
}
}
}
with provide_charm_instance() as charm_class:
charm_class.write_config()
api_principle.configure_plugin(
neutron_plugin='arista',
core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin',
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini \
--config-file=/etc/neutron/plugins/ml2/ml2_conf_arista.ini',
service_plugins=config('service-plugins'),
subordinate_configuration=inject_config)
@reactive.when_any('config.changed.eapi-host',
'config.changed.eapi-username',
'config.changed.eapi-password',
'config.changed.region-name',
'config.changed.api-type',
'config.changed.region-name')
def restart_service():
service_restart('neutron-server')
'neutron-plugin-api-subordinate.connected')
def configure_principle():
try:
api_principle = reactive.endpoint_from_flag(
'neutron-plugin-api-subordinate.connected')
mechanism_drivers = ','.join((
api_principle.neutron_config_data.get('mechanism_drivers', ''),
'arista'))
except AttributeError:
log("The principle charm isn't ready yet. "
"Postponing its configuration...")
return
log('Configuring the principle charm...')
sections = {
'ml2_arista': [
('eapi_host', config('eapi-host')),
('eapi_username', config('eapi-username')),
('eapi_password', config('eapi-password')),
('region_name', config('region-name')),
('api_type', config('api-type')),
],
}
api_principle.configure_plugin(
neutron_plugin='arista',
mechanism_drivers=mechanism_drivers,
subordinate_configuration={
'neutron-api': {
'/etc/neutron/plugins/ml2/ml2_conf.ini': {
'sections': sections,
},
},
}
)

11
src/templates/ml2_conf_arista.ini

@ -1,11 +0,0 @@
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
###############################################################################
[ml2_arista]
eapi_host = {{ eapi_host }}
eapi_username = {{ eapi_username }}
eapi_password = {{ eapi_password }}
region_name = {{ region_name }}
api_type = {{ api_type }}

7
src/tests/bundles/bionic-queens.yaml

@ -15,11 +15,9 @@ applications:
num_units: 1
neutron-api:
# Temporary fork until we refactor neutron-api-plugin-arista:
charm: cs:~aurelien-lourot/neutron-api-arista-test-fixture
charm: cs:~openstack-charmers-next/neutron-api
num_units: 1
options:
enable-arista: True
enable-ml2-dns: False
flat-network-providers: default
vlan-ranges: default:1000:3000
@ -35,7 +33,7 @@ applications:
ipv4-ptr-zone-prefix-size:
reverse-dns-lookup: False
dns-domain:
manage-neutron-plugin-legacy-mode: True
manage-neutron-plugin-legacy-mode: False
neutron-openvswitch:
charm: cs:~openstack-charmers-next/neutron-openvswitch
@ -63,7 +61,6 @@ applications:
eapi-username: admin
eapi-password: password123
api-type: EAPI
service-plugins: router
nova-compute:
charm: cs:~openstack-charmers-next/nova-compute

7
src/tests/bundles/bionic-rocky.yaml

@ -19,12 +19,10 @@ applications:
num_units: 1
neutron-api:
# Temporary fork until we refactor neutron-api-plugin-arista:
charm: cs:~aurelien-lourot/neutron-api-arista-test-fixture
charm: cs:~openstack-charmers-next/neutron-api
num_units: 1
options:
openstack-origin: cloud:bionic-rocky
enable-arista: True
enable-ml2-dns: False
flat-network-providers: default
vlan-ranges: default:1000:3000
@ -40,7 +38,7 @@ applications:
ipv4-ptr-zone-prefix-size:
reverse-dns-lookup: False
dns-domain:
manage-neutron-plugin-legacy-mode: True
manage-neutron-plugin-legacy-mode: False
neutron-openvswitch:
charm: cs:~openstack-charmers-next/neutron-openvswitch
@ -69,7 +67,6 @@ applications:
eapi-username: admin
eapi-password: password123
api-type: EAPI
service-plugins: router
nova-compute:
charm: cs:~openstack-charmers-next/nova-compute

7
src/tests/bundles/xenial-queens.yaml

@ -19,12 +19,10 @@ applications:
num_units: 1
neutron-api:
# Temporary fork until we refactor neutron-api-plugin-arista:
charm: cs:~aurelien-lourot/neutron-api-arista-test-fixture
charm: cs:~openstack-charmers-next/neutron-api
num_units: 1
options:
openstack-origin: cloud:xenial-queens
enable-arista: True
enable-ml2-dns: False
flat-network-providers: default
vlan-ranges: default:1000:3000
@ -40,7 +38,7 @@ applications:
ipv4-ptr-zone-prefix-size:
reverse-dns-lookup: False
dns-domain:
manage-neutron-plugin-legacy-mode: True
manage-neutron-plugin-legacy-mode: False
neutron-openvswitch:
charm: cs:~openstack-charmers-next/neutron-openvswitch
@ -69,7 +67,6 @@ applications:
eapi-username: admin
eapi-password: password123
api-type: EAPI
service-plugins: router
nova-compute:
charm: cs:~openstack-charmers-next/nova-compute

3
src/tests/tests.yaml

@ -5,8 +5,7 @@ gate_bundles:
- xenial-queens
- bionic-queens
# NOTE(lourot): on bionic-rocky our special neutron-api fork for Arista fails
# to start with:
# NOTE(lourot): on bionic-rocky neutron-server fails to start with:
# neutron.plugins.ml2.managers The following mechanism drivers were not found: set(['hyperv'])
# Disabling for now. To be investigated.
#- bionic-rocky

47
unit_tests/test_neutron_arista_handlers.py

@ -26,17 +26,40 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
class TestHandlers(test_utils.PatchHelper):
def _patch_provide_charm_instance(self):
the_charm = mock.MagicMock()
self.patch_object(handlers, 'provide_charm_instance',
name='provide_charm_instance',
new=mock.MagicMock())
self.provide_charm_instance().__enter__.return_value = the_charm
self.provide_charm_instance().__exit__.return_value = None
return the_charm
def test_configure_principal(self):
the_charm = self._patch_provide_charm_instance()
mocked_reactive = mock.MagicMock()
self.patch_object(handlers, 'reactive',
name='reactive',
new=mocked_reactive)
principal_charm = mock.MagicMock()
handlers.configure_principle(principal_charm)
the_charm.write_config.assert_called_once_with()
mocked_reactive.endpoint_from_flag.return_value = principal_charm
principal_charm.neutron_config_data = {
'mechanism_drivers': 'driver1,driver2'
}
mocked_config = mock.MagicMock()
self.patch_object(handlers, 'config',
name='config',
new=mocked_config)
mocked_config.return_value = 'my_config_value'
handlers.configure_principle()
principal_charm.configure_plugin.assert_called_once_with(
neutron_plugin='arista',
mechanism_drivers='driver1,driver2,arista',
subordinate_configuration={
'neutron-api': {
'/etc/neutron/plugins/ml2/ml2_conf.ini': {
'sections': {
'ml2_arista': [
('eapi_host', 'my_config_value'),
('eapi_username', 'my_config_value'),
('eapi_password', 'my_config_value'),
('region_name', 'my_config_value'),
('api_type', 'my_config_value'),
],
},
},
},
}
)

Loading…
Cancel
Save