Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions Notices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,43 +256,6 @@ END OF APACHE 2.0 NOTICES AND INFORMATION
===========================================================================



@@@@@@@@@@@@
===========================================================================
HTTPretty version 0.9.6: The Program includes HTTPretty version 0.9.6
software. IBM obtained the HTTPretty version 0.9.6 software under the
terms and conditions of the following license(s):
---------------------------------------------------------------------------

Copyright (C) <2011-2018> Gabriel Falcão <gabriel@nacaolivre.org>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


===========================================================================
END OF HTTPretty version 0.9.6 NOTICES AND INFORMATION
===========================================================================


===========================================================================
END OF NOTICES AND INFORMATION FOR IBM DS8000 Python Client
Version 1.1.0 Third Party Licenses and Notices
Expand Down
7 changes: 5 additions & 2 deletions pyds8k/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def _get_id(self):
def remove_None_fields_from_dict(self, input_dict): # noqa: N802
return {key: value for key, value in input_dict.items() if value is not None}

def remove_empty_fields_from_dict(self, input_dict):
return {key: value for key, value in input_dict.items() if value}


# all the resources are under folder "resources",
# the route prefix of a resource resources/a/b/c.py is a.b
Expand Down Expand Up @@ -234,7 +237,7 @@ def create_from_template(self, custom_info=None):
if self.id_field in _info:
del _info[self.id_field]
_info.update(custom_info)
data = self.remove_None_fields_from_dict(_info)
data = self.remove_empty_fields_from_dict(_info)

