From 2f680ccd93c103fe0165d4167892789222cfdb59 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Fri, 9 Nov 2018 08:40:03 +0100 Subject: [PATCH 1/2] Add stand-alone UnsealVault test Useful for bootstrapping Vault when it is present in test bundles for other charms. --- zaza/charm_tests/vault/tests.py | 39 +++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/zaza/charm_tests/vault/tests.py b/zaza/charm_tests/vault/tests.py index d8aa724..614b0b0 100644 --- a/zaza/charm_tests/vault/tests.py +++ b/zaza/charm_tests/vault/tests.py @@ -30,8 +30,8 @@ import zaza.utilities.cert import zaza.model -class VaultTest(unittest.TestCase): - """Encapsulate vault tests.""" +class BaseVaultTest(unittest.TestCase): + """Base class for vault tests.""" @classmethod def setUpClass(cls): @@ -44,6 +44,41 @@ class VaultTest(unittest.TestCase): vault_utils.unseal_all(cls.clients, cls.vault_creds['keys'][0]) vault_utils.auth_all(cls.clients, cls.vault_creds['root_token']) + +class UnsealVault(BaseVaultTest): + """Unseal Vault only. + + Useful for bootstrapping Vault when it is present in test bundles for other + charms. + """ + + @classmethod + def setUpClass(cls): + """Run setup for UnsealVault class.""" + super(UnsealVault, cls).setUpClass() + + def test_unseal(self, test_config=None): + """Unseal Vault. + + :param test_config: (Optional) Zaza test config + :type test_config: charm_lifecycle.utils.get_charm_config() + """ + vault_utils.run_charm_authorize(self.vault_creds['root_token']) + if not test_config: + test_config = lifecycle_utils.get_charm_config() + del test_config['target_deploy_status']['vault'] + zaza.model.wait_for_application_states( + states=test_config.get('target_deploy_status', {})) + + +class VaultTest(BaseVaultTest): + """Encapsulate vault tests.""" + + @classmethod + def setUpClass(cls): + """Run setup for Vault tests.""" + super(VaultTest, cls).setUpClass() + def test_csr(self): """Test generating a csr and uploading a signed certificate.""" vault_actions = zaza.model.get_actions( From b88447c7c678703355bc827ded47d7cdd2e64a37 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Fri, 9 Nov 2018 11:55:46 +0100 Subject: [PATCH 2/2] Add setup and test code for barbican-vault --- zaza/charm_tests/barbican_vault/__init__.py | 15 ++++++++++ zaza/charm_tests/barbican_vault/tests.py | 33 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 zaza/charm_tests/barbican_vault/__init__.py create mode 100644 zaza/charm_tests/barbican_vault/tests.py diff --git a/zaza/charm_tests/barbican_vault/__init__.py b/zaza/charm_tests/barbican_vault/__init__.py new file mode 100644 index 0000000..90a70e6 --- /dev/null +++ b/zaza/charm_tests/barbican_vault/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2018 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. + +"""Collection of code for setting up and testing barbican-vault.""" diff --git a/zaza/charm_tests/barbican_vault/tests.py b/zaza/charm_tests/barbican_vault/tests.py new file mode 100644 index 0000000..0684c77 --- /dev/null +++ b/zaza/charm_tests/barbican_vault/tests.py @@ -0,0 +1,33 @@ +# Copyright 2018 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. + +"""Encapsulate barbican-vault testing.""" + +import zaza +import zaza.charm_tests.vault.tests as vault_tests + + +class BarbicanVaultUnsealVault(vault_tests.UnsealVault): + """Helper class to unseal Vault and update deploy status expectations.""" + + @classmethod + def setUpClass(cls): + """Run setup for UnsealVault class.""" + super(BarbicanVaultUnsealVault, cls).setUpClass() + + def test_unseal(self): + """Unseal vault, update barbican-vault deploy status expectations.""" + test_config = zaza.charm_lifecycle.utils.get_charm_config() + del test_config['target_deploy_status']['barbican-vault'] + super().test_unseal(test_config)