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

[BotService] Sprint 164 - Refactor tests, make bot create idempotent #11935

Merged
merged 5 commits into from
Jan 31, 2020
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
5 changes: 5 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Release History
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails

**BotService**

* Fix issue #11697: `az bot create` is not idempotent
* Change name-correcting tests to run in Live-mode only

**IoT**

* Deprecated 'IoT hub Job' commands.
Expand Down
27 changes: 24 additions & 3 deletions src/azure-cli/azure/cli/command_modules/botservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ConnectionSetting,
ConnectionSettingProperties,
ConnectionSettingParameter,
ErrorException,
Sku)

from knack.util import CLIError
Expand Down Expand Up @@ -75,6 +76,28 @@ def __prepare_configuration_file(cmd, resource_group_name, kudu_client, folder_p
f.write(json.dumps(existing))


def __handle_failed_name_check(name_response, cmd, client, resource_group_name, resource_name):
# Creates should be idempotent, verify if the bot already exists inside of the provided Resource Group
logger.debug('Failed name availability check for provided bot name "%s".\n'
'Checking if bot exists in Resource Group "%s".', resource_name, resource_group_name)
try:
# If the bot exists, return the bot's information to the user
existing_bot = get_bot(cmd, client, resource_group_name, resource_name)
logger.warning('Provided bot name already exists in Resource Group. Returning bot information:')
return existing_bot
except ErrorException as e:
if e.error.error.code == 'ResourceNotFound':
code = e.error.error.code
message = e.error.error.message

logger.debug('Bot "%s" not found in Resource Group "%s".\n Code: "%s"\n Message: '
'"%s"', resource_name, resource_group_name, code, message)
raise CLIError('Unable to create bot.\nReason: "{}"'.format(name_response.message))
stevengum marked this conversation as resolved.
Show resolved Hide resolved

# For other error codes, raise them to the user
raise e


def create(cmd, client, resource_group_name, resource_name, kind, msa_app_id, password=None, language=None, # pylint: disable=too-many-locals, too-many-statements, inconsistent-return-statements
description=None, display_name=None, endpoint=None, tags=None, location='Central US',
sku_name='F0', deploy_echo=None):
Expand All @@ -91,9 +114,7 @@ def create(cmd, client, resource_group_name, resource_name, kind, msa_app_id, pa
# Check the resource name availability for the bot.
name_response = NameAvailability.check_name_availability(client, resource_name, kind)
if not name_response.valid:
# If the name is unavailable, gracefully exit and log the reason for the user.
raise CLIError('Unable to create a bot with a name of "{0}".\nReason: {1}'
.format(resource_name, name_response.message))
return __handle_failed_name_check(name_response, cmd, client, resource_group_name, resource_name)

if resource_name.find(".") > -1:
logger.warning('"." found in --name parameter ("%s"). "." is an invalid character for Azure Bot resource names '
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- -g -n
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: DELETE
Expand All @@ -28,7 +28,7 @@ interactions:
cache-control:
- no-cache
date:
- Wed, 27 Nov 2019 23:51:41 GMT
- Wed, 22 Jan 2020 23:48:25 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -57,7 +57,7 @@ interactions:
- -g -n
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: GET
Expand Down Expand Up @@ -113,7 +113,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 27 Nov 2019 23:51:41 GMT
- Wed, 22 Jan 2020 23:48:27 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -146,29 +146,27 @@ interactions:
- -k -g -n --appid
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: POST
uri: https://management.azure.com/providers/Microsoft.BotService/checkNameAvailability?api-version=2018-07-12
response:
body:
string: '{"valid":true,"message":""}'
string: '{"valid":true,"message":"","absCode":null}'
headers:
cache-control:
- no-cache
content-length:
- '27'
- '42'
content-type:
- application/json; charset=utf-8
date:
- Wed, 27 Nov 2019 23:51:41 GMT
- Wed, 22 Jan 2020 23:48:26 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-IIS/10.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
Expand All @@ -184,7 +182,7 @@ interactions:
message: OK
- request:
body: '{"location": "global", "sku": {"name": "F0"}, "kind": "bot", "properties":
{"displayName": "cli000002", "endpoint": "", "msaAppId": "364e79c9-7e33-4409-b252-e0cc755f3288"}}'
{"displayName": "cli000002", "endpoint": "", "msaAppId": "99a32174-c7ee-400e-8199-b0b377faf09a"}}'
headers:
Accept:
- application/json
Expand All @@ -202,14 +200,14 @@ interactions:
- -k -g -n --appid
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.BotService/botServices/cli000002?api-version=2018-07-12
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.BotService/botServices/cli000002","name":"cli000002","type":"Microsoft.BotService/botServices","etag":"\"54007c11-0000-0100-0000-5ddf0c100000\"","location":"global","sku":{"name":"F0"},"kind":"bot","tags":{},"properties":{"displayName":"cli000002","description":null,"iconUrl":"https://docs.botframework.com/static/devportal/client/images/bot-framework-default.png","endpoint":"","msaAppId":"364e79c9-7e33-4409-b252-e0cc755f3288","developerAppInsightKey":null,"developerAppInsightsApplicationId":null,"luisAppIds":[],"endpointVersion":"3.0","configuredChannels":["webchat"],"enabledChannels":["webchat","directline"],"isDeveloperAppInsightsApiKeySet":false,"isStreamingSupported":false,"publishingCredentials":null,"parameters":null,"allSettings":null,"manifestUrl":null,"storageResourceId":null,"provisioningState":"Succeeded"}}'
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.BotService/botServices/cli000002","name":"cli000002","type":"Microsoft.BotService/botServices","etag":"\"2000bded-0000-0100-0000-5e28df4d0000\"","location":"global","sku":{"name":"F0"},"kind":"bot","tags":{},"properties":{"displayName":"cli000002","description":null,"iconUrl":"https://docs.botframework.com/static/devportal/client/images/bot-framework-default.png","endpoint":"","msaAppId":"99a32174-c7ee-400e-8199-b0b377faf09a","developerAppInsightKey":null,"developerAppInsightsApplicationId":null,"luisAppIds":[],"endpointVersion":"3.0","configuredChannels":["webchat"],"enabledChannels":["webchat","directline"],"isDeveloperAppInsightsApiKeySet":false,"isStreamingSupported":false,"publishingCredentials":null,"parameters":null,"allSettings":null,"manifestUrl":null,"storageResourceId":null,"provisioningState":"Succeeded"}}'
headers:
cache-control:
- no-cache
Expand All @@ -218,21 +216,19 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 27 Nov 2019 23:51:44 GMT
- Wed, 22 Jan 2020 23:48:29 GMT
etag:
- '"54007c11-0000-0100-0000-5ddf0c100000"'
- '"2000bded-0000-0100-0000-5e28df4d0000"'
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-IIS/10.0
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1199'
- '1198'
status:
code: 201
message: Created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interactions:
- keep-alive
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: GET
Expand Down Expand Up @@ -68,7 +68,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Thu, 28 Nov 2019 00:35:56 GMT
- Wed, 22 Jan 2020 23:48:31 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -101,29 +101,27 @@ interactions:
- -k -g -n --appid -p --lang --echo
User-Agent:
- python/3.7.2 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.76
azure-mgmt-botservice/0.2.0 Azure-SDK-For-Python AZURECLI/2.0.80
accept-language:
- en-US
method: POST
uri: https://management.azure.com/providers/Microsoft.BotService/checkNameAvailability?api-version=2018-07-12
response:
body:
string: '{"valid":true,"message":""}'
string: '{"valid":true,"message":"","absCode":null}'
headers:
cache-control:
- no-cache
content-length:
- '27'
- '42'
content-type:
- application/json; charset=utf-8
date:
- Thu, 28 Nov 2019 00:35:57 GMT
- Wed, 22 Jan 2020 23:48:31 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-IIS/10.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
Expand Down
Loading