Пример #1
0
 def test_get_entity_no_use_direct_get(self):
     # test we are defaulting to the search_<resource> methods
     # if the use_direct_get flag is set to False(default).
     uuid = uuid4().hex
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, uuid, filters)
         search.assert_called_once_with(uuid, filters)
Пример #2
0
 def test_get_entity_no_uuid_like(self):
     # test we are defaulting to the search_<resource> methods
     # if the name_or_id param is a name(string) but not a uuid.
     self.cloud.use_direct_get = True
     name = 'name_no_uuid'
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, name, filters)
         search.assert_called_once_with(name, filters)
Пример #3
0
 def test_get_entity_pass_uuid(self):
     uuid = uuid4().hex
     self.cloud.use_direct_get = True
     resources = [
         'flavor', 'image', 'volume', 'network', 'subnet', 'port',
         'floating_ip', 'security_group'
     ]
     for r in resources:
         f = 'get_%s_by_id' % r
         with mock.patch.object(self.cloud, f) as get:
             _utils._get_entity(self.cloud, r, uuid, {})
             get.assert_called_once_with(uuid)
Пример #4
0
 def test_get_entity_pass_search_methods(self):
     self.cloud.use_direct_get = True
     resources = [
         'flavor', 'image', 'volume', 'network', 'subnet', 'port',
         'floating_ip', 'security_group'
     ]
     filters = {}
     name = 'name_no_uuid'
     for r in resources:
         f = 'search_%ss' % r
         with mock.patch.object(self.cloud, f) as search:
             _utils._get_entity(self.cloud, r, name, {})
             search.assert_called_once_with(name, filters)
Пример #5
0
 def get_host(self, name_or_id, filters=None, expand=True):
     if expand:
         func = self.search_hosts
     else:
         func = functools.partial(self.search_hosts, expand=False)
     return _utils._get_entity(func, name_or_id, filters)
Пример #6
0
 def get_host(self, name_or_id, filters=None):
     return _utils._get_entity(self.search_hosts, name_or_id, filters)
Пример #7
0
 def get_host(self, name_or_id, filters=None, expand=True):
     if expand:
         func = self.search_hosts
     else:
         func = functools.partial(self.search_hosts, expand=False)
     return _utils._get_entity(func, name_or_id, filters)
Пример #8
0
 def test_get_entity_pass_object(self):
     obj = mock.Mock(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(obj, _utils._get_entity(self.cloud, '', obj, {}))
Пример #9
0
 def test_get_entity_pass_dict(self):
     d = dict(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(d, _utils._get_entity(self.cloud, '', d, {}))