Enable zuul and git-review
- Add .zuul.yaml with jobs definition to run unit tests, pep8 and coverage jobs, yoga and zed are added because python 3.8 and 3.10 is desired. - Add .gitreview file - Fix unit tests, use Mock requests.get() when rendering the configuration. - Format logging messages correctly Change-Id: I78d9c632590d0601d93105ba3d13d987aa0e30d5
This commit is contained in:
parent
98901bc318
commit
1aeb6268e5
4
.gitreview
Normal file
4
.gitreview
Normal file
@ -0,0 +1,4 @@
|
||||
[gerrit]
|
||||
host=review.opendev.org
|
||||
port=29418
|
||||
project=openstack/charm-keystone-openidc.git
|
5
.zuul.yaml
Normal file
5
.zuul.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
- project:
|
||||
templates:
|
||||
- openstack-python3-charm-yoga-jobs
|
||||
- openstack-python3-charm-zed-jobs
|
||||
- openstack-cover-jobs
|
@ -60,8 +60,7 @@ def when_data_ready(func):
|
||||
def _wrapper(self, event):
|
||||
try:
|
||||
if not self.is_data_ready():
|
||||
logger.debug('relation data is not ready yet (%s)',
|
||||
event)
|
||||
logger.debug('relation data is not ready yet (%s)', event)
|
||||
return
|
||||
except CharmConfigError as ex:
|
||||
self.unit.status = BlockedStatus(ex.msg)
|
||||
@ -259,7 +258,7 @@ class KeystoneOpenIDCCharm(ops_openstack.core.OSBaseCharm):
|
||||
|
||||
def _on_keystone_fid_service_provider_relation_changed(self, event):
|
||||
if not self.is_data_ready():
|
||||
logger.debug('relation data is not ready yet: %s', event)
|
||||
logger.debug('relation data is not ready yet (%s)', event)
|
||||
return
|
||||
self.update_principal_data()
|
||||
self.update_config_if_needed()
|
||||
@ -290,8 +289,7 @@ class KeystoneOpenIDCCharm(ops_openstack.core.OSBaseCharm):
|
||||
|
||||
def _on_config_changed(self, event):
|
||||
if not self.is_data_ready():
|
||||
logger.debug('relation data is not ready yet',
|
||||
event)
|
||||
logger.debug('relation data is not ready yet (%s)', event)
|
||||
return
|
||||
|
||||
self._stored.is_started = True
|
||||
|
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
@ -24,6 +25,7 @@ CRYPTO_PASSPHRASE = '1e19bb8a-a92d-4377-8226-5e8fc475822c'
|
||||
|
||||
class BaseTestCharm(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
self.harness = Harness(charm.KeystoneOpenIDCCharm, meta='''
|
||||
name: keystone-openidc
|
||||
provides:
|
||||
@ -40,6 +42,12 @@ class BaseTestCharm(unittest.TestCase):
|
||||
self.addCleanup(self.harness.cleanup)
|
||||
self.harness.begin()
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
shutil.rmtree(self.tmpdir, ignore_errors=True)
|
||||
except Exception as ex:
|
||||
logger.debug(ex)
|
||||
|
||||
|
||||
class TestRelations(BaseTestCharm):
|
||||
def test_add_relation(self):
|
||||
@ -78,24 +86,38 @@ class TestCharm(BaseTestCharm):
|
||||
@mock.patch('os.fchown')
|
||||
@mock.patch('os.chown')
|
||||
def test_render_config_leader(self, chown, fchown):
|
||||
opts = {
|
||||
'oidc-provider-metadata-url': WELL_KNOWN_URL,
|
||||
'oidc-provider-issuer': 'foo',
|
||||
'oidc-client-id': 'keystone',
|
||||
'oidc-client-secret': 'ubuntu11',
|
||||
}
|
||||
|
||||
well_known_url_content = {
|
||||
'introspection_endpoint': INTROSPECTION_ENDPOINT_INVALID,
|
||||
}
|
||||
self.harness.set_leader(True)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
with mock.patch("charm.KeystoneOpenIDCCharm.config_dir",
|
||||
new_callable=mock.PropertyMock,
|
||||
return_value=tmpdir):
|
||||
self.harness.update_config(
|
||||
key_values={'oidc-provider-metadata-url': WELL_KNOWN_URL})
|
||||
self.harness.charm.render_config()
|
||||
fpath = self.harness.charm.options.openidc_location_config
|
||||
self.assertTrue(os.path.isfile(fpath))
|
||||
with open(fpath) as f:
|
||||
content = f.read()
|
||||
self.assertIn(f'OIDCProviderMetadataURL {WELL_KNOWN_URL}',
|
||||
content)
|
||||
self.assertIn(
|
||||
f'OIDCCryptoPassphrase {str(self.crypto_passphrase)}',
|
||||
content
|
||||
)
|
||||
with requests_mock.Mocker() as m, \
|
||||
mock.patch( # noqa: E127
|
||||
"charm.KeystoneOpenIDCCharm.config_dir",
|
||||
new_callable=mock.PropertyMock,
|
||||
return_value=self.tmpdir.name):
|
||||
m.get(WELL_KNOWN_URL, json=well_known_url_content)
|
||||
self.harness.update_config(
|
||||
key_values=opts)
|
||||
self.harness.charm.render_config()
|
||||
fpath = self.harness.charm.options.openidc_location_config
|
||||
self.assertTrue(os.path.isfile(fpath))
|
||||
with open(fpath) as f:
|
||||
content = f.read()
|
||||
self.assertIn(
|
||||
f'OIDCProviderMetadataURL {WELL_KNOWN_URL}',
|
||||
content
|
||||
)
|
||||
self.assertIn(
|
||||
f'OIDCCryptoPassphrase {str(self.crypto_passphrase)}',
|
||||
content
|
||||
)
|
||||
|
||||
def test_find_missing_keys_no_metadata_url(self):
|
||||
opts = {
|
||||
|
Loading…
Reference in New Issue
Block a user