Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #6
0
 def get_host(self, name_or_id, filters=None):
     return _utils._get_entity(self.search_hosts, name_or_id, filters)
 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)
Example #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, {}))
Example #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, {}))