| 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 |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 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. |
| 12 |
|
| 13 |
|
| 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 |
| 19 |
|
| 20 |
|
| 21 |
class FakeClient(fakes.FakeClient, client.Client): |
| 22 |
|
| 23 |
def __init__(self, *args, **kwargs): |
| 24 |
client.Client.__init__(self, 'username', 'password', |
| 25 |
'auth_url') |
| 26 |
self.client = FakeHTTPClient(**kwargs) |
| 27 |
|
| 28 |
|
| 29 |
class FakeHTTPClient(base_client.HTTPClient): |
| 30 |
|
| 31 |
def __init__(self, **kwargs): |
| 32 |
self.username = 'username' |
| 33 |
self.password = 'password' |
| 34 |
self.auth_url = 'auth_url' |
| 35 |
self.callstack = [] |
| 36 |
self.timings = 'timings' |
| 37 |
self.http_log_debug = 'http_log_debug' |
| 38 |
|
| 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 |
| 43 |
elif method == 'PUT': |
| 44 |
assert 'body' in kwargs |
| 45 |
|
| 46 |
# Call the method |
| 47 |
args = urlutils.parse_qsl(urlutils.urlparse(url)[4]) |
| 48 |
kwargs.update(args) |
| 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(' ', '_') |
| 53 |
|
| 54 |
callback = "%s_%s" % (method.lower(), munged_url) |
| 55 |
|
| 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)) |
| 60 |
|
| 61 |
# Note the call |
| 62 |
self.callstack.append((method, url, kwargs.get('body', None))) |
| 63 |
|
| 64 |
status, headers, body = getattr(self, callback)(**kwargs) |
| 65 |
r = utils.TestResponse({ |
| 66 |
"status_code": status, |
| 67 |
"text": body, |
| 68 |
"headers": headers, |
| 69 |
}) |
| 70 |
return r, body |
| 71 |
|
| 72 |
def get_servers_1(self, **kwargs): |
| 73 |
return (200, {}, {'id': 1234, 'name': 'sample-server'} |
| 74 |
) |
| 75 |
|
| 76 |
def get_servers(self, **kwargs): |
| 77 |
return (200, {}, {'0/0': {}, '1/0': {}}) |
| 78 |
|
| 79 |
def put_servers_1(self, **kwargs): |
| 80 |
return (200, {}, {}) |
| 81 |
|
| 82 |
def put_servers_1_nic_0_untaggedVlans(self, **kwargs): |
| 83 |
return (200, {}, {}) |
| 84 |
|
| 85 |
def put_servers_1_nic_0_taggedVlans(self, **kwargs): |
| 86 |
return (200, {}, {}) |
| 87 |
|
| 88 |
def get_storage_pools(self): |
| 89 |
return (200, {}, {'0/p0-0': {}, '0/p1-1': {}}) |
| 90 |
|
| 91 |
def get_storage_pools_1(self): |
| 92 |
return (200, {}, {'0/p0-0': {}}) |
| 93 |
|
| 94 |
def get_storage_volumes(self): |
| 95 |
return (200, {}, {'0/p0-0/1': {}, '0/p1-1/1': {}}) |
| 96 |
|
| 97 |
def get_storage_volumes_1(self): |
| 98 |
return (200, {}, {'1': {}}) |
| 99 |
|
| 100 |
def put_storage_volumes_0_p0_0_1(self, **kwargs): |
| 101 |
return (200, {}, {'0/p0-0/1': {}}) |
| 102 |
|
| 103 |
def get_storage_volumes_0_p0_0_1(self, **kwargs): |
| 104 |
return (200, {}, {'0/p0-0/1': {}}) |
| 105 |
|
| 106 |
def put_servers_1_vdisk_0(self, **kwargs): |
| 107 |
return (200, {}, {}) |
| 108 |
|
| 109 |
def put_servers_1_vdisk_3(self, **kwargs): |
| 110 |
return (200, {}, {}) |
| 111 |
|
| 112 |
def delete_servers_1_vdisk_0(self, **kwargs): |
| 113 |
return (200, {}, {}) |
| 114 |
|
| 115 |
def get_storage_disks(self, **kwargs): |
| 116 |
return (200, {}, {}) |
| 117 |
|
| 118 |
def get_storage_disks_1(self, **kwargs): |
| 119 |
return (200, {}, {'1': {}}) |
| 120 |
|
| 121 |
def put_storage_disks_1(self, **kwargs): |
| 122 |
return (200, {}, {'1': {}}) |
| 123 |
|
| 124 |
def get_chassis(self, **kwargs): |
| 125 |
return (200, {}, {}) |
| 126 |
|
| 127 |
def put_chassis_system_writeMem(self, **kwargs): |
| 128 |
return (200, {}, {}) |
| 129 |
|
| 130 |
def get_chassis_fanTray(self, **kwargs): |
| 131 |
return (200, {}, {}) |
| 132 |
|
| 133 |
def get_chassis_fanTray_1(self, **kwargs): |
| 134 |
return (200, {}, {}) |
| 135 |
|
| 136 |
def get_interfaces(self, **kwargs): |
| 137 |
return (200, {}, {}) |
| 138 |
|
| 139 |
def get_interfaces_1(self, **kwargs): |
| 140 |
return (200, {}, {}) |
| 141 |
|
| 142 |
def put_interfaces_1_shutdown(self, **kwargs): |
| 143 |
return (200, {}, {}) |
| 144 |
|
| 145 |
def put_interfaces_1_vlans_taggedVlans(self, **kwargs): |
| 146 |
return (200, {}, {}) |
| 147 |
|
| 148 |
def put_interfaces_1_vlans_untaggedVlans(self, **kwargs): |
| 149 |
return (200, {}, {}) |
| 150 |
|
| 151 |
def put_storage_pools_1_pool_name(self, **kwargs): |
| 152 |
return (200, {}, {}) |
| 153 |
|
| 154 |
def delete_storage_pools_1_pool_name(self, **kwargs): |
| 155 |
return (200, {}, {}) |
| 156 |
|
| 157 |
def put_storage_pools_1(self, **kwargs): |
| 158 |
return (200, {}, {}) |
| 159 |
|
| 160 |
def get_chassis_powersupply(self, **kwargs): |
| 161 |
return (200, {}, {}) |
| 162 |
|
| 163 |
def get_chassis_powersupply_1(self, **kwargs): |
| 164 |
return (200, {}, {}) |
| 165 |
|
| 166 |
def get_chassis_scard(self, **kwargs): |
| 167 |
return (200, {}, {}) |
| 168 |
|
| 169 |
def get_chassis_scard_1(self, **kwargs): |
| 170 |
return (200, {}, {}) |
| 171 |
|
| 172 |
def put_chassis_scard_1_mgmtMode(self, **kwargs): |
| 173 |
return (200, {}, {}) |
| 174 |
|
| 175 |
def get_chassis_smcard(self, **kwargs): |
| 176 |
return (200, {}, {}) |
| 177 |
|
| 178 |
def get_chassis_smcard_1(self, **kwargs): |
| 179 |
return (200, {}, {}) |
| 180 |
|
| 181 |
def get_chassis_systems(self, **kwargs): |
| 182 |
return (200, {}, {}) |
| 183 |
|
| 184 |
def put_chassis_system_switchover(self, **kwargs): |
| 185 |
return (200, {}, {}) |
| 186 |
|
| 187 |
def put_chassis_system_reload(self, **kwargs): |
| 188 |
return (200, {}, {}) |