Merge pull request #353 from gnuoy/store-keys-in-tmpdir
Use model tmp dir for key storage
This commit is contained in:
@@ -581,21 +581,27 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
nova_mock.keypairs.create.assert_called_once_with(name='mykeys')
|
||||
|
||||
def test_get_private_key_file(self):
|
||||
self.patch_object(openstack_utils.deployment_env, 'get_tmpdir',
|
||||
return_value='/tmp/zaza-model1')
|
||||
self.assertEqual(
|
||||
openstack_utils.get_private_key_file('mykeys'),
|
||||
'tests/id_rsa_mykeys')
|
||||
'/tmp/zaza-model1/id_rsa_mykeys')
|
||||
|
||||
def test_write_private_key(self):
|
||||
self.patch_object(openstack_utils.deployment_env, 'get_tmpdir',
|
||||
return_value='/tmp/zaza-model1')
|
||||
m = mock.mock_open()
|
||||
with mock.patch(
|
||||
'zaza.openstack.utilities.openstack.open', m, create=False
|
||||
):
|
||||
openstack_utils.write_private_key('mykeys', 'keycontents')
|
||||
m.assert_called_once_with('tests/id_rsa_mykeys', 'w')
|
||||
m.assert_called_once_with('/tmp/zaza-model1/id_rsa_mykeys', 'w')
|
||||
handle = m()
|
||||
handle.write.assert_called_once_with('keycontents')
|
||||
|
||||
def test_get_private_key(self):
|
||||
self.patch_object(openstack_utils.deployment_env, 'get_tmpdir',
|
||||
return_value='/tmp/zaza-model1')
|
||||
self.patch_object(openstack_utils.os.path, "isfile",
|
||||
return_value=True)
|
||||
m = mock.mock_open(read_data='myprivkey')
|
||||
@@ -607,6 +613,8 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
'myprivkey')
|
||||
|
||||
def test_get_private_key_file_missing(self):
|
||||
self.patch_object(openstack_utils.deployment_env, 'get_tmpdir',
|
||||
return_value='/tmp/zaza-model1')
|
||||
self.patch_object(openstack_utils.os.path, "isfile",
|
||||
return_value=False)
|
||||
self.assertIsNone(openstack_utils.get_private_key('mykeys'))
|
||||
|
||||
@@ -2202,7 +2202,8 @@ def get_private_key_file(keypair_name):
|
||||
:returns: Path to file containing key
|
||||
:rtype: str
|
||||
"""
|
||||
return 'tests/id_rsa_{}'.format(keypair_name)
|
||||
tmp_dir = deployment_env.get_tmpdir()
|
||||
return '{}/id_rsa_{}'.format(tmp_dir, keypair_name)
|
||||
|
||||
|
||||
def write_private_key(keypair_name, key):
|
||||
|
||||
Reference in New Issue
Block a user