Skip to content

Commit

Permalink
Merge pull request #50102 from garethgreenaway/updating_vault_integra…
Browse files Browse the repository at this point in the history
…tion_test

[develop] update integration.module.test_vault
  • Loading branch information
Mike Place committed Oct 18, 2018
2 parents 1e25bd2 + ffc702c commit 0fb0e9b
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions tests/integration/modules/test_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self):
'''
SetUp vault container
'''
if self.count == 0:
if VaultTestCase.count == 0:
config = '{"backend": {"file": {"path": "/vault/file"}}, "default_lease_ttl": "168h", "max_lease_ttl": "720h"}'
self.run_state('docker_image.present', name='vault', tag='0.9.6')
self.run_state(
Expand All @@ -54,25 +54,50 @@ def setUp(self):
cmd='/usr/local/bin/vault login token=testsecret',
env={'VAULT_ADDR': 'http://127.0.0.1:8200'},
)
if ret != 0:
self.skipTest('unable to login to vault')
login_attempts = 1
# If the login failed, container might have stopped
# attempt again, maximum of three times before
# skipping.
while ret != 0:
self.run_state(
'docker_container.running',
name='vault',
image='vault:0.9.6',
port_bindings='8200:8200',
environment={
'VAULT_DEV_ROOT_TOKEN_ID': 'testsecret',
'VAULT_LOCAL_CONFIG': config,
},
cap_add='IPC_LOCK',
)
time.sleep(5)
ret = self.run_function(
'cmd.retcode',
cmd='/usr/local/bin/vault login token=testsecret',
env={'VAULT_ADDR': 'http://127.0.0.1:8200'},
)
login_attempts += 1
if login_attempts >= 3:
self.skipTest('unable to login to vault')
ret = self.run_function(
'cmd.retcode',
cmd='/usr/local/bin/vault policy write testpolicy {0}/vault.hcl'.format(FILES),
env={'VAULT_ADDR': 'http://127.0.0.1:8200'},
)
if ret != 0:
self.skipTest('unable to assign policy to vault')
self.count += 1
VaultTestCase.count += 1

def tearDown(self):
'''
TearDown vault container
'''
def count_tests(funcobj):
return inspect.ismethod(funcobj) and funcobj.__name__.startswith('test_')
return (inspect.ismethod(funcobj) or
inspect.isfunction(funcobj)) and \
funcobj.__name__.startswith('test_')
numtests = len(inspect.getmembers(VaultTestCase, predicate=count_tests))
if self.count >= numtests:
if VaultTestCase.count >= numtests:
self.run_state('docker_container.stopped', name='vault')
self.run_state('docker_container.absent', name='vault')
self.run_state('docker_image.absent', name='vault', force=True)
Expand Down

0 comments on commit 0fb0e9b

Please sign in to comment.