diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-01-28 16:45:30 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-01-28 16:45:30 +0000 |
commit | 62cd3154c5ee0380f9ae848f63c60d48fccb6c2e (patch) | |
tree | cffeaab0bb1d66adff9a1bcf7f8ca256b8fc64e3 | |
parent | 022dce60ff96a994fb9aad5873840f788d0de922 (diff) | |
parent | 9a43fe6e82bdd13435705dc98928488136723f27 (diff) | |
download | python-heatclient-62cd3154c5ee0380f9ae848f63c60d48fccb6c2e.tar.gz |
Merge "Add support for build info API"
-rw-r--r-- | heatclient/tests/test_build_info.py | 35 | ||||
-rw-r--r-- | heatclient/tests/test_shell.py | 73 | ||||
-rw-r--r-- | heatclient/v1/build_info.py | 32 | ||||
-rw-r--r-- | heatclient/v1/client.py | 2 | ||||
-rw-r--r-- | heatclient/v1/shell.py | 10 |
5 files changed, 152 insertions, 0 deletions
diff --git a/heatclient/tests/test_build_info.py b/heatclient/tests/test_build_info.py new file mode 100644 index 0000000..51c0a95 --- /dev/null +++ b/heatclient/tests/test_build_info.py @@ -0,0 +1,35 @@ +# Copyright 2012 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock +import testtools + +from heatclient.v1.build_info import BuildInfoManager + + +class BuildInfoManagerTest(testtools.TestCase): + def setUp(self): + super(BuildInfoManagerTest, self).setUp() + self.client = mock.Mock() + self.client.json_request.return_value = ('resp', 'body') + self.manager = BuildInfoManager(self.client) + + def test_build_info_makes_a_call_to_the_api(self): + self.manager.build_info() + self.client.json_request.assert_called_once_with('GET', '/build_info') + + def test_build_info_returns_the_response_body(self): + response = self.manager.build_info() + self.assertEqual('body', response) diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index 28209a5..0fd5a31 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -761,6 +761,34 @@ class ShellTestUserPass(ShellBase): for r in required: self.assertRegexpMatches(delete_text, r) + def test_build_info(self): + self._script_keystone_client() + resp_dict = { + 'build_info': { + 'api': {'revision': 'api_revision'}, + 'engine': {'revision': 'engine_revision'} + } + } + resp_string = jsonutils.dumps(resp_dict) + headers = {'content-type': 'application/json'} + http_resp = fakes.FakeHTTPResponse(200, 'OK', headers, resp_string) + response = (http_resp, resp_dict) + http.HTTPClient.json_request('GET', '/build_info').AndReturn(response) + + self.m.ReplayAll() + + build_info_text = self.shell('build-info') + + required = [ + 'api', + 'engine', + 'revision', + 'api_revision', + 'engine_revision', + ] + for r in required: + self.assertRegexpMatches(build_info_text, r) + class ShellTestEvents(ShellBase): def setUp(self): @@ -1044,6 +1072,51 @@ class ShellTestResources(ShellBase): self.assertRegexpMatches(resource_show_text, r) +class ShellTestBuildInfo(ShellBase): + def setUp(self): + super(ShellTestBuildInfo, self).setUp() + self._set_fake_env() + + def _set_fake_env(self): + '''Patch os.environ to avoid required auth info.''' + + 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 test_build_info(self): + fakes.script_keystone_client() + resp_dict = { + 'build_info': { + 'api': {'revision': 'api_revision'}, + 'engine': {'revision': 'engine_revision'} + } + } + resp_string = jsonutils.dumps(resp_dict) + headers = {'content-type': 'application/json'} + http_resp = fakes.FakeHTTPResponse(200, 'OK', headers, resp_string) + response = (http_resp, resp_dict) + http.HTTPClient.json_request('GET', '/build_info').AndReturn(response) + + self.m.ReplayAll() + + build_info_text = self.shell('build-info') + + required = [ + 'api', + 'engine', + 'revision', + 'api_revision', + 'engine_revision', + ] + for r in required: + self.assertRegexpMatches(build_info_text, r) + + class ShellTestToken(ShellTestUserPass): # Rerun all ShellTestUserPass test with token auth diff --git a/heatclient/v1/build_info.py b/heatclient/v1/build_info.py new file mode 100644 index 0000000..0ba9491 --- /dev/null +++ b/heatclient/v1/build_info.py @@ -0,0 +1,32 @@ +# Copyright 2012 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from heatclient.openstack.common.apiclient import base + + +class BuildInfo(base.Resource): + def __repr__(self): + return "<BuildInfo %s>" % self._info + + def build_info(self): + return self.manager.build_info() + + +class BuildInfoManager(base.BaseManager): + resource_class = BuildInfo + + def build_info(self): + resp, body = self.client.json_request('GET', '/build_info') + return body diff --git a/heatclient/v1/client.py b/heatclient/v1/client.py index 39fbe6e..827a4fc 100644 --- a/heatclient/v1/client.py +++ b/heatclient/v1/client.py @@ -15,6 +15,7 @@ from heatclient.common import http from heatclient.v1 import actions +from heatclient.v1 import build_info from heatclient.v1 import events from heatclient.v1 import resource_types from heatclient.v1 import resources @@ -40,3 +41,4 @@ class Client(object): self.http_client) self.events = events.EventManager(self.http_client) self.actions = actions.ActionManager(self.http_client) + self.build_info = build_info.BuildInfoManager(self.http_client) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 690a4db..91f1a97 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -476,3 +476,13 @@ def do_event_show(hc, args): 'resource_properties': utils.json_formatter } utils.print_dict(event.to_dict(), formatters=formatters) + + +def do_build_info(hc, args): + '''Retrieve build information.''' + result = hc.build_info.build_info() + formatters = { + 'api': utils.json_formatter, + 'engine': utils.json_formatter, + } + utils.print_dict(result, formatters=formatters) |