diff options
Diffstat (limited to 'heatclient')
-rw-r--r-- | heatclient/tests/test_resources.py | 6 | ||||
-rw-r--r-- | heatclient/tests/test_shell.py | 131 | ||||
-rw-r--r-- | heatclient/v1/resources.py | 5 | ||||
-rw-r--r-- | heatclient/v1/shell.py | 12 |
4 files changed, 137 insertions, 17 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..f288952 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -56,7 +56,7 @@ class TestCase(testtools.TestCase): # required for testing with Python 2.6 def assertRegexpMatches(self, text, expected_regexp, msg=None): """Fail the test unless the text matches the regular expression.""" - if isinstance(expected_regexp, basestring): + if isinstance(expected_regexp, six.string_types): expected_regexp = re.compile(expected_regexp) if not expected_regexp.search(text): msg = msg or "Regexp didn't match" @@ -644,7 +644,7 @@ class ShellTestUserPass(ShellBase): self.m.ReplayAll() template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') - create_text = self.shell( + update_text = self.shell( 'stack-update teststack2/2 ' '--template-file=%s ' '--parameters="InstanceType=m1.large;DBUsername=wp;' @@ -658,7 +658,7 @@ class ShellTestUserPass(ShellBase): '1' ] for r in required: - self.assertRegexpMatches(create_text, r) + self.assertRegexpMatches(update_text, r) def test_stack_delete(self): self._script_keystone_client() @@ -674,7 +674,7 @@ class ShellTestUserPass(ShellBase): self.m.ReplayAll() - create_text = self.shell('stack-delete teststack2/2') + delete_text = self.shell('stack-delete teststack2/2') required = [ 'stack_name', @@ -683,7 +683,7 @@ class ShellTestUserPass(ShellBase): '1' ] for r in required: - self.assertRegexpMatches(create_text, r) + self.assertRegexpMatches(delete_text, r) def test_stack_delete_multiple(self): self._script_keystone_client() @@ -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 diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 4784791..698f234 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -361,9 +361,9 @@ def do_template_show(hc, args): raise exc.CommandError('Stack not found: %s' % args.id) else: if 'heat_template_version' in template: - print yaml.safe_dump(template, indent=2) + print(yaml.safe_dump(template, indent=2)) else: - print jsonutils.dumps(template, indent=2) + print(jsonutils.dumps(template, indent=2)) @utils.arg('-u', '--template-url', metavar='<URL>', @@ -404,7 +404,7 @@ def do_template_validate(hc, args): _process_environment_and_files(args, fields) validation = hc.stacks.validate(**fields) - print jsonutils.dumps(validation, indent=2) + print(jsonutils.dumps(validation, indent=2)) @utils.arg('id', metavar='<NAME or ID>', @@ -471,9 +471,9 @@ def do_resource_template(hc, args): raise exc.CommandError('Resource %s not found.' % args.resource) else: if args.format: - print utils.format_output(template, format=args.format) + print(utils.format_output(template, format=args.format)) else: - print utils.format_output(template) + print(utils.format_output(template)) @utils.arg('id', metavar='<NAME or ID>', @@ -490,7 +490,7 @@ def do_resource_metadata(hc, args): raise exc.CommandError('Stack or resource not found: %s %s' % (args.id, args.resource)) else: - print jsonutils.dumps(metadata, indent=2) + print(jsonutils.dumps(metadata, indent=2)) @utils.arg('id', metavar='<NAME or ID>', |