Merge "Re-enable shell completion cache"
This commit is contained in:
commit
a658526cdb
|
@ -96,14 +96,14 @@ class Manager(utils.HookableMixin):
|
||||||
"""
|
"""
|
||||||
base_dir = cliutils.env('manilaclient_UUID_CACHE_DIR',
|
base_dir = cliutils.env('manilaclient_UUID_CACHE_DIR',
|
||||||
'MANILACLIENT_UUID_CACHE_DIR',
|
'MANILACLIENT_UUID_CACHE_DIR',
|
||||||
default="~/.manilaclient")
|
default="~/.cache/manilaclient")
|
||||||
|
|
||||||
# NOTE(sirp): Keep separate UUID caches for each username + endpoint
|
# NOTE(sirp): Keep separate UUID caches for each username + endpoint
|
||||||
# pair
|
# pair
|
||||||
username = cliutils.env('OS_USERNAME', 'MANILA_USERNAME')
|
username = cliutils.env('OS_USERNAME', 'MANILA_USERNAME')
|
||||||
url = cliutils.env('OS_URL', 'MANILA_URL')
|
url = cliutils.env('OS_URL', 'MANILA_URL')
|
||||||
uniqifier = hashlib.md5(username.encode('utf-8') +
|
uniqifier = hashlib.sha1(username.encode('utf-8') +
|
||||||
url.encode('utf-8')).hexdigest()
|
url.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier))
|
cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier))
|
||||||
|
|
||||||
|
@ -139,7 +139,10 @@ class Manager(utils.HookableMixin):
|
||||||
def write_to_completion_cache(self, cache_type, val):
|
def write_to_completion_cache(self, cache_type, val):
|
||||||
cache = getattr(self, "_%s_cache" % cache_type, None)
|
cache = getattr(self, "_%s_cache" % cache_type, None)
|
||||||
if cache:
|
if cache:
|
||||||
cache.write("%s\n" % val)
|
try:
|
||||||
|
cache.write("%s\n" % val)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def _get(self, url, response_key=None):
|
def _get(self, url, response_key=None):
|
||||||
resp, body = self.api.client.get(url)
|
resp, body = self.api.client.get(url)
|
||||||
|
|
|
@ -48,6 +48,16 @@ class TestCase(testtools.TestCase):
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
return new_attr
|
return new_attr
|
||||||
|
|
||||||
|
def mock_completion(self):
|
||||||
|
patcher = mock.patch(
|
||||||
|
'manilaclient.base.Manager.write_to_completion_cache')
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
patcher = mock.patch('manilaclient.base.Manager.completion_cache')
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
|
||||||
class TestResponse(requests.Response):
|
class TestResponse(requests.Response):
|
||||||
"""Class used to wrap requests.Response.
|
"""Class used to wrap requests.Response.
|
||||||
|
|
|
@ -225,6 +225,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||||
def get_shares_detail(self, **kw):
|
def get_shares_detail(self, **kw):
|
||||||
endpoint = "http://127.0.0.1:8786/v2"
|
endpoint = "http://127.0.0.1:8786/v2"
|
||||||
share_id = '1234'
|
share_id = '1234'
|
||||||
|
|
||||||
shares = {
|
shares = {
|
||||||
'shares': [
|
'shares': [
|
||||||
{
|
{
|
||||||
|
@ -241,8 +242,11 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'count': 2,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kw.get('with_count'):
|
||||||
|
shares.update({'count': 2})
|
||||||
|
|
||||||
return (200, {}, shares)
|
return (200, {}, shares)
|
||||||
|
|
||||||
def get_snapshots_1234(self, **kw):
|
def get_snapshots_1234(self, **kw):
|
||||||
|
|
|
@ -63,6 +63,7 @@ class ShellTest(test_utils.TestCase):
|
||||||
for var in self.FAKE_ENV:
|
for var in self.FAKE_ENV:
|
||||||
self.useFixture(fixtures.EnvironmentVariable(var,
|
self.useFixture(fixtures.EnvironmentVariable(var,
|
||||||
self.FAKE_ENV[var]))
|
self.FAKE_ENV[var]))
|
||||||
|
self.mock_completion()
|
||||||
|
|
||||||
self.shell = shell.OpenStackManilaShell()
|
self.shell = shell.OpenStackManilaShell()
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ from manilaclient.common.apiclient import utils as apiclient_utils
|
||||||
from manilaclient.common import cliutils
|
from manilaclient.common import cliutils
|
||||||
from manilaclient.common import constants
|
from manilaclient.common import constants
|
||||||
from manilaclient import exceptions
|
from manilaclient import exceptions
|
||||||
|
import manilaclient.v2.shares
|
||||||
|
|
||||||
|
|
||||||
def _wait_for_resource_status(cs,
|
def _wait_for_resource_status(cs,
|
||||||
|
@ -2328,6 +2329,19 @@ def do_list(cs, args):
|
||||||
if args.count:
|
if args.count:
|
||||||
print("Shares in total: %s" % total_count)
|
print("Shares in total: %s" % total_count)
|
||||||
|
|
||||||
|
with cs.shares.completion_cache('uuid',
|
||||||
|
manilaclient.v2.shares.Share,
|
||||||
|
mode="w"):
|
||||||
|
for share in shares:
|
||||||
|
cs.shares.write_to_completion_cache('uuid', share.id)
|
||||||
|
|
||||||
|
with cs.shares.completion_cache('name',
|
||||||
|
manilaclient.v2.shares.Share,
|
||||||
|
mode="w"):
|
||||||
|
for share in shares:
|
||||||
|
if share.name is not None:
|
||||||
|
cs.shares.write_to_completion_cache('name', share.name)
|
||||||
|
|
||||||
|
|
||||||
@cliutils.arg(
|
@cliutils.arg(
|
||||||
'--share-id',
|
'--share-id',
|
||||||
|
|
|
@ -7,7 +7,7 @@ _manila()
|
||||||
|
|
||||||
opts="$(manila bash_completion)"
|
opts="$(manila bash_completion)"
|
||||||
|
|
||||||
COMPLETION_CACHE=~/.manilaclient/*/*-cache
|
COMPLETION_CACHE=~/.cache/manilaclient/*/*-cache
|
||||||
opts+=" "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ')
|
opts+=" "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ')
|
||||||
|
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||||
|
|
Loading…
Reference in New Issue