Skip to content

feat(location opt): added cr location as opt #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2021
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
Binary file modified cis.env.enc
Binary file not shown.
Binary file modified dns.env.enc
Binary file not shown.
61 changes: 60 additions & 1 deletion ibm_cloud_networking_services/dns_svcs_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# IBM OpenAPI SDK Code Generator Version: 3.32.0-4c6a3129-20210514-210323
# IBM OpenAPI SDK Code Generator Version: 3.29.1-b338fb38-20210313-010605

"""
DNS Services API
Expand Down Expand Up @@ -2296,6 +2296,65 @@ def update_custom_resolver(self,
response = self.send(request)
return response


def update_cr_locations_order(self,
instance_id: str,
resolver_id: str,
*,
locations: List[str] = None,
x_correlation_id: str = None,
**kwargs
) -> DetailedResponse:
"""
Update the locations order of a custom resolver.

Update the locations order of a custom resolver.

:param str instance_id: The unique identifier of a service instance.
:param str resolver_id: The unique identifier of a custom resolver.
:param List[str] locations: (optional) Array of custom resolver location
ID.
:param str x_correlation_id: (optional) Uniquely identifying a request.
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `CustomResolver` object
"""

if instance_id is None:
raise ValueError('instance_id must be provided')
if resolver_id is None:
raise ValueError('resolver_id must be provided')
headers = {
'X-Correlation-ID': x_correlation_id
}
sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME,
service_version='V1',
operation_id='update_cr_locations_order')
headers.update(sdk_headers)

data = {
'locations': locations
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
headers['content-type'] = 'application/json'

if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
headers['Accept'] = 'application/json'

path_param_keys = ['instance_id', 'resolver_id']
path_param_values = self.encode_path_vars(instance_id, resolver_id)
path_param_dict = dict(zip(path_param_keys, path_param_values))
url = '/instances/{instance_id}/custom_resolvers/{resolver_id}/locations_order'.format(**path_param_dict)
request = self.prepare_request(method='PUT',
url=url,
headers=headers,
data=data)

response = self.send(request)
return response

#########################
# Custom Resolver Locations
#########################
Expand Down
2 changes: 2 additions & 0 deletions test/integration/test_direct_link_provider_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
class TestDirectLinkProviderV2(unittest.TestCase):
""" Test class for DirectLink Provider sdk functions """

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
self.dl_endpoint = os.getenv("DL_SERVICES_SERVICE_URL")
Expand Down
2 changes: 2 additions & 0 deletions test/integration/test_direct_link_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
class TestDirectLinkV1(unittest.TestCase):
""" Test class for DirectLink sdk functions """

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
self.endpoint = os.getenv("DL_SERVICES_SERVICE_URL")
Expand Down
51 changes: 29 additions & 22 deletions test/integration/test_dns_svcs_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Integration test code to execute dns zones
"""

from ibm_cloud_networking_services.dns_svcs_v1 import DnsSvcsV1
import os
import unittest

from ibm_cloud_networking_services.dns_svcs_v1 import DnsSvcsV1
from dotenv import load_dotenv, find_dotenv

configFile = "dns.env"
# load the .env file containing your environment variables
try:
Expand All @@ -19,8 +19,6 @@

class TestDNSSvcsV1(unittest.TestCase):
"""The DNS V1 service test class."""

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
Expand Down Expand Up @@ -187,8 +185,6 @@ def test_1_pdns_zone_negative(self):
class TestResourceRecordsV1(unittest.TestCase):
"""The Resourse records V1 service test class."""

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
if not os.path.exists(configFile):
Expand Down Expand Up @@ -704,8 +700,6 @@ def test_1_resource_records_negative(self):
class TestPermittedNetworksForDnsZonesV1(unittest.TestCase):
"""The Permitted Networks for DNS V1 service test class."""

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
if not os.path.exists(configFile):
Expand Down Expand Up @@ -829,8 +823,6 @@ def test_1_permitted_network_negative(self):
class TestGlobalLoadBalancersV1 (unittest.TestCase):

"""The Global Load Balancers for DNS V1 service test class."""

@unittest.skip("skipping")

def setUp(self):
""" test case setup """
Expand Down Expand Up @@ -911,7 +903,7 @@ def _clean_dns_globalloadbalancers(self):
instance_id=self.instance_id, dnszone_id=zone.get("id"))

################## global load balancers integration test cases ##################
@unittest.skip('skipping...')
# @unittest.skip('skipping...')
def test_1_dns_globalloadbalancers(self):
""" create,get,update,delete GLB monitor """

Expand Down Expand Up @@ -1092,12 +1084,10 @@ def test_2_list_dns_globalloadbalancers(self):

class TestCustomResolversV1(unittest.TestCase):
"""Custom Resolvers for DNS V1 service test class."""

@unittest.skip("skipping")


def setUp(self):
""" test case setup """

