Skip to content
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

Fixed bug in sip routing. SDK shouldnt send empty patch. #27919

Merged
merged 2 commits into from
Dec 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ def set_trunks(
if x.fqdn not in [o.fqdn for o in trunks]:
config.trunks[x.fqdn] = None

self._rest_service.patch_sip_configuration(
body=config, **kwargs
)
if len(config.trunks) > 0:
self._rest_service.patch_sip_configuration(
body=config, **kwargs
)

@distributed_trace
def set_routes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ async def set_trunks(
if x.fqdn not in [o.fqdn for o in trunks]:
config.trunks[x.fqdn] = None

await self._rest_service.patch_sip_configuration(
body=config, **kwargs
)
if len(config.trunks) > 0:
await self._rest_service.patch_sip_configuration(
body=config, **kwargs
)

@distributed_trace_async
async def set_routes(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"Entries": [
{
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Strict-Transport-Security": "max-age=2592000",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE",
"X-Processing-Time": "182ms"
},
"ResponseBody": {
"trunks": {},
"routes": []
}
},
{
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Strict-Transport-Security": "max-age=2592000",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE",
"X-Processing-Time": "279ms"
},
"ResponseBody": {
"trunks": {},
"routes": []
}
}
],
"Variables": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"Entries": [
{
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "0",
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Strict-Transport-Security": "max-age=2592000",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE",
"X-Processing-Time": "270ms"
},
"ResponseBody": {
"trunks": {},
"routes": []
}
},
{
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "0",
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Strict-Transport-Security": "max-age=2592000",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE",
"X-Processing-Time": "76ms"
},
"ResponseBody": {
"trunks": {},
"routes": []
}
}
],
"Variables": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from azure.core.exceptions import HttpResponseError
from phone_numbers_testcase import PhoneNumbersTestCase
from _shared.utils import create_token_credential, get_http_logging_policy
from sip_routing_helper import get_user_domain, assert_trunks_are_equal, assert_routes_are_equal
Expand Down Expand Up @@ -79,6 +79,16 @@ def test_set_trunks_from_managed_identity(self, **kwargs):
assert result_trunks is not None, "No trunks were returned."
assert_trunks_are_equal(result_trunks,[self.additional_trunk])

@recorded_by_proxy
def test_set_trunks_empty_list(self, **kwargs):
"""Verification of bug fix. SDK shouldn't send empty PATCH, otherwise it will receive exception.
This situation occurs, when sending empty trunks list to already empty trunk configuration."""
try:
self._sip_routing_client.set_trunks([])
self._sip_routing_client.set_trunks([])
except HttpResponseError as exception:
assert False, "Trying to set empty trunks list returned Http error: " + str(exception.status_code) + ", message: " + exception.message

@recorded_by_proxy
def test_set_routes(self, **kwargs):
self._prepare_test()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

import pytest
from azure.core.exceptions import HttpResponseError
from phone_numbers_testcase import PhoneNumbersTestCase
from devtools_testutils.aio import recorded_by_proxy_async
from _shared.utils import async_create_token_credential, get_http_logging_policy
Expand Down Expand Up @@ -88,6 +88,17 @@ async def test_set_trunks_from_managed_identity(self):
result_trunks = await self._sip_routing_client.get_trunks()
assert result_trunks is not None, "No trunks were returned."
assert_trunks_are_equal(result_trunks,[self.additional_trunk]), "Trunks are not equal."

@recorded_by_proxy_async
async def test_set_trunks_empty_list(self):
"""Verification of bug fix. SDK shouldn't send empty PATCH, otherwise it will receive exception.
This situation occurs, when sending empty trunks list to already empty trunk configuration."""
async with self._sip_routing_client:
try:
await self._sip_routing_client.set_trunks([])
await self._sip_routing_client.set_trunks([])
except HttpResponseError as exception:
assert False, "Trying to set empty trunks list returned Http error: " + str(exception.status_code) + ", message: " + exception.message

@recorded_by_proxy_async
async def test_set_routes(self):
Expand Down