Skip to content

Commit 6fa1cde

Browse files
authored
{AKS} Fix azdev style issues for decorators (#7123)
* fix for decorators * fix
1 parent a0b8a52 commit 6fa1cde

File tree

5 files changed

+709
-383
lines changed

5 files changed

+709
-383
lines changed

src/aks-preview/azext_aks_preview/addonconfiguration.py

Lines changed: 115 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
import json
76
from knack.log import get_logger
87
from knack.util import CLIError
98
from azure.cli.core.azclierror import ArgumentUsageError
@@ -42,29 +41,32 @@
4241
logger = get_logger(__name__)
4342

4443

45-
def enable_addons(cmd,
46-
client,
47-
resource_group_name,
48-
name,
49-
addons,
50-
check_enabled=True,
51-
workspace_resource_id=None,
52-
subnet_name=None,
53-
appgw_name=None,
54-
appgw_subnet_prefix=None,
55-
appgw_subnet_cidr=None,
56-
appgw_id=None,
57-
appgw_subnet_id=None,
58-
appgw_watch_namespace=None,
59-
enable_sgxquotehelper=False,
60-
enable_secret_rotation=False,
61-
rotation_poll_interval=None,
62-
no_wait=False,
63-
dns_zone_resource_id=None,
64-
dns_zone_resource_ids=None,
65-
enable_msi_auth_for_monitoring=True,
66-
enable_syslog=False,
67-
data_collection_settings=None):
44+
# pylint: disable=too-many-locals
45+
def enable_addons(
46+
cmd,
47+
client,
48+
resource_group_name,
49+
name,
50+
addons,
51+
check_enabled=True,
52+
workspace_resource_id=None,
53+
subnet_name=None,
54+
appgw_name=None,
55+
appgw_subnet_prefix=None,
56+
appgw_subnet_cidr=None,
57+
appgw_id=None,
58+
appgw_subnet_id=None,
59+
appgw_watch_namespace=None,
60+
enable_sgxquotehelper=False,
61+
enable_secret_rotation=False,
62+
rotation_poll_interval=None,
63+
no_wait=False,
64+
dns_zone_resource_id=None,
65+
dns_zone_resource_ids=None,
66+
enable_msi_auth_for_monitoring=True,
67+
enable_syslog=False,
68+
data_collection_settings=None
69+
):
6870
instance = client.get(resource_group_name, name)
6971
# this is overwritten by _update_addons(), so the value needs to be recorded here
7072
msi_auth = False
@@ -74,18 +76,33 @@ def enable_addons(cmd,
7476
enable_msi_auth_for_monitoring = False
7577

7678
subscription_id = get_subscription_id(cmd.cli_ctx)
77-
instance = update_addons(cmd, instance, subscription_id, resource_group_name, name, addons, enable=True,
78-
check_enabled=check_enabled,
79-
workspace_resource_id=workspace_resource_id,
80-
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring, subnet_name=subnet_name,
81-
appgw_name=appgw_name, appgw_subnet_prefix=appgw_subnet_prefix,
82-
appgw_subnet_cidr=appgw_subnet_cidr, appgw_id=appgw_id, appgw_subnet_id=appgw_subnet_id,
83-
appgw_watch_namespace=appgw_watch_namespace,
84-
enable_sgxquotehelper=enable_sgxquotehelper,
85-
enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait,
86-
dns_zone_resource_id=dns_zone_resource_id, dns_zone_resource_ids=dns_zone_resource_ids,
87-
enable_syslog=enable_syslog,
88-
data_collection_settings=data_collection_settings)
79+
instance = update_addons(
80+
cmd,
81+
instance,
82+
subscription_id,
83+
resource_group_name,
84+
name,
85+
addons,
86+
enable=True,
87+
check_enabled=check_enabled,
88+
workspace_resource_id=workspace_resource_id,
89+
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring,
90+
subnet_name=subnet_name,
91+
appgw_name=appgw_name,
92+
appgw_subnet_prefix=appgw_subnet_prefix,
93+
appgw_subnet_cidr=appgw_subnet_cidr,
94+
appgw_id=appgw_id,
95+
appgw_subnet_id=appgw_subnet_id,
96+
appgw_watch_namespace=appgw_watch_namespace,
97+
enable_sgxquotehelper=enable_sgxquotehelper,
98+
enable_secret_rotation=enable_secret_rotation,
99+
rotation_poll_interval=rotation_poll_interval,
100+
no_wait=no_wait,
101+
dns_zone_resource_id=dns_zone_resource_id,
102+
dns_zone_resource_ids=dns_zone_resource_ids,
103+
enable_syslog=enable_syslog,
104+
data_collection_settings=data_collection_settings,
105+
)
89106

90107
if CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
91108
CONST_MONITORING_ADDON_NAME].enabled:
@@ -95,21 +112,20 @@ def enable_addons(cmd,
95112
if not msi_auth:
96113
raise ArgumentUsageError(
97114
"--enable-msi-auth-for-monitoring can not be used on clusters with service principal auth.")
98-
else:
99-
# create a Data Collection Rule (DCR) and associate it with the cluster
100-
ensure_container_insights_for_monitoring(
101-
cmd,
102-
instance.addon_profiles[CONST_MONITORING_ADDON_NAME],
103-
subscription_id,
104-
resource_group_name,
105-
name,
106-
instance.location,
107-
aad_route=True,
108-
create_dcr=True,
109-
create_dcra=True,
110-
enable_syslog=enable_syslog,
111-
data_collection_settings=data_collection_settings
112-
)
115+
# create a Data Collection Rule (DCR) and associate it with the cluster
116+
ensure_container_insights_for_monitoring(
117+
cmd,
118+
instance.addon_profiles[CONST_MONITORING_ADDON_NAME],
119+
subscription_id,
120+
resource_group_name,
121+
name,
122+
instance.location,
123+
aad_route=True,
124+
create_dcr=True,
125+
create_dcra=True,
126+
enable_syslog=enable_syslog,
127+
data_collection_settings=data_collection_settings
128+
)
113129
else:
114130
# monitoring addon will use legacy path
115131
if enable_syslog:
@@ -163,31 +179,34 @@ def enable_addons(cmd,
163179
return result
164180

165181

166-
def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
167-
instance,
168-
subscription_id,
169-
resource_group_name,
170-
name,
171-
addons,
172-
enable,
173-
check_enabled=True,
174-
workspace_resource_id=None,
175-
enable_msi_auth_for_monitoring=True,
176-
subnet_name=None,
177-
appgw_name=None,
178-
appgw_subnet_prefix=None,
179-
appgw_subnet_cidr=None,
180-
appgw_id=None,
181-
appgw_subnet_id=None,
182-
appgw_watch_namespace=None,
183-
enable_sgxquotehelper=False,
184-
enable_secret_rotation=False,
185-
rotation_poll_interval=None,
186-
dns_zone_resource_id=None,
187-
dns_zone_resource_ids=None,
188-
no_wait=False, # pylint: disable=unused-argument
189-
enable_syslog=False,
190-
data_collection_settings=None):
182+
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
183+
def update_addons(
184+
cmd,
185+
instance,
186+
subscription_id,
187+
resource_group_name,
188+
name,
189+
addons,
190+
enable,
191+
check_enabled=True,
192+
workspace_resource_id=None,
193+
enable_msi_auth_for_monitoring=True,
194+
subnet_name=None,
195+
appgw_name=None,
196+
appgw_subnet_prefix=None,
197+
appgw_subnet_cidr=None,
198+
appgw_id=None,
199+
appgw_subnet_id=None,
200+
appgw_watch_namespace=None,
201+
enable_sgxquotehelper=False,
202+
enable_secret_rotation=False,
203+
rotation_poll_interval=None,
204+
dns_zone_resource_id=None,
205+
dns_zone_resource_ids=None,
206+
no_wait=False, # pylint: disable=unused-argument
207+
enable_syslog=False, # pylint: disable=unused-argument
208+
data_collection_settings=None, # pylint: disable=unused-argument
209+
):
191210
# parse the comma-separated addons argument
192211
addon_args = addons.split(',')
193212

@@ -242,7 +261,7 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
242261
continue
243262

244263
if addon_arg not in ADDONS:
245-
raise CLIError("Invalid addon name: {}.".format(addon_arg))
264+
raise CLIError(f"Invalid addon name: {addon_arg}.")
246265
addon = ADDONS[addon_arg]
247266
if addon == CONST_VIRTUAL_NODE_ADDON_NAME:
248267
# only linux is supported for now, in the future this will be a user flag
@@ -274,13 +293,22 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
274293

275294
cloud_name = cmd.cli_ctx.cloud.name
276295
if enable_msi_auth_for_monitoring and (cloud_name.lower() == 'ussec' or cloud_name.lower() == 'usnat'):
277-
if instance.identity is not None and instance.identity.type is not None and instance.identity.type == "userassigned":
278-
logger.warning("--enable_msi_auth_for_monitoring is not supported in %s cloud and continuing monitoring enablement without this flag.", cloud_name)
296+
if (
297+
instance.identity is not None and
298+
instance.identity.type is not None and
299+
instance.identity.type == "userassigned"
300+
):
301+
logger.warning(
302+
"--enable_msi_auth_for_monitoring is not supported in %s cloud and continuing "
303+
"monitoring enablement without this flag.", cloud_name
304+
)
279305
enable_msi_auth_for_monitoring = False
280306

281307
addon_profile.config = {
282308
logAnalyticsConstName: workspace_resource_id}
283-
addon_profile.config[CONST_MONITORING_USING_AAD_MSI_AUTH] = "true" if enable_msi_auth_for_monitoring else "false"
309+
addon_profile.config[CONST_MONITORING_USING_AAD_MSI_AUTH] = (
310+
"true" if enable_msi_auth_for_monitoring else "false"
311+
)
284312
elif addon == (CONST_VIRTUAL_NODE_ADDON_NAME + os_type):
285313
if addon_profile.enabled and check_enabled:
286314
raise CLIError('The virtual-node addon is already enabled for this managed cluster.\n'
@@ -333,10 +361,11 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
333361
elif addon == CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME:
334362
if addon_profile.enabled and check_enabled:
335363
raise CLIError(
336-
'The azure-keyvault-secrets-provider addon is already enabled for this managed cluster.\n'
337-
'To change azure-keyvault-secrets-provider configuration, run '
338-
f'"az aks disable-addons -a azure-keyvault-secrets-provider -n {name} -g {resource_group_name}" '
339-
'before enabling it again.')
364+
"The azure-keyvault-secrets-provider addon is already enabled for this managed cluster.\n"
365+
"To change azure-keyvault-secrets-provider configuration, run "
366+
'"az aks disable-addons -a azure-keyvault-secrets-provider '
367+
f'-n {name} -g {resource_group_name}" before enabling it again.'
368+
)
340369
addon_profile = ManagedClusterAddonProfile(
341370
enabled=True, config={CONST_SECRET_ROTATION_ENABLED: "false", CONST_ROTATION_POLL_INTERVAL: "2m"})
342371
if enable_secret_rotation:
@@ -352,7 +381,8 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
352381
enabled=False)
353382
else:
354383
raise CLIError(
355-
"The addon {} is not installed.".format(addon))
384+
f"The addon {addon} is not installed."
385+
)
356386
addon_profiles[addon].config = None
357387
addon_profiles[addon].enabled = enable
358388

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
CONST_VIRTUAL_MACHINE_SCALE_SETS,
3333
CONST_AVAILABILITY_SET,
3434
CONST_VIRTUAL_MACHINES,
35-
CONST_OS_SKU_UBUNTU,
3635
)
37-
from azext_aks_preview._params import node_os_skus_update
3836
from azext_aks_preview._helpers import get_nodepool_snapshot_by_snapshot_id
3937

