Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 1 | # Copyright 2014 IBM Corp. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | |
| 17 | import httplib2 |
| 18 | import json |
| 19 | |
| 20 | |
| 21 | TOKEN = "fake_token" |
| 22 | ALT_TOKEN = "alt_fake_token" |
| 23 | |
| 24 | # Fake Identity v2 constants |
| 25 | COMPUTE_ENDPOINTS_V2 = { |
| 26 | "endpoints": [ |
| 27 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 28 | "adminURL": "http://fake_url/v2/first_endpoint/admin", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 29 | "region": "NoMatchRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 30 | "internalURL": "http://fake_url/v2/first_endpoint/internal", |
| 31 | "publicURL": "http://fake_url/v2/first_endpoint/public" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 32 | }, |
| 33 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 34 | "adminURL": "http://fake_url/v2/second_endpoint/admin", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 35 | "region": "FakeRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 36 | "internalURL": "http://fake_url/v2/second_endpoint/internal", |
| 37 | "publicURL": "http://fake_url/v2/second_endpoint/public" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 38 | }, |
| 39 | ], |
| 40 | "type": "compute", |
| 41 | "name": "nova" |
| 42 | } |
| 43 | |
| 44 | CATALOG_V2 = [COMPUTE_ENDPOINTS_V2, ] |
| 45 | |
| 46 | ALT_IDENTITY_V2_RESPONSE = { |
| 47 | "access": { |
| 48 | "token": { |
| 49 | "expires": "2020-01-01T00:00:10Z", |
| 50 | "id": ALT_TOKEN, |
| 51 | "tenant": { |
| 52 | "id": "fake_tenant_id" |
| 53 | }, |
| 54 | }, |
| 55 | "user": { |
| 56 | "id": "fake_user_id", |
| 57 | }, |
| 58 | "serviceCatalog": CATALOG_V2, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | IDENTITY_V2_RESPONSE = { |
| 63 | "access": { |
| 64 | "token": { |
| 65 | "expires": "2020-01-01T00:00:10Z", |
| 66 | "id": TOKEN, |
| 67 | "tenant": { |
| 68 | "id": "fake_tenant_id" |
| 69 | }, |
| 70 | }, |
| 71 | "user": { |
| 72 | "id": "fake_user_id", |
| 73 | }, |
| 74 | "serviceCatalog": CATALOG_V2, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | # Fake Identity V3 constants |
| 79 | COMPUTE_ENDPOINTS_V3 = { |
| 80 | "endpoints": [ |
| 81 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 82 | "id": "first_compute_fake_service", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 83 | "interface": "public", |
| 84 | "region": "NoMatchRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 85 | "url": "http://fake_url/v3/first_endpoint/api" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 86 | }, |
| 87 | { |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 88 | "id": "second_fake_service", |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 89 | "interface": "public", |
| 90 | "region": "FakeRegion", |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 91 | "url": "http://fake_url/v3/second_endpoint/api" |
| 92 | }, |
| 93 | { |
| 94 | "id": "third_fake_service", |
| 95 | "interface": "admin", |
| 96 | "region": "MiddleEarthRegion", |
| 97 | "url": "http://fake_url/v3/third_endpoint/api" |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 98 | } |
Mauro S. M. Rodrigues | 4e23c45 | 2014-02-24 15:21:58 -0500 | [diff] [blame] | 99 | |
Mauro S. M. Rodrigues | c3e573c | 2014-02-19 07:59:29 -0500 | [diff] [blame] | 100 | ], |
| 101 | "type": "compute", |
| 102 | "id": "fake_compute_endpoint" |
| 103 | } |
| 104 | |
| 105 | CATALOG_V3 = [COMPUTE_ENDPOINTS_V3, ] |
| 106 | |
| 107 | IDENTITY_V3_RESPONSE = { |
| 108 | "token": { |
| 109 | "methods": [ |
| 110 | "token", |
| 111 | "password" |
| 112 | ], |
| 113 | "expires_at": "2020-01-01T00:00:10.000123Z", |
| 114 | "project": { |
| 115 | "domain": { |
| 116 | "id": "fake_id", |
| 117 | "name": "fake" |
| 118 | }, |
| 119 | "id": "project_id", |
| 120 | "name": "project_name" |
| 121 | }, |
| 122 | "user": { |
| 123 | "domain": { |
| 124 | "id": "domain_id", |
| 125 | "name": "domain_name" |
| 126 | }, |
| 127 | "id": "fake_user_id", |
| 128 | "name": "username" |
| 129 | }, |
| 130 | "issued_at": "2013-05-29T16:55:21.468960Z", |
| 131 | "catalog": CATALOG_V3 |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE |
| 136 | |
| 137 | |
| 138 | def _fake_v3_response(self, uri, method="GET", body=None, headers=None, |
| 139 | redirections=5, connection_type=None): |
| 140 | fake_headers = { |
| 141 | "status": "201", |
| 142 | "x-subject-token": TOKEN |
| 143 | } |
| 144 | return (httplib2.Response(fake_headers), |
| 145 | json.dumps(IDENTITY_V3_RESPONSE)) |
| 146 | |
| 147 | |
| 148 | def _fake_v2_response(self, uri, method="GET", body=None, headers=None, |
| 149 | redirections=5, connection_type=None): |
| 150 | return (httplib2.Response({"status": "200"}), |
| 151 | json.dumps(IDENTITY_V2_RESPONSE)) |
| 152 | |
| 153 | |
| 154 | def _fake_auth_failure_response(): |
| 155 | # the response body isn't really used in this case, but lets send it anyway |
| 156 | # to have a safe check in some future change on the rest client. |
| 157 | body = { |
| 158 | "unauthorized": { |
| 159 | "message": "Unauthorized", |
| 160 | "code": "401" |
| 161 | } |
| 162 | } |
| 163 | return httplib2.Response({"status": "401"}), json.dumps(body) |