diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-08-27 15:35:58 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-08-27 15:35:58 +0000 |
commit | a5d71080efc63a174d77614c9d816a7d86423971 (patch) | |
tree | ff57ac87ca047c6e43a87fa2ac50e5c70493de90 /heatclient | |
parent | 6f99131805eafa2965a08d498fd6816c60ed935f (diff) | |
parent | 1426237c38792bcf62521f959157501b9c6d50ea (diff) | |
download | python-heatclient-a5d71080efc63a174d77614c9d816a7d86423971.tar.gz |
Merge "Add X-Region-Name parameter in HTTP request"
Diffstat (limited to 'heatclient')
-rw-r--r-- | heatclient/common/http.py | 3 | ||||
-rw-r--r-- | heatclient/tests/test_common_http.py | 24 |
2 files changed, 27 insertions, 0 deletions
diff --git a/heatclient/common/http.py b/heatclient/common/http.py index bdf212d..9fb06cb 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -53,6 +53,7 @@ class HTTPClient(object): self.auth_token = kwargs.get('token') self.username = kwargs.get('username') self.password = kwargs.get('password') + self.region_name = kwargs.get('region_name') self.connection_params = self.get_connection_params(endpoint, **kwargs) @staticmethod @@ -135,6 +136,8 @@ class HTTPClient(object): kwargs['headers'].update(self.credentials_headers()) if self.auth_url: kwargs['headers'].setdefault('X-Auth-Url', self.auth_url) + if self.region_name: + kwargs['headers'].setdefault('X-Region-Name', self.region_name) self.log_curl_request(method, url, kwargs) conn = self.get_connection() diff --git a/heatclient/tests/test_common_http.py b/heatclient/tests/test_common_http.py index cd5a951..4e0c59a 100644 --- a/heatclient/tests/test_common_http.py +++ b/heatclient/tests/test_common_http.py @@ -100,6 +100,30 @@ class HttpClientTest(testtools.TestCase): self.assertEqual(resp.status, 200) self.m.VerifyAll() + def test_region_name(self): + # Record a 200 + fake200 = fakes.FakeHTTPResponse( + 200, 'OK', + {'content-type': 'application/octet-stream'}, + '') + + # Specify region name + mock_conn = http.httplib.HTTPConnection('example.com', 8004, + timeout=600.0) + mock_conn.request('GET', '/', + headers={'Content-Type': 'application/octet-stream', + 'X-Region-Name': 'RegionOne', + 'User-Agent': 'python-heatclient'}) + mock_conn.getresponse().AndReturn(fake200) + + # Replay, create client, assert + self.m.ReplayAll() + client = http.HTTPClient('http://example.com:8004') + client.region_name = 'RegionOne' + resp, body = client.raw_request('GET', '') + self.assertEqual(resp.status, 200) + self.m.VerifyAll() + def test_http_json_request(self): # Record a 200 mock_conn = http.httplib.HTTPConnection('example.com', 8004, |