Skip to content

Commit 1ef4cf9

Browse files
feat(location opt): added cr location as opt
1 parent c2c9f3c commit 1ef4cf9

File tree

3 files changed

+208
-31
lines changed

3 files changed

+208
-31
lines changed

ibm_cloud_networking_services/dns_svcs_v1.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

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

1919
"""
2020
DNS Services API
@@ -2296,6 +2296,65 @@ def update_custom_resolver(self,
22962296
response = self.send(request)
22972297
return response
22982298

2299+
2300+
def update_cr_locations_order(self,
2301+
instance_id: str,
2302+
resolver_id: str,
2303+
*,
2304+
locations: List[str] = None,
2305+
x_correlation_id: str = None,
2306+
**kwargs
2307+
) -> DetailedResponse:
2308+
"""
2309+
Update the locations order of a custom resolver.
2310+
2311+
Update the locations order of a custom resolver.
2312+
2313+
:param str instance_id: The unique identifier of a service instance.
2314+
:param str resolver_id: The unique identifier of a custom resolver.
2315+
:param List[str] locations: (optional) Array of custom resolver location
2316+
ID.
2317+
:param str x_correlation_id: (optional) Uniquely identifying a request.
2318+
:param dict headers: A `dict` containing the request headers
2319+
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
2320+
:rtype: DetailedResponse with `dict` result representing a `CustomResolver` object
2321+
"""
2322+
2323+
if instance_id is None:
2324+
raise ValueError('instance_id must be provided')
2325+
if resolver_id is None:
2326+
raise ValueError('resolver_id must be provided')
2327+
headers = {
2328+
'X-Correlation-ID': x_correlation_id
2329+
}
2330+
sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME,
2331+
service_version='V1',
2332+
operation_id='update_cr_locations_order')
2333+
headers.update(sdk_headers)
2334+
2335+
data = {
2336+
'locations': locations
2337+
}
2338+
data = {k: v for (k, v) in data.items() if v is not None}
2339+
data = json.dumps(data)
2340+
headers['content-type'] = 'application/json'
2341+
2342+
if 'headers' in kwargs:
2343+
headers.update(kwargs.get('headers'))
2344+
headers['Accept'] = 'application/json'
2345+
2346+
path_param_keys = ['instance_id', 'resolver_id']
2347+
path_param_values = self.encode_path_vars(instance_id, resolver_id)
2348+
path_param_dict = dict(zip(path_param_keys, path_param_values))
2349+
url = '/instances/{instance_id}/custom_resolvers/{resolver_id}/locations_order'.format(**path_param_dict)
2350+
request = self.prepare_request(method='PUT',
2351+
url=url,
2352+
headers=headers,
2353+
data=data)
2354+
2355+
response = self.send(request)
2356+
return response
2357+
22992358
#########################
23002359
# Custom Resolver Locations
23012360
#########################

test/integration/test_dns_svcs_v1.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
Integration test code to execute dns zones
66
"""
77

8-
from ibm_cloud_networking_services.dns_svcs_v1 import DnsSvcsV1
98
import os
109
import unittest
11-
10+
from ibm_cloud_networking_services.dns_svcs_v1 import DnsSvcsV1
1211
from dotenv import load_dotenv, find_dotenv
12+
1313
configFile = "dns.env"
1414
# load the .env file containing your environment variables
1515
try:
@@ -19,8 +19,6 @@
1919

2020
class TestDNSSvcsV1(unittest.TestCase):
2121
"""The DNS V1 service test class."""
22-
23-
@unittest.skip("skipping")
2422

2523
def setUp(self):
2624
""" test case setup """
@@ -187,8 +185,6 @@ def test_1_pdns_zone_negative(self):
187185
class TestResourceRecordsV1(unittest.TestCase):
188186
"""The Resourse records V1 service test class."""
189187

190-
@unittest.skip("skipping")
191-
192188
def setUp(self):
193189
""" test case setup """
194190
if not os.path.exists(configFile):
@@ -704,8 +700,6 @@ def test_1_resource_records_negative(self):
704700
class TestPermittedNetworksForDnsZonesV1(unittest.TestCase):
705701
"""The Permitted Networks for DNS V1 service test class."""
706702

707-
@unittest.skip("skipping")
708-
709703
def setUp(self):
710704
""" test case setup """
711705
if not os.path.exists(configFile):
@@ -829,8 +823,6 @@ def test_1_permitted_network_negative(self):
829823
class TestGlobalLoadBalancersV1 (unittest.TestCase):
830824

