Skip to content

Commit fa9101a

Browse files
authored
Added new Managemant clinet function which calls (#119)
Added new Managemant client function which calls WebSiteManagementClient Signed-off-by: Hemant <[email protected]>
1 parent e4e3256 commit fa9101a

File tree

9 files changed

+62
-29
lines changed

9 files changed

+62
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
## [Unreleased][]
44
[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-azure/compare/0.8.3...HEAD
55

6+
### Added
7+
8+
- Individual Azure managemnt clients for website and compute resources
9+
10+
### Removed
11+
12+
- Removed common init_client
13+
614
## [0.8.3][] - 2020-05-14
715

816
[0.8.3]: https://github.com/chaostoolkit-incubator/chaostoolkit-azure/compare/0.8.2...0.8.3

chaosazure/__init__.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import List
66

77
from azure.mgmt.compute import ComputeManagementClient
8+
from azure.mgmt.web import WebSiteManagementClient
89
from azure.mgmt.resourcegraph import ResourceGraphClient
910
from chaoslib.discovery import (discover_actions, discover_probes,
1011
initialize_discovery_result)
@@ -16,8 +17,8 @@
1617
from chaosazure.common.config import load_configuration, load_secrets
1718

1819
__all__ = [
19-
"discover", "__version__", "init_client",
20-
"init_resource_graph_client"
20+
"discover", "__version__", "init_compute_management_client",
21+
"init_website_management_client", "init_resource_graph_client"
2122
]
2223
__version__ = '0.8.3'
2324

@@ -34,10 +35,13 @@ def discover(discover_system: bool = True) -> Discovery:
3435
return discovery
3536

3637

37-
def init_client(
38+
def init_compute_management_client(
3839
experiment_secrets: Secrets,
3940
experiment_configuration: Configuration) -> ComputeManagementClient:
40-
41+
"""
42+
Initializes Compute management client for virtual machine,
43+
and virtual machine scale sets resources under Azure Resource manager.
44+
"""
4145
secrets = load_secrets(experiment_secrets)
4246
configuration = load_configuration(experiment_configuration)
4347
with auth(secrets) as authentication:
@@ -50,9 +54,30 @@ def init_client(
5054
return client
5155

5256

57+
def init_website_management_client(
58+
experiment_secrets: Secrets,
59+
experiment_configuration: Configuration) -> WebSiteManagementClient:
60+
"""
61+
Initializes Website management client for webapp resource under Azure
62+
Resource manager.
63+
"""
64+
secrets = load_secrets(experiment_secrets)
65+
configuration = load_configuration(experiment_configuration)
66+
with auth(secrets) as authentication:
67+
base_url = secrets.get('cloud').endpoints.resource_manager
68+
client = WebSiteManagementClient(
69+
credentials=authentication,
70+
subscription_id=configuration.get('subscription_id'),
71+
base_url=base_url)
72+
73+
return client
74+
75+
5376
def init_resource_graph_client(
5477
experiment_secrets: Secrets) -> ResourceGraphClient:
55-
78+
"""
79+
Initializes Resource Graph client.
80+
"""
5681
secrets = load_secrets(experiment_secrets)
5782
with auth(secrets) as authentication:
5883
base_url = secrets.get('cloud').endpoints.resource_manager

chaosazure/common/compute/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from chaoslib.exceptions import FailedActivity, InterruptExecution
44
from logzero import logger
55

6-
from chaosazure import init_client
6+
from chaosazure import init_compute_management_client
77
from chaosazure.machine.constants import OS_LINUX, OS_WINDOWS, RES_TYPE_VM
88
from chaosazure.vmss.constants import RES_TYPE_VMSS_VM
99

@@ -41,7 +41,7 @@ def prepare(compute: dict, script: str):
4141

4242
def run(resource_group: str, compute: dict, timeout: int, parameters: dict,
4343
secrets, configuration):
44-
client = init_client(secrets, configuration)
44+
client = init_compute_management_client(secrets, configuration)
4545

4646
compute_type = compute.get('type').lower()
4747
if compute_type == RES_TYPE_VMSS_VM.lower():

chaosazure/machine/actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from chaoslib.types import Configuration, Secrets
55
from logzero import logger
66

7-
from chaosazure import init_client
7+
from chaosazure import init_compute_management_client
88
from chaosazure.common import cleanse
99
from chaosazure.common.compute import command
1010
from chaosazure.machine.constants import RES_TYPE_VM
@@ -521,4 +521,4 @@ def __fetch_machines(filter, configuration, secrets) -> []:
521521

522522

523523
def __compute_mgmt_client(secrets, configuration):
524-
return init_client(secrets, configuration)
524+
return init_compute_management_client(secrets, configuration)

chaosazure/vmss/actions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from chaoslib import Configuration, Secrets
44
from logzero import logger
55

6-
from chaosazure import init_client
6+
from chaosazure import init_compute_management_client
77
from chaosazure.common import cleanse
88
from chaosazure.common.compute import command
99
from chaosazure.vmss.fetcher import fetch_vmss, fetch_instances
@@ -48,7 +48,7 @@ def delete_vmss(filter: str = None,
4848
for instance in instances:
4949
logger.debug(
5050
"Deleting instance: {}".format(instance['name']))
51-
client = init_client(secrets, configuration)
51+
client = init_compute_management_client(secrets, configuration)
5252
client.virtual_machine_scale_set_vms.delete(
5353
scale_set['resourceGroup'],
5454
scale_set['name'],
@@ -90,7 +90,7 @@ def restart_vmss(filter: str = None,
9090
for instance in instances:
9191
logger.debug(
9292
"Restarting instance: {}".format(instance['name']))
93-
client = init_client(secrets, configuration)
93+
client = init_compute_management_client(secrets, configuration)
9494
client.virtual_machine_scale_set_vms.restart(
9595
scale_set['resourceGroup'],
9696
scale_set['name'],
@@ -154,7 +154,7 @@ def stop_vmss(filter: str = None,
154154
for instance in instances:
155155
logger.debug(
156156
"Stopping instance: {}".format(instance['name']))
157-
client = init_client(secrets, configuration)
157+
client = init_compute_management_client(secrets, configuration)
158158
client.virtual_machine_scale_set_vms.power_off(
159159
scale_set['resourceGroup'],
160160
scale_set['name'],
@@ -196,7 +196,7 @@ def deallocate_vmss(filter: str = None,
196196
for instance in instances:
197197
logger.debug(
198198
"Deallocating instance: {}".format(instance['name']))
199-
client = init_client(secrets, configuration)
199+
client = init_compute_management_client(secrets, configuration)
200200
client.virtual_machine_scale_set_vms.deallocate(
201201
scale_set['resourceGroup'],
202202
scale_set['name'],

chaosazure/vmss/fetcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from chaoslib.exceptions import FailedActivity
66
from logzero import logger
77

8-
from chaosazure import init_client
8+
from chaosazure import init_compute_management_client
99
from chaosazure.common.resources.graph import fetch_resources
1010
from chaosazure.vmss.constants import RES_TYPE_VMSS
1111

@@ -62,7 +62,7 @@ def fetch_vmss(filter, configuration, secrets) -> List[dict]:
6262
#############################################################################
6363
def __fetch_vmss_instances(choice, configuration, secrets) -> List[Dict]:
6464
vmss_instances = []
65-
client = init_client(secrets, configuration)
65+
client = init_compute_management_client(secrets, configuration)
6666
pages = client.virtual_machine_scale_set_vms.list(
6767
choice['resourceGroup'], choice['name'])
6868
first_page = pages.advance_page()

chaosazure/webapp/actions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from chaoslib.exceptions import FailedActivity
55
from logzero import logger
66

7-
from chaosazure import init_client
7+
from chaosazure import init_website_management_client
88
from chaosazure.common.resources.graph import fetch_resources
99
from chaosazure.webapp.constants import RES_TYPE_WEBAPP
1010

@@ -33,7 +33,7 @@ def stop_webapp(filter: str = None,
3333
choice = __fetch_webapp_at_random(filter, configuration, secrets)
3434

3535
logger.debug("Stopping web app: {}".format(choice['name']))
36-
client = init_client(secrets, configuration)
36+
client = init_website_management_client(secrets, configuration)
3737
client.web_apps.stop(choice['resourceGroup'], choice['name'])
3838

3939

@@ -58,7 +58,7 @@ def restart_webapp(filter: str = None,
5858
choice = __fetch_webapp_at_random(filter, configuration, secrets)
5959

6060
logger.debug("Restarting web app: {}".format(choice['name']))
61-
client = init_client(secrets, configuration)
61+
client = init_website_management_client(secrets, configuration)
6262
client.web_apps.restart(choice['resourceGroup'], choice['name'])
6363

6464

@@ -83,7 +83,7 @@ def start_webapp(filter: str = None,
8383
choice = __fetch_webapp_at_random(filter, configuration, secrets)
8484

8585
logger.debug("Starting web app: {}".format(choice['name']))
86-
client = init_client(secrets, configuration)
86+
client = init_website_management_client(secrets, configuration)
8787
client.web_apps.start(choice['resourceGroup'], choice['name'])
8888

8989

@@ -111,7 +111,7 @@ def delete_webapp(filter: str = None,
111111
choice = __fetch_webapp_at_random(filter, configuration, secrets)
112112

113113
logger.debug("Deleting web app: {}".format(choice['name']))
114-
client = init_client(secrets, configuration)
114+
client = init_website_management_client(secrets, configuration)
115115
client.web_apps.delete(choice['resourceGroup'], choice['name'])
116116

117117

tests/vmss/test_vmss_actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@patch('chaosazure.vmss.actions.fetch_vmss', autospec=True)
1010
@patch('chaosazure.vmss.actions.fetch_instances', autospec=True)
11-
@patch('chaosazure.vmss.actions.init_client', autospec=True)
11+
@patch('chaosazure.vmss.actions.init_compute_management_client', autospec=True)
1212
def test_deallocate_vmss(client, fetch_instances, fetch_vmss):
1313
scale_set = vmss_provider.provide_scale_set()
1414
scale_sets = [scale_set]
@@ -25,7 +25,7 @@ def test_deallocate_vmss(client, fetch_instances, fetch_vmss):
2525

2626
@patch('chaosazure.vmss.actions.fetch_vmss', autospec=True)
2727
@patch('chaosazure.vmss.actions.fetch_instances', autospec=True)
28-
@patch('chaosazure.vmss.actions.init_client', autospec=True)
28+
@patch('chaosazure.vmss.actions.init_compute_management_client', autospec=True)
2929
def test_stop_vmss(client, fetch_instances, fetch_vmss):
3030
scale_set = vmss_provider.provide_scale_set()
3131
scale_sets = [scale_set]
@@ -41,7 +41,7 @@ def test_stop_vmss(client, fetch_instances, fetch_vmss):
4141

4242
@patch('chaosazure.vmss.actions.fetch_vmss', autospec=True)
4343
@patch('chaosazure.vmss.actions.fetch_instances', autospec=True)
44-
@patch('chaosazure.vmss.actions.init_client', autospec=True)
44+
@patch('chaosazure.vmss.actions.init_compute_management_client', autospec=True)
4545
def test_restart_vmss(client, fetch_instances, fetch_vmss):
4646
scale_set = vmss_provider.provide_scale_set()
4747
scale_sets = [scale_set]
@@ -57,7 +57,7 @@ def test_restart_vmss(client, fetch_instances, fetch_vmss):
5757

5858
@patch('chaosazure.vmss.actions.fetch_vmss', autospec=True)
5959
@patch('chaosazure.vmss.actions.fetch_instances', autospec=True)
60-
@patch('chaosazure.vmss.actions.init_client', autospec=True)
60+
@patch('chaosazure.vmss.actions.init_compute_management_client', autospec=True)
6161
def test_delete_vmss(client, fetch_instances, fetch_vmss):
6262
scale_set = vmss_provider.provide_scale_set()
6363
scale_sets = [scale_set]

tests/webapp/test_webapp_actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
@patch('chaosazure.webapp.actions.fetch_webapps', autospec=True)
24-
@patch('chaosazure.webapp.actions.init_client', autospec=True)
24+
@patch('chaosazure.webapp.actions.init_website_management_client', autospec=True)
2525
def test_stop_webapp(init, fetch):
2626
client = MagicMock()
2727
init.return_value = client
@@ -37,7 +37,7 @@ def test_stop_webapp(init, fetch):
3737

3838

3939
@patch('chaosazure.webapp.actions.fetch_webapps', autospec=True)
40-
@patch('chaosazure.webapp.actions.init_client', autospec=True)
40+
@patch('chaosazure.webapp.actions.init_website_management_client', autospec=True)
4141
def test_restart_webapp(init, fetch):
4242
client = MagicMock()
4343
init.return_value = client
@@ -53,7 +53,7 @@ def test_restart_webapp(init, fetch):
5353

5454

5555
@patch('chaosazure.webapp.actions.fetch_webapps', autospec=True)
56-
@patch('chaosazure.webapp.actions.init_client', autospec=True)
56+
@patch('chaosazure.webapp.actions.init_website_management_client', autospec=True)
5757
def test_start_webapp(init, fetch):
5858
client = MagicMock()
5959
init.return_value = client
@@ -69,7 +69,7 @@ def test_start_webapp(init, fetch):
6969

7070

7171
@patch('chaosazure.webapp.actions.fetch_webapps', autospec=True)
72-
@patch('chaosazure.webapp.actions.init_client', autospec=True)
72+
@patch('chaosazure.webapp.actions.init_website_management_client', autospec=True)
7373
def test_delete_webapp(init, fetch):
7474
client = MagicMock()
7575
init.return_value = client

0 commit comments

Comments
 (0)