diff --git a/novaclient/client.py b/novaclient/client.py index 200d75c73..b2a59474f 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -90,9 +90,9 @@ class CompletionCache(object): ~/.novaclient/ / -id-cache - -human-id-cache + -name-cache """ - def __init__(self, username, auth_url, attributes=('id', 'human_id')): + def __init__(self, username, auth_url, attributes=('id', 'name')): self.directory = self._make_directory_name(username, auth_url) self.attributes = attributes diff --git a/novaclient/tests/unit/test_client.py b/novaclient/tests/unit/test_client.py index 2c7f7eaf7..b7628b956 100644 --- a/novaclient/tests/unit/test_client.py +++ b/novaclient/tests/unit/test_client.py @@ -16,6 +16,7 @@ import json import logging +import os import fixtures import mock @@ -366,3 +367,31 @@ class ClientTest(utils.TestCase): self.assertIn('RESP BODY: {"access": {"token": {"id":' ' "{SHA1}4fc49c6a671ce889078ff6b250f7066cf6d2ada2"}}}', output) + + @mock.patch('novaclient.client.HTTPClient') + def test_completion_cache(self, instance): + cp_cache = novaclient.client.CompletionCache('user', + "server/v2") + + client = novaclient.v2.client.Client("user", + "password", "project_id", + auth_url="server/v2", + completion_cache=cp_cache) + + instance.id = "v1c49c6a671ce889078ff6b250f7066cf6d2ada2" + instance.name = "foo.bar.baz v1_1" + client.write_object_to_completion_cache(instance) + self.assertTrue(os.path.isdir(cp_cache.directory)) + + for file_name in os.listdir(cp_cache.directory): + file_path = os.path.join(cp_cache.directory, file_name) + f = open(file_path, 'r') + for line in f: + line = line.rstrip() + if '-id-' in file_name: + self.assertEqual(instance.id, line) + elif '-name-' in file_name: + self.assertEqual(instance.name, line) + f.close() + os.remove(file_path) + os.rmdir(cp_cache.directory)