Skip to content

Commit

Permalink
[az fleet] Minor style & linter updates to fix checks. (#7092)
Browse files Browse the repository at this point in the history
* Style & Linter updates.

* Updated history.rst

* Fixes for pipeline detected style issues.

* Linter fix from pipeline results.

* Update src/fleet/azext_fleet/_completers.py

Co-authored-by: Jim Minter <jim-minter@users.noreply.github.com>

* Trying raise

* line break

---------

Co-authored-by: Jim Minter <jim-minter@users.noreply.github.com>
  • Loading branch information
Ealianis and jim-minter committed Dec 18, 2023
1 parent 350ac3e commit f33c6cb
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 38 deletions.
6 changes: 5 additions & 1 deletion src/fleet/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ Release History
1.0.1
++++++
* Updated help examples.
* Fixed serialization bug.
* Fixed serialization bug.

1.0.2
++++++
* Minor style & linting updates to codebase.
6 changes: 3 additions & 3 deletions src/fleet/azext_fleet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self, cli_ctx=None):
register_fleet_resource_type()

fleet_custom = CliCommandType(operations_tmpl='azext_fleet.custom#{}')
super(FleetCommandsLoader, self).__init__(cli_ctx=cli_ctx,
resource_type=CUSTOM_MGMT_FLEET,
custom_command_type=fleet_custom)
super().__init__(cli_ctx=cli_ctx,
resource_type=CUSTOM_MGMT_FLEET,
custom_command_type=fleet_custom)

def load_command_table(self, args):
from azext_fleet.commands import load_command_table
Expand Down
4 changes: 3 additions & 1 deletion src/fleet/azext_fleet/_completers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ def _get_location_from_resource_group(cli_ctx, resource_group_name):
# Print a warning if the user hit [TAB] but the `--resource-group` argument was incorrect.
# For example: "Warning: Resource group 'bogus' could not be found."
from argcomplete import warn
warn('Warning: {}'.format(err.message))
warn(f'Warning: {err.message}')

