add reload and restart action tests for vault
This commit is contained in:
@@ -244,8 +244,6 @@ class VaultTest(BaseVaultTest):
|
||||
Pause service and check services are stopped, then resume and check
|
||||
they are started.
|
||||
"""
|
||||
# Restarting vault process will set it as sealed so it's
|
||||
# important to have the test executed at the end.
|
||||
vault_actions = zaza.model.get_actions(
|
||||
'vault')
|
||||
if 'pause' not in vault_actions or 'resume' not in vault_actions:
|
||||
@@ -257,6 +255,58 @@ class VaultTest(BaseVaultTest):
|
||||
lead_client = vault_utils.extract_lead_unit_client(self.clients)
|
||||
self.assertTrue(lead_client.hvac_client.seal_status['sealed'])
|
||||
|
||||
def test_vault_reload(self):
|
||||
"""Run reload tests.
|
||||
|
||||
Reload service and check services were restarted
|
||||
by doing simple change in the running config by API.
|
||||
Then confirm that service is not sealed
|
||||
"""
|
||||
vault_actions = zaza.model.get_actions(
|
||||
'vault')
|
||||
if 'reload' not in vault_actions:
|
||||
raise unittest.SkipTest("The version of charm-vault tested does "
|
||||
"not have reload action")
|
||||
|
||||
lead_client = vault_utils.extract_lead_unit_client(self.clients)
|
||||
running_config = vault_utils.get_running_config(lead_client)
|
||||
value_to_set = not running_config['data']['disable_mlock']
|
||||
|
||||
zaza.model.set_application_config(
|
||||
'vault',
|
||||
{'disable-mlock': str(value_to_set)})
|
||||
|
||||
logging.info("Testing reload")
|
||||
zaza.model.run_action_on_leader(
|
||||
'vault',
|
||||
'reload',
|
||||
action_params={})
|
||||
|
||||
self.assertEqual(
|
||||
value_to_set,
|
||||
vault_utils.get_running_config(lead_client)[
|
||||
'data']['disable_mlock'])
|
||||
self.assertFalse(lead_client.hvac_client.seal_status['sealed'])
|
||||
|
||||
def test_vault_restart(self):
|
||||
"""Run pause and resume tests.
|
||||
|
||||
Restart service and check services are started.
|
||||
"""
|
||||
vault_actions = zaza.model.get_actions(
|
||||
'vault')
|
||||
if 'restart' not in vault_actions:
|
||||
raise unittest.SkipTest("The version of charm-vault tested does "
|
||||
"not have restart action")
|
||||
logging.info("Testing restart")
|
||||
zaza.model.run_action_on_leader(
|
||||
'vault',
|
||||
'restart',
|
||||
action_params={})
|
||||
|
||||
lead_client = vault_utils.extract_lead_unit_client(self.clients)
|
||||
self.assertTrue(lead_client.hvac_client.seal_status['sealed'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -137,6 +137,20 @@ def get_vip_client(cacert=None):
|
||||
return client
|
||||
|
||||
|
||||
def get_running_config(client):
|
||||
"""Get Vault running config.
|
||||
|
||||
:param client: Client to use for initiliasation
|
||||
:type client: CharmVaultClient
|
||||
The hvac library does not support getting info
|
||||
from endpoint /v1/sys/config/state/sanitized
|
||||
Therefore we implement it here
|
||||
"""
|
||||
return requests.get(
|
||||
client.hvac_client.adapter.base_uri + '/v1/sys/config/state/sanitized',
|
||||
headers={'X-Vault-Token': client.hvac_client.token}).json()
|
||||
|
||||
|
||||
def init_vault(client, shares=1, threshold=1):
|
||||
"""Initialise vault.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user