Merge "Add support for build info API"
This commit is contained in:
		
							
								
								
									
										35
									
								
								heatclient/tests/test_build_info.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								heatclient/tests/test_build_info.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								heatclient/v1/build_info.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								heatclient/v1/build_info.py
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user