Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit b34ba29

Browse files
Fix style issues
1 parent 2889d53 commit b34ba29

File tree

6 files changed

+39
-33
lines changed

6 files changed

+39
-33
lines changed

k8s-custom-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,4 @@ stages:
341341
displayName: "CLI Linter on Modified Extension"
342342
env:
343343
ADO_PULL_REQUEST_LATEST_COMMIT: $(System.PullRequest.SourceCommitId)
344-
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
344+
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)

src/k8s-extension/azext_k8s_extension/custom.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import json
99
from knack.log import get_logger
1010

11-
from msrestazure.azure_exceptions import CloudError
12-
1311
from azure.cli.core.azclierror import ResourceNotFoundError, MutuallyExclusiveArgumentError, \
1412
InvalidArgumentValueError, CommandNotFoundError, RequiredArgumentMissingError
1513
from azure.cli.core.commands.client_factory import get_subscription_id

src/k8s-extension/azext_k8s_extension/partner_extensions/AzureMLKubernetes.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# --------------------------------------------------------------------------------------------
55

66
# pylint: disable=unused-argument
7+
# pylint: disable=line-too-long
8+
# pylint: disable=too-many-locals
9+
710
import copy
811
from hashlib import md5
912
from typing import Any, Dict, List, Tuple
@@ -17,8 +20,6 @@
1720
import azure.mgmt.storage.models
1821
import azure.mgmt.loganalytics
1922
import azure.mgmt.loganalytics.models
20-
from ..vendored_sdks.models import (
21-
ExtensionInstance, ExtensionInstanceUpdate, Scope, ScopeCluster)
2223
from azure.cli.core.azclierror import InvalidArgumentValueError
2324
from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id
2425
from azure.mgmt.resource.locks.models import ManagementLockObject
@@ -27,12 +28,19 @@
2728

2829
from .._client_factory import cf_resources
2930
from .PartnerExtensionModel import PartnerExtensionModel
31+
from ..vendored_sdks.models import (
32+
ExtensionInstance,
33+
ExtensionInstanceUpdate,
34+
Scope,
35+
ScopeCluster
36+
)
3037

3138
logger = get_logger(__name__)
3239

3340
resource_tag = {'created_by': 'Azure Arc-enabled ML'}
3441

3542