4038
logger = get_logger(__name__)
@@ -98,7 +96,9 @@ def get_vm_set_type(self) -> str:
9896
elif vm_set_type.lower() == CONST_VIRTUAL_MACHINES.lower():
9997
vm_set_type = CONST_VIRTUAL_MACHINES
10098
else:
101-
raise InvalidArgumentValueError("--vm-set-type can only be VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(Preview)")
99+
raise InvalidArgumentValueError(
100+
"--vm-set-type can only be VirtualMachineScaleSets, AvailabilitySet or VirtualMachines(Preview)"
101+
)
102102
# this parameter does not need validation
103103
return vm_set_type
104104

@@ -132,9 +132,7 @@ def get_message_of_the_day(self) -> Union[str, None]:
132132
if message_of_the_day_file_path:
133133
if not os.path.isfile(message_of_the_day_file_path):
134134
raise InvalidArgumentValueError(
135-
"{} is not valid file, or not accessable.".format(
136-
message_of_the_day_file_path
137-
)
135+
f"{message_of_the_day_file_path} is not valid file, or not accessable."
138136
)
139137
message_of_the_day = read_file_content(
140138
message_of_the_day_file_path)
@@ -507,7 +505,7 @@ def set_up_agentpool_windows_profile(self, agentpool: AgentPool) -> AgentPool:
507505

