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
This commit is contained in:
Chris MacNaughton 2019-09-27 11:24:46 +02:00
parent 930d395d7d
commit 4480456e15
6 changed files with 141 additions and 32 deletions

View File

@ -185,22 +185,12 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm):
service_type_v2 = 'manilav2' service_type_v2 = 'manilav2'
default_service = 'manila-api' default_service = 'manila-api'
services = ['manila-api',
'manila-scheduler',
'manila-share',
'manila-data']
# Note that the hsm interface is optional - defined in config.yaml # Note that the hsm interface is optional - defined in config.yaml
required_relations = ['shared-db', 'amqp', 'identity-service'] required_relations = ['shared-db', 'amqp', 'identity-service']
adapters_class = ManilaRelationAdapters 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 # This is the command to sync the database
sync_cmd = ['sudo', 'manila-manage', 'db', 'sync'] 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'] # ha_resources = ['vips', 'haproxy']
# Custom charm configuration # Custom charm configuration
@ -368,7 +375,7 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm):
:returns: list of strings: backend sections that are configured. :returns: list of strings: backend sections that are configured.
""" """
adapter = self.get_adapter('manila-plugin.available') adapter = self.adapter
if adapter is None: if adapter is None:
return [] return []
# adapter.names is a property that provides a list of backend manila # 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 :param config_file: string, filename for configuration lines
:returns: list of strings: config lines for `config_file` :returns: list of strings: config lines for `config_file`
""" """
adapter = self.get_adapter('manila-plugin.available') adapter = self.adapter
if adapter is None: if adapter is None:
return [] return []
# get the configuration data for all plugins # get the configuration data for all plugins
@ -421,7 +428,7 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm):
:returns: [list of config files] :returns: [list of config files]
""" """
adapter = self.get_adapter('manila-plugin.available') adapter = self.adapter
if adapter is None: if adapter is None:
return [] return []
# get the configuration data for all plugins # get the configuration data for all plugins
@ -433,6 +440,11 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm):
config_files.add(config_file) config_files.add(config_file)
return list(config_files) 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): class ManilaCharmRocky(ManilaCharm):

View File

@ -29,3 +29,5 @@ requires:
manila-plugin: manila-plugin:
interface: manila-plugin interface: manila-plugin
scope: container scope: container
remote-manila-plugin:
interface: manila-plugin

View File

@ -50,15 +50,20 @@ def register_endpoints(keystone):
manila_charm.assess_status() manila_charm.assess_status()
@charms.reactive.when('identity-service.connected', @charms.reactive.when('identity-service.connected')
'manila-plugin.connected') @charms.reactive.when_any('manila-plugin.connected',
def share_to_manila_plugins_auth(keystone, manila_plugin, *args): 'remote-manila-plugin.connected')
def share_to_manila_plugins_auth():
"""When we have the identity-service and (a) backend plugin, share the auth """When we have the identity-service and (a) backend plugin, share the auth
plugin with the back end. plugin with the back end.
Note that the interface deals with ensurign that each plugin gets the same Note that the interface deals with ensurign that each plugin gets the same
data. 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 = { data = {
'username': keystone.service_username(), 'username': keystone.service_username(),
'password': keystone.service_password(), 'password': keystone.service_password(),
@ -107,7 +112,9 @@ def render_stuff(*args):
manila_charm.render_with_interfaces(args) manila_charm.render_with_interfaces(args)
manila_charm.assess_status() manila_charm.assess_status()
charms.reactive.set_state('manila.config.rendered') 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: if manila_plugin:
manila_plugin.clear_changed() manila_plugin.clear_changed()
@ -116,7 +123,8 @@ def render_stuff(*args):
'identity-service.available', 'identity-service.available',
'amqp.available') 'amqp.available')
@charms.reactive.when_any('config-changed', @charms.reactive.when_any('config-changed',
'manila-plugin.changed') 'manila-plugin.changed',
'remote-manila-plugin.changed')
def config_changed(*args): def config_changed(*args):
"""When the configuration is changed, check that we have all the interfaces """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 and then re-render all the configuration files. Note that this means that
@ -140,9 +148,14 @@ def update_status():
handlers will activate it. handlers will activate it.
""" """
if not os_utils.is_unit_paused_set(): 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( state, message = os_utils._ows_check_services_running(
services=['manila-share'], services=services,
ports=None) ports=None)
if state == 'blocked': if state == 'blocked' and services:
# try to start the 'manila-share' service # try to start the 'manila-share' service
ch_host.service_start('manila-share') ch_host.service_start('manila-share')

View File

@ -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 %}

View File

@ -98,17 +98,12 @@ class TestManilaCharm(Helper):
return c return c
def test_install(self): def test_install(self):
self.patch("charms_openstack.charm.OpenStackCharm.install", self.patch('builtins.super', 'super')
name="install")
self.patch("charms_openstack.charm.OpenStackCharm.configure_source",
name="configure_source")
self.patch("subprocess.check_call", name="check_call") self.patch("subprocess.check_call", name="check_call")
self.patch("charms_openstack.charm.OpenStackCharm.assess_status", self.patch("charms_openstack.charm.OpenStackCharm.assess_status",
name="assess_status") name="assess_status")
c = manila.ManilaCharm() c = manila.ManilaCharm()
c.install() 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.check_call.assert_called_once_with(["mkdir", "-p", "/etc/nova"])
self.assess_status.assert_called_once_with() self.assess_status.assert_called_once_with()
@ -236,7 +231,7 @@ class TestManilaCharm(Helper):
self._patch_get_adapter(c) self._patch_get_adapter(c)
self.out = None self.out = None
self.assertEqual(c.configured_backends, []) 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 = mock.Mock()
self.out.relation.names = ['a', 'b'] self.out.relation.names = ['a', 'b']
self.assertEqual(c.configured_backends, ['a', 'b']) self.assertEqual(c.configured_backends, ['a', 'b'])
@ -246,7 +241,7 @@ class TestManilaCharm(Helper):
self._patch_get_adapter(c) self._patch_get_adapter(c)
self.out = None self.out = None
self.assertEqual(c.config_lines_for('conf'), []) 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 = mock.Mock()
self.out.relation.get_configuration_data.return_value = {} self.out.relation.get_configuration_data.return_value = {}
self.assertEqual(c.config_lines_for('conf'), []) self.assertEqual(c.config_lines_for('conf'), [])

View File

@ -37,8 +37,8 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'identity-service.available', 'identity-service.available',
'amqp.available', ), 'amqp.available', ),
'register_endpoints': ('identity-service.connected', ), 'register_endpoints': ('identity-service.connected', ),
'share_to_manila_plugins_auth': ('identity-service.connected', 'share_to_manila_plugins_auth':
'manila-plugin.connected', ), ('identity-service.connected', ),
'maybe_do_syncdb': ('shared-db.available', 'maybe_do_syncdb': ('shared-db.available',
'manila.config.rendered', ), 'manila.config.rendered', ),
'config_changed': ('shared-db.available', 'config_changed': ('shared-db.available',
@ -50,8 +50,11 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
}, },
'when_any': { 'when_any': {
'config_changed': ('config-changed', '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 # test that the hooks were registered via the