831825
"""The Global Load Balancers for DNS V1 service test class."""
832-
833-
@unittest.skip("skipping")
834826

835827
def setUp(self):
836828
""" test case setup """
@@ -911,7 +903,7 @@ def _clean_dns_globalloadbalancers(self):
911903
instance_id=self.instance_id, dnszone_id=zone.get("id"))
912904

913905
################## global load balancers integration test cases ##################
914-
@unittest.skip('skipping...')
906+
# @unittest.skip('skipping...')
915907
def test_1_dns_globalloadbalancers(self):
916908
""" create,get,update,delete GLB monitor """
917909

@@ -1092,12 +1084,10 @@ def test_2_list_dns_globalloadbalancers(self):
10921084

10931085
class TestCustomResolversV1(unittest.TestCase):
10941086
"""Custom Resolvers for DNS V1 service test class."""
1095-
1096-
@unittest.skip("skipping")
1087+
10971088

10981089
def setUp(self):
10991090
""" test case setup """
1100-
11011091
if not os.path.exists(configFile):
11021092
raise unittest.SkipTest('External configuration not available, skipping...')
11031093
self.instance_id = os.getenv("DNS_SVCS_INSTANCE_ID")
@@ -1121,19 +1111,14 @@ def _clean_dns_custom_resolver(self):
11211111
result = response.get_result().get("custom_resolvers")
11221112
for crs in result:
11231113
self.cr.delete_custom_resolver(instance_id=self.instance_id, resolver_id=crs.get("id"))
1124-
1114+
11251115
def test_1_dns_customresolvers(self):
11261116
""" create,get,update,list Custom Resolvers """
11271117

11281118
name = 'testcustomresolvers'
11291119
description = "Creating Custom Resolvers"
1130-
locations = [{"subnet_crn": self.subnet_crn, "enabled": False}]
1131-
1132-
# Create Custom Resolvers
1133-
resp = self.cr.create_custom_resolver(instance_id=self.instance_id, name=name, locations=locations,
1120+
resp = self.cr.create_custom_resolver(instance_id=self.instance_id, name=name,
11341121
description=description)
1135-
1136-
11371122
assert resp is not None
11381123
assert resp.status_code == 200
11391124
resolver_id = resp.get_result().get("id")
@@ -1156,6 +1141,21 @@ def test_1_dns_customresolvers(self):
11561141
assert resp is not None
11571142
assert resp.status_code == 200
11581143

1144+
""" add,update,Custom Resolver Locations """
1145+
# Add Custom Resolver Locations
1146+
resp = self.cr.add_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
1147+
subnet_crn=self.subnet_crn_location, enabled=True)
1148+
assert resp is not None
1149+
assert resp.status_code == 200
1150+
location_id = resp.get_result().get("id")
1151+
1152+
1153+
# Update Custom Resolver Locations
1154+
resp = self.cr.update_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
1155+
location_id=location_id, enabled=False)
1156+
assert resp is not None
1157+
assert resp.status_code == 200
1158+
11591159
""" create,get,update,list Forwarding rules """
11601160
# Create Forwarding rules
11611161
type1 = 'zone'
@@ -1192,11 +1192,18 @@ def test_1_dns_customresolvers(self):
11921192
resp = self.cr.delete_forwarding_rule(instance_id=self.instance_id, resolver_id=resolver_id, rule_id=rule_id)
11931193
assert resp is not None
11941194
assert resp.status_code == 204
1195+
1196+
# Delete Custom resolver locations
1197+
resp = self.cr.delete_custom_resolver_location(instance_id=self.instance_id, resolver_id=resolver_id,
1198+
location_id=location_id)
1199+
assert resp is not None
1200+
assert resp.status_code == 204
11951201

1196-
# Delete Custom Resolver
1202+
# Delete Custom Resolver
11971203
resp = self.cr.delete_custom_resolver(instance_id=self.instance_id, resolver_id=resolver_id)
11981204
assert resp is not None
11991205
assert resp.status_code == 204
12001206

1207+
12011208
if __name__ == '__main__':
12021209
unittest.main()

test/unit/test_dns_svcs_v1.py

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,6 +4221,117 @@ def test_update_custom_resolver_value_error(self):
42214221

42224222

42234223