508506
# Construct AgentPoolWindowsProfile if one of the fields has been set
509507
if disable_windows_outbound_nat:
510-
agentpool.windows_profile = self.models.AgentPoolWindowsProfile(
508+
agentpool.windows_profile = self.models.AgentPoolWindowsProfile( # pylint: disable=no-member
511509
disable_outbound_nat=disable_windows_outbound_nat
512510
)
513511

@@ -518,7 +516,7 @@ def set_up_agentpool_network_profile(self, agentpool: AgentPool) -> AgentPool:
518516

519517
asg_ids = self.context.get_asg_ids()
520518
allowed_host_ports = self.context.get_allowed_host_ports()
521-
agentpool.network_profile = self.models.AgentPoolNetworkProfile()
519+
agentpool.network_profile = self.models.AgentPoolNetworkProfile() # pylint: disable=no-member
522520
if allowed_host_ports is not None:
523521
agentpool.network_profile.allowed_host_ports = allowed_host_ports
524522
agentpool.network_profile.application_security_groups = asg_ids
@@ -544,7 +542,9 @@ def set_up_artifact_streaming(self, agentpool: AgentPool) -> AgentPool:
544542

545543
if self.context.get_enable_artifact_streaming():
546544
if agentpool.artifact_streaming_profile is None:
547-
agentpool.artifact_streaming_profile = self.models.AgentPoolArtifactStreamingProfile()
545+
agentpool.artifact_streaming_profile = (
546+
self.models.AgentPoolArtifactStreamingProfile() # pylint: disable=no-member
547+
)
548548
agentpool.artifact_streaming_profile.enabled = True
549549
return agentpool
550550

@@ -584,7 +584,7 @@ def set_up_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
584584
"""
585585
self._ensure_agentpool(agentpool)
586586

587-
upgrade_settings = self.models.AgentPoolUpgradeSettings()
587+
upgrade_settings = self.models.AgentPoolUpgradeSettings() # pylint: disable=no-member
588588
max_surge = self.context.get_max_surge()
589589
if max_surge:
590590
upgrade_settings.max_surge = max_surge
@@ -654,7 +654,7 @@ def update_network_profile(self, agentpool: AgentPool) -> AgentPool:
654654
asg_ids = self.context.get_asg_ids()
655655
allowed_host_ports = self.context.get_allowed_host_ports()
656656
if not agentpool.network_profile and (asg_ids or allowed_host_ports):
657-
agentpool.network_profile = self.models.AgentPoolNetworkProfile()
657+
agentpool.network_profile = self.models.AgentPoolNetworkProfile() # pylint: disable=no-member
658658
if asg_ids is not None:
659659
agentpool.network_profile.application_security_groups = asg_ids
660660
if allowed_host_ports is not None:
@@ -669,7 +669,7 @@ def update_artifact_streaming(self, agentpool: AgentPool) -> AgentPool:
669669

670670
if self.context.get_enable_artifact_streaming():
671671
if agentpool.artifact_streaming_profile is None:
672-
agentpool.artifact_streaming_profile = self.models.AgentPoolArtifactStreamingProfile()
672+
agentpool.artifact_streaming_profile = self.models.AgentPoolArtifactStreamingProfile() # pylint: disable=no-member
673673
agentpool.artifact_streaming_profile.enabled = True
674674
return agentpool
675675

@@ -714,7 +714,7 @@ def update_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
714714

715715
upgrade_settings = agentpool.upgrade_settings
716716
if upgrade_settings is None:
717-
upgrade_settings = self.models.AgentPoolUpgradeSettings()
717+
upgrade_settings = self.models.AgentPoolUpgradeSettings() # pylint: disable=no-member
718718

719719
max_surge = self.context.get_max_surge()
720720
if max_surge:

0 commit comments

Comments
 (0)