Change the unsuitable item caching for completion

This fix changes the item that cached for completion from
"human_id" to "name".
A string for completion shoud not be changed in any way,
because changed keyword can not use as command line parameter.
But the "human_id" means "human readable id" that is
changed from "name" by method "to_slug". "to_slug" is meant to
create a valid path name from a string.

The tools/nova.bash_completion take the completion string from
the file ".novaclient/*/*-cache". The file is created when client
call "list" command. For example , "nova list","nova image-list",
and the others.
Currently, items that are written to the cache file is the "id"
and "human_id".

Closes-Bug: #1193049

Change-Id: I241ec8b7c8729274ee43db6e360141fd381b265e
This commit is contained in:
Ikuo Kumagai 2014-11-21 13:47:30 +00:00
parent ab6065b562
commit 9a6a7664c2
2 changed files with 31 additions and 2 deletions

View File

@ -90,9 +90,9 @@ class CompletionCache(object):
~/.novaclient/
<hash-of-endpoint-and-username>/
<resource>-id-cache
<resource>-human-id-cache
<resource>-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

View File

@ -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)