summaryrefslogtreecommitdiff
path: root/heatclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-01-15 11:41:21 +0000
committerGerrit Code Review <review@openstack.org>2014-01-15 11:41:21 +0000
commit4924a14cb0cecab837eb80c028480fb0e9539b23 (patch)
tree5e14009061a6c1cb74d49918c3cd667d7bb5d5a5 /heatclient
parent97d945e87995e61920227e5664ee3c55290c6052 (diff)
parentd19174be975219a0b9ed765df33741befcab50ea (diff)
downloadpython-heatclient-4924a14cb0cecab837eb80c028480fb0e9539b23.tar.gz
Merge "Add to_dict() method to Resource class"
Diffstat (limited to 'heatclient')
-rw-r--r--heatclient/tests/test_resources.py6
-rw-r--r--heatclient/tests/test_shell.py121
-rw-r--r--heatclient/v1/resources.py5
3 files changed, 126 insertions, 6 deletions
diff --git a/heatclient/tests/test_resources.py b/heatclient/tests/test_resources.py
index 998e3c1..90c7927 100644
--- a/heatclient/tests/test_resources.py
+++ b/heatclient/tests/test_resources.py
@@ -12,10 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-from heatclient.v1.resources import Resource
from heatclient.v1.resources import ResourceManager
-from mock import MagicMock
from mox3 import mox
import testtools
@@ -42,8 +40,6 @@ class ResourceManagerTest(testtools.TestCase):
return {}, {key: ret}
manager = ResourceManager(FakeAPI())
- Resource.__init__ = MagicMock()
- Resource.__init__.return_value = None
self.m.StubOutWithMock(manager, '_resolve_stack_id')
manager._resolve_stack_id('teststack').AndReturn('teststack/abcd1234')
self.m.ReplayAll()
@@ -87,8 +83,6 @@ class ResourceManagerTest(testtools.TestCase):
return FakeResponse()
manager = ResourceManager(FakeClient())
- Resource.__init__ = MagicMock()
- Resource.__init__.return_value = None
self.m.StubOutWithMock(manager, '_resolve_stack_id')
manager._resolve_stack_id('teststack').AndReturn('teststack/abcd1234')
self.m.ReplayAll()
diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py
index 8a78e5e..6840688 100644
--- a/heatclient/tests/test_shell.py
+++ b/heatclient/tests/test_shell.py
@@ -875,6 +875,127 @@ class ShellTestEvents(ShellBase):
self.assertRegexpMatches(event_list_text, r)
+class ShellTestResources(ShellBase):
+ def setUp(self):
+ super(ShellTestResources, self).setUp()
+ self._set_fake_env()
+
+ # Patch os.environ to avoid required auth info.
+ def _set_fake_env(self):
+ fake_env = {
+ 'OS_USERNAME': 'username',
+ 'OS_PASSWORD': 'password',
+ 'OS_TENANT_NAME': 'tenant_name',
+ 'OS_AUTH_URL': 'http://no.where',
+ }
+ self.set_fake_env(fake_env)
+
+ def _script_keystone_client(self):
+ fakes.script_keystone_client()
+
+ def test_resource_list(self):
+ self._script_keystone_client()
+ resp_dict = {"resources": [
+ {"links": [{"href": "http://heat.example.com:8004/foo",
+ "rel": "self"},
+ {"href": "http://heat.example.com:8004/foo2",
+ "rel": "resource"}],
+ "logical_resource_id": "aResource",
+ "physical_resource_id":
+ "43b68bae-ed5d-4aed-a99f-0b3d39c2418a",
+ "resource_name": "aResource",
+ "resource_status": "CREATE_COMPLETE",
+ "resource_status_reason": "state changed",
+ "resource_type": "OS::Nova::Server",
+ "updated_time": "2014-01-06T16:14:26Z"}]}
+ resp = fakes.FakeHTTPResponse(
+ 200,
+ 'OK',
+ {'content-type': 'application/json'},
+ jsonutils.dumps(resp_dict))
+ stack_id = 'teststack/1'
+ http.HTTPClient.json_request(
+ 'GET', '/stacks/%s/resources' % (
+ stack_id)).AndReturn((resp, resp_dict))
+
+ self.m.ReplayAll()
+
+ resource_list_text = self.shell('resource-list {0}'.format(stack_id))
+
+ required = [
+ 'resource_name',
+ 'resource_type',
+ 'resource_status',
+ 'updated_time',
+ 'aResource',
+ 'OS::Nova::Server',
+ 'CREATE_COMPLETE',
+ '2014-01-06T16:14:26Z'
+ ]
+ for r in required:
+ self.assertRegexpMatches(resource_list_text, r)
+
+ def test_resource_show(self):
+ self._script_keystone_client()
+ resp_dict = {"resource":
+ {"description": "",
+ "links": [{"href": "http://heat.example.com:8004/foo",
+ "rel": "self"},
+ {"href": "http://heat.example.com:8004/foo2",
+ "rel": "resource"}],
+ "logical_resource_id": "aResource",
+ "physical_resource_id":
+ "43b68bae-ed5d-4aed-a99f-0b3d39c2418a",
+ "required_by": [],
+ "resource_name": "aResource",
+ "resource_status": "CREATE_COMPLETE",
+ "resource_status_reason": "state changed",
+ "resource_type": "OS::Nova::Server",
+ "updated_time": "2014-01-06T16:14:26Z"}}
+ resp = fakes.FakeHTTPResponse(
+ 200,
+ 'OK',
+ {'content-type': 'application/json'},
+ jsonutils.dumps(resp_dict))
+ stack_id = 'teststack/1'
+ resource_name = 'aResource'
+ http.HTTPClient.json_request(
+ 'GET', '/stacks/%s/resources/%s' %
+ (
+ urlutils.quote(stack_id, ''),
+ urlutils.quote(strutils.safe_encode(
+ resource_name), '')
+ )).AndReturn((resp, resp_dict))
+
+ self.m.ReplayAll()
+
+ resource_show_text = self.shell('resource-show {0} {1}'.format(
+ stack_id, resource_name))
+
+ required = [
+ 'description',
+ 'links',
+ 'http://heat.example.com:8004/foo[0-9]',
+ 'logical_resource_id',
+ 'aResource',
+ 'physical_resource_id',
+ '43b68bae-ed5d-4aed-a99f-0b3d39c2418a',
+ 'required_by',
+ 'resource_name',
+ 'aResource',
+ 'resource_status',
+ 'CREATE_COMPLETE',
+ 'resource_status_reason',
+ 'state changed',
+ 'resource_type',
+ 'OS::Nova::Server',
+ 'updated_time',
+ '2014-01-06T16:14:26Z',
+ ]
+ for r in required:
+ self.assertRegexpMatches(resource_show_text, r)
+
+
class ShellTestToken(ShellTestUserPass):
# Rerun all ShellTestUserPass test with token auth
diff --git a/heatclient/v1/resources.py b/heatclient/v1/resources.py
index 9d66a15..2d22dcf 100644
--- a/heatclient/v1/resources.py
+++ b/heatclient/v1/resources.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import copy
+
from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils
@@ -34,6 +36,9 @@ class Resource(base.Resource):
def data(self, **kwargs):
return self.manager.data(self, **kwargs)
+ def to_dict(self):
+ return copy.deepcopy(self._info)
+
class ResourceManager(stacks.StackChildManager):
resource_class = Resource