blob: 058c9c232944e5b4e4e8f1de187bdc32cb1a504f [file] [log] [blame]
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -05001# 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
17import httplib2
18import json
19
20
21TOKEN = "fake_token"
22ALT_TOKEN = "alt_fake_token"
23
24# Fake Identity v2 constants
25COMPUTE_ENDPOINTS_V2 = {
26 "endpoints": [
27 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050028 "adminURL": "http://fake_url/v2/first_endpoint/admin",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050029 "region": "NoMatchRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050030 "internalURL": "http://fake_url/v2/first_endpoint/internal",
31 "publicURL": "http://fake_url/v2/first_endpoint/public"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050032 },
33 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050034 "adminURL": "http://fake_url/v2/second_endpoint/admin",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050035 "region": "FakeRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050036 "internalURL": "http://fake_url/v2/second_endpoint/internal",
37 "publicURL": "http://fake_url/v2/second_endpoint/public"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050038 },
39 ],
40 "type": "compute",
41 "name": "nova"
42}
43
44CATALOG_V2 = [COMPUTE_ENDPOINTS_V2, ]
45
46ALT_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
62IDENTITY_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
79COMPUTE_ENDPOINTS_V3 = {
80 "endpoints": [
81 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050082 "id": "first_compute_fake_service",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050083 "interface": "public",
84 "region": "NoMatchRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050085 "url": "http://fake_url/v3/first_endpoint/api"
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050086 },
87 {
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050088 "id": "second_fake_service",
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -050089 "interface": "public",
90 "region": "FakeRegion",
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050091 "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. Rodriguesc3e573c2014-02-19 07:59:29 -050098 }
Mauro S. M. Rodrigues4e23c452014-02-24 15:21:58 -050099
Mauro S. M. Rodriguesc3e573c2014-02-19 07:59:29 -0500100 ],
101 "type": "compute",
102 "id": "fake_compute_endpoint"
103}
104
105CATALOG_V3 = [COMPUTE_ENDPOINTS_V3, ]
106
107IDENTITY_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
135ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE
136
137
138def _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
148def _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
154def _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)