Merge "Centralize bash-completion in Novaclient"
This commit is contained in:
commit
e7d26a6f51
|
@ -32,7 +32,6 @@ from six.moves.urllib import parse
|
|||
from openstack.common.apiclient import exceptions
|
||||
from openstack.common.gettextutils import _
|
||||
from openstack.common import strutils
|
||||
from openstack.common import uuidutils
|
||||
|
||||
|
||||
def getid(obj):
|
||||
|
@ -437,21 +436,6 @@ class Resource(object):
|
|||
self._info = info
|
||||
self._add_details(info)
|
||||
self._loaded = loaded
|
||||
self._init_completion_cache()
|
||||
|
||||
def _init_completion_cache(self):
|
||||
cache_write = getattr(self.manager, 'write_to_completion_cache', None)
|
||||
if not cache_write:
|
||||
return
|
||||
|
||||
# NOTE(sirp): ensure `id` is already present because if it isn't we'll
|
||||
# enter an infinite loop of __getattr__ -> get -> __init__ ->
|
||||
# __getattr__ -> ...
|
||||
if 'id' in self.__dict__ and uuidutils.is_uuid_like(self.id):
|
||||
cache_write('uuid', self.id)
|
||||
|
||||
if self.human_id:
|
||||
cache_write('human_id', self.human_id)
|
||||
|
||||
def __repr__(self):
|
||||
reprkeys = sorted(k
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import collections
|
||||
|
||||
from oslotest import base as test_base
|
||||
|
||||
from openstack.common.apiclient import base
|
||||
|
@ -120,20 +118,7 @@ class TestClient(client.BaseClient):
|
|||
self.crud_resources = CrudResourceManager(self)
|
||||
|
||||
|
||||
class ManagerWithoutCompletionCache(object):
|
||||
def __init__(self):
|
||||
self.cache = collections.defaultdict(list)
|
||||
|
||||
|
||||
class ManagerWithCompletionCache(ManagerWithoutCompletionCache):
|
||||
def write_to_completion_cache(self, cache_type, val):
|
||||
self.cache[cache_type].append(val)
|
||||
|
||||
|
||||
class ResourceTest(test_base.BaseTestCase):
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
FAKE_UUID2 = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
|
||||
|
||||
def test_resource_repr(self):
|
||||
r = base.Resource(None, dict(foo="bar", baz="spam"))
|
||||
self.assertEqual(repr(r), "<Resource baz=spam, foo=bar>")
|
||||
|
@ -151,37 +136,6 @@ class ResourceTest(test_base.BaseTestCase):
|
|||
r = HumanResource(None, {"name": None})
|
||||
self.assertIsNone(r.human_id)
|
||||
|
||||
def test_write_to_cache_with_manager_that_supports_it(self):
|
||||
"""If a resource is using a `Manager` with a completion cache, then
|
||||
when the resource is created, it should write its UUID, and
|
||||
optionally, its human-id to the completion cache.
|
||||
"""
|
||||
manager = ManagerWithCompletionCache()
|
||||
self.assertEqual({}, manager.cache)
|
||||
|
||||
base.Resource(manager, {"id": self.FAKE_UUID})
|
||||
self.assertEqual({'uuid': [self.FAKE_UUID]}, manager.cache)
|
||||
|
||||
HumanResource(manager, {"id": self.FAKE_UUID2,
|
||||
"name": "this is a resource"})
|
||||
self.assertEqual({'uuid': [self.FAKE_UUID, self.FAKE_UUID2],
|
||||
'human_id': ['this-is-a-resource']}, manager.cache)
|
||||
|
||||
def test_write_to_cache_with_manager_that_doesnt_support_it(self):
|
||||
"""If a resource is using a `Manager` that doesn't have a
|
||||
`write_to_completion_cache` method, then it should gracefully ignore
|
||||
it.
|
||||
"""
|
||||
manager = ManagerWithoutCompletionCache()
|
||||
self.assertEqual({}, manager.cache)
|
||||
|
||||
base.Resource(manager, {"id": self.FAKE_UUID})
|
||||
self.assertEqual({}, manager.cache)
|
||||
|
||||
HumanResource(manager, {"id": self.FAKE_UUID2,
|
||||
"name": "this is a resource"})
|
||||
self.assertEqual({}, manager.cache)
|
||||
|
||||
|
||||
class BaseManagerTest(test_base.BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue