Fix CloudStack problem with ssh public keys

Change .split with .splitlines in get_public_keys.

Change-Id: I938a11518545766ea5383e827085bcada7cf2266
This commit is contained in:
Alexandru Coman 2015-02-26 14:24:02 +02:00
parent 83f523fd54
commit 8c28f2f12b
2 changed files with 6 additions and 5 deletions

View File

@ -110,7 +110,7 @@ class CloudStack(base.BaseMetadataService):
def get_public_keys(self):
"""Available ssh public keys."""
ssh_keys = []
for ssh_key in self._get_cache_data('public-keys').split():
for ssh_key in self._get_cache_data('public-keys').splitlines():
ssh_key = ssh_key.strip()
if not ssh_key:
continue

View File

@ -168,14 +168,15 @@ class CloudStackTest(unittest.TestCase):
'._get_cache_data')
def test_get_public_keys(self, mock_get_cache_data):
mock_get_cache_data.side_effect = [
"a\nb\nc",
"\n\na\n\nb\n\nc",
" \n \n a \n \n b \n \n c",
"ssh-rsa AAAA\nssh-rsa BBBB\nssh-rsa CCCC",
"\n\nssh-rsa AAAA\n\nssh-rsa BBBB\n\nssh-rsa CCCC",
" \n \n ssh-rsa AAAA \n \n ssh-rsa BBBB \n \n ssh-rsa CCCC",
" ", "\n", " \n "
]
for _ in range(3):
response = self._service.get_public_keys()
self.assertEqual(["a", "b", "c"], response)
self.assertEqual(["ssh-rsa AAAA", "ssh-rsa BBBB", "ssh-rsa CCCC"],
response)
for _ in range(3):
response = self._service.get_public_keys()