if not os.path.exists(configFile):
raise unittest.SkipTest('External configuration not available, skipping...')
self.instance_id = os.getenv("DNS_SVCS_INSTANCE_ID")
Expand All @@ -1121,19 +1111,14 @@ def _clean_dns_custom_resolver(self):
result = response.get_result().get("custom_resolvers")
for crs in result:
self.cr.delete_custom_resolver(instance_id=self.instance_id, resolver_id=crs.get("id"))

def test_1_dns_customresolvers(self):
""" create,get,update,list Custom Resolvers """

name = 'testcustomresolvers'
description = "Creating Custom Resolvers"
locations = [{"subnet_crn": self.subnet_crn, "enabled": False}]

# Create Custom Resolvers
resp = self.cr.create_custom_resolver(instance_id=self.instance_id, name=name, locations=locations,
resp = self.cr.create_custom_resolver(instance_id=self.instance_id, name=name,
description=description)


assert resp is not None
assert resp.status_code == 200
resolver_id = resp.get_result().get("id")
Expand All @@ -1156,6 +1141,21 @@ def test_1_dns_customresolvers(self):
assert resp is not None
assert resp.status_code == 200

""" add,update,Custom Resolver Locations """
# Add Custom Resolver Locations
resp = self.cr.add_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
subnet_crn=self.subnet_crn_location, enabled=True)
assert resp is not None
assert resp.status_code == 200
location_id = resp.get_result().get("id")


# Update Custom Resolver Locations
resp = self.cr.update_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
location_id=location_id, enabled=False)
assert resp is not None
assert resp.status_code == 200

""" create,get,update,list Forwarding rules """
# Create Forwarding rules
type1 = 'zone'
Expand Down Expand Up @@ -1192,11 +1192,18 @@ def test_1_dns_customresolvers(self):
resp = self.cr.delete_forwarding_rule(instance_id=self.instance_id, resolver_id=resolver_id, rule_id=rule_id)
assert resp is not None
assert resp.status_code == 204

# Delete Custom resolver locations
resp = self.cr.delete_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
location_id=location_id)
assert resp is not None
assert resp.status_code == 204

# Delete Custom Resolver
# Delete Custom Resolver
resp = self.cr.delete_custom_resolver(instance_id=self.instance_id, resolver_id=resolver_id)
assert resp is not None
assert resp.status_code == 204


if __name__ == '__main__':
unittest.main()
127 changes: 119 additions & 8 deletions test/unit/test_dns_svcs_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4221,6 +4221,117 @@ def test_update_custom_resolver_value_error(self):



class TestUpdateCrLocationsOrder():
"""
Test Class for update_cr_locations_order
"""

def preprocess_url(self, request_url: str):
"""
Preprocess the request URL to ensure the mock response will be found.
"""
if re.fullmatch('.*/+', request_url) is None:
return request_url
else:
return re.compile(request_url.rstrip('/') + '/+')

@responses.activate
def test_update_cr_locations_order_all_params(self):
"""
update_cr_locations_order()
"""
# Set up mock
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "my-resolver", "description": "custom resolver", "enabled": false, "health": "HEALTHY", "locations": [{"id": "9a234ede-c2b6-4c39-bc27-d39ec139ecdb", "subnet_crn": "crn:v1:bluemix:public:is:us-south-1:a/01652b251c3ae2787110a995d8db0135::subnet:0716-b49ef064-0f89-4fb1-8212-135b12568f04", "enabled": true, "healthy": true, "dns_server_ip": "10.10.16.8"}], "created_on": "2021-04-21T08:18:25.000Z", "modified_on": "2021-04-21T08:18:25.000Z"}'
responses.add(responses.PUT,
url,
body=mock_response,
content_type='application/json',
status=200)

# Set up parameter values
instance_id = 'testString'
resolver_id = 'testString'
locations = ['9a234ede-c2b6-4c39-bc27-d39ec139ecdb']
x_correlation_id = 'testString'

# Invoke method
response = _service.update_cr_locations_order(
instance_id,
resolver_id,
locations=locations,
x_correlation_id=x_correlation_id,
headers={}
)

# Check for correct operation
assert len(responses.calls) == 1
assert response.status_code == 200
# Validate body params
req_body = json.loads(str(responses.calls[0].request.body, 'utf-8'))
assert req_body['locations'] == ['9a234ede-c2b6-4c39-bc27-d39ec139ecdb']


@responses.activate
def test_update_cr_locations_order_required_params(self):
"""
test_update_cr_locations_order_required_params()
"""
# Set up mock
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "my-resolver", "description": "custom resolver", "enabled": false, "health": "HEALTHY", "locations": [{"id": "9a234ede-c2b6-4c39-bc27-d39ec139ecdb", "subnet_crn": "crn:v1:bluemix:public:is:us-south-1:a/01652b251c3ae2787110a995d8db0135::subnet:0716-b49ef064-0f89-4fb1-8212-135b12568f04", "enabled": true, "healthy": true, "dns_server_ip": "10.10.16.8"}], "created_on": "2021-04-21T08:18:25.000Z", "modified_on": "2021-04-21T08:18:25.000Z"}'
responses.add(responses.PUT,
url,
body=mock_response,
content_type='application/json',
status=200)

