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):
|
def _wrapper(self, event):
|
||||||
try:
|
try:
|
||||||
if not self.is_data_ready():
|
if not self.is_data_ready():
|
||||||
logger.debug('relation data is not ready yet (%s)',
|
logger.debug('relation data is not ready yet (%s)', event)
|
||||||
event)
|
|
||||||
return
|
return
|
||||||
except CharmConfigError as ex:
|
except CharmConfigError as ex:
|
||||||
self.unit.status = BlockedStatus(ex.msg)
|
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):
|
def _on_keystone_fid_service_provider_relation_changed(self, event):
|
||||||
if not self.is_data_ready():
|
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
|
return
|
||||||
self.update_principal_data()
|
self.update_principal_data()
|
||||||
self.update_config_if_needed()
|
self.update_config_if_needed()
|
||||||
@ -290,8 +289,7 @@ class KeystoneOpenIDCCharm(ops_openstack.core.OSBaseCharm):
|
|||||||
|
|
||||||
def _on_config_changed(self, event):
|
def _on_config_changed(self, event):
|
||||||
if not self.is_data_ready():
|
if not self.is_data_ready():
|
||||||
logger.debug('relation data is not ready yet',
|
logger.debug('relation data is not ready yet (%s)', event)
|
||||||
event)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._stored.is_started = True
|
self._stored.is_started = True
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
@ -24,6 +25,7 @@ CRYPTO_PASSPHRASE = '1e19bb8a-a92d-4377-8226-5e8fc475822c'
|
|||||||
|
|
||||||
class BaseTestCharm(unittest.TestCase):
|
class BaseTestCharm(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.tmpdir = tempfile.TemporaryDirectory()
|
||||||
self.harness = Harness(charm.KeystoneOpenIDCCharm, meta='''
|
self.harness = Harness(charm.KeystoneOpenIDCCharm, meta='''
|
||||||
name: keystone-openidc
|
name: keystone-openidc
|
||||||
provides:
|
provides:
|
||||||
@ -40,6 +42,12 @@ class BaseTestCharm(unittest.TestCase):
|
|||||||
self.addCleanup(self.harness.cleanup)
|
self.addCleanup(self.harness.cleanup)
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(self.tmpdir, ignore_errors=True)
|
||||||
|
except Exception as ex:
|
||||||
|
logger.debug(ex)
|
||||||
|
|
||||||
|
|
||||||
class TestRelations(BaseTestCharm):
|
class TestRelations(BaseTestCharm):
|
||||||
def test_add_relation(self):
|
def test_add_relation(self):
|
||||||
@ -78,20 +86,34 @@ class TestCharm(BaseTestCharm):
|
|||||||
@mock.patch('os.fchown')
|
@mock.patch('os.fchown')
|
||||||
@mock.patch('os.chown')
|
@mock.patch('os.chown')
|
||||||
def test_render_config_leader(self, chown, fchown):
|
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)
|
self.harness.set_leader(True)
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with requests_mock.Mocker() as m, \
|
||||||
with mock.patch("charm.KeystoneOpenIDCCharm.config_dir",
|
mock.patch( # noqa: E127
|
||||||
|
"charm.KeystoneOpenIDCCharm.config_dir",
|
||||||
new_callable=mock.PropertyMock,
|
new_callable=mock.PropertyMock,
|
||||||
return_value=tmpdir):
|
return_value=self.tmpdir.name):
|
||||||
|
m.get(WELL_KNOWN_URL, json=well_known_url_content)
|
||||||
self.harness.update_config(
|
self.harness.update_config(
|
||||||
key_values={'oidc-provider-metadata-url': WELL_KNOWN_URL})
|
key_values=opts)
|
||||||
self.harness.charm.render_config()
|
self.harness.charm.render_config()
|
||||||
fpath = self.harness.charm.options.openidc_location_config
|
fpath = self.harness.charm.options.openidc_location_config
|
||||||
self.assertTrue(os.path.isfile(fpath))
|
self.assertTrue(os.path.isfile(fpath))
|
||||||
with open(fpath) as f:
|
with open(fpath) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
self.assertIn(f'OIDCProviderMetadataURL {WELL_KNOWN_URL}',
|
self.assertIn(
|
||||||
content)
|
f'OIDCProviderMetadataURL {WELL_KNOWN_URL}',
|
||||||
|
content
|
||||||
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
f'OIDCCryptoPassphrase {str(self.crypto_passphrase)}',
|
f'OIDCCryptoPassphrase {str(self.crypto_passphrase)}',
|
||||||
content
|
content
|
||||||
|
Loading…
Reference in New Issue
Block a user