Skip to content

Commit

Permalink
Fix Pylint, run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Sep 26, 2024
1 parent 0076fe3 commit 4caf653
Show file tree
Hide file tree
Showing 27 changed files with 241 additions and 226 deletions.
33 changes: 17 additions & 16 deletions src/saltext/azurerm/clouds/azurerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
**Note:** review the details of Service Principals. Owner role is more than you normally need, and you can restrict
scope to a resource group or individual resources.
"""

import importlib
import logging
import os.path
Expand All @@ -97,27 +98,27 @@
from multiprocessing import cpu_count
from multiprocessing.pool import ThreadPool

import salt.cache # pylint: disable=import-error
import salt.config as config # pylint: disable=import-error
import salt.utils.cloud # pylint: disable=import-error
import salt.utils.files # pylint: disable=import-error
import salt.utils.stringutils # pylint: disable=import-error
import salt.utils.yaml # pylint: disable=import-error
import salt.version # pylint: disable=import-error
import saltext.azurerm.utils.azurerm
from salt.exceptions import SaltCloudConfigError # pylint: disable=import-error
from salt.exceptions import SaltCloudExecutionFailure # pylint: disable=import-error
from salt.exceptions import SaltCloudExecutionTimeout # pylint: disable=import-error
from salt.exceptions import SaltCloudSystemExit # pylint: disable=import-error
import salt.cache
import salt.utils.cloud
import salt.utils.files
import salt.utils.stringutils
import salt.utils.yaml
import salt.version
from salt import config
from salt.exceptions import SaltCloudConfigError
from salt.exceptions import SaltCloudExecutionFailure
from salt.exceptions import SaltCloudExecutionTimeout
from salt.exceptions import SaltCloudSystemExit

import saltext.azurerm.utils.azurerm

HAS_LIBS = False
try:
import azure.mgmt.compute.models as compute_models
import azure.mgmt.network.models as network_models

from azure.storage.blob import BlobServiceClient, ContainerClient
from azure.core.exceptions import HttpResponseError
from azure.storage.blob import BlobServiceClient
from azure.storage.blob import ContainerClient

HAS_LIBS = True
except ImportError:
Expand All @@ -126,7 +127,7 @@
try:
__salt__ # pylint: disable=used-before-assignment
except NameError:
import salt.loader # pylint: disable=import-error
import salt.loader

__opts__ = salt.config.minion_config("/etc/salt/minion")
__utils__ = salt.loader.utils(__opts__)
Expand Down Expand Up @@ -1706,7 +1707,7 @@ def create_or_update_vmextension(call=None, kwargs=None): # pylint: disable=unu

if not isinstance(settings, dict):
raise SaltCloudSystemExit("VM extension settings are not valid")
elif "commandToExecute" not in settings and "script" not in settings:
if "commandToExecute" not in settings and "script" not in settings:
raise SaltCloudSystemExit(
"VM extension settings are not valid. Either commandToExecute or script"
" must be specified."
Expand Down
1 change: 1 addition & 0 deletions src/saltext/azurerm/fileserver/azurefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Do not include the leading ? for sas_token if generated from the web
"""

import base64
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions src/saltext/azurerm/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Define the required entry-points functions in order for Salt to know
what and from where it should load this extension's loaders
"""

from . import PACKAGE_ROOT # pylint: disable=unused-import


Expand Down
2 changes: 1 addition & 1 deletion src/saltext/azurerm/modules/azurerm_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging


# Azure libs
HAS_LIBS = False
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -42,11 +43,9 @@
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
from azure.core.exceptions import (
ResourceNotFoundError,
HttpResponseError,
SerializationError,
)
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError

HAS_LIBS = True
except ImportError:
Expand Down
5 changes: 2 additions & 3 deletions src/saltext/azurerm/modules/azurerm_compute_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -42,9 +43,7 @@
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
from azure.core.exceptions import (
HttpResponseError,
)
from azure.core.exceptions import HttpResponseError

HAS_LIBS = True
except ImportError:
Expand Down
7 changes: 3 additions & 4 deletions src/saltext/azurerm/modules/azurerm_compute_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -42,10 +43,8 @@
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
from azure.core.exceptions import (
HttpResponseError,
SerializationError,
)
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import SerializationError
from azure.mgmt.core.tools import is_valid_resource_id

HAS_LIBS = True
Expand Down
16 changes: 8 additions & 8 deletions src/saltext/azurerm/modules/azurerm_compute_virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging
import os
Expand All @@ -43,12 +44,11 @@
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
from azure.core.exceptions import (
ResourceNotFoundError,
HttpResponseError,
SerializationError,
)
from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError
from azure.mgmt.core.tools import is_valid_resource_id
from azure.mgmt.core.tools import parse_resource_id

HAS_LIBS = True
except ImportError:
Expand Down Expand Up @@ -109,7 +109,7 @@ def create_or_update(
host_group=None,
extensions_time_budget=None,
**kwargs,
):
): # pylint: disable=too-many-arguments
"""
.. versionadded:: 2.1.0
Expand Down Expand Up @@ -660,7 +660,7 @@ def create_or_update(
"password",
)
connection_profile = {x: kwargs[x] for x in auth_kwargs if x in kwargs}
is_linux = True if result["storage_profile"]["os_disk"]["os_type"] == "Linux" else False
is_linux = result["storage_profile"]["os_disk"]["os_type"] == "Linux"
extension_info = {}

