Charmhelper sync and corresponding unit test fix.

Change-Id: I291fb02e1439a224ed91f0d7d2bd80115b73671a
This commit is contained in:
Liam Young 2019-05-07 13:38:23 +00:00
parent 91e2a4a74a
commit 1c8dcc17b5
6 changed files with 111 additions and 7 deletions

View File

@ -220,6 +220,8 @@ def process_certificates(service_name, relation_id, unit,
:type user: str :type user: str
:param group: (Optional) Group of certificate files. Defaults to 'root' :param group: (Optional) Group of certificate files. Defaults to 'root'
:type group: str :type group: str
:returns: True if certificates processed for local unit or False
:rtype: bool
""" """
data = relation_get(rid=relation_id, unit=unit) data = relation_get(rid=relation_id, unit=unit)
ssl_dir = os.path.join('/etc/apache2/ssl/', service_name) ssl_dir = os.path.join('/etc/apache2/ssl/', service_name)
@ -235,6 +237,8 @@ def process_certificates(service_name, relation_id, unit,
create_ip_cert_links( create_ip_cert_links(
ssl_dir, ssl_dir,
custom_hostname_link=custom_hostname_link) custom_hostname_link=custom_hostname_link)
return True
return False
def get_requests_for_local_unit(relation_name=None): def get_requests_for_local_unit(relation_name=None):

View File

@ -117,6 +117,7 @@ except ImportError:
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
ADDRESS_TYPES = ['admin', 'internal', 'public'] ADDRESS_TYPES = ['admin', 'internal', 'public']
HAPROXY_RUN_DIR = '/var/run/haproxy/' HAPROXY_RUN_DIR = '/var/run/haproxy/'
DEFAULT_OSLO_MESSAGING_DRIVER = "messagingv2"
def ensure_packages(packages): def ensure_packages(packages):
@ -351,10 +352,70 @@ class IdentityServiceContext(OSContextGenerator):
return cachedir return cachedir
return None return None
def _get_pkg_name(self, python_name='keystonemiddleware'):
"""Get corresponding distro installed package for python
package name.
:param python_name: nameof the python package
:type: string
"""
pkg_names = map(lambda x: x + python_name, ('python3-', 'python-'))
for pkg in pkg_names:
if not filter_installed_packages(pkg):
return pkg
return None
def _get_keystone_authtoken_ctxt(self, ctxt, keystonemiddleware_os_rel):
"""Build Jinja2 context for full rendering of [keystone_authtoken]
section with variable names included. Re-constructed from former
template 'section-keystone-auth-mitaka'.
:param ctxt: Jinja2 context returned from self.__call__()
:type: dict
:param keystonemiddleware_os_rel: OpenStack release name of
keystonemiddleware package installed
"""
c = collections.OrderedDict((('auth_type', 'password'),))
# 'www_authenticate_uri' replaced 'auth_uri' since Stein,
# see keystonemiddleware upstream sources for more info
if CompareOpenStackReleases(keystonemiddleware_os_rel) >= 'stein':
c.update((
('www_authenticate_uri', "{}://{}:{}/v3".format(
ctxt.get('service_protocol', ''),
ctxt.get('service_host', ''),
ctxt.get('service_port', ''))),))
else:
c.update((
('auth_uri', "{}://{}:{}/v3".format(
ctxt.get('service_protocol', ''),
ctxt.get('service_host', ''),
ctxt.get('service_port', ''))),))
c.update((
('auth_url', "{}://{}:{}/v3".format(
ctxt.get('auth_protocol', ''),
ctxt.get('auth_host', ''),
ctxt.get('auth_port', ''))),
('project_domain_name', ctxt.get('admin_domain_name', '')),
('user_domain_name', ctxt.get('admin_domain_name', '')),
('project_name', ctxt.get('admin_tenant_name', '')),
('username', ctxt.get('admin_user', '')),
('password', ctxt.get('admin_password', '')),
('signing_dir', ctxt.get('signing_dir', '')),))
return c
def __call__(self): def __call__(self):
log('Generating template context for ' + self.rel_name, level=DEBUG) log('Generating template context for ' + self.rel_name, level=DEBUG)
ctxt = {} ctxt = {}
keystonemiddleware_os_release = None
if self._get_pkg_name():
keystonemiddleware_os_release = os_release(self._get_pkg_name())
cachedir = self._setup_pki_cache() cachedir = self._setup_pki_cache()
if cachedir: if cachedir:
ctxt['signing_dir'] = cachedir ctxt['signing_dir'] = cachedir
@ -385,6 +446,14 @@ class IdentityServiceContext(OSContextGenerator):
ctxt.update({'admin_domain_name': ctxt.update({'admin_domain_name':
rdata.get('service_domain')}) rdata.get('service_domain')})
# we keep all veriables in ctxt for compatibility and
# add nested dictionary for keystone_authtoken generic
# templating
if keystonemiddleware_os_release:
ctxt['keystone_authtoken'] = \
self._get_keystone_authtoken_ctxt(
ctxt, keystonemiddleware_os_release)
if self.context_complete(ctxt): if self.context_complete(ctxt):
# NOTE(jamespage) this is required for >= icehouse # NOTE(jamespage) this is required for >= icehouse
# so a missing value just indicates keystone needs # so a missing value just indicates keystone needs
@ -569,6 +638,15 @@ class AMQPContext(OSContextGenerator):
ctxt['oslo_messaging_flags'] = config_flags_parser( ctxt['oslo_messaging_flags'] = config_flags_parser(
oslo_messaging_flags) oslo_messaging_flags)
oslo_messaging_driver = conf.get(
'oslo-messaging-driver', DEFAULT_OSLO_MESSAGING_DRIVER)
if oslo_messaging_driver:
ctxt['oslo_messaging_driver'] = oslo_messaging_driver
notification_format = conf.get('notification-format', None)
if notification_format:
ctxt['notification_format'] = notification_format
if not self.complete: if not self.complete:
return {} return {}

View File

@ -0,0 +1,9 @@
{% if auth_host -%}
[keystone_authtoken]
{% for option_name, option_value in keystone_authtoken.items() -%}
{{ option_name }} = {{ option_value }}
{% endfor -%}
{% if use_memcache == true %}
memcached_servers = {{ memcache_url }}
{% endif -%}
{% endif -%}

View File

@ -1,11 +1,12 @@
{% if transport_url -%} {% if transport_url -%}
[oslo_messaging_notifications] [oslo_messaging_notifications]
driver = messagingv2 driver = {{ oslo_messaging_driver }}
transport_url = {{ transport_url }} transport_url = {{ transport_url }}
{% if notification_topics -%} {% if notification_topics -%}
topics = {{ notification_topics }} topics = {{ notification_topics }}
{% endif -%} {% endif -%}
{% if notification_format -%} {% if notification_format -%}
[notifications]
notification_format = {{ notification_format }} notification_format = {{ notification_format }}
{% endif -%} {% endif -%}
{% endif -%} {% endif -%}

View File

@ -194,7 +194,7 @@ SWIFT_CODENAMES = OrderedDict([
('rocky', ('rocky',
['2.18.0', '2.19.0']), ['2.18.0', '2.19.0']),
('stein', ('stein',
['2.20.0']), ['2.20.0', '2.21.0']),
]) ])
# >= Liberty version->codename mapping # >= Liberty version->codename mapping

