From 4480456e15fcfecf65b05067aeb9325be6c0552d Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Fri, 27 Sep 2019 11:24:46 +0200 Subject: [PATCH] Add new remote-manila-plugin interface This change adds the new interface remote-manila-plugin which is treated in the same way as the existing manila-plugin interface, except that the remote version will disable the manila-share service Change-Id: I28a56a7ea4cb9679b6000a6e22a6e938eed8551f --- src/lib/charm/openstack/manila.py | 38 ++++++--- src/metadata.yaml | 2 + src/reactive/manila_handlers.py | 27 ++++-- src/templates/rocky/manila.conf | 84 +++++++++++++++++++ unit_tests/test_lib_charm_openstack_manila.py | 11 +-- unit_tests/test_manila_handlers.py | 11 ++- 6 files changed, 141 insertions(+), 32 deletions(-) create mode 100644 src/templates/rocky/manila.conf diff --git a/src/lib/charm/openstack/manila.py b/src/lib/charm/openstack/manila.py index b89f52f..641fcbc 100644 --- a/src/lib/charm/openstack/manila.py +++ b/src/lib/charm/openstack/manila.py @@ -185,22 +185,12 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): service_type_v2 = 'manilav2' default_service = 'manila-api' - services = ['manila-api', - 'manila-scheduler', - 'manila-share', - 'manila-data'] # Note that the hsm interface is optional - defined in config.yaml required_relations = ['shared-db', 'amqp', 'identity-service'] adapters_class = ManilaRelationAdapters - restart_map = { - MANILA_CONF: services, - MANILA_API_PASTE_CONF: services, - MANILA_LOGGING_CONF: services, - } - # This is the command to sync the database sync_cmd = ['sudo', 'manila-manage', 'db', 'sync'] @@ -221,6 +211,23 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): ]), } + @property + def services(self): + services = ['manila-api', + 'manila-scheduler', + 'manila-data'] + if not self.get_adapter('remote-manila-plugin.available'): + services.append('manila-share') + return services + + @property + def restart_map(self): + services = self.services + return { + MANILA_CONF: services, + MANILA_API_PASTE_CONF: services, + MANILA_LOGGING_CONF: services, + } # ha_resources = ['vips', 'haproxy'] # Custom charm configuration @@ -368,7 +375,7 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): :returns: list of strings: backend sections that are configured. """ - adapter = self.get_adapter('manila-plugin.available') + adapter = self.adapter if adapter is None: return [] # adapter.names is a property that provides a list of backend manila @@ -394,7 +401,7 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): :param config_file: string, filename for configuration lines :returns: list of strings: config lines for `config_file` """ - adapter = self.get_adapter('manila-plugin.available') + adapter = self.adapter if adapter is None: return [] # get the configuration data for all plugins @@ -421,7 +428,7 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): :returns: [list of config files] """ - adapter = self.get_adapter('manila-plugin.available') + adapter = self.adapter if adapter is None: return [] # get the configuration data for all plugins @@ -433,6 +440,11 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm): config_files.add(config_file) return list(config_files) + @property + def adapter(self): + return self.get_adapter('manila-plugin.available') or \ + self.get_adapter('remote-manila-plugin.available') + class ManilaCharmRocky(ManilaCharm): diff --git a/src/metadata.yaml b/src/metadata.yaml index 65c44e0..7af5517 100644 --- a/src/metadata.yaml +++ b/src/metadata.yaml @@ -29,3 +29,5 @@ requires: manila-plugin: interface: manila-plugin scope: container + remote-manila-plugin: + interface: manila-plugin \ No newline at end of file diff --git a/src/reactive/manila_handlers.py b/src/reactive/manila_handlers.py index 48fd527..4a51ba8 100644 --- a/src/reactive/manila_handlers.py +++ b/src/reactive/manila_handlers.py @@ -50,15 +50,20 @@ def register_endpoints(keystone): manila_charm.assess_status() -@charms.reactive.when('identity-service.connected', - 'manila-plugin.connected') -def share_to_manila_plugins_auth(keystone, manila_plugin, *args): +@charms.reactive.when('identity-service.connected') +@charms.reactive.when_any('manila-plugin.connected', + 'remote-manila-plugin.connected') +def share_to_manila_plugins_auth(): """When we have the identity-service and (a) backend plugin, share the auth plugin with the back end. Note that the interface deals with ensurign that each plugin gets the same data. """ + keystone = charms.reactive.endpoint_from_flag('identity-service.connected') + manila_plugin = \ + charms.reactive.endpoint_from_flag('manila-plugin.connected') or \ + charms.reactive.endpoint_from_flag('remote-manila-plugin.connected') data = { 'username': keystone.service_username(), 'password': keystone.service_password(), @@ -107,7 +112,9 @@ def render_stuff(*args): manila_charm.render_with_interfaces(args) manila_charm.assess_status() charms.reactive.set_state('manila.config.rendered') - manila_plugin = relations.endpoint_from_flag('manila-plugin.changed') + manila_plugin = \ + relations.endpoint_from_flag('manila-plugin.changed') or \ + relations.endpoint_from_flag('remote-manila-plugin.changed') if manila_plugin: manila_plugin.clear_changed() @@ -116,7 +123,8 @@ def render_stuff(*args): 'identity-service.available', 'amqp.available') @charms.reactive.when_any('config-changed', - 'manila-plugin.changed') + 'manila-plugin.changed', + 'remote-manila-plugin.changed') def config_changed(*args): """When the configuration is changed, check that we have all the interfaces and then re-render all the configuration files. Note that this means that @@ -140,9 +148,14 @@ def update_status(): handlers will activate it. """ if not os_utils.is_unit_paused_set(): + with charms_openstack.charm.provide_charm_instance() as manila_charm: + if manila_charm.get_adapter('remote-manila-plugin.available'): + services = [] + else: + services = ['manila-share'] state, message = os_utils._ows_check_services_running( - services=['manila-share'], + services=services, ports=None) - if state == 'blocked': + if state == 'blocked' and services: # try to start the 'manila-share' service ch_host.service_start('manila-share') diff --git a/src/templates/rocky/manila.conf b/src/templates/rocky/manila.conf new file mode 100644 index 0000000..0089ae7 --- /dev/null +++ b/src/templates/rocky/manila.conf @@ -0,0 +1,84 @@ +# Note that the original manila.conf file is extensive and has many options +# that the charm does not set. Please refer to that file if there are options +# that you think the charm should set, but doesn't, or provide options for. +# Please file a bug at: https://bugs.launchpad.net/charm-barbican/+filebug for +# any changes you need made or intend to modify in the charm. + +[DEFAULT] + +# This all needs to be configurable +enabled_share_backends = {{ options.computed_share_backends }} + +# enabled_share_protocols = NFS,CIFS +enabled_share_protocols = {{ options.computed_share_protocols }} + +#default_share_type = default_share_type +default_share_type = {{ options.default_share_type }} + +state_path = /var/lib/manila +osapi_share_extension = manila.api.contrib.standard_extenstions +rootwrap_config = /etc/manila/rootwrap.conf +api_paste_config = /etc/manila/api-paste.ini +share_name_template = share-%s + +scheduler_driver = manila.scheduler.drivers.filter.FilterScheduler + +debug = {{ options.debug }} + +# Number of workers for OpenStack Share API service. (integer value) +osapi_share_workers = {{ options.workers }} + +{% include "parts/section-transport-url" %} + +[oslo_concurrency] +lock_path = /var/lib/manila + +[cors] + +# +# From oslo.middleware.cors +# + +[cors.subdomain] + +# +# From oslo.middleware.cors +# + +# parts/section-database includes the [database] section identifier +{% include "parts/section-database" %} + + +# parts/section-keystone-authtoken includes the [keystone_authtoken] section +# identifier +{% include "parts/section-keystone-authtoken" %} + + + +[matchmaker_redis] + +# +# From oslo.messaging +# + +[oslo_messaging_amqp] + +# +# From oslo.messaging +# + +[oslo_messaging_notifications] + +# +# From oslo.messaging +# + +{% include "parts/section-oslo-messaging-rabbit" %} + +# +# Now configuration from the backend manila-plugin charms +# + +{% for line in options.computed_backend_lines_manila_conf %} +{{ line }} +{%- endfor %} diff --git a/unit_tests/test_lib_charm_openstack_manila.py b/unit_tests/test_lib_charm_openstack_manila.py index 873e578..b187a41 100644 --- a/unit_tests/test_lib_charm_openstack_manila.py +++ b/unit_tests/test_lib_charm_openstack_manila.py @@ -98,17 +98,12 @@ class TestManilaCharm(Helper): return c def test_install(self): - self.patch("charms_openstack.charm.OpenStackCharm.install", - name="install") - self.patch("charms_openstack.charm.OpenStackCharm.configure_source", - name="configure_source") + self.patch('builtins.super', 'super') self.patch("subprocess.check_call", name="check_call") self.patch("charms_openstack.charm.OpenStackCharm.assess_status", name="assess_status") c = manila.ManilaCharm() c.install() - self.install.assert_called_once_with() - self.configure_source.assert_called_once_with() self.check_call.assert_called_once_with(["mkdir", "-p", "/etc/nova"]) self.assess_status.assert_called_once_with() @@ -236,7 +231,7 @@ class TestManilaCharm(Helper): self._patch_get_adapter(c) self.out = None self.assertEqual(c.configured_backends, []) - self.assertEqual(self.var, 'manila-plugin.available') + self.assertEqual(self.var, 'remote-manila-plugin.available') self.out = mock.Mock() self.out.relation.names = ['a', 'b'] self.assertEqual(c.configured_backends, ['a', 'b']) @@ -246,7 +241,7 @@ class TestManilaCharm(Helper): self._patch_get_adapter(c) self.out = None self.assertEqual(c.config_lines_for('conf'), []) - self.assertEqual(self.var, 'manila-plugin.available') + self.assertEqual(self.var, 'remote-manila-plugin.available') self.out = mock.Mock() self.out.relation.get_configuration_data.return_value = {} self.assertEqual(c.config_lines_for('conf'), []) diff --git a/unit_tests/test_manila_handlers.py b/unit_tests/test_manila_handlers.py index 89344a1..83da11b 100644 --- a/unit_tests/test_manila_handlers.py +++ b/unit_tests/test_manila_handlers.py @@ -37,8 +37,8 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): 'identity-service.available', 'amqp.available', ), 'register_endpoints': ('identity-service.connected', ), - 'share_to_manila_plugins_auth': ('identity-service.connected', - 'manila-plugin.connected', ), + 'share_to_manila_plugins_auth': + ('identity-service.connected', ), 'maybe_do_syncdb': ('shared-db.available', 'manila.config.rendered', ), 'config_changed': ('shared-db.available', @@ -50,8 +50,11 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): }, 'when_any': { 'config_changed': ('config-changed', - 'manila-plugin.changed', ), - + 'manila-plugin.changed', + 'remote-manila-plugin.changed', ), + 'share_to_manila_plugins_auth': ( + 'manila-plugin.connected', + 'remote-manila-plugin.connected', ) }, } # test that the hooks were registered via the