Skip to content

Commit 78c7f87

Browse files
update command params healthbot (#9602)
* upgrade api version and change available skus * pr guidelines * pr notes * pr notes * pr. ntoes * fix command params * stype * Update src/healthbot/azext_healthbot/manual/_params.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * pr notes * fix style * add tests * tests * fix pr --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 36ede5c commit 78c7f87

13 files changed

+2926
-684
lines changed

src/healthbot/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.1.0
7+
++++++
8+
* Fix issue where new tiers were not being recognized.
9+
610
1.0.0
711
++++++
812
* GA with additional tiers.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
from knack.help_files import helps
8+
9+
10+
helps['healthbot update'] = """
11+
type: command
12+
short-summary: "Patch a HealthBot."
13+
examples:
14+
- name: BotUpdate
15+
text: |-
16+
az healthbot update --name "samplebotname" --sku "F0" --resource-group "healthbotClient"
17+
"""
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
#
6+
# Code generated by Microsoft (R) AutoRest Code Generator.
7+
# Changes may cause incorrect behavior and will be lost if the code is
8+
# regenerated.
9+
# --------------------------------------------------------------------------
10+
# pylint: disable=too-many-lines
11+
# pylint: disable=too-many-statements
12+
13+
from azure.cli.core.commands.parameters import get_enum_type
14+
15+
16+
def load_arguments(self, _):
17+
18+
# Only override the SKU argument where its behavior differs from the generated parameters.
19+
with self.argument_context('healthbot create') as c:
20+
c.argument('sku',
21+
arg_type=get_enum_type(['F0', 'C0', 'C1', 'PES']),
22+
help='The name of the HealthBot SKU',
23+
arg_group='Sku')
24+
25+
with self.argument_context('healthbot update') as c:
26+
c.argument('sku',
27+
arg_type=get_enum_type(['F0', 'C0', 'C1', 'PES']),
28+
help='The name of the HealthBot SKU',
29+
arg_group='Sku')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
8+
def healthbot_update(client,
9+
resource_group_name,
10+
bot_name,
11+
tags=None,
12+
sku=None):
13+
parameters = {}
14+
parameters['tags'] = tags
15+
if sku is not None:
16+
parameters['sku'] = {'name': sku}
17+
return client.update(resource_group_name=resource_group_name,
18+
bot_name=bot_name,
19+
parameters=parameters)
Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,7 @@
1-
# coding=utf-8
21
# --------------------------------------------------------------------------
32
# Copyright (c) Microsoft Corporation. All rights reserved.
43
# Licensed under the MIT License. See License.txt in the project root for
54
# license information.
6-
#
7-
# Code generated by Microsoft (R) AutoRest Code Generator.
8-
# Changes may cause incorrect behavior and will be lost if the code is
9-
# regenerated.
105
# --------------------------------------------------------------------------
11-
import inspect
12-
import logging
13-
import os
14-
import sys
15-
import traceback
16-
import datetime as dt
176

18-
from azure.core.exceptions import AzureError
19-
from azure.cli.testsdk.exceptions import CliTestError, CliExecutionError, JMESPathCheckAssertionError
20-
21-
22-
logger = logging.getLogger('azure.cli.testsdk')
23-
logger.addHandler(logging.StreamHandler())
247
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
25-
exceptions = []
26-
test_map = dict()
27-
SUCCESSED = "successed"
28-
FAILED = "failed"
29-
30-
31-
def try_manual(func):
32-
def import_manual_function(origin_func):
33-
from importlib import import_module
34-
decorated_path = inspect.getfile(origin_func).lower()
35-
module_path = __path__[0].lower()
36-
if not decorated_path.startswith(module_path):
37-
raise Exception("Decorator can only be used in submodules!")
38-
manual_path = os.path.join(
39-
decorated_path[module_path.rfind(os.path.sep) + 1:])
40-
manual_file_path, manual_file_name = os.path.split(manual_path)
41-
module_name, _ = os.path.splitext(manual_file_name)
42-
manual_module = "..manual." + \
43-
".".join(manual_file_path.split(os.path.sep) + [module_name, ])
44-
return getattr(import_module(manual_module, package=__name__), origin_func.__name__)
45-
46-
def get_func_to_call():
47-
func_to_call = func
48-
try:
49-
func_to_call = import_manual_function(func)
50-
logger.info("Found manual override for %s(...)", func.__name__)
51-
except (ImportError, AttributeError):
52-
pass
53-
return func_to_call
54-
55-
def wrapper(*args, **kwargs):
56-
func_to_call = get_func_to_call()
57-
logger.info("running %s()...", func.__name__)
58-
try:
59-
test_map[func.__name__] = dict()
60-
test_map[func.__name__]["result"] = SUCCESSED
61-
test_map[func.__name__]["error_message"] = ""
62-
test_map[func.__name__]["error_stack"] = ""
63-
test_map[func.__name__]["error_normalized"] = ""
64-
test_map[func.__name__]["start_dt"] = dt.datetime.utcnow()
65-
ret = func_to_call(*args, **kwargs)
66-
except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit,
67-
JMESPathCheckAssertionError) as e:
68-
use_exception_cache = os.getenv("TEST_EXCEPTION_CACHE")
69-
if use_exception_cache is None or use_exception_cache.lower() != "true":
70-
raise
71-
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
72-
test_map[func.__name__]["result"] = FAILED
73-
test_map[func.__name__]["error_message"] = str(e).replace("\r\n", " ").replace("\n", " ")[:500]
74-
test_map[func.__name__]["error_stack"] = traceback.format_exc().replace(
75-
"\r\n", " ").replace("\n", " ")[:500]
76-
logger.info("--------------------------------------")
77-
logger.info("step exception: %s", e)
78-
logger.error("--------------------------------------")
79-
logger.error("step exception in %s: %s", func.__name__, e)
80-
logger.info(traceback.format_exc())
81-
exceptions.append((func.__name__, sys.exc_info()))
82-
else:
83-
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
84-
return ret
85-
86-
if inspect.isclass(func):
87-
return get_func_to_call()
88-
return wrapper
89-
90-
91-
def calc_coverage(filename):
92-
filename = filename.split(".")[0]
93-
coverage_name = filename + "_coverage.md"
94-
with open(coverage_name, "w") as f:
95-
f.write("|Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt|\n")
96-
total = len(test_map)
97-
covered = 0
98-
for k, v in test_map.items():
99-
if not k.startswith("step_"):
100-
total -= 1
101-
continue
102-
if v["result"] == SUCCESSED:
103-
covered += 1
104-
f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|"
105-
"{end_dt}|\n".format(step_name=k, **v))
106-
f.write("Coverage: {}/{}\n".format(covered, total))
107-
print("Create coverage\n", file=sys.stderr)
108-
109-
110-
def raise_if():
111-
if exceptions:
112-
if len(exceptions) <= 1:
113-
raise exceptions[0][1][1]
114-
message = "{}\nFollowed with exceptions in other steps:\n".format(str(exceptions[0][1][1]))
115-
message += "\n".join(["{}: {}".format(h[0], h[1][1]) for h in exceptions[1:]])
116-
raise exceptions[0][1][0](message).with_traceback(exceptions[0][1][2])

