From 8672c634750298e327071195e2ecc6b8f4c74954 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 27 Jan 2017 11:10:44 +0000 Subject: [PATCH] Initial cut of interface --- .gitignore | 2 ++ .gitreview | 4 ++++ README.md | 37 ++++++++++++++++++++++++++++++++ interface.yaml | 3 +++ provides.py | 49 +++++++++++++++++++++++++++++++++++++++++++ test-requirements.txt | 2 ++ tox.ini | 40 +++++++++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 .gitignore create mode 100644 .gitreview create mode 100644 README.md create mode 100644 interface.yaml create mode 100644 provides.py create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9dd3eb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.tox +.testrepository diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..1b5abe8 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/charm-interface-keystone-domain-backend diff --git a/README.md b/README.md new file mode 100644 index 0000000..a52e4e6 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Overview + +This interface layer handles the communication with Keystone via the +'keystone-domain-backend' interface protocol. + +# Usage + +## Provides + +The interface layer will set the following state: + + * `{relation_name}.connected` The relation is established. + +For example: + +```python +from charms.reactive import when + + +@when('domain-backend.connected') +@when('configuration.complete') +def configure_domain(domain): + domain.domain_name('mynewkeystonedomain') + domain.trigger_restart() +``` + +Typically a domain backend charm should validate that that it +has sufficient and good configuration for the domain backend, +write its configuration to +`/etc/keystone/domains/keystone..conf` and then +trigger a restart of keystone using the `trigger_restart` +method of the inteface, supplying the domain name at this +point in time as well. + +The keystone charm will create the domain in the keystone +database, mapping to the underlying domain configuration +on disk. diff --git a/interface.yaml b/interface.yaml new file mode 100644 index 0000000..139a807 --- /dev/null +++ b/interface.yaml @@ -0,0 +1,3 @@ +name: keystone-domain-backend +summary: Interface for configuring Keystone Domain specific identity backends +maintainer: OpenStack Charmers diff --git a/provides.py b/provides.py new file mode 100644 index 0000000..085ee03 --- /dev/null +++ b/provides.py @@ -0,0 +1,49 @@ +# Copyright 2017 Canonical Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import uuid + +from charms.reactive import RelationBase +from charms.reactive import hook +from charms.reactive import scopes + + +class KeystoneDomainBackendProvides(RelationBase): + scope = scopes.GLOBAL + + @hook('{provides:keystone-domain-backend}-relation-joined') + def joined(self): + self.set_state('{relation_name}.connected') + + @hook('{provides:keystone-domain-backend}-relation-{broken,departed}') + def departed(self): + self.remove_state('{relation_name}.connected') + + def domain_name(self, name): + """ + Set the domain name for the identity backend + """ + relation_info = { + 'domain-name': name, + } + self.set_remote(**relation_info) + + def trigger_restart(self): + """ + Trigger a restart of keystone + """ + relation_info = { + 'restart-nonce': str(uuid.uuid4()) + } + self.set_remote(**relation_info) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..095ec9c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +flake8>=2.2.4,<=2.4.1 +os-testr>=0.4.1 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c395138 --- /dev/null +++ b/tox.ini @@ -0,0 +1,40 @@ +[tox] +envlist = pep8,py27,py34,py35 +skipsdist = True +skip_missing_interpreters = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +install_command = + pip install --allow-unverified python-apt {opts} {packages} +commands = ostestr {posargs} + +[testenv:py27] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:pep8] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226