From 5ba6ba2db239c120ab81b891434e19c46a6cab1d Mon Sep 17 00:00:00 2001 From: SDK Automation Date: Fri, 15 May 2020 09:56:16 +0000 Subject: [PATCH] Generated from eabd724459cc53fc9f60f12b078906ffdc3162ed upgrade pipeline scripts version to 0.8.0 (#9457) Co-authored-by: Jianye Xi --- ...lertsmanagement.test_alertsmanagement.yaml | 217 ++++++++++++++++++ .../tests/test_cli_mgmt_alertsmanagement.py | 203 ++++++++++++++++ 2 files changed, 420 insertions(+) create mode 100644 sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/recordings/test_cli_mgmt_alertsmanagement.test_alertsmanagement.yaml create mode 100644 sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/test_cli_mgmt_alertsmanagement.py diff --git a/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/recordings/test_cli_mgmt_alertsmanagement.test_alertsmanagement.yaml b/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/recordings/test_cli_mgmt_alertsmanagement.test_alertsmanagement.yaml new file mode 100644 index 000000000000..2ae89831dfeb --- /dev/null +++ b/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/recordings/test_cli_mgmt_alertsmanagement.test_alertsmanagement.yaml @@ -0,0 +1,217 @@ +interactions: +- request: + body: 'b''b\''{"location": "Global", "properties": {"scope": {"scopeType": "ResourceGroup", + "values": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568"]}, + "conditions": {"severity": {"operator": "Equals", "values": ["Sev0", "Sev2"]}, + "monitorService": {"operator": "Equals", "values": ["Platform", "Application + Insights"]}, "monitorCondition": {"operator": "Equals", "values": ["Fired"]}, + "targetResourceType": {"operator": "NotEquals", "values": ["Microsoft.Compute/VirtualMachines"]}}, + "description": "Action rule on resource group for daily suppression", "status": + "Enabled", "type": "Suppression", "suppressionConfig": {"recurrenceType": "Daily", + "schedule": {"startDate": "12/09/2018", "endDate": "12/18/2018", "startTime": + "06:00:00", "endTime": "14:00:00"}}}}\''''' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '833' + Content-Type: + - application/json; charset=utf-8 + User-Agent: + - python/3.6.9 (Linux-4.9.184-linuxkit-x86_64-with-Ubuntu-18.04-bionic) msrest/0.6.10 + msrest_azure/0.6.2 azure-mgmt-alertsmanagement/0.2.0rc2 Azure-SDK-For-Python + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568/providers/Microsoft.AlertsManagement/actionRules/myActionRule?api-version=2019-05-05-preview + response: + body: + string: '{"properties":{"conditions":{"severity":{"operator":"Equals","values":["Sev0","Sev2"]},"monitorService":{"operator":"Equals","values":["Platform","Application + Insights"]},"monitorCondition":{"operator":"Equals","values":["Fired"]},"targetResourceType":{"operator":"NotEquals","values":["Microsoft.Compute/VirtualMachines"]}},"status":"Enabled","type":"Suppression","scope":{"scopeType":"ResourceGroup","values":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568"]},"suppressionConfig":{"recurrenceType":"Daily","schedule":{"startDate":"12/09/2018","endDate":"12/18/2018","startTime":"06:00:00","endTime":"14:00:00"}},"description":"Action + rule on resource group for daily suppression","createdAt":"2020-04-19T10:14:03.4377945Z","createdBy":"User","lastModifiedAt":"2020-04-19T10:14:03.4377945Z","lastModifiedBy":"User"},"location":"Global","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568/providers/Microsoft.AlertsManagement/actionRules/myActionRule","type":"Microsoft.AlertsManagement/actionRules","name":"myActionRule"}' + headers: + cache-control: + - no-store, no-cache + content-length: + - '1186' + content-security-policy: + - script-src 'self' + content-type: + - application/json; charset=utf-8 + date: + - Sun, 19 Apr 2020 10:14:03 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1199' + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python/3.6.9 (Linux-4.9.184-linuxkit-x86_64-with-Ubuntu-18.04-bionic) msrest/0.6.10 + msrest_azure/0.6.2 azure-mgmt-alertsmanagement/0.2.0rc2 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568/providers/Microsoft.AlertsManagement/actionRules/myActionRule?api-version=2019-05-05-preview + response: + body: + string: '{"properties":{"conditions":{"severity":{"operator":"Equals","values":["Sev0","Sev2"]},"monitorService":{"operator":"Equals","values":["Platform","Application + Insights"]},"monitorCondition":{"operator":"Equals","values":["Fired"]},"targetResourceType":{"operator":"NotEquals","values":["Microsoft.Compute/VirtualMachines"]}},"status":"Enabled","type":"Suppression","scope":{"scopeType":"ResourceGroup","values":["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568"]},"suppressionConfig":{"recurrenceType":"Daily","schedule":{"startDate":"12/09/2018","endDate":"12/18/2018","startTime":"06:00:00","endTime":"14:00:00"}},"description":"Action + rule on resource group for daily suppression","createdAt":"2020-04-19T10:14:03.4377945Z","createdBy":"User","lastModifiedAt":"2020-04-19T10:14:03.4377945Z","lastModifiedBy":"User"},"location":"Global","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568/providers/Microsoft.AlertsManagement/actionRules/myActionRule","type":"Microsoft.AlertsManagement/actionRules","name":"myActionRule"}' + headers: + cache-control: + - no-store, no-cache + content-length: + - '1186' + content-security-policy: + - script-src 'self' + content-type: + - application/json; charset=utf-8 + date: + - Sun, 19 Apr 2020 10:14:04 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-resource-requests: + - '999' + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python/3.6.9 (Linux-4.9.184-linuxkit-x86_64-with-Ubuntu-18.04-bionic) msrest/0.6.10 + msrest_azure/0.6.2 azure-mgmt-alertsmanagement/0.2.0rc2 Azure-SDK-For-Python + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.AlertsManagement/alertsSummary?groupby=severity%2CalertState&api-version=2019-05-05-preview + response: + body: + string: '{"properties":{"groupedby":"severity","total":0,"values":[{"name":"Sev0","count":0,"groupedby":"alertState","values":[{"name":"New","count":0},{"name":"Acknowledged","count":0},{"name":"Closed","count":0}]},{"name":"Sev1","count":0,"groupedby":"alertState","values":[{"name":"New","count":0},{"name":"Acknowledged","count":0},{"name":"Closed","count":0}]},{"name":"Sev2","count":0,"groupedby":"alertState","values":[{"name":"New","count":0},{"name":"Acknowledged","count":0},{"name":"Closed","count":0}]},{"name":"Sev3","count":0,"groupedby":"alertState","values":[{"name":"New","count":0},{"name":"Acknowledged","count":0},{"name":"Closed","count":0}]},{"name":"Sev4","count":0,"groupedby":"alertState","values":[{"name":"New","count":0},{"name":"Acknowledged","count":0},{"name":"Closed","count":0}]}]},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.AlertsManagement/alertsSummary/current","type":"Microsoft.AlertsManagement/alertsSummary","name":"current"}' + headers: + cache-control: + - no-store, no-cache + content-length: + - '990' + content-security-policy: + - script-src 'self' + content-type: + - application/json; charset=utf-8 + date: + - Sun, 19 Apr 2020 10:14:04 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-resource-requests: + - '999' + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - python/3.6.9 (Linux-4.9.184-linuxkit-x86_64-with-Ubuntu-18.04-bionic) msrest/0.6.10 + msrest_azure/0.6.2 azure-mgmt-alertsmanagement/0.2.0rc2 Azure-SDK-For-Python + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_cli_mgmt_alertsmanagement_test_alertsmanagement37c21568/providers/Microsoft.AlertsManagement/actionRules/myActionRule?api-version=2019-05-05-preview + response: + body: + string: 'true' + headers: + cache-control: + - no-store, no-cache + content-length: + - '4' + content-security-policy: + - script-src 'self' + content-type: + - application/json; charset=utf-8 + date: + - Sun, 19 Apr 2020 10:14:07 GMT + expires: + - '-1' + pragma: + - no-cache + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/test_cli_mgmt_alertsmanagement.py b/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/test_cli_mgmt_alertsmanagement.py new file mode 100644 index 000000000000..572c559e2b17 --- /dev/null +++ b/sdk/alertsmanagement/azure-mgmt-alertsmanagement/tests/test_cli_mgmt_alertsmanagement.py @@ -0,0 +1,203 @@ +# coding: utf-8 + +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + + +# TEST SCENARIO COVERAGE +# ---------------------- +# Methods Total : 23 +# Methods Covered : 22 +# Examples Total : 22 +# Examples Tested : 21 +# Coverage % : 91 +# ---------------------- + +import unittest + +import azure.mgmt.alertsmanagement +from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer + +AZURE_LOCATION = 'eastus' + +class MgmtAlertsTest(AzureMgmtTestCase): + + def setUp(self): + super(MgmtAlertsTest, self).setUp() + self.mgmt_client = self.create_mgmt_client( + azure.mgmt.alertsmanagement.AlertsManagementClient + ) + + @ResourceGroupPreparer(location=AZURE_LOCATION) + def test_alertsmanagement(self, resource_group): + + SUBSCRIPTION_ID = self.settings.SUBSCRIPTION_ID + RESOURCE_GROUP = resource_group.name + ALERT_ID = "myAlertId" + SMART_GROUP_ID = "mySmartGroupId" + ACTION_RULE_NAME = "myActionRule" + ALERT_RULE_NAME = "myAlertRule" + + # /ActionRules/put/PutActionRule[put] + BODY = { + "location": "Global", + "properties": { + "scope": { + "scope_type": "ResourceGroup", + "values": [ + "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + ] + }, + "conditions": { + "severity": { + "operator": "Equals", + "values": [ + "Sev0", + "Sev2" + ] + }, + "monitor_service": { + "operator": "Equals", + "values": [ + "Platform", + "Application Insights" + ] + }, + "monitor_condition": { + "operator": "Equals", + "values": [ + "Fired" + ] + }, + "target_resource_type": { + "operator": "NotEquals", + "values": [ + "Microsoft.Compute/VirtualMachines" + ] + } + }, + "type": "Suppression", + "suppression_config": { + "recurrence_type": "Daily", + "schedule": { + "start_date": "12/09/2018", + "end_date": "12/18/2018", + "start_time": "06:00:00", + "end_time": "14:00:00" + } + }, + "description": "Action rule on resource group for daily suppression", + "status": "Enabled" + } + } + result = self.mgmt_client.action_rules.create_update(resource_group_name=RESOURCE_GROUP, action_rule_name=ACTION_RULE_NAME, action_rule=BODY) + + # /SmartDetectorAlertRules/put/Create or update a Smart Detector alert rule[put] + BODY = { + "description": "Sample smart detector alert rule description", + "state": "Enabled", + "severity": "Sev3", + "frequency": "PT5M", + "detector": { + "id": "VMMemoryLeak" + }, + "scope": [ + "/subscriptions/b368ca2f-e298-46b7-b0ab-012281956afa/resourceGroups/MyVms/providers/Microsoft.Compute/virtualMachines/vm1" + ], + "action_groups": { + "custom_email_subject": "My custom email subject", + "custom_webhook_payload": "{\"AlertRuleName\":\"#alertrulename\"}", + "group_ids": [ + "/subscriptions/b368ca2f-e298-46b7-b0ab-012281956afa/resourcegroups/actionGroups/providers/microsoft.insights/actiongroups/MyActionGroup" + ] + }, + "throttling": { + "duration": "PT20M" + } + } + # result = self.mgmt_client.smart_detector_alert_rules.create_or_update(resource_group_name=RESOURCE_GROUP, alert_rule_name=ALERT_RULE_NAME, parameters=BODY) + + # /SmartDetectorAlertRules/get/Get a Smart Detector alert rule[get] + # result = self.mgmt_client.smart_detector_alert_rules.get(resource_group_name=RESOURCE_GROUP, alert_rule_name=ALERT_RULE_NAME) + + # /ActionRules/get/GetActionRuleById[get] + result = self.mgmt_client.action_rules.get_by_name(resource_group_name=RESOURCE_GROUP, action_rule_name=ACTION_RULE_NAME) + + # /SmartDetectorAlertRules/get/List alert rules[get] + result = self.mgmt_client.smart_detector_alert_rules.list_by_resource_group(resource_group_name=RESOURCE_GROUP) + + # /ActionRules/get/GetActionRulesResourceGroupWide[get] + result = self.mgmt_client.action_rules.list_by_resource_group(resource_group_name=RESOURCE_GROUP) + + # /SmartGroups/get/Resolve[get] + # result = self.mgmt_client.smart_groups.get_history(smart_group_id=SMART_GROUP_ID) + + # /SmartGroups/get/Get[get] + # result = self.mgmt_client.smart_groups.get_by_id(smart_group_id=SMART_GROUP_ID) + + # /SmartDetectorAlertRules/get/List Smart Detector alert rules[get] + result = self.mgmt_client.smart_detector_alert_rules.list() + + # /Alerts/get/GetById[get] + # result = self.mgmt_client.alerts.get_by_id(alert_id=ALERT_ID) + + # /Alerts/get/Summary[get] + result = self.mgmt_client.alerts.get_summary(groupby="severity,alertState") + + # /SmartGroups/get/List[get] + result = self.mgmt_client.smart_groups.get_all() + + # /ActionRules/get/GetActionRulesSubscriptionWide[get] + result = self.mgmt_client.action_rules.list_by_subscription() + + # /Alerts/get/ListAlerts[get] + result = self.mgmt_client.alerts.get_all() + + # /Alerts/get/MonService[get] + # result = self.mgmt_client.alerts.meta_data(identifier="MonitorServiceList") + + # /SmartDetectorAlertRules/patch/Patch alert rules[patch] + BODY = { + "tags": { + "new_key": "newVal" + }, + "description": "New description for patching", + "frequency": "PT1M" + } + # result = self.mgmt_client.smart_detector_alert_rules.patch(resource_group_name=RESOURCE_GROUP, alert_rule_name=ALERT_RULE_NAME, parameters=BODY) + + # /ActionRules/patch/PatchActionRule[patch] + BODY = { + "tags": { + "key1": "value1", + "key2": "value2" + }, + "status": "Disabled" + } + # result = self.mgmt_client.action_rules.update(resource_group_name=RESOURCE_GROUP, action_rule_name=ACTION_RULE_NAME, action_rule_patch=BODY) + + # /SmartGroups/post/changestate[post] + BODY = { + "comments": "Acknowledging smart group" + } + # result = self.mgmt_client.smart_groups.change_state(smart_group_id=SMART_GROUP_ID, body=BODY, new_state="Acknowledged") + + # /Alerts/post/Resolve[post] + BODY = { + "comments": "Acknowledging alert" + } + # result = self.mgmt_client.alerts.change_state(alert_id=ALERT_ID, body=BODY, new_state="Acknowledged") + + # /SmartDetectorAlertRules/delete/Delete a Smart Detector alert rule[delete] + # result = self.mgmt_client.smart_detector_alert_rules.delete(resource_group_name=RESOURCE_GROUP, alert_rule_name=ALERT_RULE_NAME) + + # /ActionRules/delete/DeleteActionRule[delete] + result = self.mgmt_client.action_rules.delete(resource_group_name=RESOURCE_GROUP, action_rule_name=ACTION_RULE_NAME) + + +#------------------------------------------------------------------------------ +if __name__ == '__main__': + unittest.main()