Add module name to repr string
Add the module name to the repr string so we can better identify
the resource that created the string. This is also convenient
for recreating the object from a string such as:
python examples/get.py openstack/compute/v2/server.py --data "openstack.compute.v2.server.Server(attrs={u'id': u'85d8ecf3-3757-43fd-b7a2-eb6636f7af1c', u'name': u'jenkins'}, loaded=True)"
Change-Id: I7a8bdabd8150e0bd06ec46deecf81eaa126907ab
This commit is contained in:
@@ -72,7 +72,14 @@ def get_data_option(opts):
|
||||
iddy = uuid.UUID(opts.data)
|
||||
return {'id': iddy}
|
||||
except ValueError:
|
||||
return eval(opts.data)
|
||||
data = opts.data
|
||||
if data.startswith('openstack.'):
|
||||
fullname = data.split('(')[0]
|
||||
classname = fullname.split('.')[-1]
|
||||
modulename = fullname.replace('.' + classname, '')
|
||||
data = data.replace('openstack.',
|
||||
'__import__("' + modulename + '").')
|
||||
return eval(data)
|
||||
|
||||
|
||||
def get_open_fds():
|
||||
|
||||
@@ -257,8 +257,9 @@ class Resource(collections.MutableMapping):
|
||||
self.update_attrs(attrs)
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(attrs=%s, loaded=%s)" % (self.__class__.__name__,
|
||||
self._attrs, self._loaded)
|
||||
return "%s.%s(attrs=%s, loaded=%s)" % (self.__module__,
|
||||
self.__class__.__name__,
|
||||
self._attrs, self._loaded)
|
||||
|
||||
@classmethod
|
||||
def get_resource_name(cls):
|
||||
|
||||
@@ -942,6 +942,7 @@ class ResourceTests(base.TestTransportBase):
|
||||
fr.second = "hi"
|
||||
fr.third = "nah"
|
||||
the_repr = repr(fr)
|
||||
the_repr = the_repr.replace('openstack.tests.unit.test_resource.', '')
|
||||
result = eval(the_repr)
|
||||
self.assertEqual(fr._loaded, result._loaded)
|
||||
self.assertEqual(fr.first, result.first)
|
||||
|
||||
Reference in New Issue
Block a user