src/healthbot/azext_healthbot/tests/latest/example_steps.py

Lines changed: 90 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,23 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
5-
#
6-
# Code generated by Microsoft (R) AutoRest Code Generator.
7-
# Changes may cause incorrect behavior and will be lost if the code is
8-
# regenerated.
95
# --------------------------------------------------------------------------
106

117

12-
from .. import try_manual
13-
14-
158
# EXAMPLE: /Bots/put/BotCreate
16-
@try_manual
17-
def step_create(test, rg, rg_2, checks=None):
9+
def step_create_with_sku(test, rg, sku, checks=None):
1810
if checks is None:
1911
checks = []
20-
test.cmd('az healthbot create '
21-
'--name "{myBot}" '
22-
'--location "eastus" '
23-
'--sku "F0" '
24-
'--resource-group "{rg}"',
12+
test.cmd(f'az healthbot create '
13+
f'--name "{{myBot}}" '
14+
f'--location "eastus" '
15+
f'--sku "{sku}" '
16+
f'--resource-group "{{rg}}"',
2517
checks=checks)
2618

2719

2820
# EXAMPLE: /Bots/get/List Bots by Resource Group
29-
@try_manual
30-
def step_list(test, rg, rg_2, checks=None):
21+
def step_list(test, rg, checks=None):
3122
if checks is None:
3223
checks = []
3324
test.cmd('az healthbot list '
@@ -36,18 +27,15 @@ def step_list(test, rg, rg_2, checks=None):
3627

3728

3829
# EXAMPLE: /Bots/get/List Bots by Subscription
39-
@try_manual
40-
def step_list2(test, rg, rg_2, checks=None):
30+
def step_list2(test, rg, checks=None):
4131
if checks is None:
4232
checks = []
43-
test.cmd('az healthbot list '
44-
'-g ""',
33+
test.cmd('az healthbot list',
4534
checks=checks)
4635

4736

4837
# EXAMPLE: /Bots/get/ResourceInfoGet
49-
@try_manual
50-
def step_show(test, rg, rg_2, checks=None):
38+
def step_show(test, rg, checks=None):
5139
if checks is None:
5240
checks = []
5341
test.cmd('az healthbot show '
@@ -57,23 +45,97 @@ def step_show(test, rg, rg_2, checks=None):
5745

5846

5947
# EXAMPLE: /Bots/patch/BotUpdate
60-
@try_manual
61-
def step_update(test, rg, rg_2, checks=None):
48+
def step_update_with_sku(test, rg, sku, checks=None):
49+
if checks is None:
50+
checks = []
51+
test.cmd(f'az healthbot update '
52+
f'--name "{{myBot}}" '
53+
f'--sku "{sku}" '
54+
f'--resource-group "{{rg}}"',
55+
checks=checks)
56+
57+
58+
# EXAMPLE: /Bots/delete/BotDelete
59+
def step_delete(test, rg, checks=None):
60+
if checks is None:
61+
checks = []
62+
test.cmd('az healthbot delete -y '
63+
'--name "{myBot}" '
64+
'--resource-group "{rg}"',
65+
checks=checks)
66+
67+
68+
# Boundary value: update with tags only, no --sku (sku=None)
69+
def step_update_tags_only(test, rg, checks=None):
6270
if checks is None:
6371
checks = []
6472
test.cmd('az healthbot update '
6573
'--name "{myBot}" '
74+
'--tags testkey=testvalue '
75+
'--resource-group "{rg}"',
76+
checks=checks)
77+
78+
79+
# Boundary value: update with empty tags (tags='')
80+
def step_update_empty_tags(test, rg, checks=None):
81+
if checks is None:
82+
checks = []
83+
test.cmd('az healthbot update '
84+
'--name "{myBot}" '
85+
'--tags '
86+
'--resource-group "{rg}"',
87+
checks=checks)
88+
89+
90+
# Boundary value: create with empty bot name (bot_name='')
91+
def step_create_empty_name(test, rg, checks=None):
92+
if checks is None:
93+
checks = []
94+
test.cmd('az healthbot create '
95+
'--name "" '
96+
'--location "eastus" '
6697
'--sku "F0" '
6798
'--resource-group "{rg}"',
99+
checks=checks,
100+
expect_failure=True)
101+
102+
103+
# Boundary value: create with tags
104+
def step_create_with_tags(test, rg, sku, checks=None):
105+
if checks is None:
106+
checks = []
107+
test.cmd(f'az healthbot create '
108+
f'--name "{{myBot}}" '
109+
f'--location "eastus" '
110+
f'--sku "{sku}" '
111+
f'--tags env=test '
112+
f'--resource-group "{{rg}}"',
68113
checks=checks)
69114

70115

71-
# EXAMPLE: /Bots/delete/BotDelete
72-
@try_manual
73-
def step_delete(test, rg, rg_2, checks=None):
116+
# Boundary value: list with empty resource group (boundary: empty string)
117+
def step_list_empty_rg(test, rg, checks=None):
118+
if checks is None:
119+
checks = []
120+
test.cmd('az healthbot list '
121+
'-g ""',
122+
checks=checks)
123+
124+
125+
# Wait for provisioning to complete
126+
def step_wait_for_provisioned(test, rg):
127+
test.cmd('az healthbot wait '
128+
'--name "{myBot}" '
129+
'--resource-group "{rg}" '
130+
'--updated')
131+
132+
133+
# Boundary value: delete with --no-wait (no_wait=True)
134+
def step_delete_no_wait(test, rg, checks=None):
74135
if checks is None:
75136
checks = []
76137
test.cmd('az healthbot delete -y '
77138
'--name "{myBot}" '
78-
'--resource-group "{rg}"',
139+
'--resource-group "{rg}" '
140+
'--no-wait',
79141
checks=checks)

0 commit comments

Comments
 (0)