4224+
class TestUpdateCrLocationsOrder():
4225+
"""
4226+
Test Class for update_cr_locations_order
4227+
"""
4228+
4229+
def preprocess_url(self, request_url: str):
4230+
"""
4231+
Preprocess the request URL to ensure the mock response will be found.
4232+
"""
4233+
if re.fullmatch('.*/+', request_url) is None:
4234+
return request_url
4235+
else:
4236+
return re.compile(request_url.rstrip('/') + '/+')
4237+
4238+
@responses.activate
4239+
def test_update_cr_locations_order_all_params(self):
4240+
"""
4241+
update_cr_locations_order()
4242+
"""
4243+
# Set up mock
4244+
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
4245+
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"}'
4246+
responses.add(responses.PUT,
4247+
url,
4248+
body=mock_response,
4249+
content_type='application/json',
4250+
status=200)
4251+
4252+
# Set up parameter values
4253+
instance_id = 'testString'
4254+
resolver_id = 'testString'
4255+
locations = ['9a234ede-c2b6-4c39-bc27-d39ec139ecdb']
4256+
x_correlation_id = 'testString'
4257+
4258+
# Invoke method
4259+
response = _service.update_cr_locations_order(
4260+
instance_id,
4261+
resolver_id,
4262+
locations=locations,
4263+
x_correlation_id=x_correlation_id,
4264+
headers={}
4265+
)
4266+
4267+
# Check for correct operation
4268+
assert len(responses.calls) == 1
4269+
assert response.status_code == 200
4270+
# Validate body params
4271+
req_body = json.loads(str(responses.calls[0].request.body, 'utf-8'))
4272+
assert req_body['locations'] == ['9a234ede-c2b6-4c39-bc27-d39ec139ecdb']
4273+
4274+
4275+
@responses.activate
4276+
def test_update_cr_locations_order_required_params(self):
4277+
"""
4278+
test_update_cr_locations_order_required_params()
4279+
"""
4280+
# Set up mock
4281+
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
4282+
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"}'
4283+
responses.add(responses.PUT,
4284+
url,
4285+
body=mock_response,
4286+
content_type='application/json',
4287+
status=200)
4288+
4289+
# Set up parameter values
4290+
instance_id = 'testString'
4291+
resolver_id = 'testString'
4292+
4293+
# Invoke method
4294+
response = _service.update_cr_locations_order(
4295+
instance_id,
4296+
resolver_id,
4297+
headers={}
4298+
)
4299+
4300+
# Check for correct operation
4301+
assert len(responses.calls) == 1
4302+
assert response.status_code == 200
4303+
4304+
4305+
@responses.activate
4306+
def test_update_cr_locations_order_value_error(self):
4307+
"""
4308+
test_update_cr_locations_order_value_error()
4309+
"""
4310+
# Set up mock
4311+
url = self.preprocess_url(_base_url + '/instances/testString/custom_resolvers/testString/locations_order')
4312+
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"}'
4313+
responses.add(responses.PUT,
4314+
url,
4315+
body=mock_response,
4316+
content_type='application/json',
4317+
status=200)
4318+
4319+
# Set up parameter values
4320+
instance_id = 'testString'
4321+
resolver_id = 'testString'
4322+
4323+
# Pass in all but one required param and check for a ValueError
4324+
req_param_dict = {
4325+
"instance_id": instance_id,
4326+
"resolver_id": resolver_id,
4327+
}
4328+
for param in req_param_dict.keys():
4329+
req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()}
4330+
with pytest.raises(ValueError):
4331+
_service.update_cr_locations_order(**req_copy)
4332+
4333+
4334+
42244335
# endregion
42254336
##############################################################################
42264337
# End of Service: CustomResolvers
@@ -5271,8 +5382,8 @@ def test_custom_resolver_serialization(self):
52715382
custom_resolver_model_json['enabled'] = False
52725383
custom_resolver_model_json['health'] = 'HEALTHY'
52735384
custom_resolver_model_json['locations'] = [location_model]
5274-
custom_resolver_model_json['created_on'] = "2021-04-21T08:18:25Z"
5275-
custom_resolver_model_json['modified_on'] = "2021-04-21T08:18:25Z"
5385+
custom_resolver_model_json['created_on'] = '2015-03-14T09:26:53.123456Z'
5386+
custom_resolver_model_json['modified_on'] = '2015-03-14T09:26:53.123456Z'
52765387

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

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

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

54615572
# Construct a json representation of a ForwardingRuleList model
54625573
forwarding_rule_list_model_json = {}

0 commit comments

Comments
 (0)