# attach custom script extension for userdata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -42,9 +43,7 @@
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
from azure.core.exceptions import (
HttpResponseError,
)
from azure.core.exceptions import HttpResponseError

HAS_LIBS = True
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ``AZURE_US_GOV_CLOUD``
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand Down
5 changes: 4 additions & 1 deletion src/saltext/azurerm/modules/azurerm_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -47,7 +48,9 @@
try:
import azure.mgmt.dns.models # pylint: disable=unused-import
import azure.mgmt.privatedns.models # pylint: disable=unused-import
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError, SerializationError
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError

HAS_LIBS = True
except ImportError:
Expand Down
11 changes: 5 additions & 6 deletions src/saltext/azurerm/modules/azurerm_keyvault_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import datetime
import logging
Expand All @@ -43,13 +44,11 @@
# Azure libs
HAS_LIBS = False
try:
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceExistsError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError
from azure.keyvault.keys import KeyClient
from azure.core.exceptions import (
ResourceNotFoundError,
HttpResponseError,
ResourceExistsError,
SerializationError,
)

HAS_LIBS = True
except ImportError:
Expand Down
11 changes: 5 additions & 6 deletions src/saltext/azurerm/modules/azurerm_keyvault_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import datetime
import logging
Expand All @@ -43,13 +44,11 @@
# Azure libs
HAS_LIBS = False
try:
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceExistsError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError
from azure.keyvault.secrets import SecretClient
from azure.core.exceptions import (
ResourceNotFoundError,
HttpResponseError,
ResourceExistsError,
SerializationError,
)

HAS_LIBS = True
except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion src/saltext/azurerm/modules/azurerm_keyvault_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

Expand All @@ -43,7 +44,8 @@
HAS_LIBS = False
try:
import azure.mgmt.keyvault.models # pylint: disable=unused-import
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError

HAS_LIBS = True
except ImportError:
Expand Down
13 changes: 8 additions & 5 deletions src/saltext/azurerm/modules/azurerm_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging

import salt.config # pylint: disable=import-error, unused-import
import salt.loader # pylint: disable=import-error, unused-import

import saltext.azurerm.utils.azurerm

# Azure libs
HAS_LIBS = False
try:
import azure.mgmt.network.models # pylint: disable=unused-import
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError, SerializationError
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError
from azure.mgmt.core.tools import is_valid_resource_id

HAS_LIBS = True
Expand Down Expand Up @@ -1500,10 +1504,9 @@ def network_interface_create_or_update(
errmsg = "The provided Backend Pool ID is not a valid resource ID string."
log.error(errmsg)

elif (
"load_balancer_name"
and "backend_address_pool_name"
in ipconfig["load_balancer_backend_address_pools"][idx]
elif all(
key in ipconfig["load_balancer_backend_address_pools"][idx]
for key in ("load_balancer_name", "backend_address_pool_name")
):
try:
lbbep_data = (
Expand Down
16 changes: 9 additions & 7 deletions src/saltext/azurerm/modules/azurerm_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@
* ``AZURE_GERMAN_CLOUD``
"""

# Python libs
import logging
from json.decoder import JSONDecodeError

import salt.utils.files # pylint: disable=import-error
import salt.utils.json # pylint: disable=import-error

import saltext.azurerm.utils.azurerm

# Azure libs
HAS_LIBS = False
try:
import azure.mgmt.resource.resources.models # pylint: disable=unused-import
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError, SerializationError
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import SerializationError

HAS_LIBS = True
except ImportError:
Expand Down Expand Up @@ -939,12 +943,10 @@ def policy_assignment_create(name, scope, definition_name, **kwargs):
# Delete this section when the ticket above is resolved.
# BEGIN
definition_list = policy_definitions_list(**kwargs)
if definition_name in definition_list:
definition = definition_list[definition_name]
else:
definition = {
"error": f'The policy definition named "{definition_name}" could not be found.'
}
definition = definition_list.get(
definition_name,
{"error": f'The policy definition named "{definition_name}" could not be found.'},
)
# END

if "error" not in definition:
Expand Down
Loading

0 comments on commit 4caf653

Please sign in to comment.