173 lines
5.7 KiB
Python
Raw Normal View History

2013-09-02 23:42:41 -04:00
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2011 OpenStack, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from manilaclient.v1 import shares as shares_ext_module
2013-09-03 14:37:34 +03:00
from manilaclient.v1 import client
from tests.v1 import fake_clients as fakes
2013-09-02 23:42:41 -04:00
class FakeClient(fakes.FakeClient):
2013-09-02 23:42:41 -04:00
def __init__(self, *args, **kwargs):
client.Client.__init__(self, 'username', 'password',
'project_id', 'auth_url',
extensions=kwargs.get('extensions'))
self.client = FakeHTTPClient(**kwargs)
class FakeHTTPClient(fakes.FakeHTTPClient):
def get_shares_1234(self, **kw):
share = {'share': {'id': 1234, 'name': 'sharename'}}
return (200, {}, share)
2013-09-10 08:11:02 -04:00
def get_shares_detail(self, **kw):
shares = {'shares': [{'id': 1234,
'name': 'sharename',
'attachments': [{'server_id': 111}]}]}
return (200, {}, shares)
2013-09-10 08:11:02 -04:00
def get_snapshots_1234(self, **kw):
snapshot = {'snapshot': {'id': 1234, 'name': 'sharename'}}
return (200, {}, snapshot)
def post_snapshots_1234_action(self, body, **kw):
_body = None
resp = 202
assert len(list(body)) == 1
action = list(body)[0]
if action == 'os-reset_status':
assert 'status' in body['os-reset_status']
else:
raise AssertionError("Unexpected action: %s" % action)
return (resp, {}, _body)
2013-09-10 08:11:02 -04:00
def get_snapshots_detail(self, **kw):
print kw
# print kw['share_id']
snapshots = {'snapshots': [{
'id': 1234,
'created_at': '2012-08-27T00:00:00.000000',
'share_size': 1,
'share_id': 4321,
'status': 'available',
'name': 'sharename',
'display_description': 'description',
'share_proto': 'type',
'export_location': 'location',
}]}
return (200, {}, snapshots)
def post_shares_1234_action(self, body, **kw):
2013-09-02 23:42:41 -04:00
_body = None
resp = 202
assert len(body.keys()) == 1
action = body.keys()[0]
if action == 'os-allow_access':
assert body[action].keys() == ['access_type', 'access_to']
2013-09-17 16:22:28 +03:00
_body = {'access': {}}
elif action == 'os-deny_access':
assert body[action].keys() == ['access_id']
elif action == 'os-access_list':
2013-09-02 23:42:41 -04:00
assert body[action] is None
elif action == 'os-reset_status':
assert 'status' in body['os-reset_status']
2013-09-02 23:42:41 -04:00
else:
raise AssertionError("Unexpected share action: %s" % action)
2013-09-02 23:42:41 -04:00
return (resp, {}, _body)
def post_shares(self, **kwargs):
return (202, {}, {'share': {}})
2013-09-02 23:42:41 -04:00
2013-09-10 08:11:02 -04:00
def post_snapshots(self, **kwargs):
return (202, {}, {'snapshot': {}})
2013-09-02 23:42:41 -04:00
def delete_shares_1234(self, **kw):
2013-09-02 23:42:41 -04:00
return (202, {}, None)
2013-09-10 08:11:02 -04:00
def delete_snapshots_1234(self, **kwargs):
2013-09-02 23:42:41 -04:00
return (202, {}, None)
def put_shares_1234(self, **kwargs):
share = {'share': {'id': 1234, 'name': 'sharename'}}
return (200, {}, share)
def put_snapshots_1234(self, **kwargs):
snapshot = {'snapshot': {'id': 1234, 'name': 'snapshot_name'}}
return (200, {}, snapshot)
#
# Set/Unset metadata
#
def delete_shares_1234_metadata_test_key(self, **kw):
return (204, {}, None)
def delete_shares_1234_metadata_key1(self, **kw):
return (204, {}, None)
def delete_shares_1234_metadata_key2(self, **kw):
return (204, {}, None)
def post_shares_1234_metadata(self, **kw):
return (204, {}, {'metadata': {'test_key': 'test_value'}})
def put_shares_1234_metadata(self, **kw):
return (200, {}, {"metadata": {"key1": "val1", "key2": "val2"}})
def get_shares_1234_metadata(self, **kw):
return (200, {}, {"metadata": {"key1": "val1", "key2": "val2"}})
def get_types(self, **kw):
return (200, {}, {
'volume_types': [{'id': 1,
'name': 'test-type-1',
'extra_specs': {}},
{'id': 2,
'name': 'test-type-2',
'extra_specs': {}}]})
def get_types_1(self, **kw):
return (200, {}, {'volume_type': {'id': 1,
'name': 'test-type-1',
'extra_specs': {}}})
def get_types_2(self, **kw):
return (200, {}, {'volume_type': {'id': 2,
'name': 'test-type-2',
'extra_specs': {}}})
def post_types(self, body, **kw):
return (202, {}, {'volume_type': {'id': 3,
'name': 'test-type-3',
'extra_specs': {}}})
def post_types_1_extra_specs(self, body, **kw):
assert list(body) == ['extra_specs']
return (200, {}, {'extra_specs': {'k': 'v'}})
def delete_types_1_extra_specs_k(self, **kw):
return(204, {}, None)
def delete_types_1(self, **kw):
return (202, {}, None)
def fake_create(url, body, response_key):
return {'url': url, 'body': body, 'resp_key': response_key}
def fake_update(url, body, response_key):
return {'url': url, 'body': body, 'resp_key': response_key}