View File

@ -75,6 +75,8 @@ class IdentityServiceContextTest(CharmTestCase):
self.maxDiff = None self.maxDiff = None
self.cmp_pkgrevno.return_value = 1 self.cmp_pkgrevno.return_value = 1
@patch.object(charmhelpers.contrib.openstack.context,
'filter_installed_packages', return_value=['absent-pkg'])
@patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr') @patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr')
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete') @patch.object(charmhelpers.contrib.openstack.context, 'context_complete')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get') @patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@ -82,7 +84,8 @@ class IdentityServiceContextTest(CharmTestCase):
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'log') @patch.object(charmhelpers.contrib.openstack.context, 'log')
def test_ids_ctxt(self, _log, _rids, _runits, _rget, _ctxt_comp, def test_ids_ctxt(self, _log, _rids, _runits, _rget, _ctxt_comp,
_format_ipv6_addr, jewel_installed=False): _format_ipv6_addr, _filter_installed_packages,
jewel_installed=False):
self.test_config.set('operator-roles', 'Babel') self.test_config.set('operator-roles', 'Babel')
self.test_config.set('cache-size', '42') self.test_config.set('cache-size', '42')
self.test_relation.set({'admin_token': 'ubuntutesting'}) self.test_relation.set({'admin_token': 'ubuntutesting'})
@ -130,6 +133,8 @@ class IdentityServiceContextTest(CharmTestCase):
expect['auth_keystone_v3_supported'] = True expect['auth_keystone_v3_supported'] = True
self.assertEqual(expect, ids_ctxt()) self.assertEqual(expect, ids_ctxt())
@patch.object(charmhelpers.contrib.openstack.context,
'filter_installed_packages', return_value=['absent-pkg'])
@patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr') @patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr')
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete') @patch.object(charmhelpers.contrib.openstack.context, 'context_complete')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get') @patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@ -138,7 +143,7 @@ class IdentityServiceContextTest(CharmTestCase):
@patch.object(charmhelpers.contrib.openstack.context, 'log') @patch.object(charmhelpers.contrib.openstack.context, 'log')
def test_ids_ctxt_missing_admin_domain_id( def test_ids_ctxt_missing_admin_domain_id(
self, _log, _rids, _runits, _rget, _ctxt_comp, _format_ipv6_addr, self, _log, _rids, _runits, _rget, _ctxt_comp, _format_ipv6_addr,
jewel_installed=False): _filter_installed_packages, jewel_installed=False):
self.test_config.set('operator-roles', 'Babel') self.test_config.set('operator-roles', 'Babel')
self.test_config.set('cache-size', '42') self.test_config.set('cache-size', '42')
self.test_relation.set({'admin_token': 'ubuntutesting'}) self.test_relation.set({'admin_token': 'ubuntutesting'})
@ -184,6 +189,8 @@ class IdentityServiceContextTest(CharmTestCase):
expect['auth_keystone_v3_supported'] = True expect['auth_keystone_v3_supported'] = True
self.assertEqual(expect, ids_ctxt()) self.assertEqual(expect, ids_ctxt())
@patch.object(charmhelpers.contrib.openstack.context,
'filter_installed_packages', return_value=['absent-pkg'])
@patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr') @patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr')
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete') @patch.object(charmhelpers.contrib.openstack.context, 'context_complete')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get') @patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@ -192,7 +199,7 @@ class IdentityServiceContextTest(CharmTestCase):
@patch.object(charmhelpers.contrib.openstack.context, 'log') @patch.object(charmhelpers.contrib.openstack.context, 'log')
def test_ids_ctxt_v3( def test_ids_ctxt_v3(
self, _log, _rids, _runits, _rget, _ctxt_comp, _format_ipv6_addr, self, _log, _rids, _runits, _rget, _ctxt_comp, _format_ipv6_addr,
jewel_installed=False): _filter_installed_packages, jewel_installed=False):
self.test_config.set('operator-roles', 'Babel') self.test_config.set('operator-roles', 'Babel')
self.test_config.set('cache-size', '42') self.test_config.set('cache-size', '42')
self.test_relation.set({'admin_token': 'ubuntutesting'}) self.test_relation.set({'admin_token': 'ubuntutesting'})
@ -246,6 +253,8 @@ class IdentityServiceContextTest(CharmTestCase):
def test_ids_ctxt_jewel(self): def test_ids_ctxt_jewel(self):
self.test_ids_ctxt(jewel_installed=True) self.test_ids_ctxt(jewel_installed=True)
@patch.object(charmhelpers.contrib.openstack.context,
'filter_installed_packages', return_value=['absent-pkg'])
@patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr') @patch.object(charmhelpers.contrib.openstack.context, 'format_ipv6_addr')
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete') @patch.object(charmhelpers.contrib.openstack.context, 'context_complete')
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get') @patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
@ -253,7 +262,8 @@ class IdentityServiceContextTest(CharmTestCase):
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'log') @patch.object(charmhelpers.contrib.openstack.context, 'log')
def test_ids_ctxt_no_admin_token(self, _log, _rids, _runits, _rget, def test_ids_ctxt_no_admin_token(self, _log, _rids, _runits, _rget,
_ctxt_comp, _format_ipv6_addr): _ctxt_comp, _format_ipv6_addr,
_filter_installed_packages):
self.test_config.set('operator-roles', 'Babel') self.test_config.set('operator-roles', 'Babel')
self.test_config.set('cache-size', '42') self.test_config.set('cache-size', '42')
self.test_relation.set({}) self.test_relation.set({})
@ -277,9 +287,11 @@ class IdentityServiceContextTest(CharmTestCase):
ids_ctxt = context.IdentityServiceContext() ids_ctxt = context.IdentityServiceContext()
self.assertEqual({}, ids_ctxt()) self.assertEqual({}, ids_ctxt())
@patch.object(charmhelpers.contrib.openstack.context,
'filter_installed_packages', return_value=['absent-pkg'])
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
@patch.object(charmhelpers.contrib.openstack.context, 'log') @patch.object(charmhelpers.contrib.openstack.context, 'log')
def test_ids_ctxt_no_rels(self, _log, _rids): def test_ids_ctxt_no_rels(self, _log, _rids, _filter_installed_packages):
_rids.return_value = [] _rids.return_value = []
ids_ctxt = context.IdentityServiceContext() ids_ctxt = context.IdentityServiceContext()
self.assertEqual(ids_ctxt(), None) self.assertEqual(ids_ctxt(), None)