res = self.__class__(
client=self.client,
Expand Down Expand Up @@ -769,7 +772,7 @@ def _posta(self, url='', body=None):
else:
self.url = url
post_body = body or self.managed_object.representation
post_body = self.remove_None_fields_from_dict(post_body)
post_body = self.remove_empty_fields_from_dict(post_body)
resp, body = self.client.post(self.url, body=self._get_request_data(post_body))
data = self._get_data(body, method=POSTA, response=resp)
if not isinstance(data, list):
Expand Down
4 changes: 0 additions & 4 deletions pyds8k/resources/ds8k/v1/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,6 @@ def create_hmc_csr(
C=None, # noqa: N803
ST=None, # noqa: N803
L=None, # noqa: N803
days=365,
email=None,
force=True,
):
Expand All @@ -1509,8 +1508,6 @@ def create_hmc_csr(
is located. Do not abbreviate this value. Defaults to None.
L (str): Optional. The city or town where your organization is
located. Defaults to None.
days (int): Optional. The number of days the certificate is valid.
Defaults to 365.
email (str): Optional. An email contact address within your
organization. Defaults to None.
force (bool): Optional. Force the creation of a new CSR if one is
Expand All @@ -1531,7 +1528,6 @@ def create_hmc_csr(
"C": C,
"ST": ST,
"L": L,
"days": days,
"email": email,
"force": str(force),
}
Expand Down
6 changes: 0 additions & 6 deletions pyds8k/resources/ds8k/v1/resource_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ def put(self, url='', body=None):
return self._put(url=url, body=body)

def patch(self, url='', body=None):
# patch doesn't remove keys with empty values, override
if body:
body = self.remove_empty_key_values_from_dict(body)
return self._patch(url=url, body=body)

def delete(self, url=''):
return self._delete(url=url)

def remove_empty_key_values_from_dict(self, input_dict):
return {k: v for k, v in input_dict.items() if v}
2 changes: 1 addition & 1 deletion pyds8k/test/base.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. But guess it's probably better to use https on these anyway

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class TestCaseWithConnect(unittest.TestCase):
def setUp(self):
self.client = HTTPClient(
"http://localhost:8088/api/",
"https://localhost:8088/api/", # FIXME: requests required https, not sure why
'admin',
'admin',
service_type='ds8k',
Expand Down
12 changes: 5 additions & 7 deletions pyds8k/test/test_client/test_ds8k/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# limitations under the License.
##############################################################################

import httpretty
import pytest
import responses

from pyds8k.client.ds8k.v1.client import Client
from pyds8k.resources.ds8k.v1.common.types import DS8K_SYSTEM, DS8K_VOLUME
Expand All @@ -34,22 +34,20 @@
class TestClient(TestCaseWithConnect):
def setUp(self):
super().setUp()
self.rest_client = Client('http://localhost:8088/api/', 'admin', 'admin')
self.rest_client = Client('https://localhost:8088/api/', 'admin', 'admin')

@httpretty.activate
@responses.activate
def test_get_array_method(self):
domain = self.client.domain
vol_url = '/volumes'
sys_url = '/systems'
httpretty.register_uri(
httpretty.GET,
responses.get(
domain + self.base_url + vol_url,
body=volume_list_response_json,
content_type='application/json',
)

httpretty.register_uri(
httpretty.GET,
responses.get(
domain + self.base_url + sys_url,
body=system_list_response_json,
content_type='application/json',
Expand Down
57 changes: 23 additions & 34 deletions pyds8k/test/test_client/test_ds8k/test_sc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from http import HTTPStatus

import httpretty
import responses
from responses import matchers

from pyds8k.base import Resource, get_resource_and_manager_class_by_route
from pyds8k.client.ds8k.v1.sc_client import SCClient
Expand All @@ -25,7 +26,6 @@
from pyds8k.test.base import TestCaseWithConnect
from pyds8k.test.data import (
create_mappings_response_json,
get_request_json_body,
get_response_data_by_type,
get_response_json_by_type,
get_response_list_data_by_type,
Expand All @@ -44,7 +44,7 @@
class TestClient(TestUtils, TestCaseWithConnect):
def setUp(self):
super().setUp()
self.rest_client = SCClient('localhost:8088/api/', 'admin', 'admin')
self.rest_client = SCClient('https://localhost:8088/api/', 'admin', 'admin')

def _assert_equal_between_dicts(self, returned_dict, origin_dict):
for key, value in origin_dict.items():
Expand All @@ -71,43 +71,38 @@ def _set_resource_list(self, route):
base_route, resource_response, id_field
)
url = '/{}/{}'.format(route.replace('.', '/'), route_id)
httpretty.register_uri(
httpretty.GET,
responses.get(
self.domain + self.base_url + url,
body=get_response_json_by_type(base_route),
content_type='application/json',
status=HTTPStatus.OK,
status=HTTPStatus.OK.value,
)
return route_id

def _set_sub_resource(self, route, route_id, sub_route):
sub_route_url = f'/{route}/{route_id}/{sub_route}'
httpretty.register_uri(
httpretty.GET,
responses.get(
self.domain + self.base_url + sub_route_url,
body=get_response_list_json_by_type(sub_route),
content_type='application/json',
status=HTTPStatus.OK,
status=HTTPStatus.OK.value,
)

def _post_sub_resource(self, route, route_id, sub_route, body):
sub_route_url = f'/{route}/{route_id}/{sub_route}'
uri = f'{self.domain}{self.base_url}{sub_route_url}'

def _verify_request(request, uri, headers):
assert uri == f"{self.domain}{self.base_url}{sub_route_url}"

resq = RequestParser(body)
assert get_request_json_body(request.body) == resq.get_request_data()
return (HTTPStatus.OK, headers, create_mappings_response_json)
resq = RequestParser(body)

httpretty.register_uri(
httpretty.POST,
self.domain + self.base_url + sub_route_url,
body=_verify_request,
responses.post(
uri,
status=HTTPStatus.OK,
body=create_mappings_response_json,
content_type='application/json',
match=[matchers.json_params_matcher(resq.get_request_data())],
)

@httpretty.activate
@responses.activate
def _test_resource_by_route(self, route, func, sub_resource=None):
if sub_resource is None:
sub_resource = []
Expand All @@ -123,7 +118,7 @@ def _test_resource_by_route(self, route, func, sub_resource=None):
).get_representations()[0]
self._assert_equal_between_dicts(res, rep)

@httpretty.activate
@responses.activate
def _test_sub_resource(self, route, sub_route, func):
route_id = self._set_resource_list(route)
self._set_sub_resource(route, route_id, sub_route)
Expand All @@ -135,7 +130,7 @@ def _test_sub_resource(self, route, sub_route, func):
).get_representations()[0]
self._assert_equal_between_dicts(res, rep)

@httpretty.activate
@responses.activate
def _test_resource_list_by_route(self, route, func=None):
prefix = f'{self.client.service_type}.{self.client.service_version}'
res_class, _ = get_resource_and_manager_class_by_route(
Expand All @@ -146,12 +141,11 @@ def _test_resource_list_by_route(self, route, func=None):
raise Exception(msg)
url = '/{}'.format(route.replace('.', '/'))
base_route = route.split('.')[-1]
httpretty.register_uri(
httpretty.GET,
responses.get(
self.domain + self.base_url + url,
body=get_response_list_json_by_type(base_route),
content_type='application/json',
status=HTTPStatus.OK,
status=HTTPStatus.OK.value,
)
func = func or 'get_{}'.format(route.replace('.', '_'))
res = getattr(self.rest_client, func)()
Expand All @@ -162,7 +156,7 @@ def _test_resource_list_by_route(self, route, func=None):
).get_representations()[0]
self._assert_equal_between_dicts(res[0], rep)

@httpretty.activate
@responses.activate
def _test_sub_resource_post(self, route, sub_route, func, body, *params):
route_id = self._set_resource_list(route)
self._post_sub_resource(route, route_id, sub_route, body)
Expand All @@ -173,12 +167,11 @@ def _test_sub_resource_post(self, route, sub_route, func, body, *params):
).get_representations()[0]
self._assert_equal_between_obj_and_dict(res, rep)

@httpretty.activate
@responses.activate
def test_get_system(self):
sys_url = '/systems'

httpretty.register_uri(
httpretty.GET,
responses.get(
self.domain + self.base_url + sys_url,
body=system_list_res_json,
content_type='application/json',
Expand Down Expand Up @@ -271,11 +264,7 @@ def test_list_fcports(self):
def test_map_volume_to_host(self):
volume_id = '000B'
lunid = '09'
body = {
"mappings": [
{lunid: volume_id},
]
}
body = {"mappings": [{lunid: volume_id}]}
self._test_sub_resource_post(
types.DS8K_HOST,
types.DS8K_VOLMAP,
Expand Down
Loading
Loading