43+
# pylint: disable=too-many-instance-attributes
3644
class AzureMLKubernetes(PartnerExtensionModel):
3745
def __init__(self):
3846
# constants for configuration settings.
@@ -157,7 +165,7 @@ def __validate_config(self, configuration_settings, configuration_protected_sett
157165
config_keys = configuration_settings.keys()
158166
config_protected_keys = configuration_protected_settings.keys()
159167
dup_keys = set(config_keys) & set(config_protected_keys)
160-
if len(dup_keys) > 0:
168+
if dup_keys:
161169
for key in dup_keys:
162170
logger.warning(
163171
'Duplicate keys found in both configuration settings and configuration protected setttings: %s', key)
@@ -250,9 +258,8 @@ def __create_required_resource(
250258
configuration_settings[self.AZURE_LOG_ANALYTICS_CUSTOMER_ID_KEY] = ws_costumer_id
251259
configuration_protected_settings[self.AZURE_LOG_ANALYTICS_CONNECTION_STRING] = shared_key
252260

253-
if not configuration_settings.get(
254-
self.RELAY_SERVER_CONNECTION_STRING) and not configuration_protected_settings.get(
255-
self.RELAY_SERVER_CONNECTION_STRING):
261+
if not configuration_settings.get(self.RELAY_SERVER_CONNECTION_STRING) and \
262+
not configuration_protected_settings.get(self.RELAY_SERVER_CONNECTION_STRING):
256263
logger.info('==== BEGIN RELAY CREATION ====')
257264
relay_connection_string, hc_resource_id, hc_name = _get_relay_connection_str(
258265
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, self.RELAY_HC_AUTH_NAME)
@@ -261,9 +268,8 @@ def __create_required_resource(
261268
configuration_settings[self.HC_RESOURCE_ID_KEY] = hc_resource_id
262269
configuration_settings[self.RELAY_HC_NAME_KEY] = hc_name
263270

264-
if not configuration_settings.get(
265-
self.SERVICE_BUS_CONNECTION_STRING) and not configuration_protected_settings.get(
266-
self.SERVICE_BUS_CONNECTION_STRING):
271+
if not configuration_settings.get(self.SERVICE_BUS_CONNECTION_STRING) and \
272+
not configuration_protected_settings.get(self.SERVICE_BUS_CONNECTION_STRING):
267273
logger.info('==== BEGIN SERVICE BUS CREATION ====')
268274
topic_sub_mapping = {
269275
self.SERVICE_BUS_COMPUTE_STATE_TOPIC: self.SERVICE_BUS_COMPUTE_STATE_SUB,
@@ -280,7 +286,7 @@ def __create_required_resource(
280286

281287
def _get_valid_name(input_name: str, suffix_len: int, max_len: int) -> str:
282288
normalized_str = ''.join(filter(str.isalnum, input_name))
283-
assert len(normalized_str) > 0, "normalized name empty"
289+
assert normalized_str, "normalized name empty"
284290

285291
if len(normalized_str) <= max_len:
286292
return normalized_str
@@ -295,6 +301,7 @@ def _get_valid_name(input_name: str, suffix_len: int, max_len: int) -> str:
295301
return new_name
296302

297303

304+
# pylint: disable=broad-except
298305
def _lock_resource(cmd, lock_scope, lock_level='CanNotDelete'):
299306
lock_client: azure.mgmt.resource.locks.ManagementLockClient = get_mgmt_service_client(
300307
cmd.cli_ctx, azure.mgmt.resource.locks.ManagementLockClient)
@@ -303,14 +310,13 @@ def _lock_resource(cmd, lock_scope, lock_level='CanNotDelete'):
303310
try:
304311
lock_client.management_locks.create_or_update_by_scope(
305312
scope=lock_scope, lock_name='amlarc-resource-lock', parameters=lock_object)
306-
except:
313+
except Exception:
307314
# try to lock the resource if user has the owner privilege
308315
pass
309316

310317

311318
def _get_relay_connection_str(
312-
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, auth_rule_name) -> Tuple[
313-
str, str, str]:
319+
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, auth_rule_name) -> Tuple[str, str, str]:
314320
relay_client: azure.mgmt.relay.RelayManagementClient = get_mgmt_service_client(
315321
cmd.cli_ctx, azure.mgmt.relay.RelayManagementClient)
316322

@@ -398,8 +404,7 @@ def _get_service_bus_connection_string(cmd, subscription_id, resource_group_name
398404

399405

400406
def _get_log_analytics_ws_connection_string(
401-
cmd, subscription_id, resource_group_name, cluster_name, cluster_location) -> Tuple[
402-
str, str]:
407+
cmd, subscription_id, resource_group_name, cluster_name, cluster_location) -> Tuple[str, str]:
403408
log_analytics_ws_client: azure.mgmt.loganalytics.LogAnalyticsManagementClient = get_mgmt_service_client(
404409
cmd.cli_ctx, azure.mgmt.loganalytics.LogAnalyticsManagementClient)
405410

src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from azure.cli.core.commands import LongRunningOperation
1515
from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id
1616
from azure.cli.core.util import sdk_no_wait
17-
from msrestazure.azure_exceptions import CloudError
1817
from msrestazure.tools import parse_resource_id, is_valid_resource_id
1918

2019
from ..vendored_sdks.models import ExtensionInstance
@@ -104,8 +103,7 @@ def _invoke_deployment(cmd, resource_group_name, deployment_name, template, para
104103
if cmd.supported_api_version(min_api='2019-10-01', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES):
105104
validation_poller = smc.begin_validate(resource_group_name, deployment_name, deployment)
106105
return LongRunningOperation(cmd.cli_ctx)(validation_poller)
107-
else:
108-
return smc.validate(resource_group_name, deployment_name, deployment)
106+
return smc.validate(resource_group_name, deployment_name, deployment)
109107

110108
return sdk_no_wait(no_wait, smc.begin_create_or_update, resource_group_name, deployment_name, deployment)
111109

src/k8s-extension/azext_k8s_extension/tests/latest/test_azureml_extension.py

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

6+
# pylint: disable=protected-access
7+
68
import os
79
import unittest
810

@@ -13,7 +15,7 @@
1315

1416

1517
class TestAzureMlExtension(unittest.TestCase):
16-
18+
1719
def test_set_up_inference_ssl(self):
1820
azremlk8sInstance = AzureMLKubernetes()
1921
config = {'allowInsecureConnections': 'false'}
@@ -27,6 +29,6 @@ def test_set_up_inference_ssl(self):
2729
encoded_cert_and_key_file = os.path.join(TEST_DIR, 'data', 'azure_ml', 'cert_and_key_encoded.txt')
2830
with open(encoded_cert_and_key_file, "r") as text_file:
2931
cert = text_file.readline().rstrip()
30-
self.assertEquals(cert, protected_config['scoringFe.sslCert'])
32+
assert cert == protected_config['scoringFe.sslCert']
3133
key = text_file.readline()
32-
self.assertEquals(key, protected_config['scoringFe.sslKey'])
34+
assert key == protected_config['scoringFe.sslKey']

src/k8s-extension/azext_k8s_extension/tests/latest/test_k8s_extension_scenario.py

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

6-
import os
7-
import unittest
6+
# pylint: disable=line-too-long
87

8+
import os
99
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, record_only)
1010

1111

@@ -27,13 +27,16 @@ def test_k8s_extension(self):
2727
'version': '0.1.0'
2828
})
2929

30-
self.cmd('k8s-extension create -g {rg} -n {name} -c {cluster_name} --cluster-type {cluster_type} --extension-type {extension_type} --release-train {release_train} --version {version}', checks=[
31-
self.check('name', '{name}'),
32-
self.check('releaseTrain', '{release_train}'),
33-
self.check('version', '{version}'),
34-
self.check('resourceGroup', '{rg}'),
35-
self.check('extensionType', '{extension_type}')
36-
])
30+
self.cmd('k8s-extension create -g {rg} -n {name} -c {cluster_name} --cluster-type {cluster_type} '
31+
'--extension-type {extension_type} --release-train {release_train} --version {version}',
32+
checks=[
33+
self.check('name', '{name}'),
34+
self.check('releaseTrain', '{release_train}'),
35+
self.check('version', '{version}'),
36+
self.check('resourceGroup', '{rg}'),
37+
self.check('extensionType', '{extension_type}')
38+
]
39+
)
3740

3841
# Update is disabled for now
3942
# self.cmd('k8s-extension update -g {rg} -n {name} --tags foo=boo', checks=[

0 commit comments

Comments
 (0)