# Set up parameter values
instance_id = 'testString'
resolver_id = 'testString'

# Invoke method
response = _service.update_cr_locations_order(
instance_id,
resolver_id,
headers={}
)

# Check for correct operation
assert len(responses.calls) == 1
assert response.status_code == 200


@responses.activate
def test_update_cr_locations_order_value_error(self):
"""
test_update_cr_locations_order_value_error()
"""
# Set up mock
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "my-resolver", "description": "custom resolver", "enabled": false, "health": "HEALTHY", "locations": [{"id": "9a234ede-c2b6-4c39-bc27-d39ec139ecdb", "subnet_crn": "crn:v1:bluemix:public:is:us-south-1:a/01652b251c3ae2787110a995d8db0135::subnet:0716-b49ef064-0f89-4fb1-8212-135b12568f04", "enabled": true, "healthy": true, "dns_server_ip": "10.10.16.8"}], "created_on": "2021-04-21T08:18:25.000Z", "modified_on": "2021-04-21T08:18:25.000Z"}'
responses.add(responses.PUT,
url,
body=mock_response,
content_type='application/json',
status=200)

# Set up parameter values
instance_id = 'testString'
resolver_id = 'testString'

# Pass in all but one required param and check for a ValueError
req_param_dict = {
"instance_id": instance_id,
"resolver_id": resolver_id,
}
for param in req_param_dict.keys():
req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()}
with pytest.raises(ValueError):
_service.update_cr_locations_order(**req_copy)



# endregion
##############################################################################
# End of Service: CustomResolvers
Expand Down Expand Up @@ -5271,8 +5382,8 @@ def test_custom_resolver_serialization(self):
custom_resolver_model_json['enabled'] = False
custom_resolver_model_json['health'] = 'HEALTHY'
custom_resolver_model_json['locations'] = [location_model]
custom_resolver_model_json['created_on'] = "2021-04-21T08:18:25Z"
custom_resolver_model_json['modified_on'] = "2021-04-21T08:18:25Z"
custom_resolver_model_json['created_on'] = '2015-03-14T09:26:53.123456Z'
custom_resolver_model_json['modified_on'] = '2015-03-14T09:26:53.123456Z'

# Construct a model instance of CustomResolver by calling from_dict on the json representation
custom_resolver_model = CustomResolver.from_dict(custom_resolver_model_json)
Expand Down Expand Up @@ -5315,8 +5426,8 @@ def test_custom_resolver_list_serialization(self):
custom_resolver_model['enabled'] = False
custom_resolver_model['health'] = 'HEALTHY'
custom_resolver_model['locations'] = [location_model]
custom_resolver_model['created_on'] = "2021-04-21T08:18:25Z"
custom_resolver_model['modified_on'] = "2021-04-21T08:18:25Z"
custom_resolver_model['created_on'] = '2015-03-14T09:26:53.123456Z'
custom_resolver_model['modified_on'] = '2015-03-14T09:26:53.123456Z'

# Construct a json representation of a CustomResolverList model
custom_resolver_list_model_json = {}
Expand Down Expand Up @@ -5419,8 +5530,8 @@ def test_forwarding_rule_serialization(self):
forwarding_rule_model_json['type'] = 'zone'
forwarding_rule_model_json['match'] = 'example.com'
forwarding_rule_model_json['forward_to'] = ['161.26.0.7']
forwarding_rule_model_json['created_on'] = "2021-04-21T08:18:25Z"
forwarding_rule_model_json['modified_on'] = "2021-04-21T08:18:25Z"
forwarding_rule_model_json['created_on'] = '2015-03-14T09:26:53.123456Z'
forwarding_rule_model_json['modified_on'] = '2015-03-14T09:26:53.123456Z'

# Construct a model instance of ForwardingRule by calling from_dict on the json representation
forwarding_rule_model = ForwardingRule.from_dict(forwarding_rule_model_json)
Expand Down Expand Up @@ -5455,8 +5566,8 @@ def test_forwarding_rule_list_serialization(self):
forwarding_rule_model['type'] = 'zone'
forwarding_rule_model['match'] = 'example.com'
forwarding_rule_model['forward_to'] = ['161.26.0.7']
forwarding_rule_model['created_on'] = "2021-04-21T08:18:25Z"
forwarding_rule_model['modified_on'] = "2021-04-21T08:18:25Z"
forwarding_rule_model['created_on'] = '2015-03-14T09:26:53.123456Z'
forwarding_rule_model['modified_on'] = '2015-03-14T09:26:53.123456Z'

# Construct a json representation of a ForwardingRuleList model
forwarding_rule_list_model_json = {}
Expand Down