1
# Licensed under the Apache License, Version 2.0 (the "License");
2
# you may not use this file except in compliance with the License.
3
# You may obtain a copy of the License at
5
# http://www.apache.org/licenses/LICENSE-2.0
7
# Unless required by applicable law or agreed to in writing, software
8
# distributed under the License is distributed on an "AS IS" BASIS,
9
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
# See the License for the specific language governing permissions and
11
# limitations under the License.
14
from seamicroclient import client as base_client
15
from seamicroclient.openstack.common.py3kcompat import urlutils
16
from seamicroclient.tests import fakes
17
from seamicroclient.tests import utils
18
from seamicroclient.v2 import client
21
class FakeClient(fakes.FakeClient, client.Client):
23
def __init__(self, *args, **kwargs):
24
client.Client.__init__(self, 'username', 'password',
26
self.client = FakeHTTPClient(**kwargs)
29
class FakeHTTPClient(base_client.HTTPClient):
31
def __init__(self, **kwargs):
32
self.username = 'username'
33
self.password = 'password'
34
self.auth_url = 'auth_url'
36
self.timings = 'timings'
37
self.http_log_debug = 'http_log_debug'
39
def _cs_request(self, url, method, **kwargs):
40
# Check that certain things are called correctly
41
if method in ['GET', 'DELETE']:
42
assert 'body' not in kwargs
44
assert 'body' in kwargs
47
args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
49
munged_url = url.rsplit('?', 1)[0]
50
munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
51
munged_url = munged_url.replace('-', '_')
52
munged_url = munged_url.replace(' ', '_')
54
callback = "%s_%s" % (method.lower(), munged_url)
56
if not hasattr(self, callback):
57
raise AssertionError('Called unknown API method: %s %s, '
58
'expected fakes method name: %s' %
59
(method, url, callback))
62
self.callstack.append((method, url, kwargs.get('body', None)))
64
status, headers, body = getattr(self, callback)(**kwargs)
65
r = utils.TestResponse({
66
"status_code": status,
72
def get_servers_1(self, **kwargs):
73
return (200, {}, {'id': 1234, 'name': 'sample-server'}
76
def get_servers(self, **kwargs):
77
return (200, {}, {'0/0': {}, '1/0': {}})
79
def put_servers_1(self, **kwargs):
82
def put_servers_1_nic_0_untaggedVlans(self, **kwargs):
85
def put_servers_1_nic_0_taggedVlans(self, **kwargs):
88
def get_storage_pools(self):
89
return (200, {}, {'0/p0-0': {}, '0/p1-1': {}})
91
def get_storage_pools_1(self):
92
return (200, {}, {'0/p0-0': {}})
94
def get_storage_volumes(self):
95
return (200, {}, {'0/p0-0/1': {}, '0/p1-1/1': {}})
97
def get_storage_volumes_1(self):
98
return (200, {}, {'1': {}})
100
def put_storage_volumes_0_p0_0_1(self, **kwargs):
101
return (200, {}, {'0/p0-0/1': {}})
103
def get_storage_volumes_0_p0_0_1(self, **kwargs):
104
return (200, {}, {'0/p0-0/1': {}})
106
def put_servers_1_vdisk_0(self, **kwargs):
109
def put_servers_1_vdisk_3(self, **kwargs):
112
def delete_servers_1_vdisk_0(self, **kwargs):
115
def get_storage_disks(self, **kwargs):
118
def get_storage_disks_1(self, **kwargs):
119
return (200, {}, {'1': {}})
121
def put_storage_disks_1(self, **kwargs):
122
return (200, {}, {'1': {}})
124
def get_chassis(self, **kwargs):
127
def put_chassis_system_writeMem(self, **kwargs):
130
def get_chassis_fanTray(self, **kwargs):
133
def get_chassis_fanTray_1(self, **kwargs):
136
def get_interfaces(self, **kwargs):
139
def get_interfaces_1(self, **kwargs):
142
def put_interfaces_1_shutdown(self, **kwargs):
145
def put_interfaces_1_vlans_taggedVlans(self, **kwargs):
148
def put_interfaces_1_vlans_untaggedVlans(self, **kwargs):
151
def put_storage_pools_1_pool_name(self, **kwargs):
154
def delete_storage_pools_1_pool_name(self, **kwargs):
157
def put_storage_pools_1(self, **kwargs):
160
def get_chassis_powersupply(self, **kwargs):
163
def get_chassis_powersupply_1(self, **kwargs):
166
def get_chassis_scard(self, **kwargs):
169
def get_chassis_scard_1(self, **kwargs):
172
def put_chassis_scard_1_mgmtMode(self, **kwargs):
175
def get_chassis_smcard(self, **kwargs):
178
def get_chassis_smcard_1(self, **kwargs):
181
def get_chassis_systems(self, **kwargs):
184
def put_chassis_system_switchover(self, **kwargs):
187
def put_chassis_system_reload(self, **kwargs):