Skip to content

Commit

Permalink
Fix style issues (Azure#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Jun 4, 2021
1 parent 2889d53 commit 67babd8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion k8s-custom-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,4 @@ stages:
displayName: "CLI Linter on Modified Extension"
env:
ADO_PULL_REQUEST_LATEST_COMMIT: $(System.PullRequest.SourceCommitId)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
2 changes: 0 additions & 2 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import json
from knack.log import get_logger

from msrestazure.azure_exceptions import CloudError

from azure.cli.core.azclierror import ResourceNotFoundError, MutuallyExclusiveArgumentError, \
InvalidArgumentValueError, CommandNotFoundError, RequiredArgumentMissingError
from azure.cli.core.commands.client_factory import get_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument
# pylint: disable=line-too-long
# pylint: disable=too-many-locals

import copy
from hashlib import md5
from typing import Any, Dict, List, Tuple
Expand All @@ -17,8 +20,6 @@
import azure.mgmt.storage.models
import azure.mgmt.loganalytics
import azure.mgmt.loganalytics.models
from ..vendored_sdks.models import (
ExtensionInstance, ExtensionInstanceUpdate, Scope, ScopeCluster)
from azure.cli.core.azclierror import InvalidArgumentValueError
from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id
from azure.mgmt.resource.locks.models import ManagementLockObject
Expand All @@ -27,12 +28,19 @@

from .._client_factory import cf_resources
from .PartnerExtensionModel import PartnerExtensionModel
from ..vendored_sdks.models import (
ExtensionInstance,
ExtensionInstanceUpdate,
Scope,
ScopeCluster
)

logger = get_logger(__name__)

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


# pylint: disable=too-many-instance-attributes
class AzureMLKubernetes(PartnerExtensionModel):
def __init__(self):
# constants for configuration settings.
Expand Down Expand Up @@ -157,7 +165,7 @@ def __validate_config(self, configuration_settings, configuration_protected_sett
config_keys = configuration_settings.keys()
config_protected_keys = configuration_protected_settings.keys()
dup_keys = set(config_keys) & set(config_protected_keys)
if len(dup_keys) > 0:
if dup_keys:
for key in dup_keys:
logger.warning(
'Duplicate keys found in both configuration settings and configuration protected setttings: %s', key)
Expand Down Expand Up @@ -250,9 +258,8 @@ def __create_required_resource(
configuration_settings[self.AZURE_LOG_ANALYTICS_CUSTOMER_ID_KEY] = ws_costumer_id
configuration_protected_settings[self.AZURE_LOG_ANALYTICS_CONNECTION_STRING] = shared_key

if not configuration_settings.get(
self.RELAY_SERVER_CONNECTION_STRING) and not configuration_protected_settings.get(
self.RELAY_SERVER_CONNECTION_STRING):
if not configuration_settings.get(self.RELAY_SERVER_CONNECTION_STRING) and \
not configuration_protected_settings.get(self.RELAY_SERVER_CONNECTION_STRING):
logger.info('==== BEGIN RELAY CREATION ====')
relay_connection_string, hc_resource_id, hc_name = _get_relay_connection_str(
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, self.RELAY_HC_AUTH_NAME)
Expand All @@ -261,9 +268,8 @@ def __create_required_resource(
configuration_settings[self.HC_RESOURCE_ID_KEY] = hc_resource_id
configuration_settings[self.RELAY_HC_NAME_KEY] = hc_name

if not configuration_settings.get(
self.SERVICE_BUS_CONNECTION_STRING) and not configuration_protected_settings.get(
self.SERVICE_BUS_CONNECTION_STRING):
if not configuration_settings.get(self.SERVICE_BUS_CONNECTION_STRING) and \
not configuration_protected_settings.get(self.SERVICE_BUS_CONNECTION_STRING):
logger.info('==== BEGIN SERVICE BUS CREATION ====')
topic_sub_mapping = {
self.SERVICE_BUS_COMPUTE_STATE_TOPIC: self.SERVICE_BUS_COMPUTE_STATE_SUB,
Expand All @@ -280,7 +286,7 @@ def __create_required_resource(

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

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


# pylint: disable=broad-except
def _lock_resource(cmd, lock_scope, lock_level='CanNotDelete'):
lock_client: azure.mgmt.resource.locks.ManagementLockClient = get_mgmt_service_client(
cmd.cli_ctx, azure.mgmt.resource.locks.ManagementLockClient)
Expand All @@ -303,14 +310,13 @@ def _lock_resource(cmd, lock_scope, lock_level='CanNotDelete'):
try:
lock_client.management_locks.create_or_update_by_scope(
scope=lock_scope, lock_name='amlarc-resource-lock', parameters=lock_object)
except:
except Exception:
# try to lock the resource if user has the owner privilege
pass


def _get_relay_connection_str(
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, auth_rule_name) -> Tuple[
str, str, str]:
cmd, subscription_id, resource_group_name, cluster_name, cluster_location, auth_rule_name) -> Tuple[str, str, str]:
relay_client: azure.mgmt.relay.RelayManagementClient = get_mgmt_service_client(
cmd.cli_ctx, azure.mgmt.relay.RelayManagementClient)

Expand Down Expand Up @@ -398,8 +404,7 @@ def _get_service_bus_connection_string(cmd, subscription_id, resource_group_name


def _get_log_analytics_ws_connection_string(
cmd, subscription_id, resource_group_name, cluster_name, cluster_location) -> Tuple[
str, str]:
cmd, subscription_id, resource_group_name, cluster_name, cluster_location) -> Tuple[str, str]:
log_analytics_ws_client: azure.mgmt.loganalytics.LogAnalyticsManagementClient = get_mgmt_service_client(
cmd.cli_ctx, azure.mgmt.loganalytics.LogAnalyticsManagementClient)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from azure.cli.core.commands import LongRunningOperation
from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id
from azure.cli.core.util import sdk_no_wait
from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import parse_resource_id, is_valid_resource_id

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=protected-access

import os
import unittest

Expand All @@ -13,7 +15,7 @@


class TestAzureMlExtension(unittest.TestCase):

def test_set_up_inference_ssl(self):
azremlk8sInstance = AzureMLKubernetes()
config = {'allowInsecureConnections': 'false'}
Expand All @@ -27,6 +29,6 @@ def test_set_up_inference_ssl(self):
encoded_cert_and_key_file = os.path.join(TEST_DIR, 'data', 'azure_ml', 'cert_and_key_encoded.txt')
with open(encoded_cert_and_key_file, "r") as text_file:
cert = text_file.readline().rstrip()
self.assertEquals(cert, protected_config['scoringFe.sslCert'])
assert cert == protected_config['scoringFe.sslCert']
key = text_file.readline()
self.assertEquals(key, protected_config['scoringFe.sslKey'])
assert key == protected_config['scoringFe.sslKey']
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import unittest
# pylint: disable=line-too-long

import os
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, record_only)


Expand All @@ -27,13 +27,16 @@ def test_k8s_extension(self):
'version': '0.1.0'
})

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=[
self.check('name', '{name}'),
self.check('releaseTrain', '{release_train}'),
self.check('version', '{version}'),
self.check('resourceGroup', '{rg}'),
self.check('extensionType', '{extension_type}')
])
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=[
self.check('name', '{name}'),
self.check('releaseTrain', '{release_train}'),
self.check('version', '{version}'),
self.check('resourceGroup', '{rg}'),
self.check('extensionType', '{extension_type}')
]
)

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

0 comments on commit 67babd8

Please sign in to comment.