From 4b9121dc36d71ab2e9c647f7bda0a1972e267766 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Fri, 13 Sep 2024 15:36:25 -0600 Subject: [PATCH] Updated pre-commit, GitHub actions, and support of Salt (#407) * Updated pre-commit, GitHub actions, and support of Salt * Updates files due to modified pre-commit * Restored black to pre-commit * Updated pre-commit and blackened files * Reduced rstcheck to v 5.0.0 * Trying adding setuptools to install requirements for Windows and MacOS building * Trying latest pyvmomi * Dropping minimum Python version to 3.9 * Forcing setuptools 68.2.2 * Debugging pyvmomi installation * Retrying after successful build, with mimimizing changes * Reversed to Python 3.10 and forced install of setuptools and pyvmomi for Windows and MacOS * Removed missed Python 3.9 --- .github/workflows/test.yml | 34 ++-- .pre-commit-config.yaml | 147 +++--------------- docs/conf.py | 4 +- noxfile.py | 15 +- pyproject.toml | 2 +- setup.cfg | 16 +- src/saltext/vmware/modules/cluster_drs.py | 6 +- src/saltext/vmware/modules/cluster_ha.py | 48 +++--- src/saltext/vmware/modules/dvswitch.py | 4 +- src/saltext/vmware/modules/esxi.py | 46 +++--- .../vmware/modules/nsxt_compute_manager.py | 3 +- src/saltext/vmware/modules/nsxt_ip_blocks.py | 5 +- src/saltext/vmware/modules/nsxt_ip_pools.py | 5 +- src/saltext/vmware/modules/nsxt_license.py | 1 + src/saltext/vmware/modules/nsxt_manager.py | 1 + .../vmware/modules/nsxt_policy_segment.py | 3 +- .../vmware/modules/nsxt_policy_tier0.py | 3 +- .../vmware/modules/nsxt_policy_tier1.py | 3 +- .../vmware/modules/nsxt_transport_node.py | 1 + .../modules/nsxt_transport_node_profiles.py | 1 + .../vmware/modules/nsxt_transport_zone.py | 5 +- .../vmware/modules/nsxt_uplink_profiles.py | 5 +- .../vmware/modules/vmc_dhcp_profiles.py | 1 + .../vmware/modules/vmc_direct_connect.py | 1 + .../modules/vmc_distributed_firewall_rules.py | 1 + .../vmware/modules/vmc_dns_forwarder.py | 1 + src/saltext/vmware/modules/vmc_nat_rules.py | 1 + src/saltext/vmware/modules/vmc_networks.py | 5 +- src/saltext/vmware/modules/vmc_org_users.py | 7 +- src/saltext/vmware/modules/vmc_public_ip.py | 1 + src/saltext/vmware/modules/vmc_sddc.py | 5 +- .../vmware/modules/vmc_sddc_clusters.py | 1 + src/saltext/vmware/modules/vmc_sddc_host.py | 1 + .../vmware/modules/vmc_security_groups.py | 1 + .../vmware/modules/vmc_security_rules.py | 1 + .../vmware/modules/vmc_vcenter_stats.py | 3 +- src/saltext/vmware/modules/vmc_vm_disks.py | 3 +- src/saltext/vmware/modules/vmc_vm_stats.py | 1 + .../vmware/modules/vmc_vpn_statistics.py | 1 + src/saltext/vmware/returners/merge_changes.py | 1 + .../vmware/returners/merge_changes_esxi.py | 1 + .../vmware/states/compliance_control.py | 9 +- src/saltext/vmware/states/datacenter.py | 12 +- src/saltext/vmware/states/esxi.py | 100 ++++++------ .../vmware/states/nsxt_compute_manager.py | 39 ++--- src/saltext/vmware/states/nsxt_ip_blocks.py | 19 +-- src/saltext/vmware/states/nsxt_ip_pools.py | 19 +-- src/saltext/vmware/states/nsxt_license.py | 8 +- src/saltext/vmware/states/nsxt_manager.py | 1 + .../vmware/states/nsxt_policy_segment.py | 17 +- .../vmware/states/nsxt_policy_tier0.py | 59 +++---- .../vmware/states/nsxt_policy_tier1.py | 59 +++---- .../vmware/states/nsxt_transport_node.py | 33 ++-- .../states/nsxt_transport_node_profiles.py | 37 ++--- .../vmware/states/nsxt_transport_zone.py | 3 +- .../vmware/states/nsxt_uplink_profiles.py | 19 +-- .../vmware/states/vmc_dhcp_profiles.py | 15 +- .../states/vmc_distributed_firewall_rules.py | 9 +- src/saltext/vmware/states/vmc_nat_rules.py | 11 +- src/saltext/vmware/states/vmc_networks.py | 15 +- src/saltext/vmware/states/vmc_org_user.py | 13 +- src/saltext/vmware/states/vmc_public_ip.py | 11 +- src/saltext/vmware/states/vmc_sddc.py | 10 +- .../vmware/states/vmc_security_groups.py | 9 +- .../vmware/states/vmc_security_rules.py | 15 +- src/saltext/vmware/utils/cluster.py | 2 +- src/saltext/vmware/utils/common.py | 26 ++-- src/saltext/vmware/utils/esxi.py | 6 +- .../vmware/utils/nsxt_policy_base_resource.py | 6 +- src/saltext/vmware/utils/nsxt_request.py | 3 +- src/saltext/vmware/utils/vm.py | 2 +- src/saltext/vmware/utils/vmc_request.py | 1 + src/saltext/vmware/utils/vmc_state.py | 1 + .../vmware/utils/vmc_vcenter_request.py | 1 + src/saltext/vmware/utils/vsphere.py | 20 +-- tests/integration/conftest.py | 10 +- tests/integration/modules/test_datastore.py | 5 +- tests/integration/modules/test_esxi.py | 4 +- tests/integration/modules/test_folder.py | 5 +- .../modules/test_nsxt_ip_blocks.py | 7 +- .../integration/modules/test_nsxt_ip_pools.py | 7 +- .../integration/modules/test_nsxt_manager.py | 1 + .../modules/test_nsxt_transport_node.py | 1 + .../test_nsxt_transport_node_profiles.py | 3 +- .../modules/test_nsxt_transport_zone.py | 2 +- .../modules/test_nsxt_uplink_profiles.py | 5 +- tests/integration/modules/test_vm.py | 5 +- .../modules/test_vmc_dhcp_profiles.py | 7 +- .../test_vmc_distributed_firewall_rules.py | 1 + .../modules/test_vmc_dns_forwarder.py | 1 + .../integration/modules/test_vmc_nat_rules.py | 1 + .../integration/modules/test_vmc_networks.py | 11 +- .../integration/modules/test_vmc_org_users.py | 3 +- .../integration/modules/test_vmc_public_ip.py | 1 + tests/integration/modules/test_vmc_sddc.py | 1 + .../modules/test_vmc_sddc_clusters.py | 1 + .../integration/modules/test_vmc_sddc_host.py | 1 + .../modules/test_vmc_security_groups.py | 1 + .../modules/test_vmc_security_rules.py | 1 + .../integration/modules/test_vmc_vm_disks.py | 1 + .../integration/modules/test_vmc_vm_stats.py | 1 + tests/integration/states/test_datastore.py | 5 +- tests/integration/states/test_esxi.py | 30 ++-- tests/integration/states/test_folder.py | 5 +- .../states/test_nsxt_compute_manager.py | 7 +- .../integration/states/test_nsxt_ip_blocks.py | 9 +- .../integration/states/test_nsxt_ip_pools.py | 9 +- tests/integration/states/test_nsxt_license.py | 3 +- tests/integration/states/test_nsxt_manager.py | 1 + .../states/test_nsxt_transport_node.py | 2 + .../test_nsxt_transport_node_profiles.py | 12 +- .../states/test_nsxt_uplink_profiles.py | 10 +- tests/integration/states/test_tag.py | 5 +- tests/integration/states/test_vm.py | 5 +- .../states/test_vmc_dhcp_profiles.py | 1 + .../test_vmc_distributed_firewall_rules.py | 11 +- .../integration/states/test_vmc_nat_rules.py | 11 +- tests/integration/states/test_vmc_networks.py | 11 +- tests/integration/states/test_vmc_org_user.py | 5 +- .../integration/states/test_vmc_public_ip.py | 9 +- tests/integration/states/test_vmc_sddc.py | 5 +- .../states/test_vmc_security_groups.py | 11 +- .../states/test_vmc_security_rules.py | 11 +- tests/unit/modules/test_compliance_control.py | 23 ++- .../unit/modules/test_controller_metadata.py | 25 +-- tests/unit/modules/test_dvportgroup.py | 7 +- tests/unit/modules/test_esxi.py | 31 ++-- .../unit/modules/test_nsxt_compute_manager.py | 1 + tests/unit/modules/test_nsxt_ip_blocks.py | 1 + tests/unit/modules/test_nsxt_ip_pools.py | 1 + tests/unit/modules/test_nsxt_license.py | 1 + tests/unit/modules/test_nsxt_manager.py | 1 + .../unit/modules/test_nsxt_policy_segment.py | 1 + tests/unit/modules/test_nsxt_policy_tier0.py | 18 ++- .../unit/modules/test_nsxt_transport_node.py | 1 + .../unit/modules/test_nsxt_transport_zone.py | 1 + .../unit/modules/test_nsxt_uplink_profiles.py | 1 + .../modules/test_transport_node_profiles.py | 1 + tests/unit/modules/test_vm.py | 45 ++---- tests/unit/modules/test_vmc_dhcp_profiles.py | 1 + tests/unit/modules/test_vmc_direct_connect.py | 1 + .../test_vmc_distributed_firewall_rules.py | 1 + tests/unit/modules/test_vmc_dns_forwarder.py | 1 + tests/unit/modules/test_vmc_nat_rules.py | 1 + tests/unit/modules/test_vmc_networks.py | 1 + tests/unit/modules/test_vmc_org_users.py | 1 + tests/unit/modules/test_vmc_public_ip.py | 1 + tests/unit/modules/test_vmc_sddc.py | 1 + tests/unit/modules/test_vmc_sddc_clusters.py | 1 + tests/unit/modules/test_vmc_sddc_host.py | 1 + .../unit/modules/test_vmc_security_groups.py | 1 + tests/unit/modules/test_vmc_security_rules.py | 1 + tests/unit/modules/test_vmc_vcenter_stats.py | 1 + tests/unit/modules/test_vmc_vm_disks.py | 5 +- tests/unit/modules/test_vmc_vm_stats.py | 1 + tests/unit/modules/test_vmc_vpn_statistics.py | 1 + tests/unit/states/test_compliance_control.py | 23 ++- tests/unit/states/test_controller_metadata.py | 25 +-- tests/unit/states/test_esxi.py | 1 + .../unit/states/test_nsxt_compute_manager.py | 32 ++-- tests/unit/states/test_nsxt_ip_blocks.py | 16 +- tests/unit/states/test_nsxt_ip_pools.py | 18 ++- tests/unit/states/test_nsxt_manager.py | 1 + tests/unit/states/test_nsxt_policy_segment.py | 13 +- tests/unit/states/test_nsxt_policy_tier0.py | 46 +++--- tests/unit/states/test_nsxt_policy_tier1.py | 46 +++--- tests/unit/states/test_nsxt_transport_node.py | 1 + .../test_nsxt_transport_node_profiles.py | 28 ++-- tests/unit/states/test_nsxt_transport_zone.py | 28 ++-- .../unit/states/test_nsxt_uplink_profiles.py | 28 ++-- tests/unit/states/test_vmc_dhcp_profiles.py | 22 +-- .../test_vmc_distributed_firewall_rules.py | 17 +- tests/unit/states/test_vmc_nat_rules.py | 21 +-- tests/unit/states/test_vmc_networks.py | 24 +-- tests/unit/states/test_vmc_org_user.py | 18 +-- tests/unit/states/test_vmc_public_ip.py | 22 +-- tests/unit/states/test_vmc_sddc.py | 8 +- tests/unit/states/test_vmc_security_groups.py | 15 +- tests/unit/states/test_vmc_security_rules.py | 22 +-- tests/unit/utils/test_compliance_control.py | 1 + tests/unit/utils/test_connect.py | 30 ++-- tests/unit/utils/test_nsxt_request.py | 1 + tests/unit/utils/test_vmc_request.py | 1 + tests/unit/utils/test_vmc_vcenter_request.py | 1 + tools/test_value_scraper.py | 6 +- 185 files changed, 1023 insertions(+), 942 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bcd6d0f3..01413d45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,9 +7,9 @@ jobs: Pre-Commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" - name: Set Cache Key @@ -18,11 +18,11 @@ jobs: run: | sudo apt-get update sudo apt-get install -y libxml2 libxml2-dev libxslt-dev - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - - uses: pre-commit/action@v1.0.1 + - uses: pre-commit/action@v3.0.1 Docs: runs-on: ubuntu-latest @@ -31,10 +31,10 @@ jobs: timeout-minutes: 10 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python 3.10 For Nox - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" @@ -69,10 +69,10 @@ jobs: - 3006.9 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -166,7 +166,7 @@ jobs: - name: Upload Logs if: always() - uses: actions/upload-artifact@main + uses: actions/upload-artifact@v4 with: name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log path: artifacts/runtests-*.log @@ -187,10 +187,10 @@ jobs: - 3006.9 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -198,6 +198,8 @@ jobs: run: | python -m pip install --upgrade pip pip install nox + pip install setuptools==68.2.2 + pip install pyvmomi==7.0.3 - name: Install Test Requirements shell: bash @@ -288,7 +290,7 @@ jobs: - name: Upload Logs if: always() - uses: actions/upload-artifact@main + uses: actions/upload-artifact@v4 with: name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log path: artifacts/runtests-*.log @@ -309,10 +311,10 @@ jobs: - 3006.9 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -320,6 +322,8 @@ jobs: run: | python -m pip install --upgrade pip pip install nox + pip install setuptools==68.2.2 + pip install pyvmomi==7.0.3 - name: Install Test Requirements env: @@ -406,7 +410,7 @@ jobs: - name: Upload Logs if: always() - uses: actions/upload-artifact@main + uses: actions/upload-artifact@v4 with: name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log path: artifacts/runtests-*.log diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a71e983e..2d00dea0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,10 +3,10 @@ default_language_version: python: python3 exclude: ^(doc/_static/.*|doc/_themes/.*)$ -minimum_pre_commit_version: 2.4.0 +minimum_pre_commit_version: 3.6.0 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-merge-conflict # Check for files that contain merge conflict strings. - id: trailing-whitespace # Trims trailing whitespace. @@ -47,11 +47,11 @@ repos: # ----- Formatting ----------------------------------------------------------------------------> - repo: https://github.com/asottile/pyupgrade - rev: v2.37.2 + rev: v3.17.0 hooks: - id: pyupgrade - name: Rewrite Code to be Py3.7+, drop six usage and Py2 support - args: [--py3-plus, --keep-mock] + name: Rewrite Code to be Py3.10+, drop six usage and Py2 support + args: [--py310-plus, --keep-mock] exclude: src/saltext/vcenter/version.py - repo: https://github.com/saltstack/pre-commit-remove-import-headers @@ -75,9 +75,9 @@ repos: language: system pass_filenames: false - - repo: https://github.com/s0undt3ch/salt-rewrite + - repo: https://github.com/saltstack/salt-rewrite # Automatically rewrite code with known rules - rev: "2.2.0" + rev: 2.5.2 hooks: - id: salt-rewrite alias: rewrite-docstrings @@ -91,34 +91,32 @@ repos: files: ^tests/.*\.py$ args: [--silent, -E, fix_asserts, -E, fix_docstrings] - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.10.0 - hooks: - - id: reorder-python-imports - args: [ - --py3-plus, - ] - exclude: src/saltext/vcenter/version.py + ## - repo: https://github.com/asottile/reorder_python_imports + ## rev: v3.13.0 + ## hooks: + ## - id: reorder-python-imports + ## args: [ + ## --py310-plus, + ## ] + ## exclude: src/saltext/vcenter/version.py - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 24.8.0 hooks: - id: black - args: [-l 100] - exclude: src/saltext/vcenter/version.py - additional_dependencies: - - click<8.1.0 + args: [-tpy310] + exclude: ^src/saltext/vcenter/version.py - repo: https://github.com/asottile/blacken-docs - rev: v1.7.0 + rev: 1.18.0 hooks: - id: blacken-docs args: [--skip-errors] files: ^docs/.*\.rst - additional_dependencies: [black==20.8b1] + additional_dependencies: [black==24.8.0] - repo: https://github.com/myint/rstcheck - rev: 3f92957 + rev: v5.0.0 hooks: - id: rstcheck name: Check reST files using rstcheck @@ -128,7 +126,7 @@ repos: # ----- Security ------------------------------------------------------------------------------> - repo: https://github.com/PyCQA/bandit - rev: "1.7.4" + rev: "1.7.9" hooks: - id: bandit alias: bandit-salt @@ -137,7 +135,7 @@ repos: exclude: src/saltext/vcenter/version.py additional_dependencies: ['importlib_metadata<5'] - repo: https://github.com/PyCQA/bandit - rev: "1.7.4" + rev: "1.7.9" hooks: - id: bandit alias: bandit-tests @@ -180,39 +178,6 @@ repos: - repo: https://github.com/saltstack/pip-tools-compile-impersonate rev: '4.8' hooks: - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/tests.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Test Requirements - files: ^requirements/tests.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/tests.in - - id: pip-tools-compile alias: compile-3.10-test-requirements name: Py3.10 Test Requirements @@ -226,39 +191,6 @@ repos: # <---- Static Test Requirements --------------------------------------------------------------- # ----- Static Lint Requirements --------------------------------------------------------------> - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/lint.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Lint Requirements - files: ^requirements/lint.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/lint.in - - id: pip-tools-compile alias: compile-3.10-test-requirements name: Py3.10 Lint Requirements @@ -272,39 +204,6 @@ repos: # <---- Static Lint Requirements --------------------------------------------------------------- # ----- Static Docs Requirements --------------------------------------------------------------> - - id: pip-tools-compile - alias: compile-3.7-test-requirements - name: Py3.7 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.7 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.8-test-requirements - name: Py3.8 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.8 - - --platform=linux - - requirements/docs.in - - - id: pip-tools-compile - alias: compile-3.9-test-requirements - name: Py3.9 Docs Requirements - files: ^requirements/docs.in$ - pass_filenames: false - args: - - -v - - --py-version=3.9 - - --platform=linux - - requirements/docs.in - - id: pip-tools-compile alias: compile-3.10-test-requirements name: Py3.10 Docs Requirements diff --git a/docs/conf.py b/docs/conf.py index 29ea5cf8..ad1b752e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,10 +40,10 @@ if this_year == 2020: copyright_year = 2020 else: - copyright_year = "2020 - {}".format(this_year) + copyright_year = f"2020 - {this_year}" project = dist.metadata["Summary"] author = dist.metadata["Author"] -copyright = "{}, {}".format(copyright_year, author) +copyright = f"{copyright_year}, {author}" # The full version, including alpha/beta/rc tags release = dist.version diff --git a/noxfile.py b/noxfile.py index 06c1c59e..1ea084f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -4,6 +4,7 @@ Nox configuration script """ + # pylint: disable=missing-module-docstring,import-error,protected-access,missing-function-docstring import datetime import json @@ -33,7 +34,7 @@ nox.options.error_on_missing_interpreters = False # Python versions to test against -PYTHON_VERSIONS = ("3", "3.7", "3.8", "3.9", "3.10") +PYTHON_VERSIONS = ("3", "3.10") # Be verbose when running under a CI context CI_RUN = ( os.environ.get("JENKINS_URL") or os.environ.get("CI") or os.environ.get("DRONE") is not None @@ -161,10 +162,10 @@ def tests(session): args = [ "--rootdir", str(REPO_ROOT), - "--log-file={}".format(RUNTESTS_LOGFILE.relative_to(REPO_ROOT)), + f"--log-file={RUNTESTS_LOGFILE.relative_to(REPO_ROOT)}", "--log-file-level=debug", "--show-capture=no", - "--junitxml={}".format(JUNIT_REPORT), + f"--junitxml={JUNIT_REPORT}", "--showlocals", "-ra", "-s", @@ -183,7 +184,7 @@ def tests(session): for arg in session.posargs: if arg.startswith("-"): continue - if arg.startswith("tests{}".format(os.sep)): + if arg.startswith(f"tests{os.sep}"): break try: pathlib.Path(arg).resolve().relative_to(REPO_ROOT / "tests") @@ -223,7 +224,7 @@ def _lint(session, rcfile, flags, paths, tee_output=True): session.run("pylint", "--version") pylint_report_path = os.environ.get("PYLINT_REPORT") - cmd_args = ["pylint", "--rcfile={}".format(rcfile)] + list(flags) + list(paths) + cmd_args = ["pylint", f"--rcfile={rcfile}"] + list(flags) + list(paths) src_path = str(REPO_ROOT / "src") python_path_env_var = os.environ.get("PYTHONPATH") or None @@ -295,8 +296,8 @@ def lint(session): """ Run PyLint against the code and the test suite. Set PYLINT_REPORT to a path to capture output. """ - session.notify("lint-code-{}".format(session.python)) - session.notify("lint-tests-{}".format(session.python)) + session.notify(f"lint-code-{session.python}") + session.notify(f"lint-tests-{session.python}") @nox.session(python="3", name="lint-code") diff --git a/pyproject.toml b/pyproject.toml index b89be6e9..2334d5e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=50.3.2", "wheel", "setuptools-declarative-requirements"] +requires = ["setuptools<69.0,>=65.6.3", "wheel", "setuptools-declarative-requirements"] build-backend = "setuptools.build_meta" [tool.black] diff --git a/setup.cfg b/setup.cfg index 78503088..9ebdb30a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,9 +18,6 @@ classifiers = Programming Language :: Cython Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Development Status :: 4 - Beta Intended Audience :: Developers @@ -33,15 +30,15 @@ include_package_data = True package_dir = =src packages = find_namespace: -python_requires = >= 3.7 +python_requires = >= 3.10 setup_requires = wheel - setuptools>=50.3.2 + setuptools<69.0,>=65.6.3 setuptools-declarative-requirements install_requires = + setuptools<69.0,>=65.6.3 salt>=3006 pyvmomi==7.0.3 - importlib_metadata; python_version < "3.8" jinja2>=3.1.0 config_modules_vmware @@ -52,18 +49,17 @@ tests = pytest-salt-factories>=1.0.1 dev = nox - towncrier==21.9.0rc1 + towncrier==23.11.0 release = twine wheel - towncrier==21.9.0rc1 + towncrier==22.12.0 docs = sphinx furo sphinx-prompt sphinxcontrib-spelling - importlib_metadata; python_version < "3.8" - towncrier==21.9.0rc1 + towncrier==22.12.0 [options.packages.find] diff --git a/src/saltext/vmware/modules/cluster_drs.py b/src/saltext/vmware/modules/cluster_drs.py index defb3ea6..b73375d4 100644 --- a/src/saltext/vmware/modules/cluster_drs.py +++ b/src/saltext/vmware/modules/cluster_drs.py @@ -149,9 +149,9 @@ def get(cluster_name, datacenter_name, service_instance=None, profile=None): dc_ref = utils_datacenter.get_datacenter(service_instance, datacenter_name) cluster_ref = utils_cluster.get_cluster(dc_ref=dc_ref, cluster=cluster_name) ret["enabled"] = cluster_ref.configurationEx.drsConfig.enabled - ret[ - "enable_vm_behavior_overrides" - ] = cluster_ref.configurationEx.drsConfig.enableVmBehaviorOverrides + ret["enable_vm_behavior_overrides"] = ( + cluster_ref.configurationEx.drsConfig.enableVmBehaviorOverrides + ) ret["default_vm_behavior"] = cluster_ref.configurationEx.drsConfig.defaultVmBehavior ret["vmotion_rate"] = 6 - cluster_ref.configurationEx.drsConfig.vmotionRate ret["advanced_settings"] = {} diff --git a/src/saltext/vmware/modules/cluster_ha.py b/src/saltext/vmware/modules/cluster_ha.py index 26a28898..a1768335 100644 --- a/src/saltext/vmware/modules/cluster_ha.py +++ b/src/saltext/vmware/modules/cluster_ha.py @@ -375,26 +375,26 @@ def get(cluster_name, datacenter_name, service_instance=None, profile=None): component_protection_settings = ( das_config.defaultVmSettings.vmComponentProtectionSettings ) - ret[ - "enable_apd_timeout_for_hosts" - ] = component_protection_settings.enableAPDTimeoutForHosts + ret["enable_apd_timeout_for_hosts"] = ( + component_protection_settings.enableAPDTimeoutForHosts + ) ret["vm_reaction_on_apd_cleared"] = component_protection_settings.vmReactionOnAPDCleared - ret[ - "vm_storage_protection_for_apd" - ] = component_protection_settings.vmStorageProtectionForAPD - ret[ - "vm_storage_protection_for_pdl" - ] = component_protection_settings.vmStorageProtectionForPDL - ret[ - "vm_terminate_delay_for_apd_sec" - ] = component_protection_settings.vmTerminateDelayForAPDSec + ret["vm_storage_protection_for_apd"] = ( + component_protection_settings.vmStorageProtectionForAPD + ) + ret["vm_storage_protection_for_pdl"] = ( + component_protection_settings.vmStorageProtectionForPDL + ) + ret["vm_terminate_delay_for_apd_sec"] = ( + component_protection_settings.vmTerminateDelayForAPDSec + ) ret["admission_control_enabled"] = das_config.admissionControlEnabled ret["admission_control_policy"] = None ret["failover_level"] = das_config.admissionControlPolicy.failoverLevel - ret[ - "resource_reduction_to_tolerate_percent" - ] = das_config.admissionControlPolicy.resourceReductionToToleratePercent + ret["resource_reduction_to_tolerate_percent"] = ( + das_config.admissionControlPolicy.resourceReductionToToleratePercent + ) if isinstance( das_config.admissionControlPolicy, vim.cluster.FailoverLevelAdmissionControlPolicy, @@ -413,15 +413,15 @@ def get(cluster_name, datacenter_name, service_instance=None, profile=None): vim.cluster.FailoverResourcesAdmissionControlPolicy, ): ret["admission_control_policy"] = "reservation_based_admission_control" - ret[ - "autocompute_percentages" - ] = das_config.admissionControlPolicy.autoComputePercentages - ret[ - "cpu_failover_resources_percent" - ] = das_config.admissionControlPolicy.cpuFailoverResourcesPercent - ret[ - "memory_failover_resources_percent" - ] = das_config.admissionControlPolicy.memoryFailoverResourcesPercent + ret["autocompute_percentages"] = ( + das_config.admissionControlPolicy.autoComputePercentages + ) + ret["cpu_failover_resources_percent"] = ( + das_config.admissionControlPolicy.cpuFailoverResourcesPercent + ) + ret["memory_failover_resources_percent"] = ( + das_config.admissionControlPolicy.memoryFailoverResourcesPercent + ) ret["advanced_settings"] = {} for obj in cluster_ref.configurationEx.dasConfig.option: diff --git a/src/saltext/vmware/modules/dvswitch.py b/src/saltext/vmware/modules/dvswitch.py index 00e89200..98a5e364 100644 --- a/src/saltext/vmware/modules/dvswitch.py +++ b/src/saltext/vmware/modules/dvswitch.py @@ -162,9 +162,7 @@ def configure( if uplink_count: config_spec.uplinkPortPolicy = vim.DistributedVirtualSwitch.NameArrayUplinkPortPolicy() for i in range(uplink_count): - config_spec.uplinkPortPolicy.uplinkPortName.append( - "{}{}".format(uplink_prefix, i + 1) - ) + config_spec.uplinkPortPolicy.uplinkPortName.append(f"{uplink_prefix}{i + 1}") if switch_version: product_spec = vim.dvs.ProductSpec() diff --git a/src/saltext/vmware/modules/esxi.py b/src/saltext/vmware/modules/esxi.py index 805655ae..aa518b4a 100644 --- a/src/saltext/vmware/modules/esxi.py +++ b/src/saltext/vmware/modules/esxi.py @@ -492,9 +492,7 @@ def get_service_policy( # Check if the service_name provided is a valid one. # If we don't have a valid service, return. The service will be invalid for all hosts. if service_name not in valid_services: - ret.update( - {host_name: {"Error": "{} is not a valid service name.".format(service_name)}} - ) + ret.update({host_name: {"Error": f"{service_name} is not a valid service name."}}) return ret services = host.configManager.serviceSystem.serviceInfo.service @@ -513,12 +511,12 @@ def get_service_policy( # Updated host.name value with an error message. break else: - msg = "Could not find service '{}' for host '{}'.".format(service_name, host.name) + msg = f"Could not find service '{service_name}' for host '{host.name}'." ret.update({host.name: {"Error": msg}}) # If we made it this far, something else has gone wrong. if ret.get(host.name) is None: - msg = "'vsphere.get_service_policy' failed for host {}.".format(host.name) + msg = f"'vsphere.get_service_policy' failed for host {host.name}." log.debug(msg) ret.update({host.name: {"Error": msg}}) @@ -607,9 +605,7 @@ def get_service_running( # Check if the service_name provided is a valid one. # If we don't have a valid service, return. The service will be invalid for all hosts. if service_name not in valid_services: - ret.update( - {host.name: {"Error": "{} is not a valid service name.".format(service_name)}} - ) + ret.update({host.name: {"Error": f"{service_name} is not a valid service name."}}) return ret services = host.configManager.serviceSystem.serviceInfo.service @@ -628,12 +624,12 @@ def get_service_running( # Updated host.name value with an error message. break else: - msg = "Could not find service '{}' for host '{}'.".format(service_name, host.name) + msg = f"Could not find service '{service_name}' for host '{host.name}'." ret.update({host.name: {"Error": msg}}) # If we made it this far, something else has gone wrong. if ret.get(host.name) is None: - msg = "'vsphere.get_service_running' failed for host {}.".format(host.name) + msg = f"'vsphere.get_service_running' failed for host {host.name}." log.debug(msg) ret.update({host.name: {"Error": msg}}) @@ -1122,7 +1118,7 @@ def get_all_firewall_configs( "ip_address": list(ruleset.allowedHosts.ipAddress), "all_ip": ruleset.allowedHosts.allIp, "ip_network": [ - "{}/{}".format(ip.network, ip.prefixLength) + f"{ip.network}/{ip.prefixLength}" for ip in ruleset.allowedHosts.ipNetwork ], }, @@ -1205,7 +1201,7 @@ def get_firewall_config( "ip_address": list(ruleset.allowedHosts.ipAddress), "all_ip": ruleset.allowedHosts.allIp, "ip_network": [ - "{}/{}".format(ip.network, ip.prefixLength) + f"{ip.network}/{ip.prefixLength}" for ip in ruleset.allowedHosts.ipNetwork ], }, @@ -1528,7 +1524,7 @@ def restore_config( h.configManager.firmwareSystem.RestoreFirmwareConfiguration(force=False) ret[h.name] = True except Exception as exc: - msg = "Unable to restore configuration for host - {}. Error - {}".format(h.name, exc) + msg = f"Unable to restore configuration for host - {h.name}. Error - {exc}" log.error(msg) ret[h.name] = msg if h.runtime.inMaintenanceMode: @@ -1588,11 +1584,11 @@ def reset_config( h.configManager.firmwareSystem.ResetFirmwareToFactoryDefaults() ret[h.name] = True except vmodl.fault.HostCommunication as exc: - msg = "Unable to reach host - {}. Error - {}".format(h.name, str(exc)) + msg = f"Unable to reach host - {h.name}. Error - {str(exc)}" ret[h.name] = msg log.error(msg) except Exception as exc: - msg = "Unable to reset configuration for host - {}. Error - {}".format(h.name, str(exc)) + msg = f"Unable to reset configuration for host - {h.name}. Error - {str(exc)}" ret[h.name] = msg log.error(msg) log.debug("Host - %s exiting maintenance mode", h.name) @@ -1704,9 +1700,11 @@ def get_ntp_config( "time_zone_description": ntp_config.dateTimeInfo.timeZone.description, "time_zone_gmt_offset": ntp_config.dateTimeInfo.timeZone.gmtOffset, "ntp_servers": list(ntp_config.dateTimeInfo.ntpConfig.server), - "ntp_config_file": list(ntp_config.dateTimeInfo.ntpConfig.configFile) - if ntp_config.dateTimeInfo.ntpConfig.configFile - else None, + "ntp_config_file": ( + list(ntp_config.dateTimeInfo.ntpConfig.configFile) + if ntp_config.dateTimeInfo.ntpConfig.configFile + else None + ), } return ret except DEFAULT_EXCEPTIONS as exc: @@ -2724,7 +2722,7 @@ def update_role( try: role = get_role(role_name=role_name, service_instance=service_instance) if not role: - raise salt.exceptions.SaltException("Role {} not found".format(role_name)) + raise salt.exceptions.SaltException(f"Role {role_name} not found") service_instance.content.authorizationManager.UpdateAuthorizationRole( roleId=role["role_id"], newName=role_name, privIds=privilege_ids ) @@ -2767,7 +2765,7 @@ def remove_role( try: role = get_role(role_name=role_name, service_instance=service_instance) if not role: - raise salt.exceptions.SaltException("Role {} not found".format(role_name)) + raise salt.exceptions.SaltException(f"Role {role_name} not found") service_instance.content.authorizationManager.RemoveAuthorizationRole( roleId=role["role_id"], failIfUsed=force ) @@ -3576,7 +3574,7 @@ def _get_vsan_eligible_disks(hosts): # No suitable disks were found to add. Warn and move on. # This isn't an error as the state may run repeatedly after all eligible disks are added. if not suitable_disks: - msg = "The host '{}' does not have any VSAN eligible disks.".format(host.name) + msg = f"The host '{host.name}' does not have any VSAN eligible disks." log.warning(msg) ret.update({host.name: {"Eligible": msg}}) continue @@ -3735,14 +3733,12 @@ def vsan_add_disks( ret.update({host_name: {"Error": err.msg}}) continue except Exception as err: - msg = "'vsphere.vsan_add_disks' failed for host {}: {}".format(host_name, err) + msg = f"'vsphere.vsan_add_disks' failed for host {host_name}: {err}" log.debug(msg) ret.update({host_name: {"Error": msg}}) continue - log.debug( - "Successfully added disks to the VSAN system for host '{}'.".format(host_name) - ) + log.debug(f"Successfully added disks to the VSAN system for host '{host_name}'.") # We need to return ONLY the disk names, otherwise Message Pack can't deserialize the disk objects. disk_names = [] for disk in eligible: diff --git a/src/saltext/vmware/modules/nsxt_compute_manager.py b/src/saltext/vmware/modules/nsxt_compute_manager.py index 8e4f67a7..620aee40 100644 --- a/src/saltext/vmware/modules/nsxt_compute_manager.py +++ b/src/saltext/vmware/modules/nsxt_compute_manager.py @@ -1,6 +1,7 @@ """ Execution module for NSX-T compute manager registration and de-registration """ + import json import logging @@ -89,7 +90,7 @@ def get( """ url = BASE_URL.format(management_host=hostname) - log.info("Retrieving compute managers from NSX Manager {}".format(hostname)) + log.info(f"Retrieving compute managers from NSX Manager {hostname}") params = common._filter_kwargs( allowed_kwargs=( diff --git a/src/saltext/vmware/modules/nsxt_ip_blocks.py b/src/saltext/vmware/modules/nsxt_ip_blocks.py index 3542fd39..084e5ebd 100644 --- a/src/saltext/vmware/modules/nsxt_ip_blocks.py +++ b/src/saltext/vmware/modules/nsxt_ip_blocks.py @@ -1,6 +1,7 @@ """ Salt Module to perform CRUD operations for NSX-T's IP Address Blocks """ + import logging from saltext.vmware.utils import common @@ -338,7 +339,7 @@ def update( """ log.info("Updating IP Address block %s", display_name) - url = IP_BLOCKS_BASE_URL.format(hostname) + "/{}".format(ip_block_id) + url = IP_BLOCKS_BASE_URL.format(hostname) + f"/{ip_block_id}" req_data = common._filter_kwargs( allowed_kwargs=["description", "tags"], @@ -406,7 +407,7 @@ def delete( log.info("Deleting IP Address Block %s", ip_block_id) - url = IP_BLOCKS_BASE_URL.format(hostname) + "/{}".format(ip_block_id) + url = IP_BLOCKS_BASE_URL.format(hostname) + f"/{ip_block_id}" response = nsxt_request.call_api( method="delete", diff --git a/src/saltext/vmware/modules/nsxt_ip_pools.py b/src/saltext/vmware/modules/nsxt_ip_pools.py index 15f236bf..d7b3f780 100644 --- a/src/saltext/vmware/modules/nsxt_ip_pools.py +++ b/src/saltext/vmware/modules/nsxt_ip_pools.py @@ -1,6 +1,7 @@ """ Salt Module to perform CRUD operations for NSX-T's IP Address Pools """ + import logging from saltext.vmware.utils import common @@ -387,7 +388,7 @@ def update( """ log.info("Updating IP Address Pool %s", display_name) - url = IP_POOLS_BASE_URL.format(hostname) + "/{}".format(ip_pool_id) + url = IP_POOLS_BASE_URL.format(hostname) + f"/{ip_pool_id}" req_data = common._filter_kwargs( allowed_kwargs=["description", "subnets", "tags", "ip_release_delay"], @@ -456,7 +457,7 @@ def delete( log.info("Deleting IP Address Pool %s", ip_pool_id) - url = IP_POOLS_BASE_URL.format(hostname) + "/{}".format(ip_pool_id) + url = IP_POOLS_BASE_URL.format(hostname) + f"/{ip_pool_id}" response = nsxt_request.call_api( method="delete", diff --git a/src/saltext/vmware/modules/nsxt_license.py b/src/saltext/vmware/modules/nsxt_license.py index 9065c649..9b0b4f7e 100644 --- a/src/saltext/vmware/modules/nsxt_license.py +++ b/src/saltext/vmware/modules/nsxt_license.py @@ -2,6 +2,7 @@ Manage VMware NSX-T Data Center Licenses """ + import json import logging diff --git a/src/saltext/vmware/modules/nsxt_manager.py b/src/saltext/vmware/modules/nsxt_manager.py index 0a7bc77d..be66b3d3 100644 --- a/src/saltext/vmware/modules/nsxt_manager.py +++ b/src/saltext/vmware/modules/nsxt_manager.py @@ -2,6 +2,7 @@ Salt Module to manage VMware NSX-T configuration """ + import json import logging diff --git a/src/saltext/vmware/modules/nsxt_policy_segment.py b/src/saltext/vmware/modules/nsxt_policy_segment.py index 0717c4ff..f582c32f 100644 --- a/src/saltext/vmware/modules/nsxt_policy_segment.py +++ b/src/saltext/vmware/modules/nsxt_policy_segment.py @@ -1,6 +1,7 @@ """ Execution module to perform CRUD operations for NSX-T's Segment """ + import logging from salt.exceptions import SaltInvocationError @@ -322,7 +323,7 @@ def get_hierarchy( nsxt_segment.get_hierarchy( hostname, username, password, segment_id, cert, cert_common_name, verify_ssl, result ) - log.info("Hierarchy result for tier 0 gateway: {}".format(result)) + log.info(f"Hierarchy result for tier 0 gateway: {result}") return result except SaltInvocationError as e: return {"error": str(e)} diff --git a/src/saltext/vmware/modules/nsxt_policy_tier0.py b/src/saltext/vmware/modules/nsxt_policy_tier0.py index eeca1bbb..a7d1039e 100644 --- a/src/saltext/vmware/modules/nsxt_policy_tier0.py +++ b/src/saltext/vmware/modules/nsxt_policy_tier0.py @@ -1,6 +1,7 @@ """ Execution module to perform CRUD operations for NSX-T's Tier 0 Gateway """ + import logging from salt.exceptions import SaltInvocationError @@ -2048,7 +2049,7 @@ def get_hierarchy( nsxt_tier0.get_hierarchy( hostname, username, password, tier0_id, cert, cert_common_name, verify_ssl, result ) - log.info("Hierarchy result for tier 0 gateway: {}".format(result)) + log.info(f"Hierarchy result for tier 0 gateway: {result}") return result except SaltInvocationError as e: return {"error": str(e)} diff --git a/src/saltext/vmware/modules/nsxt_policy_tier1.py b/src/saltext/vmware/modules/nsxt_policy_tier1.py index 8a632343..274e7906 100644 --- a/src/saltext/vmware/modules/nsxt_policy_tier1.py +++ b/src/saltext/vmware/modules/nsxt_policy_tier1.py @@ -1,6 +1,7 @@ """ Execution module to perform CRUD operations for NSX-T's Tier 1 Gateway """ + import logging from salt.exceptions import SaltInvocationError @@ -1691,7 +1692,7 @@ def get_hierarchy( nsxt_tier1.get_hierarchy( hostname, username, password, tier1_id, cert, cert_common_name, verify_ssl, result ) - log.info("Hierarchy result for tier 1 gateway: {}".format(result)) + log.info(f"Hierarchy result for tier 1 gateway: {result}") return result except SaltInvocationError as e: return {"error": str(e)} diff --git a/src/saltext/vmware/modules/nsxt_transport_node.py b/src/saltext/vmware/modules/nsxt_transport_node.py index a5a7a6a9..538e5d2b 100644 --- a/src/saltext/vmware/modules/nsxt_transport_node.py +++ b/src/saltext/vmware/modules/nsxt_transport_node.py @@ -1,6 +1,7 @@ """ Salt execution Module to manage VMware NSX-T transport-nodes """ + import logging from saltext.vmware.utils import common diff --git a/src/saltext/vmware/modules/nsxt_transport_node_profiles.py b/src/saltext/vmware/modules/nsxt_transport_node_profiles.py index 65556113..7b4d1847 100644 --- a/src/saltext/vmware/modules/nsxt_transport_node_profiles.py +++ b/src/saltext/vmware/modules/nsxt_transport_node_profiles.py @@ -1,6 +1,7 @@ """ Salt Module to perform CRUD operations for NSX-T transport node profiles """ + import logging from saltext.vmware.utils import common diff --git a/src/saltext/vmware/modules/nsxt_transport_zone.py b/src/saltext/vmware/modules/nsxt_transport_zone.py index f92f1db7..3a7852d8 100644 --- a/src/saltext/vmware/modules/nsxt_transport_zone.py +++ b/src/saltext/vmware/modules/nsxt_transport_zone.py @@ -1,6 +1,7 @@ """ Salt execution Module to manage VMware NSX-T transport-zones """ + import logging from saltext.vmware.utils import common @@ -373,7 +374,7 @@ def update( (Optional) Opaque identifiers meaningful to the API user """ log.info("Updating transport zones") - url = TRANSPORT_ZONE_BASE_URL.format(hostname) + "/{}".format(transport_zone_id) + url = TRANSPORT_ZONE_BASE_URL.format(hostname) + f"/{transport_zone_id}" update_body = common._filter_kwargs( allowed_kwargs=create_params_for_transport_zones, default_dict={}, @@ -448,7 +449,7 @@ def delete( """ log.info("Deleting transport zones for %s", transport_zone_id) - url = TRANSPORT_ZONE_BASE_URL.format(hostname) + "/{}".format(transport_zone_id) + url = TRANSPORT_ZONE_BASE_URL.format(hostname) + f"/{transport_zone_id}" delete_response = nsxt_request.call_api( method="delete", url=url, diff --git a/src/saltext/vmware/modules/nsxt_uplink_profiles.py b/src/saltext/vmware/modules/nsxt_uplink_profiles.py index 37888714..a9650812 100644 --- a/src/saltext/vmware/modules/nsxt_uplink_profiles.py +++ b/src/saltext/vmware/modules/nsxt_uplink_profiles.py @@ -1,6 +1,7 @@ """ Salt Module to perform CRUD operations for NSX-T uplink profiles """ + import logging from saltext.vmware.utils import common @@ -511,7 +512,7 @@ def update( (Optional) Description for the resource """ log.info("Updating nsxt uplink profile %s", display_name) - url = UPLINK_PROFILES_BASE_URL.format(hostname) + "/{}".format(uplink_profile_id) + url = UPLINK_PROFILES_BASE_URL.format(hostname) + f"/{uplink_profile_id}" req_data = common._filter_kwargs( allowed_kwargs=create_params_for_uplink_profies, default_dict={}, @@ -585,7 +586,7 @@ def delete( compare against certificate common name """ log.info("Deleting uplink profile with id %s", uplink_profile_id) - url = UPLINK_PROFILES_BASE_URL.format(hostname) + "/{}".format(uplink_profile_id) + url = UPLINK_PROFILES_BASE_URL.format(hostname) + f"/{uplink_profile_id}" result = nsxt_request.call_api( method="delete", url=url, diff --git a/src/saltext/vmware/modules/vmc_dhcp_profiles.py b/src/saltext/vmware/modules/vmc_dhcp_profiles.py index 5a378099..2f643983 100644 --- a/src/saltext/vmware/modules/vmc_dhcp_profiles.py +++ b/src/saltext/vmware/modules/vmc_dhcp_profiles.py @@ -2,6 +2,7 @@ Salt execution module for VMC DHCP Profiles Provides methods to Create, Read, Update and Delete DHCP Profiles. """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/modules/vmc_direct_connect.py b/src/saltext/vmware/modules/vmc_direct_connect.py index 476d61fb..1cd8d90a 100644 --- a/src/saltext/vmware/modules/vmc_direct_connect.py +++ b/src/saltext/vmware/modules/vmc_direct_connect.py @@ -2,6 +2,7 @@ Salt execution module for VMC Direct Connect Provides methods to Display Direct Connect Information of an SDDC. """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/modules/vmc_distributed_firewall_rules.py b/src/saltext/vmware/modules/vmc_distributed_firewall_rules.py index 37599fb3..5776b9b3 100644 --- a/src/saltext/vmware/modules/vmc_distributed_firewall_rules.py +++ b/src/saltext/vmware/modules/vmc_distributed_firewall_rules.py @@ -2,6 +2,7 @@ Salt execution module for VMC distributed firewall rules Provides methods to Create, Read, Update and Delete distributed firewall rules. """ + import logging import os diff --git a/src/saltext/vmware/modules/vmc_dns_forwarder.py b/src/saltext/vmware/modules/vmc_dns_forwarder.py index 888e5272..7d39c92c 100644 --- a/src/saltext/vmware/modules/vmc_dns_forwarder.py +++ b/src/saltext/vmware/modules/vmc_dns_forwarder.py @@ -2,6 +2,7 @@ Salt execution module for VMC DNS Forwarder zones and services Provides methods to show DNS zones and services. """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/modules/vmc_nat_rules.py b/src/saltext/vmware/modules/vmc_nat_rules.py index a16f13f2..c6566f77 100644 --- a/src/saltext/vmware/modules/vmc_nat_rules.py +++ b/src/saltext/vmware/modules/vmc_nat_rules.py @@ -2,6 +2,7 @@ Salt execution module for nat rules Provides methods to Create, Update, Read and Delete nat rules. """ + import logging import os diff --git a/src/saltext/vmware/modules/vmc_networks.py b/src/saltext/vmware/modules/vmc_networks.py index e9717279..a09c634a 100644 --- a/src/saltext/vmware/modules/vmc_networks.py +++ b/src/saltext/vmware/modules/vmc_networks.py @@ -2,6 +2,7 @@ Salt execution module for VMC Networks Provides methods to Create, Read, Update and Delete Networks/Segments. """ + import logging from saltext.vmware.utils import vmc_constants @@ -494,7 +495,7 @@ def create( req_data = vmc_request._filter_kwargs( allowed_kwargs=allowed_dict.keys(), allow_none=["tags", "subnets", "l2_extension"], - **allowed_dict + **allowed_dict, ) payload = _create_payload_for_network(network_id, req_data) @@ -765,7 +766,7 @@ def update( req_data = vmc_request._filter_kwargs( allowed_kwargs=allowed_dict.keys(), allow_none=["tags", "subnets", "l2_extension"], - **allowed_dict + **allowed_dict, ) payload = vmc_request.create_payload_for_request( diff --git a/src/saltext/vmware/modules/vmc_org_users.py b/src/saltext/vmware/modules/vmc_org_users.py index 7272429d..1a0ea4a3 100644 --- a/src/saltext/vmware/modules/vmc_org_users.py +++ b/src/saltext/vmware/modules/vmc_org_users.py @@ -2,6 +2,7 @@ Salt execution module for VMC org users. Provides methods to get, add and remove user within a org. """ + import logging from saltext.vmware.utils import vmc_constants @@ -386,7 +387,7 @@ def add( ) if search_result["results"]: log.info("Added %s in the org successfully %s", user_name, org_id) - result.update(message="Added {} successfully".format(user_name)) + result.update(message=f"Added {user_name} successfully") else: # check if user_name is in invitation list api_base_url = vmc_request.set_base_url(hostname) @@ -415,13 +416,13 @@ def add( if user_name == invitation["username"] and invitation["status"] == "AVAILABLE": log.info("Invited %s successfully", user_name) result = { - "message": "Invited {} successfully".format(user_name), + "message": f"Invited {user_name} successfully", "invitation": invitation, } break else: log.info("Failed to add %s", user_name) - result = {vmc_constants.ERROR: "Failed to add {}".format(user_name)} + result = {vmc_constants.ERROR: f"Failed to add {user_name}"} return result diff --git a/src/saltext/vmware/modules/vmc_public_ip.py b/src/saltext/vmware/modules/vmc_public_ip.py index 797b43de..73d40f74 100644 --- a/src/saltext/vmware/modules/vmc_public_ip.py +++ b/src/saltext/vmware/modules/vmc_public_ip.py @@ -2,6 +2,7 @@ Salt execution module for public IP Provides methods to Create, Update, Read and Delete public IP. """ + import json import logging import os diff --git a/src/saltext/vmware/modules/vmc_sddc.py b/src/saltext/vmware/modules/vmc_sddc.py index 0a060a5a..a862f30e 100644 --- a/src/saltext/vmware/modules/vmc_sddc.py +++ b/src/saltext/vmware/modules/vmc_sddc.py @@ -1,6 +1,7 @@ """ Manage VMware VMC SDDC """ + import logging from saltext.vmware.utils import vmc_constants @@ -64,7 +65,7 @@ def list_( """ log.info("Retrieving the List of SDDCs for the given organization %s", org_id) api_base_url = vmc_request.set_base_url(hostname) - api_url = "{base_url}vmc/api/orgs/{org_id}/sddcs".format(base_url=api_base_url, org_id=org_id) + api_url = f"{api_base_url}vmc/api/orgs/{org_id}/sddcs" params = vmc_request._filter_kwargs( allowed_kwargs=["includeDeleted"], @@ -341,7 +342,7 @@ def create( """ log.info("Creating a new SDDC %s in the organization %s", sddc_name, org_id) api_base_url = vmc_request.set_base_url(hostname) - api_url = "{base_url}vmc/api/orgs/{org_id}/sddcs".format(base_url=api_base_url, org_id=org_id) + api_url = f"{api_base_url}vmc/api/orgs/{org_id}/sddcs" allowed_dict = { "name": sddc_name, diff --git a/src/saltext/vmware/modules/vmc_sddc_clusters.py b/src/saltext/vmware/modules/vmc_sddc_clusters.py index bde7451c..09987821 100644 --- a/src/saltext/vmware/modules/vmc_sddc_clusters.py +++ b/src/saltext/vmware/modules/vmc_sddc_clusters.py @@ -2,6 +2,7 @@ Salt execution module for Cluster management Provides methods to Retrieve, Create and Delete cluster in the target SDDC """ + import logging from saltext.vmware.modules import vmc_sddc diff --git a/src/saltext/vmware/modules/vmc_sddc_host.py b/src/saltext/vmware/modules/vmc_sddc_host.py index 0b61ae55..42e97c29 100644 --- a/src/saltext/vmware/modules/vmc_sddc_host.py +++ b/src/saltext/vmware/modules/vmc_sddc_host.py @@ -3,6 +3,7 @@ Provides methods to Add/Remove one or more ESX hosts in the target SDDC """ + import logging from saltext.vmware.modules import vmc_sddc diff --git a/src/saltext/vmware/modules/vmc_security_groups.py b/src/saltext/vmware/modules/vmc_security_groups.py index 63cf9c57..6fe7f1e8 100644 --- a/src/saltext/vmware/modules/vmc_security_groups.py +++ b/src/saltext/vmware/modules/vmc_security_groups.py @@ -2,6 +2,7 @@ Salt execution module for security groups Provides methods to Create, Read, Update and Delete security groups. """ + import logging import os diff --git a/src/saltext/vmware/modules/vmc_security_rules.py b/src/saltext/vmware/modules/vmc_security_rules.py index 84918053..30ba23f0 100644 --- a/src/saltext/vmware/modules/vmc_security_rules.py +++ b/src/saltext/vmware/modules/vmc_security_rules.py @@ -2,6 +2,7 @@ Salt execution module for VMC Security Rules Provides methods to Create, Read, Update and Delete security rules. """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/modules/vmc_vcenter_stats.py b/src/saltext/vmware/modules/vmc_vcenter_stats.py index 26461c24..dd738e53 100644 --- a/src/saltext/vmware/modules/vmc_vcenter_stats.py +++ b/src/saltext/vmware/modules/vmc_vcenter_stats.py @@ -3,6 +3,7 @@ Provides methods to get monitored items list and to query monitored item data for given vCenter. To get the data from this module, admin credentials for vCenter are required. """ + import logging from saltext.vmware.utils import vmc_constants @@ -119,7 +120,7 @@ def query_monitored_items( The certificate can be retrieved from browser. """ - msg = "Retrieving the vCenter monitoring data for {}".format(monitored_items) + msg = f"Retrieving the vCenter monitoring data for {monitored_items}" log.info(msg) api_url_base = vmc_request.set_base_url(hostname) api_url = "{base_url}api/appliance/monitoring/query" diff --git a/src/saltext/vmware/modules/vmc_vm_disks.py b/src/saltext/vmware/modules/vmc_vm_disks.py index def7ec84..aeb3db11 100644 --- a/src/saltext/vmware/modules/vmc_vm_disks.py +++ b/src/saltext/vmware/modules/vmc_vm_disks.py @@ -2,6 +2,7 @@ Salt execution module for VMC vm disks Provides methods to Create, Read, Update and Delete virtual disks from the VM. """ + import logging import os @@ -232,7 +233,7 @@ def update( validation_result.append("vmdk_file") if validation_result: - error_msg = "Mandatory params {} are missing from user input".format(validation_result) + error_msg = f"Mandatory params {validation_result} are missing from user input" log.error(error_msg) return {vmc_constants.ERROR: error_msg} diff --git a/src/saltext/vmware/modules/vmc_vm_stats.py b/src/saltext/vmware/modules/vmc_vm_stats.py index b33cb850..fa73231b 100644 --- a/src/saltext/vmware/modules/vmc_vm_stats.py +++ b/src/saltext/vmware/modules/vmc_vm_stats.py @@ -2,6 +2,7 @@ Salt execution module for VMC vm stats Provides methods to get cpu or memory related settings of a virtual machine """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/modules/vmc_vpn_statistics.py b/src/saltext/vmware/modules/vmc_vpn_statistics.py index af459004..9db30593 100644 --- a/src/saltext/vmware/modules/vmc_vpn_statistics.py +++ b/src/saltext/vmware/modules/vmc_vpn_statistics.py @@ -2,6 +2,7 @@ Salt execution module for VPN statistics Provides methods to Display VPN Statistics and Sessions. """ + import logging from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/returners/merge_changes.py b/src/saltext/vmware/returners/merge_changes.py index 9c7d77b8..e947f2fd 100644 --- a/src/saltext/vmware/returners/merge_changes.py +++ b/src/saltext/vmware/returners/merge_changes.py @@ -9,6 +9,7 @@ Default is ``/var/log/salt/changes``. """ + import logging import salt.returners diff --git a/src/saltext/vmware/returners/merge_changes_esxi.py b/src/saltext/vmware/returners/merge_changes_esxi.py index 4a1bbe21..ace8f721 100644 --- a/src/saltext/vmware/returners/merge_changes_esxi.py +++ b/src/saltext/vmware/returners/merge_changes_esxi.py @@ -9,6 +9,7 @@ Default is ``/var/log/salt/changes``. """ + import logging import salt.returners diff --git a/src/saltext/vmware/states/compliance_control.py b/src/saltext/vmware/states/compliance_control.py index 7e76ef14..d53562e7 100644 --- a/src/saltext/vmware/states/compliance_control.py +++ b/src/saltext/vmware/states/compliance_control.py @@ -87,9 +87,12 @@ def check_control(name, control_config, product, ids=None): ): ret = { "name": name, - "result": None - if check_control_compliance_response["status"] == ComplianceStatus.NON_COMPLIANT - else False, + "result": ( + None + if check_control_compliance_response["status"] + == ComplianceStatus.NON_COMPLIANT + else False + ), "comment": check_control_compliance_response["status"], "changes": check_control_compliance_response.get("changes", {}), } diff --git a/src/saltext/vmware/states/datacenter.py b/src/saltext/vmware/states/datacenter.py index 043c2b22..226691f7 100644 --- a/src/saltext/vmware/states/datacenter.py +++ b/src/saltext/vmware/states/datacenter.py @@ -36,15 +36,15 @@ def present(name): ret = {"name": name, "result": None, "comment": "", "changes": {}} dcs = __salt__["vmware_datacenter.list"]() if name in dcs: - ret["comment"] = "Datacenter {} is already present. No changes made.".format(name) + ret["comment"] = f"Datacenter {name} is already present. No changes made." ret["result"] = True elif __opts__["test"]: - ret["comment"] = "Datacenter {} will be created.".format(name) + ret["comment"] = f"Datacenter {name} will be created." ret["result"] = None else: dc = __salt__["vmware_datacenter.create"](name) if isinstance(dc, dict) and dc.get(name) is not False: - ret["comment"] = "Datacenter - {} created.".format(name) + ret["comment"] = f"Datacenter - {name} created." ret["changes"] = dc ret["result"] = True @@ -67,15 +67,15 @@ def absent(name): ret = {"name": name, "result": None, "comment": "", "changes": {}} dcs = __salt__["vmware_datacenter.list"]() if name not in dcs: - ret["comment"] = "Datacenter {} does not exist. No changes made.".format(name) + ret["comment"] = f"Datacenter {name} does not exist. No changes made." ret["result"] = True elif __opts__["test"]: - ret["comment"] = "Datacenter {} will be deleted.".format(name) + ret["comment"] = f"Datacenter {name} will be deleted." ret["result"] = None else: dc = __salt__["vmware_datacenter.delete"](name) if isinstance(dc, dict) and dc.get(name) is not False: - ret["comment"] = "Datacenter - {} deleted.".format(name) + ret["comment"] = f"Datacenter - {name} deleted." ret["changes"] = dc ret["result"] = True diff --git a/src/saltext/vmware/states/esxi.py b/src/saltext/vmware/states/esxi.py index 32ecb9ac..61faf5f8 100644 --- a/src/saltext/vmware/states/esxi.py +++ b/src/saltext/vmware/states/esxi.py @@ -79,31 +79,31 @@ def role_present(name, privilege_ids, esxi_host_name=None, service_instance=None } if not role: if __opts__["test"]: - ret["comment"] = "Role {} will be created.".format(name) + ret["comment"] = f"Role {name} will be created." ret["result"] = None else: role = __salt__["vmware_esxi.add_role"]( role_name=name, privilege_ids=privilege_ids, service_instance=service_instance ) changes["new"]["role_id"] = role["role_id"] - ret["comment"] = "Role {} created.".format(name) + ret["comment"] = f"Role {name} created." ret["result"] = True ret["changes"] = changes elif not new_privs and not del_privs: - ret["comment"] = "Role {} is in the correct state".format(name) + ret["comment"] = f"Role {name} is in the correct state" ret["result"] = None elif __opts__["test"]: - ret[ - "comment" - ] = "Role {} will be updated. {} privileges will be added. {} privileges will be removed.".format( - name, ",".join(sorted(new_privs)) or "No", ",".join(sorted(del_privs)) or "No" + ret["comment"] = ( + "Role {} will be updated. {} privileges will be added. {} privileges will be removed.".format( + name, ",".join(sorted(new_privs)) or "No", ",".join(sorted(del_privs)) or "No" + ) ) ret["result"] = None else: __salt__["vmware_esxi.update_role"]( role_name=name, privilege_ids=privilege_ids, service_instance=service_instance ) - ret["comment"] = "Role {} updated.".format(name) + ret["comment"] = f"Role {name} updated." ret["result"] = True ret["changes"] = changes return ret @@ -135,14 +135,14 @@ def role_absent(name, esxi_host_name=None, service_instance=None, profile=None): ) role = __salt__["vmware_esxi.get_role"](role_name=name, service_instance=service_instance) if not role: - ret["comment"] = "Role {} is not present.".format(name) + ret["comment"] = f"Role {name} is not present." ret["result"] = None elif __opts__["test"]: - ret["comment"] = "Role {} will be deleted.".format(name) + ret["comment"] = f"Role {name} will be deleted." ret["result"] = None else: __salt__["vmware_esxi.remove_role"](role_name=name, service_instance=service_instance) - ret["comment"] = "Role {} deleted.".format(name) + ret["comment"] = f"Role {name} deleted." ret["result"] = True return ret @@ -277,16 +277,16 @@ def vmkernel_adapter_present( add_on_hosts.append(h.name) if __opts__["test"]: - ret[ - "comment" - ] = "vmkernel adapter {!r} will be created on {} host(s) and updated on {} host(s).".format( - name, len(add_on_hosts), len(update_on_hosts) + ret["comment"] = ( + "vmkernel adapter {!r} will be created on {} host(s) and updated on {} host(s).".format( + name, len(add_on_hosts), len(update_on_hosts) + ) ) ret["result"] = None elif not add_on_hosts and not update_on_hosts: - ret[ - "comment" - ] = "vmkernel adapter {!r} not created/updated on any host. No changes made.".format(name) + ret["comment"] = ( + f"vmkernel adapter {name!r} not created/updated on any host. No changes made." + ) ret["result"] = True else: hosts_in_error = [] @@ -404,7 +404,7 @@ def vmkernel_adapter_absent( ) ret["result"] = None elif not delete_on_hosts: - ret["comment"] = "vmkernel adapter {!r} absent on all hosts. No changes made.".format(name) + ret["comment"] = f"vmkernel adapter {name!r} absent on all hosts. No changes made." else: hosts_in_error = [] sample_exception = None @@ -515,10 +515,10 @@ def user_present( create += 1 for host in diff.copy(): if __opts__["test"]: - ret[ - "comment" - ] = "User {} will be created on {} host(s) and updated on {} host(s).".format( - name, create, update + ret["comment"] = ( + "User {} will be created on {} host(s) and updated on {} host(s).".format( + name, create, update + ) ) ret["result"] = None elif diff[host]["action"] == "update": @@ -537,10 +537,10 @@ def user_present( update -= 1 failed_hosts.append(host) diff.pop(host) - ret[ - "comment" - ] = "User {} created on {} host(s), updated on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( - name, create, update, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ret["comment"] = ( + "User {} created on {} host(s), updated on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( + name, create, update, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ) ) ret["changes"] = diff ret["result"] = False @@ -565,10 +565,10 @@ def user_present( create -= 1 failed_hosts.append(host) diff.pop(host) - ret[ - "comment" - ] = "User {} created on {} host(s), updated on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( - name, create, update, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ret["comment"] = ( + "User {} created on {} host(s), updated on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( + name, create, update, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ) ) ret["changes"] = diff ret["result"] = False @@ -649,7 +649,7 @@ def user_absent( for host in diff.copy(): if __opts__["test"]: if not ret["comment"]: - ret["comment"] = "User {} will be deleted on {} host(s).".format(name, delete) + ret["comment"] = f"User {name} will be deleted on {delete} host(s)." ret["result"] = None elif diff[host][name]: try: @@ -664,19 +664,19 @@ def user_absent( delete -= 1 failed_hosts.append(host) diff.pop(host) - ret[ - "comment" - ] = "User {} removed on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( - name, delete, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ret["comment"] = ( + "User {} removed on {} host(s), failed on {} host(s). List of failed host(s) - {}. Sample Error: {}".format( + name, delete, len(failed_hosts), ",".join(sorted(failed_hosts)), exc + ) ) ret["changes"] = diff ret["result"] = False if not ret["comment"]: - ret["comment"] = "User {} removed on {} host(s).".format(name, delete) + ret["comment"] = f"User {name} removed on {delete} host(s)." ret["changes"] = diff ret["result"] = True if not ret["comment"]: - ret["comment"] = "User {} doesn't exist on {} host(s).".format(name, no_user) + ret["comment"] = f"User {name} doesn't exist on {no_user} host(s)." ret["result"] = None return ret @@ -763,9 +763,9 @@ def maintenance_mode( "new": f"Host entered {'Maintenance' if enter_maintenance_mode else 'Normal'} mode." } else: - ret[ - "comment" - ] = f"Failed to put host {str(name)} in {'Maintenance' if enter_maintenance_mode else 'Normal'} mode." + ret["comment"] = ( + f"Failed to put host {str(name)} in {'Maintenance' if enter_maintenance_mode else 'Normal'} mode." + ) return ret @@ -1220,7 +1220,7 @@ def ntp_config( error = response.get("Error") if error: ret["result"] = False - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret # Set changes dictionary for ntp_servers ret["changes"][host.name].update( @@ -1552,7 +1552,7 @@ def password_present( ) except salt.exceptions.CommandExecutionError as err: ret["result"] = False - ret["comment"] = "Error: {}".format(err) + ret["comment"] = f"Error: {err}" return ret ret["comment"] = "Host password changed." return ret @@ -1628,7 +1628,7 @@ def vsan_config( ) error = current_vsan_enabled.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret current_vsan_enabled = current_vsan_enabled.get(host.name) @@ -1641,7 +1641,7 @@ def vsan_config( ) error = response.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret ret["changes"][host.name].update( {"enabled": {"old": current_vsan_enabled, "new": enabled}} @@ -1654,7 +1654,7 @@ def vsan_config( ) error = current_eligible_disks.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret disks = current_eligible_disks.get("Eligible") if disks and isinstance(disks, list): @@ -1665,7 +1665,7 @@ def vsan_config( ) error = response.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret ret["changes"][host.name].update({"add_disks_to_vsan": {"old": "", "new": disks}}) @@ -1757,7 +1757,7 @@ def vmotion_configured( response = __salt__["vmware_esxi.vmotion_enable"](device=device).get(host) error = response.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret # Disable VMotion if enabled=False else: @@ -1766,7 +1766,7 @@ def vmotion_configured( response = __salt__["vmware_esxi.vmotion_disable"]().get(host) error = response.get("Error") if error: - ret["comment"] = "Error: {}".format(error) + ret["comment"] = f"Error: {error}" return ret ret["changes"].update( {host: {"enabled": {"old": current_vmotion_enabled, "new": enabled}}} @@ -1783,7 +1783,7 @@ def vmotion_configured( except salt.exceptions.CommandExecutionError as err: ret["result"] = False - ret["comment"] = "Error: {}".format(err) + ret["comment"] = f"Error: {err}" return ret return ret diff --git a/src/saltext/vmware/states/nsxt_compute_manager.py b/src/saltext/vmware/states/nsxt_compute_manager.py index d23a8f0f..bad6f7dc 100644 --- a/src/saltext/vmware/states/nsxt_compute_manager.py +++ b/src/saltext/vmware/states/nsxt_compute_manager.py @@ -1,6 +1,7 @@ """ State module for NSX-T compute manager registration and de-registration """ + import logging log = logging.getLogger(__name__) @@ -191,9 +192,9 @@ def present( thumbprint = credential.get("thumbprint", None) else: ret["result"] = False - ret[ - "comment" - ] = "Parameter credential must be of type dictionary. Please refer documentation" + ret["comment"] = ( + "Parameter credential must be of type dictionary. Please refer documentation" + ) return ret if existing_compute_manager is None: @@ -219,10 +220,10 @@ def present( ) return ret else: - ret[ - "comment" - ] = "Compute manager {compute_manager_server} successfully registered with NSX-T".format( - compute_manager_server=compute_manager_server + ret["comment"] = ( + "Compute manager {compute_manager_server} successfully registered with NSX-T".format( + compute_manager_server=compute_manager_server + ) ) ret["changes"]["new"] = result return ret @@ -255,17 +256,17 @@ def present( ) if "error" in result: ret["result"] = False - ret[ - "comment" - ] = "Failed to update existing registration of compute manager with NSX-T Manager : {}".format( - result["error"] + ret["comment"] = ( + "Failed to update existing registration of compute manager with NSX-T Manager : {}".format( + result["error"] + ) ) return ret else: - ret[ - "comment" - ] = "Compute manager {compute_manager_server} registration successfully updated with NSX-T".format( - compute_manager_server=compute_manager_server + ret["comment"] = ( + "Compute manager {compute_manager_server} registration successfully updated with NSX-T".format( + compute_manager_server=compute_manager_server + ) ) ret["changes"]["old"] = existing_compute_manager ret["changes"]["new"] = result @@ -391,10 +392,10 @@ def absent( ) if "error" in result: ret["result"] = False - ret[ - "comment" - ] = "Failed to remove registration of compute manager with NSX-T Manager : {}".format( - result["error"] + ret["comment"] = ( + "Failed to remove registration of compute manager with NSX-T Manager : {}".format( + result["error"] + ) ) return ret else: diff --git a/src/saltext/vmware/states/nsxt_ip_blocks.py b/src/saltext/vmware/states/nsxt_ip_blocks.py index 2c8de51e..682ee3f9 100644 --- a/src/saltext/vmware/states/nsxt_ip_blocks.py +++ b/src/saltext/vmware/states/nsxt_ip_blocks.py @@ -22,6 +22,7 @@ scope: cidr: """ + import logging log = logging.getLogger(__name__) @@ -186,7 +187,7 @@ def present( None, None, False, - "Multiple IP Blocks found for the provided display name {}".format(display_name), + f"Multiple IP Blocks found for the provided display name {display_name}", ) existing_ip_block = ip_blocks[0] if len(ip_blocks) > 0 else None @@ -199,7 +200,7 @@ def present( None, None, None, - "State present will update IP Block with name {}".format(display_name), + f"State present will update IP Block with name {display_name}", ) else: return _create_state_response( @@ -207,7 +208,7 @@ def present( None, None, None, - "State present will create IP Block with name {}".format(display_name), + f"State present will create IP Block with name {display_name}", ) if existing_ip_block: is_update_required = _check_for_updates(existing_ip_block, input_dict) @@ -239,7 +240,7 @@ def present( existing_ip_block, updated_ip_block, True, - "Updated IP Block {}".format(display_name), + f"Updated IP Block {display_name}", ) else: log.info("All fields are same as existing IP Address Block %s", display_name) @@ -265,7 +266,7 @@ def present( return _create_state_response(name, None, None, False, created_ip_block["error"]) return _create_state_response( - name, None, created_ip_block, True, "Created IP Block {}".format(display_name) + name, None, created_ip_block, True, f"Created IP Block {display_name}" ) @@ -348,7 +349,7 @@ def absent( None, None, False, - "Multiple IP Blocks found for the provided display name {}".format(display_name), + f"Multiple IP Blocks found for the provided display name {display_name}", ) existing_ip_block = ip_blocks[0] if len(ip_blocks) > 0 else None @@ -361,7 +362,7 @@ def absent( None, None, None, - "State absent will delete IP Block with name {}".format(display_name), + f"State absent will delete IP Block with name {display_name}", ) else: return _create_state_response( @@ -390,10 +391,10 @@ def absent( return _create_state_response(name, None, None, False, deleted_response["error"]) return _create_state_response( - name, existing_ip_block, None, True, "Deleted IP Block {}".format(display_name) + name, existing_ip_block, None, True, f"Deleted IP Block {display_name}" ) else: log.info("No IP Address Block found with name %s", display_name) return _create_state_response( - name, None, None, True, "No IP Address Block found with name {}".format(display_name) + name, None, None, True, f"No IP Address Block found with name {display_name}" ) diff --git a/src/saltext/vmware/states/nsxt_ip_pools.py b/src/saltext/vmware/states/nsxt_ip_pools.py index 015049f5..72a2314b 100644 --- a/src/saltext/vmware/states/nsxt_ip_pools.py +++ b/src/saltext/vmware/states/nsxt_ip_pools.py @@ -31,6 +31,7 @@ "end": ip_release_delay: """ + import logging log = logging.getLogger(__name__) @@ -223,7 +224,7 @@ def present( None, None, False, - "Multiple IP Pools found for the provided display name {}".format(display_name), + f"Multiple IP Pools found for the provided display name {display_name}", ) existing_ip_pool = ip_pools[0] if len(ip_pools) > 0 else None @@ -236,7 +237,7 @@ def present( None, None, None, - "State present will update IP Pool with name {}".format(display_name), + f"State present will update IP Pool with name {display_name}", ) else: return _create_state_response( @@ -244,7 +245,7 @@ def present( None, None, None, - "State present will create IP Pool with name {}".format(display_name), + f"State present will create IP Pool with name {display_name}", ) if existing_ip_pool: is_update_required = _needs_update(existing_ip_pool, input_dict) @@ -277,7 +278,7 @@ def present( existing_ip_pool, updated_ip_pool, True, - "Updated IP Pool {}".format(display_name), + f"Updated IP Pool {display_name}", ) else: log.info("All fields are same as existing IP Address Pool %s", display_name) @@ -304,7 +305,7 @@ def present( return _create_state_response(name, None, None, False, created_ip_pool["error"]) return _create_state_response( - name, None, created_ip_pool, True, "Created IP Pool {}".format(display_name) + name, None, created_ip_pool, True, f"Created IP Pool {display_name}" ) @@ -387,7 +388,7 @@ def absent( None, None, False, - "Multiple IP Pools found for the provided display name {}".format(display_name), + f"Multiple IP Pools found for the provided display name {display_name}", ) existing_ip_pool = ip_pools[0] if len(ip_pools) > 0 else None @@ -400,7 +401,7 @@ def absent( None, None, None, - "State absent will delete IP Pool with name {}".format(display_name), + f"State absent will delete IP Pool with name {display_name}", ) else: return _create_state_response( @@ -429,10 +430,10 @@ def absent( return _create_state_response(name, None, None, False, deleted_response["error"]) return _create_state_response( - name, existing_ip_pool, None, True, "Deleted IP Pool {}".format(display_name) + name, existing_ip_pool, None, True, f"Deleted IP Pool {display_name}" ) else: log.info("No IP Address Pool found with name %s", display_name) return _create_state_response( - name, None, None, True, "No IP Address Pool found with name {}".format(display_name) + name, None, None, True, f"No IP Address Pool found with name {display_name}" ) diff --git a/src/saltext/vmware/states/nsxt_license.py b/src/saltext/vmware/states/nsxt_license.py index 6221fa5b..c60b0465 100644 --- a/src/saltext/vmware/states/nsxt_license.py +++ b/src/saltext/vmware/states/nsxt_license.py @@ -136,10 +136,10 @@ def present( if "error" in get_licenses_result_after_apply: ret["result"] = False - ret[ - "comment" - ] = "Failed to retrieve licenses after applying current license from NSX-T Manager : {}".format( - get_licenses_result_after_apply["error"] + ret["comment"] = ( + "Failed to retrieve licenses after applying current license from NSX-T Manager : {}".format( + get_licenses_result_after_apply["error"] + ) ) return ret diff --git a/src/saltext/vmware/states/nsxt_manager.py b/src/saltext/vmware/states/nsxt_manager.py index d3a1fb22..ba10c0fc 100644 --- a/src/saltext/vmware/states/nsxt_manager.py +++ b/src/saltext/vmware/states/nsxt_manager.py @@ -26,6 +26,7 @@ files. """ + import logging log = logging.getLogger(__name__) diff --git a/src/saltext/vmware/states/nsxt_policy_segment.py b/src/saltext/vmware/states/nsxt_policy_segment.py index 1e6aa625..18512837 100644 --- a/src/saltext/vmware/states/nsxt_policy_segment.py +++ b/src/saltext/vmware/states/nsxt_policy_segment.py @@ -1,6 +1,7 @@ """ State module for NSX-T segment """ + import logging log = logging.getLogger(__name__) @@ -707,7 +708,7 @@ def present( segment_ports=segment_ports, ) - log.info("Execution logs for segment create : {}".format(execution_logs_create)) + log.info(f"Execution logs for segment create : {execution_logs_create}") if "error" in execution_logs_create[len(execution_logs_create) - 1]: ret["result"] = False ret["comment"] = "Failed while doing create segment or its sub resource: {}".format( @@ -799,7 +800,7 @@ def present( segment_ports=segment_ports, ) - log.info("Execution logs for updating segment : {}".format(execution_logs_update)) + log.info(f"Execution logs for updating segment : {execution_logs_update}") if "error" in execution_logs_update[len(execution_logs_update) - 1]: ret["result"] = False ret["comment"] = "Failed while updating segment and sub-resources: {}".format( @@ -964,16 +965,16 @@ def absent( cert_common_name=cert_common_name, segment_id=segment_id, ) - log.info("Execution logs for deleting segment : {}".format(execution_logs_delete)) + log.info(f"Execution logs for deleting segment : {execution_logs_delete}") if "error" in execution_logs_delete[len(execution_logs_delete) - 1]: ret["result"] = False - ret["comment"] = "Failed to delete segment : {}".format(execution_logs_delete) + ret["comment"] = f"Failed to delete segment : {execution_logs_delete}" return ret else: - ret[ - "comment" - ] = "Segment with display_name: {} and its sub-resources deleted successfully".format( - display_name + ret["comment"] = ( + "Segment with display_name: {} and its sub-resources deleted successfully".format( + display_name + ) ) ret["changes"]["old"] = segment_hierarchy ret["changes"]["new"] = {} diff --git a/src/saltext/vmware/states/nsxt_policy_tier0.py b/src/saltext/vmware/states/nsxt_policy_tier0.py index 7e5e167a..3f29d716 100644 --- a/src/saltext/vmware/states/nsxt_policy_tier0.py +++ b/src/saltext/vmware/states/nsxt_policy_tier0.py @@ -1,6 +1,7 @@ """ State module for NSX-T tier0 gateway """ + import logging log = logging.getLogger(__name__) @@ -1467,14 +1468,14 @@ def present( locale_services=locale_services, ) - log.info("Execution logs for creating tier 0 : {}".format(create_execution_logs)) + log.info(f"Execution logs for creating tier 0 : {create_execution_logs}") if "error" in create_execution_logs[len(create_execution_logs) - 1]: ret["result"] = False - ret[ - "comment" - ] = "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( - create_execution_logs[len(create_execution_logs) - 1]["error"], - create_execution_logs, + ret["comment"] = ( + "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( + create_execution_logs[len(create_execution_logs) - 1]["error"], + create_execution_logs, + ) ) return ret tier0_execution_log = next( @@ -1521,10 +1522,10 @@ def present( ) if "error" in tier0_hierarchy_before_update: ret["result"] = False - ret[ - "comment" - ] = "Failed while querying tier0 gateway and its sub-resources.: {}".format( - tier0_hierarchy_before_update["error"] + ret["comment"] = ( + "Failed while querying tier0 gateway and its sub-resources.: {}".format( + tier0_hierarchy_before_update["error"] + ) ) return ret @@ -1558,7 +1559,7 @@ def present( locale_services=locale_services, ) - log.info("Execution logs for updating tier 0 : {}".format(update_execution_logs)) + log.info(f"Execution logs for updating tier 0 : {update_execution_logs}") # update execution logs can come empty if there is nothing to update if ( @@ -1566,11 +1567,11 @@ def present( and "error" in update_execution_logs[len(update_execution_logs) - 1] ): ret["result"] = False - ret[ - "comment" - ] = "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( - update_execution_logs[len(update_execution_logs) - 1]["error"], - update_execution_logs, + ret["comment"] = ( + "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( + update_execution_logs[len(update_execution_logs) - 1]["error"], + update_execution_logs, + ) ) return ret @@ -1585,10 +1586,10 @@ def present( ) if "error" in tier0_hierarchy_after_update: ret["result"] = False - ret[ - "comment" - ] = "Failure while querying tier0 gateway and its sub-resources: {}".format( - tier0_hierarchy_after_update["error"] + ret["comment"] = ( + "Failure while querying tier0 gateway and its sub-resources: {}".format( + tier0_hierarchy_after_update["error"] + ) ) return ret @@ -1710,10 +1711,10 @@ def absent( ) if "error" in tier0_hierarchy: ret["result"] = False - ret[ - "comment" - ] = "Failure while querying tier0 gateway and its sub-resources: {}".format( - tier0_hierarchy["error"] + ret["comment"] = ( + "Failure while querying tier0 gateway and its sub-resources: {}".format( + tier0_hierarchy["error"] + ) ) return ret @@ -1726,7 +1727,7 @@ def absent( cert=cert, cert_common_name=cert_common_name, ) - log.info("Execution logs for deleting tier 0 : {}".format(delete_execution_logs)) + log.info(f"Execution logs for deleting tier 0 : {delete_execution_logs}") if "error" in delete_execution_logs[len(delete_execution_logs) - 1]: ret["result"] = False ret["comment"] = "Failed to delete tier0 gateway : {}\n Execution logs: {}".format( @@ -1735,10 +1736,10 @@ def absent( ) return ret else: - ret[ - "comment" - ] = "Tier0 gateway with display_name: {} and its sub-resources deleted successfully".format( - display_name + ret["comment"] = ( + "Tier0 gateway with display_name: {} and its sub-resources deleted successfully".format( + display_name + ) ) ret["changes"]["old"] = tier0_hierarchy ret["changes"]["new"] = {} diff --git a/src/saltext/vmware/states/nsxt_policy_tier1.py b/src/saltext/vmware/states/nsxt_policy_tier1.py index ac12dad4..35000677 100644 --- a/src/saltext/vmware/states/nsxt_policy_tier1.py +++ b/src/saltext/vmware/states/nsxt_policy_tier1.py @@ -1,6 +1,7 @@ """ State module for NSX-T tier1 gateway """ + import logging log = logging.getLogger(__name__) @@ -1157,14 +1158,14 @@ def present( arp_limit=arp_limit, type=type, ) - log.info("Execution logs for creating tier 1 : {}".format(create_execution_logs)) + log.info(f"Execution logs for creating tier 1 : {create_execution_logs}") if "error" in create_execution_logs[len(create_execution_logs) - 1]: ret["result"] = False - ret[ - "comment" - ] = "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( - create_execution_logs[len(create_execution_logs) - 1]["error"], - create_execution_logs, + ret["comment"] = ( + "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( + create_execution_logs[len(create_execution_logs) - 1]["error"], + create_execution_logs, + ) ) return ret tier1_execution_log = next( @@ -1210,10 +1211,10 @@ def present( ) if "error" in tier1_hierarchy_before_update: ret["result"] = False - ret[ - "comment" - ] = "Failed while querying tier1 gateway and its sub-resources.: {}".format( - tier1_hierarchy_before_update["error"] + ret["comment"] = ( + "Failed while querying tier1 gateway and its sub-resources.: {}".format( + tier1_hierarchy_before_update["error"] + ) ) return ret update_execution_logs = __salt__["nsxt_policy_tier1.create_or_update"]( @@ -1250,18 +1251,18 @@ def present( arp_limit=arp_limit, type=type, ) - log.info("Execution logs for updating tier 1 : {}".format(update_execution_logs)) + log.info(f"Execution logs for updating tier 1 : {update_execution_logs}") # update execution logs can come empty if there is nothing to update if ( update_execution_logs and "error" in update_execution_logs[len(update_execution_logs) - 1] ): ret["result"] = False - ret[ - "comment" - ] = "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( - update_execution_logs[len(update_execution_logs) - 1]["error"], - update_execution_logs, + ret["comment"] = ( + "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( + update_execution_logs[len(update_execution_logs) - 1]["error"], + update_execution_logs, + ) ) return ret tier1_hierarchy_after_update = __salt__["nsxt_policy_tier1.get_hierarchy"]( @@ -1275,10 +1276,10 @@ def present( ) if "error" in tier1_hierarchy_after_update: ret["result"] = False - ret[ - "comment" - ] = "Failure while querying tier1 gateway and its sub-resources: {}".format( - tier1_hierarchy_after_update["error"] + ret["comment"] = ( + "Failure while querying tier1 gateway and its sub-resources: {}".format( + tier1_hierarchy_after_update["error"] + ) ) return ret ret["comment"] = "Updated Tier-1 gateway {display_name} successfully".format( @@ -1404,10 +1405,10 @@ def absent( ) if "error" in tier1_hierarchy: ret["result"] = False - ret[ - "comment" - ] = "Failure while querying tier1 gateway and its sub-resources: {}".format( - tier1_hierarchy["error"] + ret["comment"] = ( + "Failure while querying tier1 gateway and its sub-resources: {}".format( + tier1_hierarchy["error"] + ) ) return ret delete_execution_logs = __salt__["nsxt_policy_tier1.delete"]( @@ -1419,7 +1420,7 @@ def absent( cert=cert, cert_common_name=cert_common_name, ) - log.info("Execution logs for deleting tier 1 : {}".format(delete_execution_logs)) + log.info(f"Execution logs for deleting tier 1 : {delete_execution_logs}") if "error" in delete_execution_logs[len(delete_execution_logs) - 1]: ret["result"] = False ret["comment"] = "Failed to delete tier1 gateway : {} \n Execution logs: {}".format( @@ -1428,10 +1429,10 @@ def absent( ) return ret else: - ret[ - "comment" - ] = "tier1 gateway with display_name: {} and its sub-resources deleted successfully".format( - display_name + ret["comment"] = ( + "tier1 gateway with display_name: {} and its sub-resources deleted successfully".format( + display_name + ) ) ret["changes"]["old"] = tier1_hierarchy ret["changes"]["new"] = {} diff --git a/src/saltext/vmware/states/nsxt_transport_node.py b/src/saltext/vmware/states/nsxt_transport_node.py index 8b619bf6..a7201461 100644 --- a/src/saltext/vmware/states/nsxt_transport_node.py +++ b/src/saltext/vmware/states/nsxt_transport_node.py @@ -51,6 +51,7 @@ password: "ca$hc0w" thumbprint: "e7fd7dd84267da10f991812ca62b2bedea3a4a62965396a04728da1e7f8e1cb9" """ + import logging import salt.utils.dictdiffer @@ -239,10 +240,10 @@ def _get_id_for_resource( return if len(get_transport_zone_response["results"]) > 1: ret["result"] = False - ret[ - "comment" - ] = "More than one transport zone exist with same display name : {}".format( - resource_name + ret["comment"] = ( + "More than one transport zone exist with same display name : {}".format( + resource_name + ) ) return transport_zone_response_by_display_name = get_transport_zone_response["results"] @@ -273,10 +274,10 @@ def _get_id_for_resource( return if len(get_host_switch_profile["results"]) > 1: ret["result"] = False - ret[ - "comment" - ] = "More than one host switch profile exist with same display name : {}".format( - resource_name + ret["comment"] = ( + "More than one host switch profile exist with same display name : {}".format( + resource_name + ) ) return host_profile_profile_by_display_name = get_host_switch_profile["results"] @@ -307,10 +308,10 @@ def _get_id_for_resource( return if len(get_compute_manager_response["results"]) > 1: ret["result"] = False - ret[ - "comment" - ] = "More than one host compute managers exist with same display name : {}".format( - resource_name + ret["comment"] = ( + "More than one host compute managers exist with same display name : {}".format( + resource_name + ) ) return compute_manager_by_display_name = get_compute_manager_response["results"] @@ -339,10 +340,10 @@ def _get_id_for_resource( return if len(get_compute_manager_response["results"]) > 1: ret["result"] = False - ret[ - "comment" - ] = "More than one host compute managers exist with same display name : {}".format( - resource_name + ret["comment"] = ( + "More than one host compute managers exist with same display name : {}".format( + resource_name + ) ) return compute_manager_by_display_name = get_compute_manager_response["results"] diff --git a/src/saltext/vmware/states/nsxt_transport_node_profiles.py b/src/saltext/vmware/states/nsxt_transport_node_profiles.py index f6a7c21a..991ba837 100644 --- a/src/saltext/vmware/states/nsxt_transport_node_profiles.py +++ b/src/saltext/vmware/states/nsxt_transport_node_profiles.py @@ -1,6 +1,7 @@ """ State module for NSX-T transport node profiles """ + import logging import salt.utils.dictdiffer @@ -74,7 +75,7 @@ def _get_by_display_name_result_from_module( ) } if not result["results"]: - return {"error": "No results for {} with display_name {}".format(module_name, display_name)} + return {"error": f"No results for {module_name} with display_name {display_name}"} return result["results"][0] @@ -91,7 +92,7 @@ def _get_by_display_name( url=url, username=username, password=password, - **kwargs + **kwargs, ) if "error" in object_list: @@ -104,7 +105,7 @@ def _get_by_display_name( ) } if not object_list: - return {"error": "No results for {} with display_name {}".format(object_type, display_name)} + return {"error": f"No results for {object_type} with display_name {display_name}"} return object_list[0] @@ -535,9 +536,9 @@ def present( log.info( "Update is not required. Transport node profile with same params already exists" ) - ret[ - "comment" - ] = "Transport node profile already exists with similar params. No action to perform" + ret["comment"] = ( + "Transport node profile already exists with similar params. No action to perform" + ) return ret @@ -637,10 +638,10 @@ def absent( if __opts__["test"]: if result_count == 0: ret["result"] = None - ret[ - "comment" - ] = "No transport node profile with display_name: {} found in NSX-T Manager".format( - display_name + ret["comment"] = ( + "No transport node profile with display_name: {} found in NSX-T Manager".format( + display_name + ) ) else: ret["result"] = None @@ -650,10 +651,10 @@ def absent( return ret if result_count == 0: - ret[ - "comment" - ] = "No transport node profile with display_name: {} found in NSX-T Manager".format( - display_name + ret["comment"] = ( + "No transport node profile with display_name: {} found in NSX-T Manager".format( + display_name + ) ) return ret else: @@ -674,10 +675,10 @@ def absent( ) return ret else: - ret[ - "comment" - ] = "Transport node profile with display_name: {} successfully deleted".format( - display_name + ret["comment"] = ( + "Transport node profile with display_name: {} successfully deleted".format( + display_name + ) ) ret["changes"]["old"] = transport_node_profile_to_delete ret["changes"]["new"] = {} diff --git a/src/saltext/vmware/states/nsxt_transport_zone.py b/src/saltext/vmware/states/nsxt_transport_zone.py index 761f071b..d82a4d11 100644 --- a/src/saltext/vmware/states/nsxt_transport_zone.py +++ b/src/saltext/vmware/states/nsxt_transport_zone.py @@ -1,6 +1,7 @@ """ NSX-T Transport_Zone state module """ + import logging log = logging.getLogger(__name__) @@ -370,7 +371,7 @@ def absent( if len(transport_zone_response_by_display_name) == 0: ret["result"] = True - ret["comment"] = "No transport zone exist with same display name : {}".format(display_name) + ret["comment"] = f"No transport zone exist with same display name : {display_name}" return ret if transport_zone_dict is not None: diff --git a/src/saltext/vmware/states/nsxt_uplink_profiles.py b/src/saltext/vmware/states/nsxt_uplink_profiles.py index 6b9a4544..47fa2d89 100644 --- a/src/saltext/vmware/states/nsxt_uplink_profiles.py +++ b/src/saltext/vmware/states/nsxt_uplink_profiles.py @@ -1,6 +1,7 @@ """ State module for NSX-T uplink profiles """ + import logging import salt.utils.dictdiffer @@ -338,7 +339,7 @@ def present( ret["comment"] = create_result["error"] return ret - ret["comment"] = "Created uplink profile {display_name}".format(display_name=display_name) + ret["comment"] = f"Created uplink profile {display_name}" ret["changes"]["new"] = create_result return ret else: @@ -386,7 +387,7 @@ def present( teaming=teaming, uplink_profile_id=existing_uplink_profile["id"], revision=existing_uplink_profile["_revision"], - **optional_params_dict + **optional_params_dict, ) if "error" in update_result: @@ -402,9 +403,9 @@ def present( return ret else: log.info("Update is not required. Uplink profile with same params already exists") - ret[ - "comment" - ] = "Uplink profile already exists with similar params. No action to perform" + ret["comment"] = ( + "Uplink profile already exists with similar params. No action to perform" + ) return ret @@ -501,10 +502,10 @@ def absent( if __opts__["test"]: if result_count == 0: ret["result"] = None - ret[ - "comment" - ] = "No uplink profile with display_name: {} found in NSX-T Manager".format( - display_name + ret["comment"] = ( + "No uplink profile with display_name: {} found in NSX-T Manager".format( + display_name + ) ) else: ret["result"] = None diff --git a/src/saltext/vmware/states/vmc_dhcp_profiles.py b/src/saltext/vmware/states/vmc_dhcp_profiles.py index 1b1b4f4c..ac3566e9 100644 --- a/src/saltext/vmware/states/vmc_dhcp_profiles.py +++ b/src/saltext/vmware/states/vmc_dhcp_profiles.py @@ -26,6 +26,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -185,12 +186,12 @@ def present( if dhcp_profile: return vmc_state._create_state_response( name=name, - comment="State present will update DHCP Profile {}".format(dhcp_profile_id), + comment=f"State present will update DHCP Profile {dhcp_profile_id}", ) else: return vmc_state._create_state_response( name=name, - comment="State present will create DHCP Profile {}".format(dhcp_profile_id), + comment=f"State present will create DHCP Profile {dhcp_profile_id}", ) if dhcp_profile: @@ -237,7 +238,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated DHCP Profile {}".format(dhcp_profile_id), + comment=f"Updated DHCP Profile {dhcp_profile_id}", old_state=dhcp_profile, new_state=updated_dhcp_profile, result=True, @@ -271,7 +272,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created DHCP Profile {}".format(dhcp_profile_id), + comment=f"Created DHCP Profile {dhcp_profile_id}", new_state=created_dhcp_profile, result=True, ) @@ -347,7 +348,7 @@ def absent( if dhcp_profile: return vmc_state._create_state_response( name=name, - comment="State absent will delete DHCP Profile with Id {}".format(dhcp_profile_id), + comment=f"State absent will delete DHCP Profile with Id {dhcp_profile_id}", ) else: return vmc_state._create_state_response( @@ -378,7 +379,7 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted DHCP Profile {}".format(dhcp_profile_id), + comment=f"Deleted DHCP Profile {dhcp_profile_id}", old_state=dhcp_profile, result=True, ) @@ -386,6 +387,6 @@ def absent( log.info("No DHCP Profile found with Id %s", dhcp_profile_id) return vmc_state._create_state_response( name=name, - comment="No DHCP Profile found with Id {}".format(dhcp_profile_id), + comment=f"No DHCP Profile found with Id {dhcp_profile_id}", result=True, ) diff --git a/src/saltext/vmware/states/vmc_distributed_firewall_rules.py b/src/saltext/vmware/states/vmc_distributed_firewall_rules.py index 066ab957..3d74161d 100644 --- a/src/saltext/vmware/states/vmc_distributed_firewall_rules.py +++ b/src/saltext/vmware/states/vmc_distributed_firewall_rules.py @@ -27,6 +27,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -314,7 +315,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated distributed firewall rule {}".format(rule_id), + comment=f"Updated distributed firewall rule {rule_id}", old_state=distributed_firewall_rule, new_state=updated_distributed_firewall_rule, result=True, @@ -361,7 +362,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created distributed firewall rule {}".format(rule_id), + comment=f"Created distributed firewall rule {rule_id}", new_state=created_distributed_firewall_rule, result=True, ) @@ -478,7 +479,7 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted distributed firewall rule {}".format(rule_id), + comment=f"Deleted distributed firewall rule {rule_id}", old_state=distributed_firewall_rule, result=True, ) @@ -486,6 +487,6 @@ def absent( log.info("No distributed firewall rule found with ID %s", rule_id) return vmc_state._create_state_response( name=name, - comment="No distributed firewall rule found with ID {}".format(rule_id), + comment=f"No distributed firewall rule found with ID {rule_id}", result=True, ) diff --git a/src/saltext/vmware/states/vmc_nat_rules.py b/src/saltext/vmware/states/vmc_nat_rules.py index 37cf0466..7343e35c 100644 --- a/src/saltext/vmware/states/vmc_nat_rules.py +++ b/src/saltext/vmware/states/vmc_nat_rules.py @@ -29,6 +29,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -312,7 +313,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated nat rule {}".format(nat_rule), + comment=f"Updated nat rule {nat_rule}", old_state=get_nat_rule_response, new_state=updated_nat_rule, result=True, @@ -357,7 +358,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created nat rule {}".format(nat_rule), + comment=f"Created nat rule {nat_rule}", new_state=created_nat_rule, result=True, ) @@ -436,7 +437,7 @@ def absent( log.info("absent is called with test option") if get_nat_rule_response: return vmc_state._create_state_response( - name=name, comment="State absent will delete nat rule with Id {}".format(nat_rule) + name=name, comment=f"State absent will delete nat rule with Id {nat_rule}" ) else: return vmc_state._create_state_response( @@ -468,12 +469,12 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted nat rule {}".format(nat_rule), + comment=f"Deleted nat rule {nat_rule}", old_state=get_nat_rule_response, result=True, ) else: log.info("No nat rule found with Id %s", nat_rule) return vmc_state._create_state_response( - name=name, comment="No nat rule found with Id {}".format(nat_rule), result=True + name=name, comment=f"No nat rule found with Id {nat_rule}", result=True ) diff --git a/src/saltext/vmware/states/vmc_networks.py b/src/saltext/vmware/states/vmc_networks.py index 6dc6faf4..5748a3ca 100644 --- a/src/saltext/vmware/states/vmc_networks.py +++ b/src/saltext/vmware/states/vmc_networks.py @@ -25,6 +25,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -268,11 +269,11 @@ def present( log.info("present is called with test option") if network: return vmc_state._create_state_response( - name=name, comment="State present will update network {}".format(network_id) + name=name, comment=f"State present will update network {network_id}" ) else: return vmc_state._create_state_response( - name=name, comment="State present will create network {}".format(network_id) + name=name, comment=f"State present will create network {network_id}" ) if network: @@ -325,7 +326,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated network {}".format(network_id), + comment=f"Updated network {network_id}", old_state=network, new_state=updated_network, result=True, @@ -363,7 +364,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created network {}".format(network_id), + comment=f"Created network {network_id}", new_state=created_network, result=True, ) @@ -433,7 +434,7 @@ def absent( log.info("absent is called with test option") if network: return vmc_state._create_state_response( - name=name, comment="State absent will delete network with ID {}".format(network_id) + name=name, comment=f"State absent will delete network with ID {network_id}" ) else: return vmc_state._create_state_response( @@ -463,12 +464,12 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted network {}".format(network_id), + comment=f"Deleted network {network_id}", old_state=network, result=True, ) else: log.info("No Network found with Id %s", network_id) return vmc_state._create_state_response( - name=name, comment="No network found with ID {}".format(network_id), result=True + name=name, comment=f"No network found with ID {network_id}", result=True ) diff --git a/src/saltext/vmware/states/vmc_org_user.py b/src/saltext/vmware/states/vmc_org_user.py index e50f7ed8..71a1795e 100644 --- a/src/saltext/vmware/states/vmc_org_user.py +++ b/src/saltext/vmware/states/vmc_org_user.py @@ -21,6 +21,7 @@ It is recommended to pass the VMC authentication details using Pillars rather than specifying as plain text in SLS files. """ + import logging from saltext.vmware.utils import vmc_state @@ -168,12 +169,12 @@ def invited( if org_user: return vmc_state._create_state_response( name=name, - comment="User {} is already part of the organization".format(username), + comment=f"User {username} is already part of the organization", ) else: return vmc_state._create_state_response( name=name, - comment="User {} would have been invited".format(username), + comment=f"User {username} would have been invited", ) if not org_user: @@ -209,7 +210,7 @@ def invited( else: return vmc_state._create_state_response( name=name, - comment="User {} is already part of the organization".format(username), + comment=f"User {username} is already part of the organization", result=True, ) @@ -296,7 +297,7 @@ def absent( log.info("vmc_org_user.absent is called with test option") return vmc_state._create_state_response( name=name, - comment="Would have removed user with username {}".format(username), + comment=f"Would have removed user with username {username}", ) else: removed_org_user = __salt__["vmc_org_users.remove"]( @@ -316,7 +317,7 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Removed user {}".format(username), + comment=f"Removed user {username}", old_state=org_user, result=True, ) @@ -327,6 +328,6 @@ def absent( ) return vmc_state._create_state_response( name=name, - comment="No user found with username {}".format(username), + comment=f"No user found with username {username}", result=True, ) diff --git a/src/saltext/vmware/states/vmc_public_ip.py b/src/saltext/vmware/states/vmc_public_ip.py index f5048ccd..2e188f74 100644 --- a/src/saltext/vmware/states/vmc_public_ip.py +++ b/src/saltext/vmware/states/vmc_public_ip.py @@ -24,6 +24,7 @@ files. """ + import logging from saltext.vmware.utils import vmc_state @@ -127,7 +128,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated public IP {}".format(public_ip_id), + comment=f"Updated public IP {public_ip_id}", old_state=public_ip_response, new_state=updated_public_ip, result=True, @@ -156,7 +157,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created public IP {}".format(public_ip_id), + comment=f"Created public IP {public_ip_id}", new_state=created_public_ip, result=True, ) @@ -228,7 +229,7 @@ def absent( if public_ip_response: return vmc_state._create_state_response( name=name, - comment="State absent will delete public IP with ID {}".format(public_ip_id), + comment=f"State absent will delete public IP with ID {public_ip_id}", ) else: return vmc_state._create_state_response( @@ -258,12 +259,12 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted public IP {}".format(public_ip_id), + comment=f"Deleted public IP {public_ip_id}", old_state=public_ip_response, result=True, ) else: log.info("No public IP found with ID %s", public_ip_id) return vmc_state._create_state_response( - name=name, comment="No public IP found with ID {}".format(public_ip_id), result=True + name=name, comment=f"No public IP found with ID {public_ip_id}", result=True ) diff --git a/src/saltext/vmware/states/vmc_sddc.py b/src/saltext/vmware/states/vmc_sddc.py index 5ccee522..649292e9 100644 --- a/src/saltext/vmware/states/vmc_sddc.py +++ b/src/saltext/vmware/states/vmc_sddc.py @@ -31,6 +31,7 @@ files. """ + import logging from saltext.vmware.utils import vmc_state @@ -221,7 +222,7 @@ def present( log.info("vmc_sddc present is called with test option") return vmc_state._create_state_response( name=name, - comment="SDDC {} would have been created".format(sddc_name), + comment=f"SDDC {sddc_name} would have been created", ) created_sddc = __salt__["vmc_sddc.create"]( @@ -259,7 +260,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created SDDC {}".format(sddc_name), + comment=f"Created SDDC {sddc_name}", new_state=created_sddc, result=True, ) @@ -277,7 +278,6 @@ def absent( verify_ssl=True, cert=None, ): - """ Ensure a given SDDC does not exist for the given organization. @@ -346,7 +346,7 @@ def absent( if vmc_sddc: return vmc_state._create_state_response( name=name, - comment="State absent will delete SDDC with ID {}".format(sddc_id), + comment=f"State absent will delete SDDC with ID {sddc_id}", ) else: return vmc_state._create_state_response( @@ -378,7 +378,7 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted SDDC {}".format(sddc_id), + comment=f"Deleted SDDC {sddc_id}", old_state=vmc_sddc, result=True, ) diff --git a/src/saltext/vmware/states/vmc_security_groups.py b/src/saltext/vmware/states/vmc_security_groups.py index 32085648..459a4196 100644 --- a/src/saltext/vmware/states/vmc_security_groups.py +++ b/src/saltext/vmware/states/vmc_security_groups.py @@ -25,6 +25,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -237,7 +238,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated security group {}".format(security_group_id), + comment=f"Updated security group {security_group_id}", old_state=security_group, new_state=updated_security_group, result=True, @@ -273,7 +274,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created security group {}".format(security_group_id), + comment=f"Created security group {security_group_id}", new_state=created_security_group, result=True, ) @@ -384,7 +385,7 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted security group {}".format(security_group_id), + comment=f"Deleted security group {security_group_id}", old_state=security_group, result=True, ) @@ -392,6 +393,6 @@ def absent( log.info("No security group found with ID %s", security_group_id) return vmc_state._create_state_response( name=name, - comment="No security group found with ID {}".format(security_group_id), + comment=f"No security group found with ID {security_group_id}", result=True, ) diff --git a/src/saltext/vmware/states/vmc_security_rules.py b/src/saltext/vmware/states/vmc_security_rules.py index 67915d68..2595aa9d 100644 --- a/src/saltext/vmware/states/vmc_security_rules.py +++ b/src/saltext/vmware/states/vmc_security_rules.py @@ -26,6 +26,7 @@ """ + import logging from saltext.vmware.utils import vmc_constants @@ -250,11 +251,11 @@ def present( log.info("present is called with test option") if existing_security_rule: return vmc_state._create_state_response( - name=name, comment="State present will update Security rule {}".format(rule_id) + name=name, comment=f"State present will update Security rule {rule_id}" ) else: return vmc_state._create_state_response( - name=name, comment="State present will create Security rule {}".format(rule_id) + name=name, comment=f"State present will create Security rule {rule_id}" ) if existing_security_rule: @@ -312,7 +313,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Updated Security rule {}".format(rule_id), + comment=f"Updated Security rule {rule_id}", old_state=existing_security_rule, new_state=get_security_rule_after_update, result=True, @@ -354,7 +355,7 @@ def present( return vmc_state._create_state_response( name=name, - comment="Created Security rule {}".format(rule_id), + comment=f"Created Security rule {rule_id}", new_state=created_security_rule, result=True, ) @@ -434,7 +435,7 @@ def absent( if existing_security_rule: return vmc_state._create_state_response( name=name, - comment="State absent will delete Security rule with Id {}".format(rule_id), + comment=f"State absent will delete Security rule with Id {rule_id}", ) else: return vmc_state._create_state_response( @@ -465,12 +466,12 @@ def absent( return vmc_state._create_state_response( name=name, - comment="Deleted Security rule {}".format(rule_id), + comment=f"Deleted Security rule {rule_id}", old_state=existing_security_rule, result=True, ) else: log.info("No Security rule found with Id %s", rule_id) return vmc_state._create_state_response( - name=name, comment="No Security rule found with Id {}".format(rule_id), result=True + name=name, comment=f"No Security rule found with Id {rule_id}", result=True ) diff --git a/src/saltext/vmware/utils/cluster.py b/src/saltext/vmware/utils/cluster.py index 7dd17762..e5b1b6cb 100644 --- a/src/saltext/vmware/utils/cluster.py +++ b/src/saltext/vmware/utils/cluster.py @@ -172,7 +172,7 @@ def delete_cluster(service_instance, cluster_name, datacenter_name): except vim.fault.NoPermission as exc: log.exception(exc) raise salt.exceptions.VMwareApiError( - "Not enough permissions. Required privilege: {}".format(exc.privilegeId) + f"Not enough permissions. Required privilege: {exc.privilegeId}" ) except vim.fault.VimFault as exc: log.exception(exc) diff --git a/src/saltext/vmware/utils/common.py b/src/saltext/vmware/utils/common.py index 8e89bd0b..5828000f 100644 --- a/src/saltext/vmware/utils/common.py +++ b/src/saltext/vmware/utils/common.py @@ -583,7 +583,7 @@ def wait_for_task(task, instance_name, task_type, sleep_seconds=1, log_level="de log.exception(exc) exc_message = exc.msg if exc.faultMessage: - exc_message = "{} ({})".format(exc_message, exc.faultMessage[0].message) + exc_message = f"{exc_message} ({exc.faultMessage[0].message})" raise salt.exceptions.VMwareApiError(exc_message) @@ -664,7 +664,7 @@ def get_datacenter(service_instance, datacenter_name): items = get_datacenters(service_instance, datacenter_names=[datacenter_name]) if not items: raise salt.exceptions.VMwareObjectRetrievalError( - "Datacenter '{}' was not found".format(datacenter_name) + f"Datacenter '{datacenter_name}' was not found" ) return items[0] @@ -903,7 +903,7 @@ def get_storage_system(service_instance, host_ref, hostname=None): ) if not objs: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' storage system was not retrieved".format(hostname) + f"Host's '{hostname}' storage system was not retrieved" ) log.trace("[%s] Retrieved storage system", hostname) return objs[0]["object"] @@ -935,7 +935,7 @@ def _get_scsi_address_to_lun_key_map( except vim.fault.NoPermission as exc: log.exception(exc) raise salt.exceptions.VMwareApiError( - "Not enough permissions. Required privilege: {}".format(exc.privilegeId) + f"Not enough permissions. Required privilege: {exc.privilegeId}" ) except vim.fault.VimFault as exc: log.exception(exc) @@ -945,16 +945,16 @@ def _get_scsi_address_to_lun_key_map( raise salt.exceptions.VMwareRuntimeError(exc.msg) if not device_info: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' storage device info was not retrieved".format(hostname) + f"Host's '{hostname}' storage device info was not retrieved" ) multipath_info = device_info.multipathInfo if not multipath_info: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' multipath info was not retrieved".format(hostname) + f"Host's '{hostname}' multipath info was not retrieved" ) if multipath_info.lun is None: raise salt.exceptions.VMwareObjectRetrievalError( - "No luns were retrieved from host '{}'".format(hostname) + f"No luns were retrieved from host '{hostname}'" ) lun_key_by_scsi_addr = {} for l in multipath_info.lun: @@ -985,14 +985,14 @@ def get_all_luns(host_ref, storage_system=None, hostname=None): storage_system = get_storage_system(si, host_ref, hostname) if not storage_system: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' storage system was not retrieved".format(hostname) + f"Host's '{hostname}' storage system was not retrieved" ) try: device_info = storage_system.storageDeviceInfo except vim.fault.NoPermission as exc: log.exception(exc) raise salt.exceptions.VMwareApiError( - "Not enough permissions. Required privilege: {}".format(exc.privilegeId) + f"Not enough permissions. Required privilege: {exc.privilegeId}" ) except vim.fault.VimFault as exc: log.exception(exc) @@ -1002,7 +1002,7 @@ def get_all_luns(host_ref, storage_system=None, hostname=None): raise salt.exceptions.VMwareRuntimeError(exc.msg) if not device_info: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' storage device info was not retrieved".format(hostname) + f"Host's '{hostname}' storage device info was not retrieved" ) scsi_luns = device_info.scsiLun @@ -1149,7 +1149,7 @@ def get_diskgroups(host_ref, cache_disk_ids=None, get_all_disk_groups=False): except vim.fault.NoPermission as exc: log.exception(exc) raise salt.exceptions.VMwareApiError( - "Not enough permissions. Required privilege: {}".format(exc.privilegeId) + f"Not enough permissions. Required privilege: {exc.privilegeId}" ) except vim.fault.VimFault as exc: log.exception(exc) @@ -1159,12 +1159,12 @@ def get_diskgroups(host_ref, cache_disk_ids=None, get_all_disk_groups=False): raise salt.exceptions.VMwareRuntimeError(exc.msg) if not vsan_host_config: raise salt.exceptions.VMwareObjectRetrievalError( - "No host config found on host '{}'".format(hostname) + f"No host config found on host '{hostname}'" ) vsan_storage_info = vsan_host_config.storageInfo if not vsan_storage_info: raise salt.exceptions.VMwareObjectRetrievalError( - "No vsan storage info found on host '{}'".format(hostname) + f"No vsan storage info found on host '{hostname}'" ) vsan_disk_mappings = vsan_storage_info.diskMapping if not vsan_disk_mappings: diff --git a/src/saltext/vmware/utils/esxi.py b/src/saltext/vmware/utils/esxi.py index 8d696516..5d32cc40 100644 --- a/src/saltext/vmware/utils/esxi.py +++ b/src/saltext/vmware/utils/esxi.py @@ -120,9 +120,7 @@ def configure_host_cache(host_ref, datastore_ref, swap_size_MiB, host_cache_mana host_ref, ["configManager.cacheConfigurationManager"] ) if not props.get("configManager.cacheConfigurationManager"): - raise salt.exceptions.VMwareObjectRetrievalError( - "Host '{}' has no host cache".format(hostname) - ) + raise salt.exceptions.VMwareObjectRetrievalError(f"Host '{hostname}' has no host cache") host_cache_manager = props["configManager.cacheConfigurationManager"] log.trace( "Configuring the host cache on host '%s', datastore '%s', " "swap size=%s MiB", @@ -371,7 +369,7 @@ def get_firewall_config( "ip_address": list(ruleset.allowedHosts.ipAddress), "all_ip": ruleset.allowedHosts.allIp, "ip_network": [ - "{}/{}".format(ip.network, ip.prefixLength) + f"{ip.network}/{ip.prefixLength}" for ip in ruleset.allowedHosts.ipNetwork ], }, diff --git a/src/saltext/vmware/utils/nsxt_policy_base_resource.py b/src/saltext/vmware/utils/nsxt_policy_base_resource.py index 834497e1..fb943b38 100644 --- a/src/saltext/vmware/utils/nsxt_policy_base_resource.py +++ b/src/saltext/vmware/utils/nsxt_policy_base_resource.py @@ -148,7 +148,7 @@ def create_or_update( cert_common_name=None, verify_ssl=True, execution_logs=[], - **kwargs + **kwargs, ): # must call this method for creation of resource and sub-resources @@ -312,7 +312,7 @@ def _patch_subresource(self, execution_logs, **kwargs): self.nsx_resource_params.get("cert_common_name"), self.nsx_resource_params.get("verify_ssl"), execution_logs, - **kwargs + **kwargs, ) self._parent_info["_parent"] = my_parent @@ -470,7 +470,7 @@ def _delete_resource_with_id(self, execution_logs, resource_id): execution_logs.append( { "resourceType": self.get_spec_identifier(), - "results": "{} deleted successfully".format(resource_id), + "results": f"{resource_id} deleted successfully", } ) diff --git a/src/saltext/vmware/utils/nsxt_request.py b/src/saltext/vmware/utils/nsxt_request.py index c2c37326..4a128cc1 100644 --- a/src/saltext/vmware/utils/nsxt_request.py +++ b/src/saltext/vmware/utils/nsxt_request.py @@ -1,6 +1,7 @@ """ NSX-T API Request Module """ + import json import logging @@ -52,7 +53,7 @@ def call_api( params=params, data=json.dumps(data), ) - log.info("Response status code: {}".format(response.status_code)) + log.info(f"Response status code: {response.status_code}") # raise error for any client/server HTTP Error codes response.raise_for_status() diff --git a/src/saltext/vmware/utils/vm.py b/src/saltext/vmware/utils/vm.py index 4066af55..6da7da28 100644 --- a/src/saltext/vmware/utils/vm.py +++ b/src/saltext/vmware/utils/vm.py @@ -100,7 +100,7 @@ def power_cycle_vm(virtual_machine, action="on"): " ".join( [ "An error occurred during power", - "operation, a file was not found: {}".format(exc), + f"operation, a file was not found: {exc}", ] ) ) diff --git a/src/saltext/vmware/utils/vmc_request.py b/src/saltext/vmware/utils/vmc_request.py index 80cd153d..da2c9664 100644 --- a/src/saltext/vmware/utils/vmc_request.py +++ b/src/saltext/vmware/utils/vmc_request.py @@ -1,6 +1,7 @@ """ VMC API Request Module """ + import json import logging import os diff --git a/src/saltext/vmware/utils/vmc_state.py b/src/saltext/vmware/utils/vmc_state.py index 541d3619..6cd25bf4 100644 --- a/src/saltext/vmware/utils/vmc_state.py +++ b/src/saltext/vmware/utils/vmc_state.py @@ -1,6 +1,7 @@ """ Util Module for VMC states. """ + from salt.utils import dictdiffer from saltext.vmware.utils import vmc_constants diff --git a/src/saltext/vmware/utils/vmc_vcenter_request.py b/src/saltext/vmware/utils/vmc_vcenter_request.py index 5d9eb398..7f63143c 100644 --- a/src/saltext/vmware/utils/vmc_vcenter_request.py +++ b/src/saltext/vmware/utils/vmc_vcenter_request.py @@ -1,6 +1,7 @@ """ VMC vCenter API Request Module """ + import logging import requests diff --git a/src/saltext/vmware/utils/vsphere.py b/src/saltext/vmware/utils/vsphere.py index cd58a203..bd5e020c 100644 --- a/src/saltext/vmware/utils/vsphere.py +++ b/src/saltext/vmware/utils/vsphere.py @@ -197,7 +197,7 @@ def _get_service_instance( ) raise salt.exceptions.CommandExecutionError(err_msg) else: - raise salt.exceptions.CommandExecutionError("Unsupported mechanism: '{}'".format(mechanism)) + raise salt.exceptions.CommandExecutionError(f"Unsupported mechanism: '{mechanism}'") log.trace( "Connecting using the '%s' mechanism, with username '%s'", @@ -641,7 +641,7 @@ def get_gssapi_token(principal, host, domain): if not HAS_GSSAPI: raise ImportError("The gssapi library is not imported.") - service = "{}/{}@{}".format(principal, host, domain) + service = f"{principal}/{host}@{domain}" log.debug("Retrieving gsspi token for service %s", service) service_name = gssapi.Name(service, gssapi.C_NT_USER_NAME) ctx = gssapi.InitContext(service_name) @@ -1096,7 +1096,7 @@ def get_uplink_dvportgroup(dvs_ref): ] if not items: raise salt.exceptions.VMwareObjectRetrievalError( - "Uplink portgroup of DVS '{}' wasn't found".format(dvs_name) + f"Uplink portgroup of DVS '{dvs_name}' wasn't found" ) return items[0] @@ -1573,7 +1573,7 @@ def get_datastore_files(service_instance, directory, datastores, container_objec for datobj in datastore_objects: try: task = datobj.browser.SearchDatastore_Task( - datastorePath="[{}] {}".format(datobj.name, directory), + datastorePath=f"[{datobj.name}] {directory}", searchSpec=browser_spec, ) except vim.fault.NoPermission as exc: @@ -1897,7 +1897,7 @@ def _get_scsi_address_to_lun_key_map( ) if multipath_info.lun is None: raise salt.exceptions.VMwareObjectRetrievalError( - "No luns were retrieved from host '{}'".format(hostname) + f"No luns were retrieved from host '{hostname}'" ) lun_key_by_scsi_addr = {} for l in multipath_info.lun: @@ -2083,7 +2083,7 @@ def get_disk_partition_info(host_ref, disk_id, storage_system=None): ) if not props.get("storageDeviceInfo.scsiLun"): raise salt.exceptions.VMwareObjectRetrievalError( - "No devices were retrieved in host '{}'".format(hostname) + f"No devices were retrieved in host '{hostname}'" ) log.trace( "[%s] Retrieved %s devices: %s", @@ -2150,7 +2150,7 @@ def erase_disk_partitions(service_instance, host_ref, disk_id, hostname=None, st ) if not results: raise salt.exceptions.VMwareObjectRetrievalError( - "Host's '{}' devices were not retrieved".format(hostname) + f"Host's '{hostname}' devices were not retrieved" ) log.trace( "[%s] Retrieved %s devices: %s", @@ -2230,12 +2230,12 @@ def get_diskgroups(host_ref, cache_disk_ids=None, get_all_disk_groups=False): raise salt.exceptions.VMwareRuntimeError(exc.msg) if not vsan_host_config: raise salt.exceptions.VMwareObjectRetrievalError( - "No host config found on host '{}'".format(hostname) + f"No host config found on host '{hostname}'" ) vsan_storage_info = vsan_host_config.storageInfo if not vsan_storage_info: raise salt.exceptions.VMwareObjectRetrievalError( - "No vsan storage info found on host '{}'".format(hostname) + f"No vsan storage info found on host '{hostname}'" ) vsan_disk_mappings = vsan_storage_info.diskMapping if not vsan_disk_mappings: @@ -2463,7 +2463,7 @@ def get_proxy_target(service_instance): "ESXi host '{}' was not found".format(details["esxi_host"]) ) reference = references[0] - log.trace("reference = {}".format(reference)) + log.trace(f"reference = {reference}") return reference diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 0695caa1..d8032754 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -290,8 +290,9 @@ def patch_salt_globals_datacenter(vmware_conf, patch_salt_globals): """ Patch __opts__ and __pillar__ """ - with patch.dict(datacenter_mod.__opts__, {"test": False}), patch.dict( - datacenter_mod.__pillar__, vmware_conf + with ( + patch.dict(datacenter_mod.__opts__, {"test": False}), + patch.dict(datacenter_mod.__pillar__, vmware_conf), ): yield @@ -301,8 +302,9 @@ def patch_salt_globals_tag(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(tagging, "__opts__", {"test": False}, create=True), patch.object( - tagging, "__pillar__", vmware_conf, create=True + with ( + patch.object(tagging, "__opts__", {"test": False}, create=True), + patch.object(tagging, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/modules/test_datastore.py b/tests/integration/modules/test_datastore.py index 3bb70280..3fa3929b 100644 --- a/tests/integration/modules/test_datastore.py +++ b/tests/integration/modules/test_datastore.py @@ -11,8 +11,9 @@ def patch_salt_globals_datastore(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(datastore, "__opts__", {}, create=True), patch.object( - datastore, "__pillar__", vmware_conf, create=True + with ( + patch.object(datastore, "__opts__", {}, create=True), + patch.object(datastore, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/modules/test_esxi.py b/tests/integration/modules/test_esxi.py index 76b873c8..8fbc5d6f 100644 --- a/tests/integration/modules/test_esxi.py +++ b/tests/integration/modules/test_esxi.py @@ -585,7 +585,7 @@ def test_add_update_remove_user(service_instance): """ Test add/get/update/remove a local ESXi user """ - user_name = "A{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" ret = esxi.add_user( service_instance=service_instance, datacenter_name="Datacenter", @@ -654,7 +654,7 @@ def test_add_update_remove_role(service_instance): """ Test add/update/remove a local ESXi role """ - role_name = "A{}".format(uuid.uuid4()) + role_name = f"A{uuid.uuid4()}" ret = esxi.add_role( service_instance=service_instance, role_name=role_name, diff --git a/tests/integration/modules/test_folder.py b/tests/integration/modules/test_folder.py index 0afb5032..d4bd39fc 100644 --- a/tests/integration/modules/test_folder.py +++ b/tests/integration/modules/test_folder.py @@ -11,8 +11,9 @@ def patch_salt_globals_folder(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(folder, "__opts__", {}, create=True), patch.object( - folder, "__pillar__", vmware_conf, create=True + with ( + patch.object(folder, "__opts__", {}, create=True), + patch.object(folder, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/modules/test_nsxt_ip_blocks.py b/tests/integration/modules/test_nsxt_ip_blocks.py index 108f9fb1..d11b1fb9 100644 --- a/tests/integration/modules/test_nsxt_ip_blocks.py +++ b/tests/integration/modules/test_nsxt_ip_blocks.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_ip_blocks module """ + from urllib.parse import urljoin import pytest @@ -41,7 +42,7 @@ def _delete_ip_block(hostname, password, salt_call_cli, updated_ip_block_json, u password=password, verify_ssl=False, ip_block_id=updated_ip_block_json["id"], - **updated_ip_block_json + **updated_ip_block_json, ).json @@ -54,7 +55,7 @@ def _update_ip_block(created_ip_block_json, hostname, password, salt_call_cli, u revision=created_ip_block_json["_revision"], ip_block_id=created_ip_block_json["id"], verify_ssl=False, - **created_ip_block_json + **created_ip_block_json, ).json @@ -65,7 +66,7 @@ def _create_ip_block(hostname, password, request_data, salt_call_cli, username): username=username, password=password, verify_ssl=False, - **request_data + **request_data, ).json diff --git a/tests/integration/modules/test_nsxt_ip_pools.py b/tests/integration/modules/test_nsxt_ip_pools.py index 7d07f738..35aab1ea 100644 --- a/tests/integration/modules/test_nsxt_ip_pools.py +++ b/tests/integration/modules/test_nsxt_ip_pools.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_ip_pools module """ + from urllib.parse import urljoin import pytest @@ -42,7 +43,7 @@ def _delete_ip_pool(hostname, password, salt_call_cli, updated_ip_pool_json, use password=password, verify_ssl=False, ip_pool_id=updated_ip_pool_json["id"], - **updated_ip_pool_json + **updated_ip_pool_json, ).json @@ -55,7 +56,7 @@ def _update_ip_pool(created_ip_pool_json, hostname, password, salt_call_cli, use revision=created_ip_pool_json["_revision"], ip_pool_id=created_ip_pool_json["id"], verify_ssl=False, - **created_ip_pool_json + **created_ip_pool_json, ).json @@ -66,7 +67,7 @@ def _create_ip_pool(hostname, password, request_data, salt_call_cli, username): username=username, password=password, verify_ssl=False, - **request_data + **request_data, ).json diff --git a/tests/integration/modules/test_nsxt_manager.py b/tests/integration/modules/test_nsxt_manager.py index 28f14960..4ba626bd 100644 --- a/tests/integration/modules/test_nsxt_manager.py +++ b/tests/integration/modules/test_nsxt_manager.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_manager execution module """ + import pytest from saltext.vmware.utils import nsxt_request diff --git a/tests/integration/modules/test_nsxt_transport_node.py b/tests/integration/modules/test_nsxt_transport_node.py index 4f9f1623..a4a389d2 100644 --- a/tests/integration/modules/test_nsxt_transport_node.py +++ b/tests/integration/modules/test_nsxt_transport_node.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt-transport-nodes module """ + import pytest _hostname = "" diff --git a/tests/integration/modules/test_nsxt_transport_node_profiles.py b/tests/integration/modules/test_nsxt_transport_node_profiles.py index dde01c28..73b6060b 100644 --- a/tests/integration/modules/test_nsxt_transport_node_profiles.py +++ b/tests/integration/modules/test_nsxt_transport_node_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_transport_node_profiles execution module """ + import json import pytest @@ -280,7 +281,7 @@ def _create_transport_zone_using_nsxt_api(nsxt_config, display_name): payload = { "display_name": display_name, "host_switch_name": "test-host-switch-1", - "description": "Transport Zone: {}".format(display_name), + "description": f"Transport Zone: {display_name}", "transport_type": "OVERLAY", } headers = {"Accept": "application/json", "content-Type": "application/json"} diff --git a/tests/integration/modules/test_nsxt_transport_zone.py b/tests/integration/modules/test_nsxt_transport_zone.py index 5e7a0672..b5e83846 100644 --- a/tests/integration/modules/test_nsxt_transport_zone.py +++ b/tests/integration/modules/test_nsxt_transport_zone.py @@ -17,7 +17,7 @@ def setup(nsxt_config): @pytest.fixture def delete_transport_zone(): - url = "https://{management_host}/api/v1/transport-zones".format(management_host=_hostname) + url = f"https://{_hostname}/api/v1/transport-zones" session = requests.Session() headers = dict({"Accept": "application/json", "Content-Type": "application/json"}) verify_ssl = False diff --git a/tests/integration/modules/test_nsxt_uplink_profiles.py b/tests/integration/modules/test_nsxt_uplink_profiles.py index 8aa546b0..c95c233f 100644 --- a/tests/integration/modules/test_nsxt_uplink_profiles.py +++ b/tests/integration/modules/test_nsxt_uplink_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_uplink_profiles execution module """ + import pytest import requests @@ -113,7 +114,7 @@ def _create_uplink_profile(nsxt_config, request_data, salt_call_cli): username=username, password=password, verify_ssl=False, - **request_data + **request_data, ).json @@ -145,7 +146,7 @@ def _update_uplink_profile(nsxt_config, uplink_profile_json, salt_call_cli): revision=uplink_profile_json["_revision"], uplink_profile_id=uplink_profile_json["id"], verify_ssl=False, - **uplink_profile_json + **uplink_profile_json, ).json diff --git a/tests/integration/modules/test_vm.py b/tests/integration/modules/test_vm.py index f55420e7..83fc1b00 100644 --- a/tests/integration/modules/test_vm.py +++ b/tests/integration/modules/test_vm.py @@ -23,8 +23,9 @@ def patch_salt_globals_vm(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(virtual_machine, "__opts__", {}, create=True), patch.object( - virtual_machine, "__pillar__", vmware_conf, create=True + with ( + patch.object(virtual_machine, "__opts__", {}, create=True), + patch.object(virtual_machine, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/modules/test_vmc_dhcp_profiles.py b/tests/integration/modules/test_vmc_dhcp_profiles.py index 34aa0cd8..b8f5a7ee 100644 --- a/tests/integration/modules/test_vmc_dhcp_profiles.py +++ b/tests/integration/modules/test_vmc_dhcp_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_dhcp_profiles execution module """ + import pytest import requests from saltext.vmware.utils import vmc_constants @@ -94,9 +95,9 @@ def delete_dhcp_profile( session = requests.Session() response = session.delete( url=profile_url, - verify=common_data_for_dhcp["cert"] - if common_data_for_dhcp["verify_ssl"] - else False, + verify=( + common_data_for_dhcp["cert"] if common_data_for_dhcp["verify_ssl"] else False + ), headers=request_headers, ) # raise error if any diff --git a/tests/integration/modules/test_vmc_distributed_firewall_rules.py b/tests/integration/modules/test_vmc_distributed_firewall_rules.py index 61d46418..2d5f4766 100644 --- a/tests/integration/modules/test_vmc_distributed_firewall_rules.py +++ b/tests/integration/modules/test_vmc_distributed_firewall_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_distributed_firewall_rules execution module """ + import json import pytest diff --git a/tests/integration/modules/test_vmc_dns_forwarder.py b/tests/integration/modules/test_vmc_dns_forwarder.py index a8cc17ff..f0637c4e 100644 --- a/tests/integration/modules/test_vmc_dns_forwarder.py +++ b/tests/integration/modules/test_vmc_dns_forwarder.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_dns_forwarder execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request diff --git a/tests/integration/modules/test_vmc_nat_rules.py b/tests/integration/modules/test_vmc_nat_rules.py index 48e2979f..48374bef 100644 --- a/tests/integration/modules/test_vmc_nat_rules.py +++ b/tests/integration/modules/test_vmc_nat_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_nat_rules execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request diff --git a/tests/integration/modules/test_vmc_networks.py b/tests/integration/modules/test_vmc_networks.py index a09e1f5a..412f3934 100644 --- a/tests/integration/modules/test_vmc_networks.py +++ b/tests/integration/modules/test_vmc_networks.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_networks execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request @@ -81,9 +82,11 @@ def delete_network(get_networks, network_url, common_data_for_network, request_h session = requests.Session() response = session.delete( url=network_url, - verify=common_data_for_network["cert"] - if common_data_for_network["verify_ssl"] - else False, + verify=( + common_data_for_network["cert"] + if common_data_for_network["verify_ssl"] + else False + ), headers=request_headers, ) # raise error if any @@ -106,7 +109,7 @@ def test_vmc_network_execution_module( "vmc_networks.update", network_id=network_id, display_name="network1", - **common_data_for_network + **common_data_for_network, ) response_as_json = response.json assert "error" not in response_as_json diff --git a/tests/integration/modules/test_vmc_org_users.py b/tests/integration/modules/test_vmc_org_users.py index 387e6643..c2cd73be 100644 --- a/tests/integration/modules/test_vmc_org_users.py +++ b/tests/integration/modules/test_vmc_org_users.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_org_users execution module """ + import json import pytest @@ -35,7 +36,7 @@ def test_org_users_smoke_test(salt_call_cli, vmc_common_data): ) result_as_json = ret.json assert "error" not in result_as_json - assert "Invited {} successfully".format(user_name) in result_as_json["message"] + assert f"Invited {user_name} successfully" in result_as_json["message"] # search the user ret = salt_call_cli.run( diff --git a/tests/integration/modules/test_vmc_public_ip.py b/tests/integration/modules/test_vmc_public_ip.py index 043f0e14..722a0be1 100644 --- a/tests/integration/modules/test_vmc_public_ip.py +++ b/tests/integration/modules/test_vmc_public_ip.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_public_ip execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request diff --git a/tests/integration/modules/test_vmc_sddc.py b/tests/integration/modules/test_vmc_sddc.py index af50e9e3..931bc86d 100644 --- a/tests/integration/modules/test_vmc_sddc.py +++ b/tests/integration/modules/test_vmc_sddc.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_sddc execution module """ + import json import pytest diff --git a/tests/integration/modules/test_vmc_sddc_clusters.py b/tests/integration/modules/test_vmc_sddc_clusters.py index 559a7dc2..8bf2b7fb 100644 --- a/tests/integration/modules/test_vmc_sddc_clusters.py +++ b/tests/integration/modules/test_vmc_sddc_clusters.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_sddc_cluster execution module """ + import json import os diff --git a/tests/integration/modules/test_vmc_sddc_host.py b/tests/integration/modules/test_vmc_sddc_host.py index 22c743e5..03af287a 100644 --- a/tests/integration/modules/test_vmc_sddc_host.py +++ b/tests/integration/modules/test_vmc_sddc_host.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_sddc_host execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request diff --git a/tests/integration/modules/test_vmc_security_groups.py b/tests/integration/modules/test_vmc_security_groups.py index 10a8fdcd..79f99735 100644 --- a/tests/integration/modules/test_vmc_security_groups.py +++ b/tests/integration/modules/test_vmc_security_groups.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_security_groups execution module """ + import json import pytest diff --git a/tests/integration/modules/test_vmc_security_rules.py b/tests/integration/modules/test_vmc_security_rules.py index f9944c00..429c631a 100644 --- a/tests/integration/modules/test_vmc_security_rules.py +++ b/tests/integration/modules/test_vmc_security_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_security_rules execution module """ + import pytest import requests from saltext.vmware.utils import vmc_request diff --git a/tests/integration/modules/test_vmc_vm_disks.py b/tests/integration/modules/test_vmc_vm_disks.py index 4896e0e5..92ca491a 100644 --- a/tests/integration/modules/test_vmc_vm_disks.py +++ b/tests/integration/modules/test_vmc_vm_disks.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_vm_disks execution module """ + import pytest import requests from saltext.vmware.utils import vmc_vcenter_request diff --git a/tests/integration/modules/test_vmc_vm_stats.py b/tests/integration/modules/test_vmc_vm_stats.py index e1842583..c6f25704 100644 --- a/tests/integration/modules/test_vmc_vm_stats.py +++ b/tests/integration/modules/test_vmc_vm_stats.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_vm_stats execution module """ + import pytest diff --git a/tests/integration/states/test_datastore.py b/tests/integration/states/test_datastore.py index 00589247..de925322 100644 --- a/tests/integration/states/test_datastore.py +++ b/tests/integration/states/test_datastore.py @@ -11,8 +11,9 @@ def patch_salt_globals_datastore_state(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(datastore, "__opts__", {"test": False}, create=True), patch.object( - datastore, "__pillar__", vmware_conf, create=True + with ( + patch.object(datastore, "__opts__", {"test": False}, create=True), + patch.object(datastore, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/states/test_esxi.py b/tests/integration/states/test_esxi.py index 42fb901c..43a3dc2c 100644 --- a/tests/integration/states/test_esxi.py +++ b/tests/integration/states/test_esxi.py @@ -41,8 +41,8 @@ def test_user_present_absent(patch_salt_globals): """ Test scenarios for user_present state run """ - user_name = "A{}".format(uuid.uuid4()) - random_user = "Random{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" + random_user = f"Random{uuid.uuid4()}" password = "Secret@123" # create a new user @@ -74,7 +74,7 @@ def test_user_add_error(patch_salt_globals, user_add_error): """ Test scenarios for user add error """ - user_name = "A{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" password = "Secret@123" ret = esxi.user_present(name=user_name, password=password) assert ret["result"] is False @@ -87,7 +87,7 @@ def test_user_remove_error(patch_salt_globals, user_remove_error): Test scenarios for user remove error """ # Remove the user - user_name = "A{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" password = "Secret@123" ret = esxi.user_present(name=user_name, password=password) assert ret["result"] is True @@ -102,7 +102,7 @@ def test_user_update_error(patch_salt_globals, user_update_error): Test scenarios for user remove error """ # Remove the user - user_name = "A{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" password = "Secret@123" ret = esxi.user_present(name=user_name, password=password) assert ret["result"] is True @@ -117,8 +117,8 @@ def test_user_present_absent_dry_run(vmware_datacenter, service_instance, dry_ru Test scenarios for vmware_esxi.user_present state run with test=True """ - user_name = "A{}".format(uuid.uuid4()) - random_user = "Random{}".format(uuid.uuid4()) + user_name = f"A{uuid.uuid4()}" + random_user = f"Random{uuid.uuid4()}" password = "GVh3J69oMcJ0tA" # create a new user @@ -153,8 +153,8 @@ def test_role_present_absent(patch_salt_globals): """ Test scenarios for role_present state run """ - role_name = "A{}".format(uuid.uuid4()) - random_role = "Random{}".format(uuid.uuid4()) + role_name = f"A{uuid.uuid4()}" + random_role = f"Random{uuid.uuid4()}" # create a new role ret = esxi.role_present(name=role_name, privilege_ids=["Folder.Create"]) @@ -183,7 +183,7 @@ def test_role_present_absent(patch_salt_globals): # Remove the role ret = esxi.role_absent(name=role_name) assert ret["result"] - assert "Role {} deleted.".format(role_name) == ret["comment"] + assert f"Role {role_name} deleted." == ret["comment"] # Remove a non-existent user ret = esxi.user_absent(name=random_role) @@ -196,14 +196,14 @@ def test_role_present_absent_dry_run(vmware_datacenter, service_instance, dry_ru Test scenarios for vmware_esxi.role_present state run with test=True """ - role_name = "A{}".format(uuid.uuid4()) - random_role = "Random{}".format(uuid.uuid4()) + role_name = f"A{uuid.uuid4()}" + random_role = f"Random{uuid.uuid4()}" # create a new role ret = esxi.role_present(name=role_name, privilege_ids=["Folder.Create"]) assert ret["result"] is None assert not ret["changes"] - assert "Role {} will be created.".format(role_name) == ret["comment"] + assert f"Role {role_name} will be created." == ret["comment"] # create the role using exec mod ret = esxi_mod.add_role( @@ -219,13 +219,13 @@ def test_role_present_absent_dry_run(vmware_datacenter, service_instance, dry_ru ret = esxi.role_absent(name=role_name) assert ret["result"] is None assert not ret["changes"] - assert "Role {} will be deleted.".format(role_name) == ret["comment"] + assert f"Role {role_name} will be deleted." == ret["comment"] # Remove a non-existent user ret = esxi.role_absent(name=random_role) assert ret["result"] is None assert not ret["changes"] - assert "Role {} is not present.".format(random_role) in ret["comment"] + assert f"Role {random_role} is not present." in ret["comment"] def test_vmkernel_adapter_present(vmware_datacenter, service_instance): diff --git a/tests/integration/states/test_folder.py b/tests/integration/states/test_folder.py index 040a9af4..c88ea621 100644 --- a/tests/integration/states/test_folder.py +++ b/tests/integration/states/test_folder.py @@ -11,8 +11,9 @@ def patch_salt_globals_folder_state(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(folder, "__opts__", {"test": False}, create=True), patch.object( - folder, "__pillar__", vmware_conf, create=True + with ( + patch.object(folder, "__opts__", {"test": False}, create=True), + patch.object(folder, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/states/test_nsxt_compute_manager.py b/tests/integration/states/test_nsxt_compute_manager.py index f5fb48a1..fa02a70c 100644 --- a/tests/integration/states/test_nsxt_compute_manager.py +++ b/tests/integration/states/test_nsxt_compute_manager.py @@ -66,9 +66,10 @@ def test_register_update_and_delete(nsxt_config, salt_call_cli, delete_compute_m result_as_json = ret[list(ret.keys())[0]] assert result_as_json["name"] == "compute manager registration" assert result_as_json["result"] is True - assert result_as_json[ - "comment" - ] == "Compute manager {} successfully registered with NSX-T".format(compute_manager_server) + assert ( + result_as_json["comment"] + == f"Compute manager {compute_manager_server} successfully registered with NSX-T" + ) new_changes_json = result_as_json["changes"]["new"] assert new_changes_json["server"] == compute_manager_server assert new_changes_json["description"] == "compute manager registered by IT" diff --git a/tests/integration/states/test_nsxt_ip_blocks.py b/tests/integration/states/test_nsxt_ip_blocks.py index 7a6f13d3..0ad76e2c 100644 --- a/tests/integration/states/test_nsxt_ip_blocks.py +++ b/tests/integration/states/test_nsxt_ip_blocks.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_ip_blocks state module """ + from urllib.parse import urljoin import pytest @@ -124,7 +125,7 @@ def test_nsxt_ip_blocks_state_module(nsxt_config, salt_call_cli): assert dict(changes)["old"] is None assert dict(changes)["new"]["display_name"] == display_name assert dict(changes)["new"]["description"] == description - assert comment == "Created IP Block {}".format(display_name) + assert comment == f"Created IP Block {display_name}" # Test present to update with identical fields changes, comment = _execute_present_state( @@ -145,7 +146,7 @@ def test_nsxt_ip_blocks_state_module(nsxt_config, salt_call_cli): assert dict(changes)["old"]["cidr"] == cidr assert dict(changes)["new"]["description"] == updated_description assert dict(changes)["new"]["cidr"] == updated_cidr - assert comment == "Updated IP Block {}".format(display_name) + assert comment == f"Updated IP Block {display_name}" # Test absent to delete IP Address Block changes, comment = _execute_absent_state( @@ -155,7 +156,7 @@ def test_nsxt_ip_blocks_state_module(nsxt_config, salt_call_cli): assert dict(changes)["new"] is None assert dict(changes)["old"]["display_name"] == display_name assert dict(changes)["old"]["description"] == updated_description - assert comment == "Deleted IP Block {}".format(display_name) + assert comment == f"Deleted IP Block {display_name}" # Test absent to delete non existing IP Address Block changes, comment = _execute_absent_state( @@ -163,4 +164,4 @@ def test_nsxt_ip_blocks_state_module(nsxt_config, salt_call_cli): ) assert not changes - assert comment == "No IP Address Block found with name {}".format(display_name) + assert comment == f"No IP Address Block found with name {display_name}" diff --git a/tests/integration/states/test_nsxt_ip_pools.py b/tests/integration/states/test_nsxt_ip_pools.py index 7cb14fd0..b8851340 100644 --- a/tests/integration/states/test_nsxt_ip_pools.py +++ b/tests/integration/states/test_nsxt_ip_pools.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_ip_pools state module """ + from urllib.parse import urljoin import pytest @@ -119,7 +120,7 @@ def test_nsxt_ip_pools_present_and_absent_states(nsxt_config, salt_call_cli): assert dict(changes)["old"] is None assert dict(changes)["new"]["display_name"] == display_name assert dict(changes)["new"]["description"] == description - assert comment == "Created IP Pool {}".format(display_name) + assert comment == f"Created IP Pool {display_name}" # Test present to update with identical fields changes, comment = _execute_present_state( @@ -137,7 +138,7 @@ def test_nsxt_ip_pools_present_and_absent_states(nsxt_config, salt_call_cli): assert dict(changes)["old"]["description"] == description assert dict(changes)["new"]["description"] == updated_description - assert comment == "Updated IP Pool {}".format(display_name) + assert comment == f"Updated IP Pool {display_name}" # Test absent to delete IP Address Pool changes, comment = _execute_absent_state( @@ -147,7 +148,7 @@ def test_nsxt_ip_pools_present_and_absent_states(nsxt_config, salt_call_cli): assert dict(changes)["new"] is None assert dict(changes)["old"]["display_name"] == display_name assert dict(changes)["old"]["description"] == updated_description - assert comment == "Deleted IP Pool {}".format(display_name) + assert comment == f"Deleted IP Pool {display_name}" # Test absent to delete non existing IP Address Pool changes, comment = _execute_absent_state( @@ -155,4 +156,4 @@ def test_nsxt_ip_pools_present_and_absent_states(nsxt_config, salt_call_cli): ) assert not changes - assert comment == "No IP Address Pool found with name {}".format(display_name) + assert comment == f"No IP Address Pool found with name {display_name}" diff --git a/tests/integration/states/test_nsxt_license.py b/tests/integration/states/test_nsxt_license.py index 169e59b7..a2684885 100644 --- a/tests/integration/states/test_nsxt_license.py +++ b/tests/integration/states/test_nsxt_license.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_license state module """ + import json import pytest @@ -20,7 +21,7 @@ def delete_license(nsxt_config): license_key = nsxt_config["license_key"] verify_ssl = nsxt_config.get("cert", False) - url = "https://{management_host}/api/v1/licenses".format(management_host=hostname) + url = f"https://{hostname}/api/v1/licenses" session = requests.Session() headers = {"Accept": "application/json", "Content-Type": "application/json"} response = session.get(url=url, auth=(username, password), verify=verify_ssl, headers=headers) diff --git a/tests/integration/states/test_nsxt_manager.py b/tests/integration/states/test_nsxt_manager.py index 2eeae18f..1fd7882d 100644 --- a/tests/integration/states/test_nsxt_manager.py +++ b/tests/integration/states/test_nsxt_manager.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_manager state module """ + import logging import pytest diff --git a/tests/integration/states/test_nsxt_transport_node.py b/tests/integration/states/test_nsxt_transport_node.py index 079b3dc0..d66375fd 100644 --- a/tests/integration/states/test_nsxt_transport_node.py +++ b/tests/integration/states/test_nsxt_transport_node.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_transport_node state module """ + import pytest _display_name = "Test_Create-State-Module-Transport-Node-IT01" @@ -38,6 +39,7 @@ "display_name": "Check-Display", } + # Creation of the transport nodes using the present state module and later deleting the same using absent call @pytest.mark.xfail(reason="no nsx test setup yet") def test_state_transport_node_verify(nsxt_config, salt_call_cli): diff --git a/tests/integration/states/test_nsxt_transport_node_profiles.py b/tests/integration/states/test_nsxt_transport_node_profiles.py index a96c8686..7b0c6721 100644 --- a/tests/integration/states/test_nsxt_transport_node_profiles.py +++ b/tests/integration/states/test_nsxt_transport_node_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_transport_node_profiles state module """ + import json from urllib.parse import urljoin @@ -153,7 +154,7 @@ def _execute_present_state( verify_ssl=False, display_name=display_name, host_switch_spec=host_switch_spec, - **params + **params, ).json return response[list(response.keys())[0]] @@ -177,7 +178,7 @@ def _create_transport_zone_using_nsxt_api(hostname, username, password, display_ payload = { "display_name": display_name, "host_switch_name": "test-host-switch-1", - "description": "Transport Zone: {}".format(display_name), + "description": f"Transport Zone: {display_name}", "transport_type": "OVERLAY", } headers = {"Accept": "application/json", "content-Type": "application/json"} @@ -292,9 +293,10 @@ def test_nsxt_transport_node_profiles_present_and_absent_states(nsxt_config, set hostname, username, password, salt_call_cli=salt_call_cli, display_name=_display_name ) assert result_as_json["result"] is True - assert result_as_json[ - "comment" - ] == "Transport node profile with display_name: {} successfully deleted".format(_display_name) + assert ( + result_as_json["comment"] + == f"Transport node profile with display_name: {_display_name} successfully deleted" + ) old_changes_json = result_as_json["changes"]["old"] assert old_changes_json["display_name"] == _display_name assert old_changes_json["description"] == _update_description diff --git a/tests/integration/states/test_nsxt_uplink_profiles.py b/tests/integration/states/test_nsxt_uplink_profiles.py index db0ac395..39c43dfc 100644 --- a/tests/integration/states/test_nsxt_uplink_profiles.py +++ b/tests/integration/states/test_nsxt_uplink_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for nsxt_uplink_profiles state module """ + from urllib.parse import urljoin import pytest @@ -47,7 +48,7 @@ def _execute_present_state(nsxt_config, salt_call_cli, display_name, teaming, ** verify_ssl=False, display_name=display_name, teaming=teaming, - **params + **params, ).json return response[list(response.keys())[0]] @@ -161,9 +162,10 @@ def test_nsxt_uplink_profiles_present_and_absent_states(nsxt_config, setup, salt nsxt_config=nsxt_config, salt_call_cli=salt_call_cli, display_name=_display_name ) assert result_as_json["result"] is True - assert result_as_json[ - "comment" - ] == "Uplink profile with display_name: {} successfully deleted".format(_display_name) + assert ( + result_as_json["comment"] + == f"Uplink profile with display_name: {_display_name} successfully deleted" + ) old_changes_json = result_as_json["changes"]["old"] assert old_changes_json["display_name"] == _display_name diff --git a/tests/integration/states/test_tag.py b/tests/integration/states/test_tag.py index e98c6372..17a9e18c 100644 --- a/tests/integration/states/test_tag.py +++ b/tests/integration/states/test_tag.py @@ -11,8 +11,9 @@ def patch_salt_globals_tag_state(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(tagging_state, "__opts__", {"test": False}, create=True), patch.object( - tagging_state, "__pillar__", vmware_conf, create=True + with ( + patch.object(tagging_state, "__opts__", {"test": False}, create=True), + patch.object(tagging_state, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/states/test_vm.py b/tests/integration/states/test_vm.py index b25c06d0..b3ee272b 100644 --- a/tests/integration/states/test_vm.py +++ b/tests/integration/states/test_vm.py @@ -21,8 +21,9 @@ def patch_salt_globals_vm_state(vmware_conf): """ Patch __opts__ and __pillar__ """ - with patch.object(virtual_machine, "__opts__", {"test": False}, create=True), patch.object( - virtual_machine, "__pillar__", vmware_conf, create=True + with ( + patch.object(virtual_machine, "__opts__", {"test": False}, create=True), + patch.object(virtual_machine, "__pillar__", vmware_conf, create=True), ): yield diff --git a/tests/integration/states/test_vmc_dhcp_profiles.py b/tests/integration/states/test_vmc_dhcp_profiles.py index 35e84db8..267e04a5 100644 --- a/tests/integration/states/test_vmc_dhcp_profiles.py +++ b/tests/integration/states/test_vmc_dhcp_profiles.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_dhcp_profiles state module """ + import pytest import requests from saltext.vmware.utils import vmc_constants diff --git a/tests/integration/states/test_vmc_distributed_firewall_rules.py b/tests/integration/states/test_vmc_distributed_firewall_rules.py index 29a10064..39df5b23 100644 --- a/tests/integration/states/test_vmc_distributed_firewall_rules.py +++ b/tests/integration/states/test_vmc_distributed_firewall_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_distributed_firewall_rules state module """ + import pytest import requests from saltext.vmware.utils import vmc_request @@ -116,7 +117,7 @@ def test_vmc_distributed_firewall_rules_state_module( assert changes["old"] is None assert changes["new"]["id"] == rule_id - assert result["comment"] == "Created distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Created distributed firewall rule {rule_id}" # Test present to update with identical fields response = salt_call_cli.run( @@ -147,7 +148,7 @@ def test_vmc_distributed_firewall_rules_state_module( assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Updated distributed firewall rule {rule_id}" # Invoke present state to update distributed firewall rule with tags field updated_tags = [{"tag": "tag1", "scope": "scope1"}] @@ -163,7 +164,7 @@ def test_vmc_distributed_firewall_rules_state_module( changes = result["changes"] assert changes["new"]["tags"] == updated_tags - assert result["comment"] == "Updated distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Updated distributed firewall rule {rule_id}" # Invoke absent to delete the distributed firewall rule response = salt_call_cli.run( @@ -175,7 +176,7 @@ def test_vmc_distributed_firewall_rules_state_module( assert changes["new"] is None assert changes["old"]["id"] == rule_id - assert result["comment"] == "Deleted distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Deleted distributed firewall rule {rule_id}" # Invoke absent when distributed firewall rule is not present response = salt_call_cli.run( @@ -189,4 +190,4 @@ def test_vmc_distributed_firewall_rules_state_module( changes = result["changes"] # assert no changes are done assert changes == {} - assert result["comment"] == "No distributed firewall rule found with ID {}".format(rule_id) + assert result["comment"] == f"No distributed firewall rule found with ID {rule_id}" diff --git a/tests/integration/states/test_vmc_nat_rules.py b/tests/integration/states/test_vmc_nat_rules.py index 0649874d..89a1aaad 100644 --- a/tests/integration/states/test_vmc_nat_rules.py +++ b/tests/integration/states/test_vmc_nat_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_nat_rules state module """ + import json import pytest @@ -154,7 +155,7 @@ def test_vmc_nat_rules_state_module( assert changes["old"] is None assert changes["new"]["id"] == nat_rule - assert result["comment"] == "Created nat rule {}".format(nat_rule) + assert result["comment"] == f"Created nat rule {nat_rule}" # Test present to update with identical fields response = salt_call_cli.run( @@ -206,7 +207,7 @@ def test_vmc_nat_rules_state_module( assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated nat rule {}".format(nat_rule) + assert result["comment"] == f"Updated nat rule {nat_rule}" # Invoke present state to update nat rule with tags field response = salt_call_cli.run( @@ -232,7 +233,7 @@ def test_vmc_nat_rules_state_module( changes = result["changes"] assert changes["new"]["tags"] == updated_tags - assert result["comment"] == "Updated nat rule {}".format(nat_rule) + assert result["comment"] == f"Updated nat rule {nat_rule}" # Invoke absent to delete the nat rule response = salt_call_cli.run( @@ -256,7 +257,7 @@ def test_vmc_nat_rules_state_module( assert changes["new"] is None assert changes["old"]["id"] == nat_rule - assert result["comment"] == "Deleted nat rule {}".format(nat_rule) + assert result["comment"] == f"Deleted nat rule {nat_rule}" # Invoke absent when nat rule is not present response = salt_call_cli.run( @@ -279,4 +280,4 @@ def test_vmc_nat_rules_state_module( changes = result["changes"] # assert no changes are done assert changes == {} - assert result["comment"] == "No nat rule found with Id {}".format(nat_rule) + assert result["comment"] == f"No nat rule found with Id {nat_rule}" diff --git a/tests/integration/states/test_vmc_networks.py b/tests/integration/states/test_vmc_networks.py index 4d802d95..f4a340dd 100644 --- a/tests/integration/states/test_vmc_networks.py +++ b/tests/integration/states/test_vmc_networks.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_networks state module """ + import pytest import requests from saltext.vmware.utils import vmc_request @@ -96,7 +97,7 @@ def test_vmc_networks_state_module(salt_call_cli, delete_network, common_data, n assert changes["old"] is None assert changes["new"]["id"] == network_id - assert result["comment"] == "Created network {}".format(network_id) + assert result["comment"] == f"Created network {network_id}" # Test present to update with identical fields # Invoke state when network is already present @@ -128,7 +129,7 @@ def test_vmc_networks_state_module(salt_call_cli, delete_network, common_data, n assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated network {}".format(network_id) + assert result["comment"] == f"Updated network {network_id}" # Invoke present state to update Network with tags field updated_tags = [{"tag": "tag1", "scope": "scope1"}] @@ -144,7 +145,7 @@ def test_vmc_networks_state_module(salt_call_cli, delete_network, common_data, n changes = result["changes"] assert changes["new"]["tags"] == updated_tags - assert result["comment"] == "Updated network {}".format(network_id) + assert result["comment"] == f"Updated network {network_id}" # Invoke absent to delete the network response = salt_call_cli.run( @@ -159,7 +160,7 @@ def test_vmc_networks_state_module(salt_call_cli, delete_network, common_data, n assert changes["new"] is None assert changes["old"]["id"] == network_id - assert result["comment"] == "Deleted network {}".format(network_id) + assert result["comment"] == f"Deleted network {network_id}" # Invoke absent when network is not present response = salt_call_cli.run( @@ -174,4 +175,4 @@ def test_vmc_networks_state_module(salt_call_cli, delete_network, common_data, n # assert no changes are done assert changes == {} - assert result["comment"] == "No network found with ID {}".format(network_id) + assert result["comment"] == f"No network found with ID {network_id}" diff --git a/tests/integration/states/test_vmc_org_user.py b/tests/integration/states/test_vmc_org_user.py index 44307572..b1d3613d 100644 --- a/tests/integration/states/test_vmc_org_user.py +++ b/tests/integration/states/test_vmc_org_user.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_org_user state module """ + import pytest @@ -39,7 +40,7 @@ def test_vmc_org_user_state_module(salt_call_cli, vmc_common_data, user_name): changes = result["changes"] assert changes["old"] is None - assert result["comment"] == "Invited {} successfully".format(user_name) + assert result["comment"] == f"Invited {user_name} successfully" # Invoke absent to remove the user response = salt_call_cli.run( @@ -50,4 +51,4 @@ def test_vmc_org_user_state_module(salt_call_cli, vmc_common_data, user_name): changes = result["changes"] assert changes == {} - assert result["comment"] == "No user found with username {}".format(user_name) + assert result["comment"] == f"No user found with username {user_name}" diff --git a/tests/integration/states/test_vmc_public_ip.py b/tests/integration/states/test_vmc_public_ip.py index 7cec3196..20aebb26 100644 --- a/tests/integration/states/test_vmc_public_ip.py +++ b/tests/integration/states/test_vmc_public_ip.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_public_ip state module """ + import pytest import requests from saltext.vmware.utils import vmc_request @@ -89,7 +90,7 @@ def test_vmc_public_ip_state_module(salt_call_cli, delete_public_ip, common_data assert changes["old"] is None assert changes["new"]["id"] == public_ip_id - assert result["comment"] == "Created public IP {}".format(public_ip_id) + assert result["comment"] == f"Created public IP {public_ip_id}" # Test present to update public IP with identical fields response = salt_call_cli.run( @@ -122,7 +123,7 @@ def test_vmc_public_ip_state_module(salt_call_cli, delete_public_ip, common_data assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated public IP {}".format(public_ip_id) + assert result["comment"] == f"Updated public IP {public_ip_id}" # Invoke absent to delete the public IP response = salt_call_cli.run( @@ -137,7 +138,7 @@ def test_vmc_public_ip_state_module(salt_call_cli, delete_public_ip, common_data assert changes["new"] is None assert changes["old"]["id"] == public_ip_id - assert result["comment"] == "Deleted public IP {}".format(public_ip_id) + assert result["comment"] == f"Deleted public IP {public_ip_id}" # Invoke absent when public IP is not present response = salt_call_cli.run( @@ -151,4 +152,4 @@ def test_vmc_public_ip_state_module(salt_call_cli, delete_public_ip, common_data changes = result["changes"] # assert no changes are done assert changes == {} - assert result["comment"] == "No public IP found with ID {}".format(public_ip_id) + assert result["comment"] == f"No public IP found with ID {public_ip_id}" diff --git a/tests/integration/states/test_vmc_sddc.py b/tests/integration/states/test_vmc_sddc.py index 8c8426ff..349adcf8 100644 --- a/tests/integration/states/test_vmc_sddc.py +++ b/tests/integration/states/test_vmc_sddc.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_sddc state module """ + from datetime import datetime import pytest @@ -96,7 +97,7 @@ def test_vmc_sddc_state_module(salt_call_cli, vmc_common_data, delete_sddc, sddc changes = result["changes"] assert changes["old"] is None assert changes["new"]["params"]["sddcConfig"]["name"] == sddc_name - assert result["comment"] == "Created SDDC {}".format(sddc_name) + assert result["comment"] == f"Created SDDC {sddc_name}" # get the sddc_id of newly created SDDC sddc_id = result["changes"]["new"]["resource_id"] @@ -143,6 +144,6 @@ def test_vmc_sddc_state_module(salt_call_cli, vmc_common_data, delete_sddc, sddc else: assert changes["new"] is None assert changes["old"]["id"] == sddc_id - assert result["comment"] == "Deleted SDDC {}".format(sddc_id) + assert result["comment"] == f"Deleted SDDC {sddc_id}" else: assert "Failed to add SDDC" in result["comment"] diff --git a/tests/integration/states/test_vmc_security_groups.py b/tests/integration/states/test_vmc_security_groups.py index 37cc0af8..8a5c33a9 100644 --- a/tests/integration/states/test_vmc_security_groups.py +++ b/tests/integration/states/test_vmc_security_groups.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_security_groups state module """ + import json import pytest @@ -106,7 +107,7 @@ def test_vmc_security_groups_state_module( assert changes["old"] is None assert changes["new"]["id"] == security_group_id - assert result["comment"] == "Created security group {}".format(security_group_id) + assert result["comment"] == f"Created security group {security_group_id}" # Test present to update with identical fields response = salt_call_cli.run( @@ -137,7 +138,7 @@ def test_vmc_security_groups_state_module( assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated security group {}".format(security_group_id) + assert result["comment"] == f"Updated security group {security_group_id}" # Invoke present state to update security group with tags field updated_tags = [{"tag": "tag1", "scope": "scope1"}] @@ -153,7 +154,7 @@ def test_vmc_security_groups_state_module( changes = result["changes"] assert changes["new"]["tags"] == updated_tags - assert result["comment"] == "Updated security group {}".format(security_group_id) + assert result["comment"] == f"Updated security group {security_group_id}" # Invoke absent to delete the security group response = salt_call_cli.run( @@ -168,7 +169,7 @@ def test_vmc_security_groups_state_module( assert changes["new"] is None assert changes["old"]["id"] == security_group_id - assert result["comment"] == "Deleted security group {}".format(security_group_id) + assert result["comment"] == f"Deleted security group {security_group_id}" # Invoke absent when security group is not present response = salt_call_cli.run( @@ -182,4 +183,4 @@ def test_vmc_security_groups_state_module( changes = result["changes"] # assert no changes are done assert changes == {} - assert result["comment"] == "No security group found with ID {}".format(security_group_id) + assert result["comment"] == f"No security group found with ID {security_group_id}" diff --git a/tests/integration/states/test_vmc_security_rules.py b/tests/integration/states/test_vmc_security_rules.py index 048170ed..46849ad5 100644 --- a/tests/integration/states/test_vmc_security_rules.py +++ b/tests/integration/states/test_vmc_security_rules.py @@ -1,6 +1,7 @@ """ Integration Tests for vmc_security_rules state module """ + import pytest import requests from saltext.vmware.utils import vmc_request @@ -88,7 +89,7 @@ def test_vmc_security_rules_state_module( assert changes["old"] is None assert changes["new"]["id"] == rule_id - assert result["comment"] == "Created Security rule {}".format(rule_id) + assert result["comment"] == f"Created Security rule {rule_id}" # Test present to update with identical fields response = salt_call_cli.run( @@ -134,7 +135,7 @@ def test_vmc_security_rules_state_module( assert changes["old"]["display_name"] != changes["new"]["display_name"] assert changes["new"]["display_name"] == updated_display_name - assert result["comment"] == "Updated Security rule {}".format(rule_id) + assert result["comment"] == f"Updated Security rule {rule_id}" # Invoke present state to update security rule with tags field response = salt_call_cli.run( @@ -157,7 +158,7 @@ def test_vmc_security_rules_state_module( changes = result["changes"] assert changes["new"]["tags"] == updated_tags - assert result["comment"] == "Updated Security rule {}".format(rule_id) + assert result["comment"] == f"Updated Security rule {rule_id}" # Invoke absent to delete the security rule response = salt_call_cli.run( @@ -180,7 +181,7 @@ def test_vmc_security_rules_state_module( assert changes["new"] is None assert changes["old"]["id"] == rule_id - assert result["comment"] == "Deleted Security rule {}".format(rule_id) + assert result["comment"] == f"Deleted Security rule {rule_id}" # Invoke absent when security rule is not present response = salt_call_cli.run( @@ -202,4 +203,4 @@ def test_vmc_security_rules_state_module( changes = result["changes"] # assert no changes are done assert changes == {} - assert result["comment"] == "No Security rule found with Id {}".format(rule_id) + assert result["comment"] == f"No Security rule found with Id {rule_id}" diff --git a/tests/unit/modules/test_compliance_control.py b/tests/unit/modules/test_compliance_control.py index 3f301477..b91480c6 100644 --- a/tests/unit/modules/test_compliance_control.py +++ b/tests/unit/modules/test_compliance_control.py @@ -1,6 +1,7 @@ """ Unit Tests for compliance control execution module. """ + import logging from unittest.mock import patch @@ -18,14 +19,20 @@ def configure_loader_modules(): @pytest.fixture(autouse=True) def patch_salt_loaded_objects(): - with patch( - "saltext.vmware.modules.compliance_control.__opts__", - { - "saltext.vmware": {"host": "test.vcenter.local", "user": "test", "password": "test"}, - }, - create=True, - ), patch.object(compliance_control, "__pillar__", {}, create=True), patch.object( - compliance_control, "__salt__", {}, create=True + with ( + patch( + "saltext.vmware.modules.compliance_control.__opts__", + { + "saltext.vmware": { + "host": "test.vcenter.local", + "user": "test", + "password": "test", + }, + }, + create=True, + ), + patch.object(compliance_control, "__pillar__", {}, create=True), + patch.object(compliance_control, "__salt__", {}, create=True), ): yield diff --git a/tests/unit/modules/test_controller_metadata.py b/tests/unit/modules/test_controller_metadata.py index 25d267eb..65cb2c87 100644 --- a/tests/unit/modules/test_controller_metadata.py +++ b/tests/unit/modules/test_controller_metadata.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + import logging from unittest.mock import patch @@ -26,15 +27,21 @@ def configure_loader_modules(): @pytest.fixture(autouse=True) def patch_salt_loaded_objects(): # This needs to be the same as the module we're importing - with patch( - "saltext.vmware.modules.controller_metadata.__opts__", - { - "cachedir": ".", - "saltext.vmware": {"host": "test.vcenter.local", "user": "test", "password": "test"}, - }, - create=True, - ), patch.object(controller_metadata, "__pillar__", {}, create=True), patch.object( - controller_metadata, "__salt__", {}, create=True + with ( + patch( + "saltext.vmware.modules.controller_metadata.__opts__", + { + "cachedir": ".", + "saltext.vmware": { + "host": "test.vcenter.local", + "user": "test", + "password": "test", + }, + }, + create=True, + ), + patch.object(controller_metadata, "__pillar__", {}, create=True), + patch.object(controller_metadata, "__salt__", {}, create=True), ): yield diff --git a/tests/unit/modules/test_dvportgroup.py b/tests/unit/modules/test_dvportgroup.py index af8e33b9..4ab685aa 100644 --- a/tests/unit/modules/test_dvportgroup.py +++ b/tests/unit/modules/test_dvportgroup.py @@ -233,9 +233,10 @@ def test_dvportgroup_get_should_return_expected_data( def test_get_should_feed_results_through_VmomiJSONEncoder(): expected_data = {"blerp": "lawl"} - with patch("saltext.vmware.utils.vsphere._get_dvs", autospec=True) as fake_dvs, patch( - "pyVmomi.VmomiSupport.VmomiJSONEncoder", autospec=True - ) as fake_encoder: + with ( + patch("saltext.vmware.utils.vsphere._get_dvs", autospec=True) as fake_dvs, + patch("pyVmomi.VmomiSupport.VmomiJSONEncoder", autospec=True) as fake_encoder, + ): fake_dvs.return_value.portgroup = [] fake_encoder.return_value.encode.return_value = '{"blerp": "lawl"}' ret = dvportgroup.get( diff --git a/tests/unit/modules/test_esxi.py b/tests/unit/modules/test_esxi.py index ed5ad29c..8ac24b49 100644 --- a/tests/unit/modules/test_esxi.py +++ b/tests/unit/modules/test_esxi.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + import logging import os import uuid @@ -29,15 +30,21 @@ def configure_loader_modules(): @pytest.fixture(autouse=True) def patch_salt_loaded_objects(): # This esxi needs to be the same as the module we're importing - with patch( - "saltext.vmware.modules.esxi.__opts__", - { - "cachedir": ".", - "saltext.vmware": {"host": "fnord.example.com", "user": "fnord", "password": "fnord"}, - }, - create=True, - ), patch.object(esxi, "__pillar__", {}, create=True), patch.object( - esxi, "__salt__", {}, create=True + with ( + patch( + "saltext.vmware.modules.esxi.__opts__", + { + "cachedir": ".", + "saltext.vmware": { + "host": "fnord.example.com", + "user": "fnord", + "password": "fnord", + }, + }, + create=True, + ), + patch.object(esxi, "__pillar__", {}, create=True), + patch.object(esxi, "__salt__", {}, create=True), ): yield @@ -46,9 +53,9 @@ def patch_salt_loaded_objects(): def fake_hosts(): hosts = [MagicMock()] hosts[0].name = "blerp" - hosts[ - 0 - ].configManager.firmwareSystem.QueryFirmwareConfigUploadURL.return_value = "something/cool/*" + hosts[0].configManager.firmwareSystem.QueryFirmwareConfigUploadURL.return_value = ( + "something/cool/*" + ) with patch("saltext.vmware.utils.esxi.get_hosts", autospec=True, return_value=hosts): yield hosts diff --git a/tests/unit/modules/test_nsxt_compute_manager.py b/tests/unit/modules/test_nsxt_compute_manager.py index 58df1f38..88d2165d 100644 --- a/tests/unit/modules/test_nsxt_compute_manager.py +++ b/tests/unit/modules/test_nsxt_compute_manager.py @@ -1,6 +1,7 @@ """ Tests for execution module of NSX-T compute manager registration and de-registration """ + from unittest.mock import patch import saltext.vmware.modules.nsxt_compute_manager as nsxt_compute_manager diff --git a/tests/unit/modules/test_nsxt_ip_blocks.py b/tests/unit/modules/test_nsxt_ip_blocks.py index b0020db0..f6119805 100644 --- a/tests/unit/modules/test_nsxt_ip_blocks.py +++ b/tests/unit/modules/test_nsxt_ip_blocks.py @@ -1,6 +1,7 @@ """ Tests for nsxt_manager module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_nsxt_ip_pools.py b/tests/unit/modules/test_nsxt_ip_pools.py index 54d72bfe..129bd241 100644 --- a/tests/unit/modules/test_nsxt_ip_pools.py +++ b/tests/unit/modules/test_nsxt_ip_pools.py @@ -1,6 +1,7 @@ """ Tests for nsxt_manager module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_nsxt_license.py b/tests/unit/modules/test_nsxt_license.py index f09192a9..8260003e 100644 --- a/tests/unit/modules/test_nsxt_license.py +++ b/tests/unit/modules/test_nsxt_license.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + from unittest.mock import patch from saltext.vmware.modules import nsxt_license diff --git a/tests/unit/modules/test_nsxt_manager.py b/tests/unit/modules/test_nsxt_manager.py index 98e48f1a..768b9bba 100644 --- a/tests/unit/modules/test_nsxt_manager.py +++ b/tests/unit/modules/test_nsxt_manager.py @@ -1,6 +1,7 @@ """ Tests for nsxt_manager module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_nsxt_policy_segment.py b/tests/unit/modules/test_nsxt_policy_segment.py index 8aeb363c..a9813ca7 100644 --- a/tests/unit/modules/test_nsxt_policy_segment.py +++ b/tests/unit/modules/test_nsxt_policy_segment.py @@ -1,6 +1,7 @@ """ Tests for execution module of NSX-T Segment """ + from unittest.mock import patch import saltext.vmware.modules.nsxt_policy_segment as nsxt_policy_segment diff --git a/tests/unit/modules/test_nsxt_policy_tier0.py b/tests/unit/modules/test_nsxt_policy_tier0.py index 1bcec3e3..749a35e4 100644 --- a/tests/unit/modules/test_nsxt_policy_tier0.py +++ b/tests/unit/modules/test_nsxt_policy_tier0.py @@ -1,6 +1,7 @@ """ Tests for execution module of NSX-T tier 0 """ + from unittest.mock import patch import saltext.vmware.modules.nsxt_policy_tier0 as nsxt_policy_tier0 @@ -929,13 +930,16 @@ def test_get_hierarchy_with_error_while_getting_list_response(api_mock): err_msg = "Generic error" static_routes_list_response = {"error": err_msg} api_mock.side_effect = [tier0_obj, static_routes_list_response] - assert nsxt_policy_tier0.get_hierarchy( - hostname="hostname", - username="username", - password="pass", - tier0_id=tier0_obj["id"], - verify_ssl=False, - )["error"] == "Failure while querying static_routes: {}".format(err_msg) + assert ( + nsxt_policy_tier0.get_hierarchy( + hostname="hostname", + username="username", + password="pass", + tier0_id=tier0_obj["id"], + verify_ssl=False, + )["error"] + == f"Failure while querying static_routes: {err_msg}" + ) @patch.object(nsxt_request, "call_api") diff --git a/tests/unit/modules/test_nsxt_transport_node.py b/tests/unit/modules/test_nsxt_transport_node.py index e3ce3409..564e4006 100644 --- a/tests/unit/modules/test_nsxt_transport_node.py +++ b/tests/unit/modules/test_nsxt_transport_node.py @@ -1,6 +1,7 @@ """ Tests for nsxt_transport_nodes module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_nsxt_transport_zone.py b/tests/unit/modules/test_nsxt_transport_zone.py index 01efd1e0..00891c4c 100644 --- a/tests/unit/modules/test_nsxt_transport_zone.py +++ b/tests/unit/modules/test_nsxt_transport_zone.py @@ -1,6 +1,7 @@ """ Tests for nsxt_transport_zone modules """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_nsxt_uplink_profiles.py b/tests/unit/modules/test_nsxt_uplink_profiles.py index d0fdf610..1812fcd9 100644 --- a/tests/unit/modules/test_nsxt_uplink_profiles.py +++ b/tests/unit/modules/test_nsxt_uplink_profiles.py @@ -1,6 +1,7 @@ """ Tests for execution module of NSX-T uplink profiles """ + from unittest.mock import patch import saltext.vmware.modules.nsxt_uplink_profiles as nsxt_uplink_profiles diff --git a/tests/unit/modules/test_transport_node_profiles.py b/tests/unit/modules/test_transport_node_profiles.py index ea124edd..51656fbc 100644 --- a/tests/unit/modules/test_transport_node_profiles.py +++ b/tests/unit/modules/test_transport_node_profiles.py @@ -1,6 +1,7 @@ """ Tests for execution module of NSX-T transport node profiles """ + from unittest.mock import patch import saltext.vmware.modules.nsxt_transport_node_profiles as nsxt_transport_node_profiles diff --git a/tests/unit/modules/test_vm.py b/tests/unit/modules/test_vm.py index 9bee1156..ae2a1c93 100644 --- a/tests/unit/modules/test_vm.py +++ b/tests/unit/modules/test_vm.py @@ -220,18 +220,9 @@ def test_when_vm_list_is_given_a_cluster_name_and_datacenter_name_then_parent_sh cluster_name="anything not false/empty", ) - if sys.version_info < (3, 8): - from pyVmomi import vim - - expected_call = mock.call( - all=False, pathSet=["name", "config", "parent"], type=vim.VirtualMachine - ) - assert fake_vmodl.query.PropertyCollector.PropertySpec.has_call(expected_call) - else: - assert ( - "parent" - in fake_vmodl.query.PropertyCollector.PropertySpec.mock_calls[0].kwargs["pathSet"] - ) + assert ( + "parent" in fake_vmodl.query.PropertyCollector.PropertySpec.mock_calls[0].kwargs["pathSet"] + ) def test_when_vm_list_is_given_a_datacenter_name_but_no_cluster_name_then_it_should_return_expected_vms_as_filtered_by_datacenter( @@ -248,25 +239,19 @@ def test_when_vm_list_is_given_a_datacenter_name_but_no_cluster_name_then_it_sho assert actual_vm_names == expected_vm_names - if sys.version_info < (3, 8): - assert ( - fake_service_instance.content.viewManager.CreateContainerView.mock_calls[0][1][0] - is fake_datacenter - ) - else: - # Yes, these assertions are kind of gross - but we're dealing with pyvmomi and all that that entails. I don't think that there's really a great way to make these assertions. - assert ( - fake_service_instance.content.viewManager.CreateContainerView.mock_calls[0].args[0] - is fake_datacenter - ) + # Yes, these assertions are kind of gross - but we're dealing with pyvmomi and all that that entails. I don't think that there's really a great way to make these assertions. + assert ( + fake_service_instance.content.viewManager.CreateContainerView.mock_calls[0].args[0] + is fake_datacenter + ) - assert ( - fake_vmodl.query.PropertyCollector.ObjectSpec.mock_calls[0].kwargs["obj"] - == fake_service_instance.content.viewManager.CreateContainerView.return_value - ) - assert fake_vmodl.query.PropertyCollector.FilterSpec.mock_calls[0].kwargs["objectSet"] == [ - fake_vmodl.query.PropertyCollector.ObjectSpec.return_value - ] + assert ( + fake_vmodl.query.PropertyCollector.ObjectSpec.mock_calls[0].kwargs["obj"] + == fake_service_instance.content.viewManager.CreateContainerView.return_value + ) + assert fake_vmodl.query.PropertyCollector.FilterSpec.mock_calls[0].kwargs["objectSet"] == [ + fake_vmodl.query.PropertyCollector.ObjectSpec.return_value + ] def test_when_vm_is_not_found_then_get_mks_ticket_should_return_empty_data(fake_service_instance): diff --git a/tests/unit/modules/test_vmc_dhcp_profiles.py b/tests/unit/modules/test_vmc_dhcp_profiles.py index bf28f829..89a7a72c 100644 --- a/tests/unit/modules/test_vmc_dhcp_profiles.py +++ b/tests/unit/modules/test_vmc_dhcp_profiles.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_dhcp_profiles execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_direct_connect.py b/tests/unit/modules/test_vmc_direct_connect.py index 330498e3..a0e4bcaa 100644 --- a/tests/unit/modules/test_vmc_direct_connect.py +++ b/tests/unit/modules/test_vmc_direct_connect.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_direct_connect execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_distributed_firewall_rules.py b/tests/unit/modules/test_vmc_distributed_firewall_rules.py index 86af4c39..6d17fd54 100644 --- a/tests/unit/modules/test_vmc_distributed_firewall_rules.py +++ b/tests/unit/modules/test_vmc_distributed_firewall_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_distributed_firewall_rules execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_dns_forwarder.py b/tests/unit/modules/test_vmc_dns_forwarder.py index 9f47676f..e1771e3a 100644 --- a/tests/unit/modules/test_vmc_dns_forwarder.py +++ b/tests/unit/modules/test_vmc_dns_forwarder.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_dns_forwarder execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_nat_rules.py b/tests/unit/modules/test_vmc_nat_rules.py index 91a14ecd..b4e4d2fd 100644 --- a/tests/unit/modules/test_vmc_nat_rules.py +++ b/tests/unit/modules/test_vmc_nat_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_nat_rules execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_networks.py b/tests/unit/modules/test_vmc_networks.py index fca3f36c..73d9479d 100644 --- a/tests/unit/modules/test_vmc_networks.py +++ b/tests/unit/modules/test_vmc_networks.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_networks execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_org_users.py b/tests/unit/modules/test_vmc_org_users.py index 7c7a8235..fa27775f 100644 --- a/tests/unit/modules/test_vmc_org_users.py +++ b/tests/unit/modules/test_vmc_org_users.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_vmc_public_ip.py b/tests/unit/modules/test_vmc_public_ip.py index 87f7adc6..a38c50dd 100644 --- a/tests/unit/modules/test_vmc_public_ip.py +++ b/tests/unit/modules/test_vmc_public_ip.py @@ -2,6 +2,7 @@ Unit tests for vmc_public_ip execution module :codeauthor: VMware """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_sddc.py b/tests/unit/modules/test_vmc_sddc.py index 3bfd8ba0..fbb9081f 100644 --- a/tests/unit/modules/test_vmc_sddc.py +++ b/tests/unit/modules/test_vmc_sddc.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_vmc_sddc_clusters.py b/tests/unit/modules/test_vmc_sddc_clusters.py index d2df670c..db802dce 100644 --- a/tests/unit/modules/test_vmc_sddc_clusters.py +++ b/tests/unit/modules/test_vmc_sddc_clusters.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_sddc_clusters execution module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_vmc_sddc_host.py b/tests/unit/modules/test_vmc_sddc_host.py index 2dfc77cf..c6776458 100644 --- a/tests/unit/modules/test_vmc_sddc_host.py +++ b/tests/unit/modules/test_vmc_sddc_host.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_sddc_host execution module """ + import logging from unittest.mock import patch diff --git a/tests/unit/modules/test_vmc_security_groups.py b/tests/unit/modules/test_vmc_security_groups.py index 2496bead..0df68a22 100644 --- a/tests/unit/modules/test_vmc_security_groups.py +++ b/tests/unit/modules/test_vmc_security_groups.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_security_groups execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_security_rules.py b/tests/unit/modules/test_vmc_security_rules.py index e20f21c3..796f7595 100644 --- a/tests/unit/modules/test_vmc_security_rules.py +++ b/tests/unit/modules/test_vmc_security_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_security_rules execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_vcenter_stats.py b/tests/unit/modules/test_vmc_vcenter_stats.py index a2c526eb..2a360e0f 100644 --- a/tests/unit/modules/test_vmc_vcenter_stats.py +++ b/tests/unit/modules/test_vmc_vcenter_stats.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_vcenter_stats execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_vm_disks.py b/tests/unit/modules/test_vmc_vm_disks.py index 200d376e..5e7c302c 100644 --- a/tests/unit/modules/test_vmc_vm_disks.py +++ b/tests/unit/modules/test_vmc_vm_disks.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_vm_disks execution module """ + from unittest.mock import patch import pytest @@ -129,7 +130,7 @@ def test_create_with_dot_vmdk_file_name_and_capacity_and_storage_policy_id_shoul vm_id="vm_id", bus_adapter_type="IDE", verify_ssl=False, - **kwargs + **kwargs, ) == expected_error ) @@ -183,7 +184,7 @@ def test_create_with_vmdk_name_and_capacity_and_storage_policy_id_should_pass_ex vm_id="vm_id", bus_adapter_type="IDE", verify_ssl=False, - **kwargs + **kwargs, ) call_kwargs = vmc_call_api.mock_calls[0][-1] diff --git a/tests/unit/modules/test_vmc_vm_stats.py b/tests/unit/modules/test_vmc_vm_stats.py index cc02c406..a1f01209 100644 --- a/tests/unit/modules/test_vmc_vm_stats.py +++ b/tests/unit/modules/test_vmc_vm_stats.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_vm_stats execution module """ + from unittest.mock import patch import pytest diff --git a/tests/unit/modules/test_vmc_vpn_statistics.py b/tests/unit/modules/test_vmc_vpn_statistics.py index ad4f2d7a..d3ffed4f 100644 --- a/tests/unit/modules/test_vmc_vpn_statistics.py +++ b/tests/unit/modules/test_vmc_vpn_statistics.py @@ -1,6 +1,7 @@ """ :codeauthor: VMware """ + from unittest.mock import patch import pytest diff --git a/tests/unit/states/test_compliance_control.py b/tests/unit/states/test_compliance_control.py index 6a3d5bca..8093ce9f 100644 --- a/tests/unit/states/test_compliance_control.py +++ b/tests/unit/states/test_compliance_control.py @@ -1,6 +1,7 @@ """ Unit Tests for compliance control state module. """ + from unittest.mock import MagicMock from unittest.mock import patch @@ -17,14 +18,20 @@ def configure_loader_modules(): @pytest.fixture(autouse=True) def patch_salt_loaded_objects(): - with patch( - "saltext.vmware.states.compliance_control.__opts__", - { - "saltext.vmware": {"host": "test.vcenter.local", "user": "test", "password": "test"}, - }, - create=True, - ), patch.object(compliance_control, "__pillar__", {}, create=True), patch.object( - compliance_control, "__salt__", {}, create=True + with ( + patch( + "saltext.vmware.states.compliance_control.__opts__", + { + "saltext.vmware": { + "host": "test.vcenter.local", + "user": "test", + "password": "test", + }, + }, + create=True, + ), + patch.object(compliance_control, "__pillar__", {}, create=True), + patch.object(compliance_control, "__salt__", {}, create=True), ): yield diff --git a/tests/unit/states/test_controller_metadata.py b/tests/unit/states/test_controller_metadata.py index 559fdf12..fa2b12f5 100644 --- a/tests/unit/states/test_controller_metadata.py +++ b/tests/unit/states/test_controller_metadata.py @@ -1,6 +1,7 @@ """ Unit Tests for controller metadata """ + from unittest.mock import MagicMock from unittest.mock import patch @@ -18,15 +19,21 @@ def configure_loader_modules(): @pytest.fixture(autouse=True) def patch_salt_loaded_objects(): # This needs to be the same as the module we're importing - with patch( - "saltext.vmware.states.controller_metadata.__opts__", - { - "cachedir": ".", - "saltext.vmware": {"host": "test.vcenter.local", "user": "test", "password": "test"}, - }, - create=True, - ), patch.object(controller_metadata, "__pillar__", {}, create=True), patch.object( - controller_metadata, "__salt__", {}, create=True + with ( + patch( + "saltext.vmware.states.controller_metadata.__opts__", + { + "cachedir": ".", + "saltext.vmware": { + "host": "test.vcenter.local", + "user": "test", + "password": "test", + }, + }, + create=True, + ), + patch.object(controller_metadata, "__pillar__", {}, create=True), + patch.object(controller_metadata, "__salt__", {}, create=True), ): yield diff --git a/tests/unit/states/test_esxi.py b/tests/unit/states/test_esxi.py index 3799daab..af438e1c 100644 --- a/tests/unit/states/test_esxi.py +++ b/tests/unit/states/test_esxi.py @@ -1,6 +1,7 @@ """ Unit Tests for esxi state """ + from unittest.mock import MagicMock from unittest.mock import patch diff --git a/tests/unit/states/test_nsxt_compute_manager.py b/tests/unit/states/test_nsxt_compute_manager.py index d8c8fbd4..2d41593b 100644 --- a/tests/unit/states/test_nsxt_compute_manager.py +++ b/tests/unit/states/test_nsxt_compute_manager.py @@ -230,9 +230,9 @@ def test_present_state_to_update_existing_compute_manager_registration_during_up "nsxt_compute_manager.update": MagicMock(return_value=updated_compute_manager), }, ): - ret[ - "comment" - ] = "Compute manager existing-server.local registration successfully updated with NSX-T" + ret["comment"] = ( + "Compute manager existing-server.local registration successfully updated with NSX-T" + ) ret["changes"]["new"] = updated_compute_manager ret["changes"]["old"] = old_compute_manager with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): @@ -326,9 +326,9 @@ def test_present_state_error_with_wrong_compute_manager_credential(): "nsxt_compute_manager.get": MagicMock(return_value=existing_compute_managers), }, ): - ret[ - "comment" - ] = "Parameter credential must be of type dictionary. Please refer documentation" + ret["comment"] = ( + "Parameter credential must be of type dictionary. Please refer documentation" + ) with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): assert ( nsxt_compute_manager.present( @@ -374,10 +374,10 @@ def test_present_state_error_when_existing_compute_manager_registration_update_f "nsxt_compute_manager.update": MagicMock(return_value=err_json), }, ): - ret[ - "comment" - ] = "Failed to update existing registration of compute manager with NSX-T Manager : {}".format( - error_msg + ret["comment"] = ( + "Failed to update existing registration of compute manager with NSX-T Manager : {}".format( + error_msg + ) ) with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): assert ( @@ -439,7 +439,7 @@ def test_present_state_error_while_new_registration_fails_when_calling_get(): nsxt_compute_manager.__salt__, {"nsxt_compute_manager.get": MagicMock(return_value=err_json)}, ): - ret["comment"] = "Failed to get compute managers from NSX-T Manager : {}".format(error_msg) + ret["comment"] = f"Failed to get compute managers from NSX-T Manager : {error_msg}" with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): assert ( nsxt_compute_manager.present( @@ -573,10 +573,10 @@ def test_absent_state_error_when_delete_compute_manager_call_fails(): "nsxt_compute_manager.remove": MagicMock(return_value=error_json), }, ): - ret[ - "comment" - ] = "Failed to remove registration of compute manager with NSX-T Manager : {}".format( - err_msg + ret["comment"] = ( + "Failed to remove registration of compute manager with NSX-T Manager : {}".format( + err_msg + ) ) with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): assert ( @@ -602,7 +602,7 @@ def test_absent_state_error_get_compute_manager_call_fails(): "nsxt_compute_manager.get": MagicMock(return_value=error_json), }, ): - ret["comment"] = "Failed to get compute managers from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get compute managers from NSX-T Manager : {err_msg}" with patch.dict(nsxt_compute_manager.__opts__, {"test": False}): assert ( nsxt_compute_manager.absent( diff --git a/tests/unit/states/test_nsxt_ip_blocks.py b/tests/unit/states/test_nsxt_ip_blocks.py index 49b5697d..85baf01f 100644 --- a/tests/unit/states/test_nsxt_ip_blocks.py +++ b/tests/unit/states/test_nsxt_ip_blocks.py @@ -1,6 +1,7 @@ """ Unit Tests for nsxt_ip_blocks state """ + from unittest.mock import MagicMock from unittest.mock import patch @@ -184,7 +185,7 @@ def test_present_to_create_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": mocked_ok_response, "old": None} - assert result["comment"] == "Created IP Block {}".format(display_name) + assert result["comment"] == f"Created IP Block {display_name}" assert result["result"] @@ -216,7 +217,7 @@ def test_present_to_update_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": mocked_updated_ip_block, "old": mocked_ok_response} - assert result["comment"] == "Updated IP Block {}".format(display_name) + assert result["comment"] == f"Updated IP Block {display_name}" assert result["result"] @@ -356,7 +357,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted IP Block {}".format(display_name) + assert result["comment"] == f"Deleted IP Block {display_name}" assert result["result"] @@ -380,7 +381,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No IP Address Block found with name {}".format(display_name) + assert result["comment"] == f"No IP Address Block found with name {display_name}" assert result["result"] @@ -432,9 +433,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no IP Block found with name {}".format(display_name) + assert ( + result["comment"] + == f"State absent will do nothing as no IP Block found with name {display_name}" + ) assert result["result"] is None diff --git a/tests/unit/states/test_nsxt_ip_pools.py b/tests/unit/states/test_nsxt_ip_pools.py index 2a769016..d1688338 100644 --- a/tests/unit/states/test_nsxt_ip_pools.py +++ b/tests/unit/states/test_nsxt_ip_pools.py @@ -1,6 +1,7 @@ """ Unit Tests for nsxt_ip_pools state """ + from unittest.mock import MagicMock from unittest.mock import patch @@ -179,7 +180,7 @@ def test_present_to_create_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": mocked_ok_response, "old": None} - assert result["comment"] == "Created IP Pool {}".format(display_name) + assert result["comment"] == f"Created IP Pool {display_name}" assert result["result"] @@ -210,7 +211,7 @@ def test_present_to_update_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": mocked_updated_ip_pool, "old": mocked_ok_response} - assert result["comment"] == "Updated IP Pool {}".format(display_name) + assert result["comment"] == f"Updated IP Pool {display_name}" assert result["result"] @@ -346,7 +347,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(): assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted IP Pool {}".format(display_name) + assert result["comment"] == f"Deleted IP Pool {display_name}" assert result["result"] @@ -370,7 +371,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No IP Address Pool found with name {}".format(display_name) + assert result["comment"] == f"No IP Address Pool found with name {display_name}" assert result["result"] @@ -395,7 +396,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete IP Pool with name {}".format(display_name) + assert result["comment"] == f"State absent will delete IP Pool with name {display_name}" assert result["result"] is None @@ -420,9 +421,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no IP Pool found with name {}".format(display_name) + assert ( + result["comment"] + == f"State absent will do nothing as no IP Pool found with name {display_name}" + ) assert result["result"] is None diff --git a/tests/unit/states/test_nsxt_manager.py b/tests/unit/states/test_nsxt_manager.py index f6ab55ee..409cff52 100644 --- a/tests/unit/states/test_nsxt_manager.py +++ b/tests/unit/states/test_nsxt_manager.py @@ -1,6 +1,7 @@ """ Unit Tests for nsxt_manager state """ + from unittest.mock import MagicMock from unittest.mock import patch diff --git a/tests/unit/states/test_nsxt_policy_segment.py b/tests/unit/states/test_nsxt_policy_segment.py index f1b71fae..56c93e89 100644 --- a/tests/unit/states/test_nsxt_policy_segment.py +++ b/tests/unit/states/test_nsxt_policy_segment.py @@ -1,6 +1,7 @@ """ Unit Tests for nsxt_policy_segment state """ + from unittest.mock import MagicMock from unittest.mock import patch @@ -52,7 +53,7 @@ def test_present_error_in_get_by_display_name(): nsxt_policy_segment.__salt__, {"nsxt_policy_segment.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get segment from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get segment from NSX-T Manager : {err_msg}" assert ( nsxt_policy_segment.present( name="create segment", @@ -384,7 +385,7 @@ def test_absent_error_in_get_by_display_name(): nsxt_policy_segment.__salt__, {"nsxt_policy_segment.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get the segment response : {}".format(err_msg) + ret["comment"] = f"Failed to get the segment response : {err_msg}" assert ( nsxt_policy_segment.absent( name="delete segment", @@ -567,10 +568,10 @@ def test_absent(): }, ): with patch.dict(nsxt_policy_segment.__opts__, {"test": False}): - ret[ - "comment" - ] = "Segment with display_name: {} and its sub-resources deleted successfully".format( - _mock_segment["display_name"] + ret["comment"] = ( + "Segment with display_name: {} and its sub-resources deleted successfully".format( + _mock_segment["display_name"] + ) ) ret["changes"]["new"] = {} ret["changes"]["old"] = _mock_segment diff --git a/tests/unit/states/test_nsxt_policy_tier0.py b/tests/unit/states/test_nsxt_policy_tier0.py index 9debc243..1d507aba 100644 --- a/tests/unit/states/test_nsxt_policy_tier0.py +++ b/tests/unit/states/test_nsxt_policy_tier0.py @@ -48,7 +48,7 @@ def test_present_error_in_get_by_display_name(): nsxt_policy_tier0.__salt__, {"nsxt_policy_tier0.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get tier-0 gateways from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get tier-0 gateways from NSX-T Manager : {err_msg}" assert ( nsxt_policy_tier0.present( name="create tier0", @@ -180,10 +180,10 @@ def test_present_create_new_tier0_error_in_execution_logs(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( - _err_msg, execution_logs + ret["comment"] = ( + "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( + _err_msg, execution_logs + ) ) assert ( nsxt_policy_tier0.present( @@ -278,10 +278,10 @@ def test_present_update_tier0_error_in_execution_logs(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( - _err_msg, execution_logs + ret["comment"] = ( + "Failed while creating tier0 gateway and sub-resources: {}\n Execution logs: {}".format( + _err_msg, execution_logs + ) ) assert ( nsxt_policy_tier0.present( @@ -312,9 +312,9 @@ def test_present_update_tier0_error_in_hierarchy_before_update(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while querying tier0 gateway and its sub-resources.: {}".format(_err_msg) + ret["comment"] = ( + f"Failed while querying tier0 gateway and its sub-resources.: {_err_msg}" + ) assert ( nsxt_policy_tier0.present( name="update tier0", @@ -346,9 +346,9 @@ def test_present_update_tier0_error_in_hierarchy_after_update(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failure while querying tier0 gateway and its sub-resources: {}".format(_err_msg) + ret["comment"] = ( + f"Failure while querying tier0 gateway and its sub-resources: {_err_msg}" + ) assert ( nsxt_policy_tier0.present( name="update tier0", @@ -391,7 +391,7 @@ def test_absent_error_in_get_by_display_name(): nsxt_policy_tier0.__salt__, {"nsxt_policy_tier0.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get tier0 gateways from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get tier0 gateways from NSX-T Manager : {err_msg}" assert ( nsxt_policy_tier0.absent( name="delete tier0", @@ -549,9 +549,9 @@ def test_absent_with_error_in_get_hierarchy(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failure while querying tier0 gateway and its sub-resources: {}".format(_err_msg) + ret["comment"] = ( + f"Failure while querying tier0 gateway and its sub-resources: {_err_msg}" + ) assert ( nsxt_policy_tier0.absent( name="delete tier0", @@ -578,10 +578,10 @@ def test_absent(): }, ): with patch.dict(nsxt_policy_tier0.__opts__, {"test": False}): - ret[ - "comment" - ] = "Tier0 gateway with display_name: {} and its sub-resources deleted successfully".format( - _mocked_tier0["display_name"] + ret["comment"] = ( + "Tier0 gateway with display_name: {} and its sub-resources deleted successfully".format( + _mocked_tier0["display_name"] + ) ) ret["changes"]["new"] = {} ret["changes"]["old"] = _mocked_tier0 diff --git a/tests/unit/states/test_nsxt_policy_tier1.py b/tests/unit/states/test_nsxt_policy_tier1.py index 6d4abe7b..56327644 100644 --- a/tests/unit/states/test_nsxt_policy_tier1.py +++ b/tests/unit/states/test_nsxt_policy_tier1.py @@ -53,7 +53,7 @@ def test_present_error_in_get_by_display_name(): nsxt_policy_tier1.__salt__, {"nsxt_policy_tier1.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get tier-1 gateways from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get tier-1 gateways from NSX-T Manager : {err_msg}" assert ( nsxt_policy_tier1.present( name="create tier1", @@ -185,10 +185,10 @@ def test_present_create_new_tier1_error_in_execution_logs(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( - _err_msg, execution_logs + ret["comment"] = ( + "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( + _err_msg, execution_logs + ) ) assert ( nsxt_policy_tier1.present( @@ -283,10 +283,10 @@ def test_present_update_tier1_error_in_execution_logs(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( - _err_msg, execution_logs + ret["comment"] = ( + "Failed while creating tier1 gateway and sub-resources: {} \n Execution logs: {}".format( + _err_msg, execution_logs + ) ) assert ( nsxt_policy_tier1.present( @@ -317,9 +317,9 @@ def test_present_update_tier1_error_in_hierarchy_before_update(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failed while querying tier1 gateway and its sub-resources.: {}".format(_err_msg) + ret["comment"] = ( + f"Failed while querying tier1 gateway and its sub-resources.: {_err_msg}" + ) assert ( nsxt_policy_tier1.present( name="update tier1", @@ -351,9 +351,9 @@ def test_present_update_tier1_error_in_hierarchy_after_update(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failure while querying tier1 gateway and its sub-resources: {}".format(_err_msg) + ret["comment"] = ( + f"Failure while querying tier1 gateway and its sub-resources: {_err_msg}" + ) assert ( nsxt_policy_tier1.present( name="update tier1", @@ -396,7 +396,7 @@ def test_absent_error_in_get_by_display_name(): nsxt_policy_tier1.__salt__, {"nsxt_policy_tier1.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get tier1 gateways from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get tier1 gateways from NSX-T Manager : {err_msg}" assert ( nsxt_policy_tier1.absent( name="delete tier1", @@ -556,9 +556,9 @@ def test_absent_with_error_in_get_hierarchy(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "Failure while querying tier1 gateway and its sub-resources: {}".format(_err_msg) + ret["comment"] = ( + f"Failure while querying tier1 gateway and its sub-resources: {_err_msg}" + ) assert ( nsxt_policy_tier1.absent( name="delete tier1", @@ -585,10 +585,10 @@ def test_absent(): }, ): with patch.dict(nsxt_policy_tier1.__opts__, {"test": False}): - ret[ - "comment" - ] = "tier1 gateway with display_name: {} and its sub-resources deleted successfully".format( - _mocked_tier1["display_name"] + ret["comment"] = ( + "tier1 gateway with display_name: {} and its sub-resources deleted successfully".format( + _mocked_tier1["display_name"] + ) ) ret["changes"]["new"] = {} ret["changes"]["old"] = _mocked_tier1 diff --git a/tests/unit/states/test_nsxt_transport_node.py b/tests/unit/states/test_nsxt_transport_node.py index 474bbc8e..dae475de 100644 --- a/tests/unit/states/test_nsxt_transport_node.py +++ b/tests/unit/states/test_nsxt_transport_node.py @@ -1,6 +1,7 @@ """ Unit Tests for nsxt_transport_nodes state """ + from unittest.mock import MagicMock from unittest.mock import patch diff --git a/tests/unit/states/test_nsxt_transport_node_profiles.py b/tests/unit/states/test_nsxt_transport_node_profiles.py index caad16cf..8bb6ec6f 100644 --- a/tests/unit/states/test_nsxt_transport_node_profiles.py +++ b/tests/unit/states/test_nsxt_transport_node_profiles.py @@ -355,7 +355,7 @@ def test_present_state_error_when_update_tnp_returns_error(mock_call_api): "nsxt_transport_node_profiles.update": MagicMock(return_value=json_response), }, ): - ret["comment"] = "Failure while updating transport node profile: {}".format(err_msg) + ret["comment"] = f"Failure while updating transport node profile: {err_msg}" with patch.dict(nsxt_transport_node_profiles.__opts__, {"test": False}): assert ( nsxt_transport_node_profiles.present( @@ -570,10 +570,10 @@ def test_absent_state_when_opts_true_during_create(): }, ): with patch.dict(nsxt_transport_node_profiles.__opts__, {"test": True}): - ret[ - "comment" - ] = "No transport node profile with display_name: {} found in NSX-T Manager".format( - _mock_transport_node_profile["display_name"] + ret["comment"] = ( + "No transport node profile with display_name: {} found in NSX-T Manager".format( + _mock_transport_node_profile["display_name"] + ) ) assert ( nsxt_transport_node_profiles.absent( @@ -626,10 +626,10 @@ def test_absent_state_when_no_transport_node_profile_exists_with_given_name(): }, ): with patch.dict(nsxt_transport_node_profiles.__opts__, {"test": False}): - ret[ - "comment" - ] = "No transport node profile with display_name: {} found in NSX-T Manager".format( - _mock_transport_node_profile["display_name"] + ret["comment"] = ( + "No transport node profile with display_name: {} found in NSX-T Manager".format( + _mock_transport_node_profile["display_name"] + ) ) assert ( nsxt_transport_node_profiles.absent( @@ -657,7 +657,7 @@ def test_absent_state_when_delete_call_returns_error(): }, ): with patch.dict(nsxt_transport_node_profiles.__opts__, {"test": False}): - ret["comment"] = "Failed to delete transport node profile : {}".format(err_msg) + ret["comment"] = f"Failed to delete transport node profile : {err_msg}" assert ( nsxt_transport_node_profiles.absent( name="delete transport node profile", @@ -685,10 +685,10 @@ def test_absent_state_to_delete_existing_transport_node_profile(): }, ): with patch.dict(nsxt_transport_node_profiles.__opts__, {"test": False}): - ret[ - "comment" - ] = "Transport node profile with display_name: {} successfully deleted".format( - _mock_transport_node_profile["display_name"] + ret["comment"] = ( + "Transport node profile with display_name: {} successfully deleted".format( + _mock_transport_node_profile["display_name"] + ) ) ret["changes"]["new"] = {} ret["changes"]["old"] = _mock_transport_node_profile diff --git a/tests/unit/states/test_nsxt_transport_zone.py b/tests/unit/states/test_nsxt_transport_zone.py index cea5739e..62fe62b4 100644 --- a/tests/unit/states/test_nsxt_transport_zone.py +++ b/tests/unit/states/test_nsxt_transport_zone.py @@ -101,7 +101,7 @@ def test_present_state_to_create_new_transport_zone_with_error_in_get_call(): transport_zone.__salt__, {"nsxt_transport_zone.get_by_display_name": MagicMock(return_value=err_json)}, ): - ret["comment"] = "Failed to get the transport zones : {}".format(error_msg) + ret["comment"] = f"Failed to get the transport zones : {error_msg}" ret["result"] = False with patch.dict(transport_zone.__opts__, {"test": False}): @@ -210,9 +210,9 @@ def test_present_state_to_create_new_transport_zone_with_error_from_execution_mo "nsxt_transport_zone.create": MagicMock(return_value=err_json), }, ): - ret[ - "comment" - ] = "Fail to create transport_zone : Http error occurred. Please provide correct credentials" + ret["comment"] = ( + "Fail to create transport_zone : Http error occurred. Please provide correct credentials" + ) ret["changes"] = {} ret["result"] = False @@ -277,7 +277,7 @@ def test_present_state_to_create_new_transport_zone_when_same_transport_zone_alr username=_mocked_username, password=_mocked_password, verify_ssl=False, - **new_transport_zone + **new_transport_zone, ) == ret ) @@ -377,9 +377,9 @@ def test_present_state_to_update_transport_zone_when_error_from_update_call(): "nsxt_transport_zone.update": MagicMock(return_value=err_json), }, ): - ret[ - "comment" - ] = "Fail to update transport_zone : Http error occurred. Please provide correct credentials" + ret["comment"] = ( + "Fail to update transport_zone : Http error occurred. Please provide correct credentials" + ) ret["changes"] = {} ret["result"] = False @@ -454,9 +454,9 @@ def test_absent_state_error_when_get_transport_zone_call_returns_error(): transport_zone.__salt__, {"nsxt_transport_zone.get_by_display_name": MagicMock(return_value=err_json)}, ): - ret[ - "comment" - ] = "Failed to get the transport zones : Http error occurred. Please provide correct credentials" + ret["comment"] = ( + "Failed to get the transport zones : Http error occurred. Please provide correct credentials" + ) ret["result"] = False with patch.dict(transport_zone.__opts__, {"test": False}): @@ -504,9 +504,9 @@ def test_absent_state_error_when_delete_call_returns_error(): "nsxt_transport_zone.delete": MagicMock(return_value=err_json), }, ): - ret[ - "comment" - ] = "Failed to delete the transport-zone : Http error occurred. Please provide correct credentials" + ret["comment"] = ( + "Failed to delete the transport-zone : Http error occurred. Please provide correct credentials" + ) ret["result"] = False with patch.dict(transport_zone.__opts__, {"test": False}): diff --git a/tests/unit/states/test_nsxt_uplink_profiles.py b/tests/unit/states/test_nsxt_uplink_profiles.py index 3f75718d..7b2abe7d 100644 --- a/tests/unit/states/test_nsxt_uplink_profiles.py +++ b/tests/unit/states/test_nsxt_uplink_profiles.py @@ -63,7 +63,7 @@ def test_present_state_error_when_get_by_display_name_returns_error(): nsxt_uplink_profiles.__salt__, {"nsxt_uplink_profiles.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get uplink profiles from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get uplink profiles from NSX-T Manager : {err_msg}" assert ( nsxt_uplink_profiles.present( name="create uplink profile", @@ -229,9 +229,9 @@ def test_present_state_when_nothing_to_update_in_the_existing_uplink_profile(): }, ): with patch.dict(nsxt_uplink_profiles.__opts__, {"test": False}): - ret[ - "comment" - ] = "Uplink profile already exists with similar params. No action to perform" + ret["comment"] = ( + "Uplink profile already exists with similar params. No action to perform" + ) assert ( nsxt_uplink_profiles.present( name="create uplink profile", @@ -426,7 +426,7 @@ def test_absent_state_error_when_get_by_display_name_returns_error(): nsxt_uplink_profiles.__salt__, {"nsxt_uplink_profiles.get_by_display_name": MagicMock(return_value={"error": err_msg})}, ): - ret["comment"] = "Failed to get uplink profiles from NSX-T Manager : {}".format(err_msg) + ret["comment"] = f"Failed to get uplink profiles from NSX-T Manager : {err_msg}" assert ( nsxt_uplink_profiles.absent( name="delete uplink profile", @@ -474,10 +474,10 @@ def test_absent_state_when_opts_test_is_true_during_create(): {"nsxt_uplink_profiles.get_by_display_name": MagicMock(return_value={"results": []})}, ): with patch.dict(nsxt_uplink_profiles.__opts__, {"test": True}): - ret[ - "comment" - ] = "No uplink profile with display_name: {} found in NSX-T Manager".format( - _mock_uplink_profile["display_name"] + ret["comment"] = ( + "No uplink profile with display_name: {} found in NSX-T Manager".format( + _mock_uplink_profile["display_name"] + ) ) assert ( nsxt_uplink_profiles.absent( @@ -526,10 +526,10 @@ def test_absent_state_when_no_uplink_profile_exists_with_given_display_name(): {"nsxt_uplink_profiles.get_by_display_name": MagicMock(return_value={"results": []})}, ): with patch.dict(nsxt_uplink_profiles.__opts__, {"test": False}): - ret[ - "comment" - ] = "No uplink profile with display_name: {} found in NSX-T Manager".format( - _mock_uplink_profile["display_name"] + ret["comment"] = ( + "No uplink profile with display_name: {} found in NSX-T Manager".format( + _mock_uplink_profile["display_name"] + ) ) assert ( nsxt_uplink_profiles.absent( @@ -557,7 +557,7 @@ def test_absent_error_when_delete_call_returns_error(): }, ): with patch.dict(nsxt_uplink_profiles.__opts__, {"test": False}): - ret["comment"] = "Failed to delete uplink profile : {}".format(err_msg) + ret["comment"] = f"Failed to delete uplink profile : {err_msg}" assert ( nsxt_uplink_profiles.absent( name="delete uplink profile", diff --git a/tests/unit/states/test_vmc_dhcp_profiles.py b/tests/unit/states/test_vmc_dhcp_profiles.py index c897338f..afffaa00 100644 --- a/tests/unit/states/test_vmc_dhcp_profiles.py +++ b/tests/unit/states/test_vmc_dhcp_profiles.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_dhcp_profiles state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -210,7 +211,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"Created DHCP Profile {dhcp_profile_id}" assert result["result"] @@ -249,7 +250,7 @@ def test_present_to_update_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_updated_dhcp_profile assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"Updated DHCP Profile {dhcp_profile_id}" assert result["result"] @@ -345,7 +346,7 @@ def test_present_state_for_create_when_opts_test_is_true(): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will create DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"State present will create DHCP Profile {dhcp_profile_id}" assert result["result"] is None @@ -373,7 +374,7 @@ def test_present_state_for_update_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will update DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"State present will update DHCP Profile {dhcp_profile_id}" assert result["result"] is None @@ -406,7 +407,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"Deleted DHCP Profile {dhcp_profile_id}" assert result["result"] @@ -431,7 +432,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No DHCP Profile found with Id {}".format(dhcp_profile_id) + assert result["comment"] == f"No DHCP Profile found with Id {dhcp_profile_id}" assert result["result"] @@ -487,9 +488,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no DHCP Profile found with Id {}".format(dhcp_profile_id) + assert ( + result["comment"] + == f"State absent will do nothing as no DHCP Profile found with Id {dhcp_profile_id}" + ) assert result["result"] is None @@ -725,5 +727,5 @@ def test_present_when_get_by_id_returns_not_found_error(mocked_ok_response): assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created DHCP Profile {}".format(dhcp_profile_id) + assert result["comment"] == f"Created DHCP Profile {dhcp_profile_id}" assert result["result"] diff --git a/tests/unit/states/test_vmc_distributed_firewall_rules.py b/tests/unit/states/test_vmc_distributed_firewall_rules.py index 9c28d3b3..676c07e4 100644 --- a/tests/unit/states/test_vmc_distributed_firewall_rules.py +++ b/tests/unit/states/test_vmc_distributed_firewall_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_distributed_firewall_rules state module """ + from unittest.mock import create_autospec from unittest.mock import MagicMock from unittest.mock import patch @@ -229,7 +230,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Created distributed firewall rule {rule_id}" assert result["result"] @@ -269,7 +270,7 @@ def test_present_to_update_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_updated_distributed_firewall_rule assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Updated distributed firewall rule {rule_id}" assert result["result"] @@ -586,7 +587,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Deleted distributed firewall rule {rule_id}" assert result["result"] @@ -613,7 +614,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(mocked_ok_response): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No distributed firewall rule found with ID {}".format(rule_id) + assert result["comment"] == f"No distributed firewall rule found with ID {rule_id}" assert result["result"] @@ -642,9 +643,9 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will delete distributed firewall rule with ID {}".format(rule_id) + assert ( + result["comment"] == f"State absent will delete distributed firewall rule with ID {rule_id}" + ) assert result["result"] is None @@ -779,5 +780,5 @@ def test_present_when_get_by_id_returns_not_found_error(mocked_ok_response): assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created distributed firewall rule {}".format(rule_id) + assert result["comment"] == f"Created distributed firewall rule {rule_id}" assert result["result"] diff --git a/tests/unit/states/test_vmc_nat_rules.py b/tests/unit/states/test_vmc_nat_rules.py index 59798670..84dd9150 100644 --- a/tests/unit/states/test_vmc_nat_rules.py +++ b/tests/unit/states/test_vmc_nat_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_nat_rules state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -288,7 +289,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created nat rule {}".format(nat_rule) + assert result["comment"] == f"Created nat rule {nat_rule}" assert result["result"] @@ -398,7 +399,7 @@ def test_present_to_update_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_updated_nat_rule assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated nat rule {}".format(nat_rule) + assert result["comment"] == f"Updated nat rule {nat_rule}" assert result["result"] @@ -497,7 +498,7 @@ def test_present_state_for_create_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will create nat rule {}".format(nat_rule) + assert result["comment"] == f"State present will create nat rule {nat_rule}" assert result["result"] is None @@ -526,7 +527,7 @@ def test_present_state_for_update_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will update nat rule {}".format(nat_rule) + assert result["comment"] == f"State present will update nat rule {nat_rule}" assert result["result"] is None @@ -560,7 +561,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted nat rule {}".format(nat_rule) + assert result["comment"] == f"Deleted nat rule {nat_rule}" assert result["result"] @@ -586,7 +587,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(mocked_ok_response): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No nat rule found with Id {}".format(nat_rule) + assert result["comment"] == f"No nat rule found with Id {nat_rule}" assert result["result"] @@ -615,7 +616,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete nat rule with Id {}".format(nat_rule) + assert result["comment"] == f"State absent will delete nat rule with Id {nat_rule}" assert result["result"] is None @@ -644,9 +645,9 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no nat rule found with Id {}".format(nat_rule) + assert ( + result["comment"] == f"State absent will do nothing as no nat rule found with Id {nat_rule}" + ) assert result["result"] is None diff --git a/tests/unit/states/test_vmc_networks.py b/tests/unit/states/test_vmc_networks.py index 09a11859..de7a30fe 100644 --- a/tests/unit/states/test_vmc_networks.py +++ b/tests/unit/states/test_vmc_networks.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_networks state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -201,7 +202,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created network {}".format(network_id) + assert result["comment"] == f"Created network {network_id}" assert result["result"] @@ -238,7 +239,7 @@ def test_present_to_update_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_updated_network assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated network {}".format(network_id) + assert result["comment"] == f"Updated network {network_id}" assert result["result"] @@ -330,7 +331,7 @@ def test_present_state_for_create_when_opts_test_is_true(): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will create network {}".format(network_id) + assert result["comment"] == f"State present will create network {network_id}" assert result["result"] is None @@ -357,7 +358,7 @@ def test_present_state_for_update_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will update network {}".format(network_id) + assert result["comment"] == f"State present will update network {network_id}" assert result["result"] is None @@ -389,7 +390,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted network {}".format(network_id) + assert result["comment"] == f"Deleted network {network_id}" assert result["result"] @@ -413,7 +414,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No network found with ID {}".format(network_id) + assert result["comment"] == f"No network found with ID {network_id}" assert result["result"] @@ -440,7 +441,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete network with ID {}".format(network_id) + assert result["comment"] == f"State absent will delete network with ID {network_id}" assert result["result"] is None @@ -465,9 +466,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no network found with ID {}".format(network_id) + assert ( + result["comment"] + == f"State absent will do nothing as no network found with ID {network_id}" + ) assert result["result"] is None @@ -680,5 +682,5 @@ def test_present_when_get_by_id_returns_not_found_error(mocked_ok_response): assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created network {}".format(network_id) + assert result["comment"] == f"Created network {network_id}" assert result["result"] diff --git a/tests/unit/states/test_vmc_org_user.py b/tests/unit/states/test_vmc_org_user.py index 6088ae02..e446d0c5 100644 --- a/tests/unit/states/test_vmc_org_user.py +++ b/tests/unit/states/test_vmc_org_user.py @@ -91,7 +91,7 @@ def test_absent_state_to_remove_user_when_module_returns_success_response(mocked assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response["results"][0]} - assert result["comment"] == "Removed user {}".format(user_name) + assert result["comment"] == f"Removed user {user_name}" assert result["result"] @@ -115,7 +115,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(mocked_ok_response): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No user found with username {}".format(user_name) + assert result["comment"] == f"No user found with username {user_name}" assert result["result"] @@ -140,7 +140,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "Would have removed user with username {}".format(user_name) + assert result["comment"] == f"Would have removed user with username {user_name}" assert result["result"] is None @@ -167,7 +167,7 @@ def test_absent_state_when_object_to_delete_does_not_exists_and_opts_test_mode_i assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "No user found with username {}".format(user_name) + assert result["comment"] == f"No user found with username {user_name}" assert result["result"] @@ -294,7 +294,7 @@ def test_invited_to_add_user_when_module_returns_success_response(mocked_ok_resp ) mock_invite_response = create_autospec(vmc_org_users_exec.add, return_value=mocked_ok_response) user_name = mocked_ok_response["results"][0]["user"]["username"] - mocked_ok_response.update(message="Invited {} successfully".format(user_name)) + mocked_ok_response.update(message=f"Invited {user_name} successfully") with patch.dict( vmc_org_user.__salt__, @@ -314,7 +314,7 @@ def test_invited_to_add_user_when_module_returns_success_response(mocked_ok_resp assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Invited {} successfully".format(user_name) + assert result["comment"] == f"Invited {user_name} successfully" assert result["result"] @@ -339,7 +339,7 @@ def test_invite_state_for_create_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "User {} would have been invited".format(user_name) + assert result["comment"] == f"User {user_name} would have been invited" assert result["result"] is None @@ -367,7 +367,7 @@ def test_invite_state_during_create_should_correctly_pass_args(mocked_ok_respons ) mock_invite_response = mocked_ok_response.copy() user_name = mocked_ok_response["results"][0]["user"]["username"] - mock_invite_response.update(message="Invited {} successfully".format(user_name)) + mock_invite_response.update(message=f"Invited {user_name} successfully") common_actual_args = { "hostname": "hostname", "refresh_key": "refresh_key", @@ -397,5 +397,5 @@ def test_invite_state_during_create_should_correctly_pass_args(mocked_ok_respons assert result is not None assert result["changes"]["old"] is None assert result["changes"]["new"] == mock_invite_response - assert result["comment"] == "Invited {} successfully".format(user_name) + assert result["comment"] == f"Invited {user_name} successfully" assert result["result"] diff --git a/tests/unit/states/test_vmc_public_ip.py b/tests/unit/states/test_vmc_public_ip.py index 00bb0930..b79d2edd 100644 --- a/tests/unit/states/test_vmc_public_ip.py +++ b/tests/unit/states/test_vmc_public_ip.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_public_ip state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -183,7 +184,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created public IP {}".format(public_ip) + assert result["comment"] == f"Created public IP {public_ip}" assert result["result"] @@ -207,7 +208,7 @@ def test_present_state_for_create_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "Public IP {} would have been created".format(public_ip_id) + assert result["comment"] == f"Public IP {public_ip_id} would have been created" assert result["result"] is None @@ -234,7 +235,7 @@ def test_present_state_for_update_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "Public IP {} would have been updated".format(public_ip_id) + assert result["comment"] == f"Public IP {public_ip_id} would have been updated" assert result["result"] is None @@ -291,7 +292,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted public IP {}".format(public_ip_id) + assert result["comment"] == f"Deleted public IP {public_ip_id}" assert result["result"] @@ -314,7 +315,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(mocked_ok_response): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No public IP found with ID {}".format(public_ip_id) + assert result["comment"] == f"No public IP found with ID {public_ip_id}" assert result["result"] @@ -340,7 +341,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete public IP with ID {}".format(public_ip_id) + assert result["comment"] == f"State absent will delete public IP with ID {public_ip_id}" assert result["result"] is None @@ -366,9 +367,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no public IP found with ID {}".format(public_ip_id) + assert ( + result["comment"] + == f"State absent will do nothing as no public IP found with ID {public_ip_id}" + ) assert result["result"] is None @@ -453,7 +455,7 @@ def test_present_when_get_by_id_returns_not_found_error(mocked_ok_response): assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created public IP {}".format(public_ip_id) + assert result["comment"] == f"Created public IP {public_ip_id}" assert result["result"] diff --git a/tests/unit/states/test_vmc_sddc.py b/tests/unit/states/test_vmc_sddc.py index 6ca36e0e..3bc25e0b 100644 --- a/tests/unit/states/test_vmc_sddc.py +++ b/tests/unit/states/test_vmc_sddc.py @@ -405,7 +405,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted SDDC {}".format(sddc_id) + assert result["comment"] == f"Deleted SDDC {sddc_id}" assert result["result"] @@ -463,7 +463,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete SDDC with ID {}".format(sddc_id) + assert result["comment"] == f"State absent will delete SDDC with ID {sddc_id}" assert result["result"] is None @@ -644,7 +644,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created SDDC {}".format(sddc_name) + assert result["comment"] == f"Created SDDC {sddc_name}" assert result["result"] @@ -670,7 +670,7 @@ def test_present_state_for_create_when_opts_test_is_true(mocked_ok_response): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "SDDC {} would have been created".format(sddc_name) + assert result["comment"] == f"SDDC {sddc_name} would have been created" assert result["result"] is None diff --git a/tests/unit/states/test_vmc_security_groups.py b/tests/unit/states/test_vmc_security_groups.py index 35ad0eb9..d7faf1c1 100644 --- a/tests/unit/states/test_vmc_security_groups.py +++ b/tests/unit/states/test_vmc_security_groups.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_security_groups state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -223,7 +224,7 @@ def test_present_to_create_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created security group {}".format(security_group_id) + assert result["comment"] == f"Created security group {security_group_id}" assert result["result"] @@ -261,7 +262,7 @@ def test_present_to_update_when_module_returns_success_response(mocked_ok_respon assert result is not None assert result["changes"]["new"] == mocked_updated_security_group assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated security group {}".format(security_group_id) + assert result["comment"] == f"Updated security group {security_group_id}" assert result["result"] @@ -354,7 +355,7 @@ def test_present_state_for_create_when_opts_test_is_true(mocked_ok_response): assert result is not None assert not result["changes"] - assert result["comment"] == "Security group {} will be created".format(security_group_id) + assert result["comment"] == f"Security group {security_group_id} will be created" assert result["result"] is None @@ -450,7 +451,7 @@ def test_present_state_for_update_when_opts_test_is_true(mocked_ok_response): assert result is not None assert not result["changes"] - assert result["comment"] == "Security group {} will be updated".format(security_group_id) + assert result["comment"] == f"Security group {security_group_id} will be updated" assert result["result"] is None @@ -553,7 +554,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(mocked_ok_r assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted security group {}".format(security_group_id) + assert result["comment"] == f"Deleted security group {security_group_id}" assert result["result"] @@ -577,7 +578,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(mocked_ok_response): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No security group found with ID {}".format(security_group_id) + assert result["comment"] == f"No security group found with ID {security_group_id}" assert result["result"] @@ -733,5 +734,5 @@ def test_present_when_get_by_id_returns_not_found_error(mocked_ok_response): assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created security group {}".format(security_group_id) + assert result["comment"] == f"Created security group {security_group_id}" assert result["result"] diff --git a/tests/unit/states/test_vmc_security_rules.py b/tests/unit/states/test_vmc_security_rules.py index 77658113..6c6760ac 100644 --- a/tests/unit/states/test_vmc_security_rules.py +++ b/tests/unit/states/test_vmc_security_rules.py @@ -1,6 +1,7 @@ """ Unit tests for vmc_security_rules state module """ + from unittest.mock import create_autospec from unittest.mock import patch @@ -226,7 +227,7 @@ def test_present_to_create_when_module_returns_success_response(get_mocked_data) assert result is not None assert result["changes"]["new"] == mocked_ok_response assert result["changes"]["old"] is None - assert result["comment"] == "Created Security rule {}".format(rule_id) + assert result["comment"] == f"Created Security rule {rule_id}" assert result["result"] @@ -266,7 +267,7 @@ def test_present_to_update_when_module_returns_success_response(get_mocked_data) assert result is not None assert result["changes"]["new"] == mocked_updated_security_rule assert result["changes"]["old"] == mocked_ok_response - assert result["comment"] == "Updated Security rule {}".format(rule_id) + assert result["comment"] == f"Updated Security rule {rule_id}" assert result["result"] @@ -365,7 +366,7 @@ def test_present_state_for_create_when_opts_test_is_true(get_mocked_data): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will create Security rule {}".format(rule_id) + assert result["comment"] == f"State present will create Security rule {rule_id}" assert result["result"] is None @@ -395,7 +396,7 @@ def test_present_state_for_update_when_opts_test_is_true(get_mocked_data): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State present will update Security rule {}".format(rule_id) + assert result["comment"] == f"State present will update Security rule {rule_id}" assert result["result"] is None @@ -430,7 +431,7 @@ def test_absent_state_to_delete_when_module_returns_success_response(get_mocked_ assert result is not None assert result["changes"] == {"new": None, "old": mocked_ok_response} - assert result["comment"] == "Deleted Security rule {}".format(rule_id) + assert result["comment"] == f"Deleted Security rule {rule_id}" assert result["result"] @@ -457,7 +458,7 @@ def test_absent_state_when_object_to_delete_does_not_exists(get_mocked_data): assert result is not None assert result["changes"] == {} - assert result["comment"] == "No Security rule found with Id {}".format(rule_id) + assert result["comment"] == f"No Security rule found with Id {rule_id}" assert result["result"] @@ -487,7 +488,7 @@ def test_absent_state_to_delete_when_opts_test_mode_is_true(get_mocked_data): assert result is not None assert len(result["changes"]) == 0 - assert result["comment"] == "State absent will delete Security rule with Id {}".format(rule_id) + assert result["comment"] == f"State absent will delete Security rule with Id {rule_id}" assert result["result"] is None @@ -517,9 +518,10 @@ def test_absent_state_when_object_to_delete_doesn_not_exists_and_opts_test_mode_ assert result is not None assert len(result["changes"]) == 0 - assert result[ - "comment" - ] == "State absent will do nothing as no Security rule found with Id {}".format(rule_id) + assert ( + result["comment"] + == f"State absent will do nothing as no Security rule found with Id {rule_id}" + ) assert result["result"] is None diff --git a/tests/unit/utils/test_compliance_control.py b/tests/unit/utils/test_compliance_control.py index 21f3e802..416fd16f 100644 --- a/tests/unit/utils/test_compliance_control.py +++ b/tests/unit/utils/test_compliance_control.py @@ -1,6 +1,7 @@ """ Unit Tests for compliance control utils. """ + import pytest import salt.exceptions from config_modules_vmware.framework.auth.contexts.base_context import BaseContext diff --git a/tests/unit/utils/test_connect.py b/tests/unit/utils/test_connect.py index a884119d..6a2ead98 100644 --- a/tests/unit/utils/test_connect.py +++ b/tests/unit/utils/test_connect.py @@ -21,10 +21,13 @@ def test_when_no_config_and_environ_is_missing_conf_values_get_service_instance_should_raise_error( environ_values, ): - with pytest.raises( - ValueError, - match="Cannot create service instance, VMware credentials incomplete.", - ), mock.patch.dict(os.environ, environ_values): + with ( + pytest.raises( + ValueError, + match="Cannot create service instance, VMware credentials incomplete.", + ), + mock.patch.dict(os.environ, environ_values), + ): connect.get_service_instance(config={}) @@ -46,10 +49,13 @@ def test_when_no_config_and_environ_is_missing_conf_values_get_service_instance_ def test_when_no_environ_values_and_config_is_missing_conf_values_get_service_instance_should_raise_error( config_values, ): - with pytest.raises( - ValueError, - match="Cannot create service instance, VMware credentials incomplete.", - ), mock.patch.dict(os.environ, {}): + with ( + pytest.raises( + ValueError, + match="Cannot create service instance, VMware credentials incomplete.", + ), + mock.patch.dict(os.environ, {}), + ): connect.get_service_instance(config=config_values) @@ -313,10 +319,10 @@ def test_get_service_instance_should_correctly_pass_config_values_to_SmartConnec expected_values, esxi_host, profile, conf_values, environ_values ): fake_ssl_ctx = object() - with mock.patch.dict(os.environ, environ_values), mock.patch( - "pyVim.connect.SmartConnect", autospec=True - ) as fake_pyvimconnect, mock.patch( - "ssl._create_unverified_context", autospec=True, return_value=fake_ssl_ctx + with ( + mock.patch.dict(os.environ, environ_values), + mock.patch("pyVim.connect.SmartConnect", autospec=True) as fake_pyvimconnect, + mock.patch("ssl._create_unverified_context", autospec=True, return_value=fake_ssl_ctx), ): connect.get_service_instance(config=conf_values, esxi_host=esxi_host, profile=profile) fake_pyvimconnect.assert_called_with(**expected_values, sslContext=fake_ssl_ctx) diff --git a/tests/unit/utils/test_nsxt_request.py b/tests/unit/utils/test_nsxt_request.py index cd2352ba..f14e1e92 100644 --- a/tests/unit/utils/test_nsxt_request.py +++ b/tests/unit/utils/test_nsxt_request.py @@ -1,6 +1,7 @@ """ Unit test for nsxt_request util """ + import json from unittest import mock from unittest.mock import patch diff --git a/tests/unit/utils/test_vmc_request.py b/tests/unit/utils/test_vmc_request.py index 736deff5..3c3d99a2 100644 --- a/tests/unit/utils/test_vmc_request.py +++ b/tests/unit/utils/test_vmc_request.py @@ -1,6 +1,7 @@ """ Unit test for vmc_request util """ + from unittest import mock from unittest.mock import patch diff --git a/tests/unit/utils/test_vmc_vcenter_request.py b/tests/unit/utils/test_vmc_vcenter_request.py index 38da10e7..e64e562a 100644 --- a/tests/unit/utils/test_vmc_vcenter_request.py +++ b/tests/unit/utils/test_vmc_vcenter_request.py @@ -1,6 +1,7 @@ """ Unit test for vmc_vcenter_request util """ + from unittest import mock from unittest.mock import patch diff --git a/tools/test_value_scraper.py b/tools/test_value_scraper.py index 18e570d0..b02c085f 100755 --- a/tools/test_value_scraper.py +++ b/tools/test_value_scraper.py @@ -51,9 +51,9 @@ def do_it(*, config_file): for cluster in dc.hostFolder.childEntity: config["datacenters"][dc.name][cluster.name] = {} for rule in cluster.configuration.rule: - config["datacenters"][dc.name][cluster.name][ - rule.name - ] = utils_cluster.drs_rule_info(rule) + config["datacenters"][dc.name][cluster.name][rule.name] = ( + utils_cluster.drs_rule_info(rule) + ) hosts = si.content.rootFolder.childEntity[0].hostFolder.childEntity[0].host for host in hosts: config["esxi_host_name"] = host.name