return None
2 changes: 1 addition & 1 deletion src/fleet/azext_fleet/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
text: az fleet create -g MyFleetResourceGroup -l MyLocation -n MyFleetName --enable-hub --tags "TagKey=TagValue"
- name: Create a fleet with a system assigned managed service identity.
text: az fleet create -g MyFleetResourceGroup -l MyLocation -n MyFleetName --enable-managed-identity
- name: Create a fleet with a user provided managed service identity.
- name: Create a fleet with a user assigned managed service identity.
text: az fleet create -g MyFleetResourceGroup -l MyLocation -n MyFleetName --enable-managed-identity --assign-identity "/subscription/00000000-0000-0000-0000-000000000000/resourcegroup/MyFleetResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/MyIdentity"
"""

Expand Down
11 changes: 6 additions & 5 deletions src/fleet/azext_fleet/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def _merge_kubernetes_configurations(existing_file, addition_file, replace, cont

# check that ~/.kube/config is only read- and writable by its owner
if platform.system() != "Windows" and not os.path.islink(existing_file):
existing_file_perms = "{:o}".format(stat.S_IMODE(os.lstat(existing_file).st_mode))
existing_file_perms = f"{stat.S_IMODE(os.lstat(existing_file).st_mode):o}"
if not existing_file_perms.endswith("600"):
logger.warning(
'%s has permissions "%s".\nIt should be readable and writable only by its owner.',
existing_file,
existing_file_perms,
)

with open(existing_file, 'w+') as stream:
with open(existing_file, 'w+', encoding='utf-8') as stream:
yaml.safe_dump(existing, stream, default_flow_style=False)

current_context = addition.get('current-context', 'UNKNOWN')
Expand Down Expand Up @@ -133,10 +133,11 @@ def _handle_merge(existing, addition, key, replace):

def _load_kubernetes_configuration(filename):
try:
with open(filename) as stream:
with open(filename, encoding='utf-8') as stream:
return yaml.safe_load(stream)
except (IOError, OSError) as ex:
if getattr(ex, 'errno', 0) == errno.ENOENT:
raise CLIError(f'{filename} does not exist')
raise CLIError(f'{filename} does not exist') from ex
raise
except (yaml.parser.ParserError, UnicodeDecodeError) as ex:
raise CLIError(f'Error parsing {filename} ({str(ex)})')
raise CLIError(f'Error parsing {filename} ({str(ex)})') from ex
2 changes: 1 addition & 1 deletion src/fleet/azext_fleet/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def load_arguments(self, _):
c.argument('apiserver_subnet_id', validator=validate_apiserver_subnet_id, is_preview=True, help='The subnet to be used when apiserver vnet integration is enabled. It is required when creating a new Fleet with BYO vnet.')
c.argument('agent_subnet_id', validator=validate_agent_subnet_id, is_preview=True, help='The ID of the subnet which the Fleet hub node will join on startup. If this is not specified, a vnet and subnet will be generated and used.')
c.argument('enable_managed_identity', action='store_true', help='Enable system assigned managed identity (MSI) on the Fleet resource.')
c.argument('assign_identity', validator=validate_assign_identity, help='With --enable-managed-identity, enable user assigned managed identity (MSI) on the Fleet resource. Specify the existing user assigned identity resource.')
c.argument('assign_identity', validator=validate_assign_identity, help='With --enable-managed-identity, enable user assigned managed identity (MSI) on the Fleet resource by specifying the user assigned identity\'s resource Id.')
c.argument('enable_hub', action='store_true', is_preview=True, help='If set, the Fleet will be created with a hub cluster.')
c.argument('vm_size', is_preview=True, validator=validate_vm_size, help='The virtual machine size of the Fleet hub.')

Expand Down
7 changes: 4 additions & 3 deletions src/fleet/azext_fleet/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def validate_kubernetes_version(namespace):
found = k8s_release_regex.findall(namespace.kubernetes_version)
if not found:
raise InvalidArgumentValueError(
'--kubernetes-version should be the full version number or alias minor version, such as "1.7.12" or "1.7"')
'--kubernetes-version should be the full version number '
'or alias minor version, such as "1.7.12" or "1.7"')


def validate_apiserver_subnet_id(namespace):
Expand All @@ -36,12 +37,12 @@ def validate_agent_subnet_id(namespace):

def validate_update_strategy_name(namespace):
if namespace.update_strategy_name is not None and not namespace.update_strategy_name.strip():
raise CLIError("--update-strategy-name is not a valid name")
raise CLIError("--update-strategy-name is not a valid name")


def validate_vm_size(namespace):
if namespace.vm_size is not None and not namespace.vm_size.strip():
raise CLIError("--vm-size is not a valid value")
raise CLIError("--vm-size is not a valid value")


def _validate_subnet_id(subnet_id, name):
Expand Down
7 changes: 3 additions & 4 deletions src/fleet/azext_fleet/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def create_fleet(cmd,
enable_managed_identity=False,
assign_identity=None,
no_wait=False):

fleet_model = cmd.get_models(
"Fleet",
resource_type=CUSTOM_MGMT_FLEET,
Expand Down Expand Up @@ -208,8 +207,8 @@ def get_credentials(cmd, # pylint: disable=unused-argument
encoding='UTF-8')
print_or_merge_credentials(
path, kubeconfig, overwrite_existing, context_name)
except (IndexError, ValueError):
raise CLIError("Fail to find kubeconfig file.")
except (IndexError, ValueError) as exc:
raise CLIError("Fail to find kubeconfig file.") from exc


def create_fleet_member(cmd,
Expand Down Expand Up @@ -385,7 +384,7 @@ def get_update_run_strategy(cmd, operation_group, stages):
if stages is None:
return None

with open(stages, 'r') as fp:
with open(stages, 'r', encoding='utf-8') as fp:
data = json.load(fp)
fp.close()

Expand Down
2 changes: 1 addition & 1 deletion src/fleet/azext_fleet/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion src/fleet/azext_fleet/tests/latest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: '{"error":{"code":"ResourceNotFound","message":"The Resource ''Microsoft.ContainerService/managedClusters/flmc-000003''
Expand Down Expand Up @@ -784,7 +784,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1291,7 +1291,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1759,7 +1759,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1852,7 +1852,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1945,7 +1945,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -2038,7 +2038,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -2131,7 +2131,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: '{"error":{"code":"ResourceNotFound","message":"The Resource ''Microsoft.ContainerService/managedClusters/flmc-000003''
Expand Down Expand Up @@ -601,7 +601,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1246,7 +1246,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1718,7 +1718,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1811,7 +1811,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down Expand Up @@ -1904,7 +1904,7 @@ interactions:
- AZURECLI/2.53.0 azsdk-python-azure-mgmt-containerservice/25.0.0b Python/3.10.12
(Linux-6.2.0-1012-azure-x86_64-with-glibc2.35)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-08-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003?api-version=2023-10-01
response:
body:
string: "{\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/flmc-000003\",\n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk.scenario_tests import AllowLargeResponse


class FleetHubfulScenarioTest(ScenarioTest):

@classmethod
Expand Down Expand Up @@ -47,7 +48,7 @@ def test_fleet_hubful(self):
'ssh_key_value': self.generate_ssh_keys()
})

self.cmd('fleet create -g {rg} -n {fleet_name} --enable-hub --vm-size Standard_DS1 ' , checks=[
self.cmd('fleet create -g {rg} -n {fleet_name} --enable-hub --vm-size Standard_DS1 ', checks=[
self.check('name', '{fleet_name}')
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
from azure.cli.testsdk.scenario_tests import AllowLargeResponse


def _get_test_data_file(filename):
curr_dir = os.path.dirname(os.path.realpath(__file__))
return os.path.join(curr_dir, 'data', filename)


class FleetHublessScenarioTest(ScenarioTest):

@classmethod
Expand Down
Loading

0 comments on commit f33c6cb

Please sign in to comment.