diff options
Diffstat (limited to 'ansible_collections/netapp/storagegrid')
41 files changed, 577 insertions, 908 deletions
diff --git a/ansible_collections/netapp/storagegrid/.github/workflows/main.yml b/ansible_collections/netapp/storagegrid/.github/workflows/main.yml index ec05c061d..b7f88fa13 100644 --- a/ansible_collections/netapp/storagegrid/.github/workflows/main.yml +++ b/ansible_collections/netapp/storagegrid/.github/workflows/main.yml @@ -19,6 +19,9 @@ jobs: - stable-2.11 - stable-2.12 - stable-2.13 + - stable-2.14 + - stable-2.15 + - stable-2.16 - devel steps: diff --git a/ansible_collections/netapp/storagegrid/CHANGELOG.rst b/ansible_collections/netapp/storagegrid/CHANGELOG.rst index c3d64be86..75609239d 100644 --- a/ansible_collections/netapp/storagegrid/CHANGELOG.rst +++ b/ansible_collections/netapp/storagegrid/CHANGELOG.rst @@ -5,6 +5,20 @@ NetApp StorageGRID Collection Release Notes .. contents:: Topics +v21.12.0 +======== + +Minor Changes +------------- + +- na_sg_grid_account - New option ``allow_select_object_content`` for enabling use of the S3 SelectObjectContent API. +- na_sg_grid_account - New option ``description`` for setting additional identifying information for the tenant account. + +Bugfixes +-------- + +- Removed fetch limit in API request and implemented pagination. + v21.11.1 ======== diff --git a/ansible_collections/netapp/storagegrid/FILES.json b/ansible_collections/netapp/storagegrid/FILES.json index 86ed3f4c8..23ff957ab 100644 --- a/ansible_collections/netapp/storagegrid/FILES.json +++ b/ansible_collections/netapp/storagegrid/FILES.json @@ -46,14 +46,14 @@ "name": "plugins/module_utils/netapp.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "9f7a966f44fca740564887beea1232f8e89bad232cde62d9de9a12428ec442c4", + "chksum_sha256": "1ed0567216aa4701bfee854b7de2f62d60949abf94489aac0fef5f6913c694ce", "format": 1 }, { "name": "plugins/module_utils/netapp_module.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "b1a4b77fd27fd5bf2810c0db1d4692093ae5b310992fb183e3817e2e3903891a", + "chksum_sha256": "6bd2c1e2c7184dd19ac5497937d70af8eeea461a838e937316555f3a8cd9b9c4", "format": 1 }, { @@ -67,49 +67,49 @@ "name": "plugins/modules/na_sg_grid_client_certificate.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "e0df90a4c30e50481afe5f508798187ecfbe31b1f5bb7e29e3d724d41203373f", + "chksum_sha256": "dc771ed95fb2b54b73a232729e3a0007a37d106494d856dce767443d910cd71f", "format": 1 }, { "name": "plugins/modules/na_sg_grid_traffic_classes.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "e27c214bb0ff1e9022a575647d1c05d7e0f7bf5c2b35fa49b576f7beb64ce79c", + "chksum_sha256": "53365a83916bd51a3801c5c5458a834daffa5ae8ed4df138b44780bf58df91bf", "format": 1 }, { "name": "plugins/modules/na_sg_org_user_s3_key.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "d71cb0c2c53424b5ce28ead1b06f9c3b3106c709e4d2f0b74879b0eef2d668b6", + "chksum_sha256": "db40e1fd70c92188d6930061fcb24fbd1972c12b817d49800181721192d4da7e", "format": 1 }, { "name": "plugins/modules/na_sg_grid_certificate.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "6b10f9a744d3f78024f3b82f082338aed13f31b5aa71efa86f4ba8ed8cce3088", + "chksum_sha256": "a1b4bde0d686c43c1aa4fdc448a7b5f06c8c0772784af503d8acd2ee4802bfdf", "format": 1 }, { "name": "plugins/modules/na_sg_org_identity_federation.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "93bf629ba06db59b1c74bfda8422471a64d3804776207dc925b175ed3378ed9c", + "chksum_sha256": "99f3d21fdace40abe805fd0818da7645dc304363fa79cc8dd4de31a673b99b8a", "format": 1 }, { "name": "plugins/modules/na_sg_grid_account.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "a20270da62abd5c22c977081e1c4a11b9f96e39d56254711edb21f7c5cbe7f5b", + "chksum_sha256": "4db18b848d3b84d564582ae427343bad23f161ad37d2eda83988eadd2520ecfd", "format": 1 }, { "name": "plugins/modules/na_sg_grid_user.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "bc4be89bd9b2977d59fa51e1ef72b0522d2aad116e7dcb531ba0b214854d878b", + "chksum_sha256": "46d3ee5b4245b496d31a8c0b1274c23b8fcbfb30351ed438bdc68509bffa426a", "format": 1 }, { @@ -123,14 +123,14 @@ "name": "plugins/modules/na_sg_grid_ha_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "48017730eff1e3a04c47c9187488eb915b18ef9293ca06b9dd49832eb2877856", + "chksum_sha256": "0900d7386c65eec20382d4ac5cf517eb828d8f30b4627f99fe71e24d74ba2ad7", "format": 1 }, { "name": "plugins/modules/na_sg_org_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "6b6e5bff028d0bd999f8b7a6998e59451c7bd4e5c0de63953ddd19ee13fafad5", + "chksum_sha256": "58b6d593f1f01bfcee93df320eb041f5fffc049e5d6c5cd9553b0e30e4ce41c0", "format": 1 }, { @@ -144,21 +144,21 @@ "name": "plugins/modules/na_sg_grid_identity_federation.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "279f42f668b563bf22aa79be77fd3b90de7dab0a8bccbfe4773900acf820e64c", + "chksum_sha256": "76763a610daaa395c25a4d16493f9c31688acad7c7d16e5f99ada9f7ba943c9f", "format": 1 }, { "name": "plugins/modules/na_sg_grid_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "0fe8a0e6ce5aefad01638e493dda3964019360e0c04cd6aa3b1e432d586b00d9", + "chksum_sha256": "d6601e316694a46048dbb6e2c7a1508d00f6005f1887cb9a0b713deb6455a5fc", "format": 1 }, { "name": "plugins/modules/na_sg_org_user.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "5766c6c0c639b848c6ce3007533059d570f66f9c48f477e0e915b3f5c90a96ae", + "chksum_sha256": "39c2b19ca896f01a67032f5aa4e020f23e7a5ba0ee184955e9c9bc09bc9b33a2", "format": 1 }, { @@ -179,7 +179,7 @@ "name": "plugins/modules/na_sg_org_container.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "70b7ca86ed2853ca6fa99a5dc712770e342d1d5b95fea154a67d7c7db3df3c8c", + "chksum_sha256": "a8ffb8ce1e634d6590fe5977331b9109f97522e9b55db943d29cc8c9d01797f6", "format": 1 }, { @@ -228,7 +228,7 @@ "name": "tests/unit/compat/builtins.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "ba13a350ade8ef804336f888d5883b8e54f8bddfb9d0fadc10277a8ca6540f4e", + "chksum_sha256": "1c80c30f37ac8fd42b620229e7f77c740c290d33ee6dee5a1421231599440b45", "format": 1 }, { @@ -270,21 +270,21 @@ "name": "tests/unit/plugins/modules/test_na_sg_grid_dns.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "a96a6d0218e6e7764786af0bf8dc8fbb24c3b492d57a627a7cf827bb33b2c327", + "chksum_sha256": "44f6a5d02d27a2364a23672136591dcb01abcd0277d92525f6031632d437806c", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_regions.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "870928ef29b01babed679fb5d207eb997ed724aa97135528f45cfda0314705c3", + "chksum_sha256": "1c8ac5797b1d6c7bd7d22441d7aa3bcae3fa769ee15211aba88fed3c64572a33", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_org_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "ff42467a461b8a69a2a2895242852444c89e0471bc0101ae10f99bbcf54528cb", + "chksum_sha256": "3f561eaac51b9985e7712cc11b8dc27a662966183c618cfc5782fafa36113f10", "format": 1 }, { @@ -298,49 +298,49 @@ "name": "tests/unit/plugins/modules/test_na_sg_org_user.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "c7fa1a8212a01dd81411129c7a31048d3e154c9729a0ac28a8016ace1fbd6e87", + "chksum_sha256": "733d1f3f60a7f6f7ea79607b7fa234acd4714208d729f02ba6500a38d1b9c2b2", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_ntp.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "7299330b0ddfa005c4976c10b3c564b4c84c5f3cc620d566f9baa0ebe63460b1", + "chksum_sha256": "eb9db311f0ea56a8f127a04309ccece5ae7b600323655f6ba38dc2c5bee4375c", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "15ad7caefc2c6fc3c9e473d176e032473f2065dfb249f3524263ec6129b61e6c", + "chksum_sha256": "be611950d6a14f995c887deb8182fafd8c67cdfe6b0ade79397a14b99ed0153e", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_identity_federation.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "3943d740fc467010966238cce4d10aa484ea70d6e689704043cee7344e1916b5", + "chksum_sha256": "04ba5f49437eccbb9bb5442f7ef212ea6166125b316708abab40789b81b0760a", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_gateway.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "c87e92555fb3aafaa82e197910b8fa61976ce358e220da2e0968469ea0df505c", + "chksum_sha256": "a523e1f825dd4b6208a43053e9cb65e8b989623f068407ab4ae62faddbdf6b8e", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_client_certificate.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "1ab3f4d2b408d5943dfb334ed64729ba5b9a2974c78ef1c2cb48622289181e52", + "chksum_sha256": "f7eb0e4d25d9d7e9c763cbc2672843cb19ddfd0d04c50912f0fde46a8c0b93f4", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_certificate.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "d046329c9ba078773c442a8bc47b00c76b49eac762f05f1b43789689056e295a", + "chksum_sha256": "b7a86230f98f2c484f2ea95bac11db493b773331df376cc5160699a04c7dd9b0", "format": 1 }, { @@ -354,49 +354,49 @@ "name": "tests/unit/plugins/modules/test_na_sg_grid_account.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "eebfa82a09b7b3413d77749c1afc10a69cde0d90e940b0d454af807cebc476be", + "chksum_sha256": "5e17ee5fccccb6c8bd0e2d7502cb7692a36fc35be907a1d83deaa2912b2ca757", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_org_identity_federation.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "cda86d8e2632609873d7ccda496ca69e0884ba82712418e23148025f0f3a5482", + "chksum_sha256": "0caaa9aa11d0bca838c04c69f08a3990bbc3c62dac8a8e10c9a0a68e29e3b27c", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_traffic_classes.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "4ec3ad3f3716e69cd39a3dddbbffc1796d415b4a8a729f5d61289a3f39967b18", + "chksum_sha256": "3777b53e784b63fb0ce0d94ba2aed6d3a78c17e4f188c563bf5c30ccdffa6b58", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_ha_group.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "a0782c6e1a6a9185cf4724da8d7e4363f6af13934efd4152779fcbe9aa05c2b7", + "chksum_sha256": "a622cabb46a8312f46aea74652924cc95cf83e8e3f0e0f68f8144c0ac37049ab", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_org_container.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "9593869384f8f9f0f0de69e63f72a90de414e858dbfead681966e54b9ebd4b23", + "chksum_sha256": "3371709800c15ef720d1d6fb61d5b6dee1810f88876c3d990ebb972773875be2", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_org_user_s3_key.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "d39947658ff5fdbc740275959f4fc82fcbdfd84553b771d78632d461e1638b4f", + "chksum_sha256": "e86f607484396e16104520acf982085d94762ff1b38858e68a1b89d9f8a7e18e", "format": 1 }, { "name": "tests/unit/plugins/modules/test_na_sg_grid_user.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "614c50a7ef9b7fe296025441e0350b78cb5e381f04d336f1cb49512d60404605", + "chksum_sha256": "757616d3d4eeec338164e5222485e0482a1847f5d4349413a975dd5b9d3b0f3c", "format": 1 }, { @@ -410,7 +410,7 @@ "name": "meta/runtime.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "fe82353b93dc1bedb4d4f8695b23d6a33537fd0401c406547d132d4497ff7ca2", + "chksum_sha256": "67abe4b8350d451263b18bca0b9327596ccbe500c698254821a89bee74e06416", "format": 1 }, { @@ -498,6 +498,13 @@ "format": 1 }, { + "name": "changelogs/fragments/github-18-19.yaml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "227377dc70d736516f2a4f7173b0b0d84ba8d267b484caf33969f352a27dde33", + "format": 1 + }, + { "name": "changelogs/fragments/DEVOPS-4416.yaml", "ftype": "file", "chksum_type": "sha256", @@ -515,14 +522,14 @@ "name": "changelogs/changelog.yaml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "2d6b62b96b1a730bbb09d926e37a0dc4f1d3cf9f4218e8a2feb4a00c30c66171", + "chksum_sha256": "2d99a19800ede00d0b9518ac1a1e8ce27bdd39e150f6763edf172111b29d6beb", "format": 1 }, { "name": "README.md", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "1fb8b745f8becd6ea2348808e1979a31486ab9357ec1197cb3136c2727d712b2", + "chksum_sha256": "d47ce7e19a1440ac93d9157658df1d57c089475498bb5d37be5a93c40fdbe427", "format": 1 }, { @@ -557,14 +564,14 @@ "name": ".github/workflows/main.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "07c19a69adcb2c9c482cadf8785c3bc0bf621ff161a592b48db9458e0673b1c5", + "chksum_sha256": "2c07ade8e33b766310fd78e9024731e887a52008fad17a6c4f5e1813419c70ce", "format": 1 }, { "name": "CHANGELOG.rst", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "131e7c4ca2ddb153d23af2174d262f4b0ae62079e892ecf36f062e929d43f729", + "chksum_sha256": "b1fed61f9f0be28033409bcfe32813ce411d9424c66c1ed7627eb2185a7a506c", "format": 1 } ], diff --git a/ansible_collections/netapp/storagegrid/MANIFEST.json b/ansible_collections/netapp/storagegrid/MANIFEST.json index 53238fc0d..e784fbb86 100644 --- a/ansible_collections/netapp/storagegrid/MANIFEST.json +++ b/ansible_collections/netapp/storagegrid/MANIFEST.json @@ -2,7 +2,7 @@ "collection_info": { "namespace": "netapp", "name": "storagegrid", - "version": "21.11.1", + "version": "21.12.0", "authors": [ "NetApp Ansible Team <ng-ansibleteam@netapp.com>" ], @@ -25,7 +25,7 @@ "name": "FILES.json", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "c9021a8a169b205830d9914712b6c039123456973f905ab635b85e37192f132c", + "chksum_sha256": "82b72a79f55eabbcf3d3d2b0106888aba71788eb07dd1135a4e28040d7857335", "format": 1 }, "format": 1 diff --git a/ansible_collections/netapp/storagegrid/README.md b/ansible_collections/netapp/storagegrid/README.md index 582a77329..fe48d71b8 100644 --- a/ansible_collections/netapp/storagegrid/README.md +++ b/ansible_collections/netapp/storagegrid/README.md @@ -79,6 +79,15 @@ This collection follows the [Ansible project's Code of Conduct](https://docs.ans # Release Notes +## 21.12.0 + +### Minor Changes + - na_sg_grid_account - New option ``description`` for setting additional identifying information for the tenant account. + - na_sg_grid_account - New option ``allow_select_object_content`` for enabling use of the S3 SelectObjectContent API. + +### Bug Fixes + - Removed fetch limit in API request and implemented pagination. + ## 21.11.1 ### Bug Fixes diff --git a/ansible_collections/netapp/storagegrid/changelogs/changelog.yaml b/ansible_collections/netapp/storagegrid/changelogs/changelog.yaml index 288cbdc34..89e14c37a 100644 --- a/ansible_collections/netapp/storagegrid/changelogs/changelog.yaml +++ b/ansible_collections/netapp/storagegrid/changelogs/changelog.yaml @@ -117,6 +117,18 @@ releases: fragments: - 21.11.1.yaml release_date: '2022-09-23' + 21.12.0: + changes: + bugfixes: + - Removed fetch limit in API request and implemented pagination. + minor_changes: + - na_sg_grid_account - New option ``allow_select_object_content`` for enabling + use of the S3 SelectObjectContent API. + - na_sg_grid_account - New option ``description`` for setting additional identifying + information for the tenant account. + fragments: + - github-18-19.yaml + release_date: '2024-01-11' 21.6.0: changes: bugfixes: diff --git a/ansible_collections/netapp/storagegrid/changelogs/fragments/github-18-19.yaml b/ansible_collections/netapp/storagegrid/changelogs/fragments/github-18-19.yaml new file mode 100644 index 000000000..43bc9fcad --- /dev/null +++ b/ansible_collections/netapp/storagegrid/changelogs/fragments/github-18-19.yaml @@ -0,0 +1,6 @@ +minor_changes: + - na_sg_grid_account - New option ``description`` for setting additional identifying information for the tenant account. + - na_sg_grid_account - New option ``allow_select_object_content`` for enabling use of the S3 SelectObjectContent API. + +bugfixes: + - Removed fetch limit in API request and implemented pagination. diff --git a/ansible_collections/netapp/storagegrid/meta/runtime.yml b/ansible_collections/netapp/storagegrid/meta/runtime.yml index 4625ad259..269689657 100644 --- a/ansible_collections/netapp/storagegrid/meta/runtime.yml +++ b/ansible_collections/netapp/storagegrid/meta/runtime.yml @@ -1,5 +1,5 @@ --- -requires_ansible: ">=2.9.10" +requires_ansible: ">=2.14" action_groups: netapp_storagegrid: - na_sg_grid_account diff --git a/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp.py b/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp.py index 9892ae7b5..eaa7836a5 100644 --- a/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp.py +++ b/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp.py @@ -30,20 +30,9 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import json -import mimetypes -import os -import random +from ansible.module_utils.basic import missing_required_lib -from pprint import pformat -from ansible.module_utils import six -from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError -from ansible.module_utils.urls import open_url -from ansible.module_utils.api import basic_auth_argument_spec -from ansible.module_utils._text import to_native - -COLLECTION_VERSION = "21.11.1" +COLLECTION_VERSION = "21.12.0" try: import requests @@ -52,13 +41,6 @@ try: except ImportError: HAS_REQUESTS = False -import ssl - -try: - from urlparse import urlparse, urlunparse -except ImportError: - from urllib.parse import urlparse, urlunparse - POW2_BYTE_MAP = dict( # Here, 1 kb = 1024 @@ -76,7 +58,6 @@ POW2_BYTE_MAP = dict( def na_storagegrid_host_argument_spec(): - return dict( api_url=dict(required=True, type="str"), validate_certs=dict(required=False, type="bool", default=True), diff --git a/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp_module.py b/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp_module.py index f562938cf..4cbf55c2f 100644 --- a/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp_module.py +++ b/ansible_collections/netapp/storagegrid/plugins/module_utils/netapp_module.py @@ -34,8 +34,6 @@ from copy import deepcopy __metaclass__ = type -import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils - def cmp(obj1, obj2): """ @@ -79,14 +77,14 @@ class NetAppModule(object): return self.parameters def get_cd_action(self, current, desired): - """ takes a desired state and a current state, and return an action: - create, delete, None - eg: - is_present = 'absent' - some_object = self.get_object(source) - if some_object is not None: - is_present = 'present' - action = cd_action(current=is_present, desired = self.desired.state()) + """takes a desired state and a current state, and return an action: + create, delete, None + eg: + is_present = 'absent' + some_object = self.get_object(source) + if some_object is not None: + is_present = 'present' + action = cd_action(current=is_present, desired = self.desired.state()) """ if "state" in desired: desired_state = desired["state"] @@ -121,19 +119,19 @@ class NetAppModule(object): @staticmethod def check_keys(current, desired): - ''' TODO: raise an error if keys do not match - with the exception of: - new_name, state in desired - ''' + """TODO: raise an error if keys do not match + with the exception of: + new_name, state in desired + """ def is_rename_action(self, source, target): - """ takes a source and target object, and returns True - if a rename is required - eg: - source = self.get_object(source_name) - target = self.get_object(target_name) - action = is_rename_action(source, target) - :return: None for error, True for rename action, False otherwise + """takes a source and target object, and returns True + if a rename is required + eg: + source = self.get_object(source_name) + target = self.get_object(target_name) + action = is_rename_action(source, target) + :return: None for error, True for rename action, False otherwise """ if source is None and target is None: # error, do nothing @@ -155,14 +153,14 @@ class NetAppModule(object): @staticmethod def compare_lists(current, desired, get_list_diff): - ''' compares two lists and return a list of elements that are either the desired elements or elements that are - modified from the current state depending on the get_list_diff flag - :param: current: current item attribute in ONTAP - :param: desired: attributes from playbook - :param: get_list_diff: specifies whether to have a diff of desired list w.r.t current list for an attribute - :return: list of attributes to be modified - :rtype: list - ''' + """compares two lists and return a list of elements that are either the desired elements or elements that are + modified from the current state depending on the get_list_diff flag + :param: current: current item attribute in ONTAP + :param: desired: attributes from playbook + :param: get_list_diff: specifies whether to have a diff of desired list w.r.t current list for an attribute + :return: list of attributes to be modified + :rtype: list + """ current_copy = deepcopy(current) desired_copy = deepcopy(desired) @@ -192,19 +190,19 @@ class NetAppModule(object): return None def get_modified_attributes(self, current, desired, get_list_diff=False): - ''' takes two dicts of attributes and return a dict of attributes that are - not in the current state - It is expected that all attributes of interest are listed in current and - desired. - :param: current: current attributes on StorageGRID - :param: desired: attributes from playbook - :param: get_list_diff: specifies whether to have a diff of desired list w.r.t current list for an attribute - :return: dict of attributes to be modified - :rtype: dict - NOTE: depending on the attribute, the caller may need to do a modify or a - different operation (eg move volume if the modified attribute is an - aggregate name) - ''' + """takes two dicts of attributes and return a dict of attributes that are + not in the current state + It is expected that all attributes of interest are listed in current and + desired. + :param: current: current attributes on StorageGRID + :param: desired: attributes from playbook + :param: get_list_diff: specifies whether to have a diff of desired list w.r.t current list for an attribute + :return: dict of attributes to be modified + :rtype: dict + NOTE: depending on the attribute, the caller may need to do a modify or a + different operation (eg move volume if the modified attribute is an + aggregate name) + """ # if the object does not exist, we can't modify it modified = {} if current is None: @@ -217,7 +215,9 @@ class NetAppModule(object): for key, value in current.items(): if key in desired and desired[key] is not None: if isinstance(value, list): - modified_list = self.compare_lists(value, desired[key], get_list_diff) # get modified list from current and desired + modified_list = self.compare_lists( + value, desired[key], get_list_diff + ) # get modified list from current and desired if modified_list is not None: modified[key] = modified_list elif isinstance(value, dict): @@ -228,7 +228,9 @@ class NetAppModule(object): try: result = cmp(value, desired[key]) except TypeError as exc: - raise TypeError("%s, key: %s, value: %s, desired: %s" % (repr(exc), key, repr(value), repr(desired[key]))) + raise TypeError( + "%s, key: %s, value: %s, desired: %s" % (repr(exc), key, repr(value), repr(desired[key])) + ) else: if result != 0: modified[key] = desired[key] diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_account.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_account.py index 88943c082..a800a8c67 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_account.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_account.py @@ -39,6 +39,11 @@ options: - Name of the tenant. - Required for create or modify operation. type: str + description: + description: + - Additional identifying information for the tenant account. + type: str + version_added: 21.12.0 account_id: description: - Account Id of the tenant. @@ -63,6 +68,11 @@ options: description: - Allows tenant to use platform services features such as CloudMirror. type: bool + allow_select_object_content: + description: + - Allows tenant to use the S3 SelectObjectContent API to filter and retrieve object data. + type: bool + version_added: 21.12.0 root_access_group: description: - Existing federated group to have initial Root Access permissions for the tenant. @@ -177,13 +187,20 @@ class SgGridAccount(object): self.argument_spec = netapp_utils.na_storagegrid_host_argument_spec() self.argument_spec.update( dict( - state=dict(required=False, type="str", choices=["present", "absent"], default="present"), + state=dict( + required=False, + type="str", + choices=["present", "absent"], + default="present", + ), name=dict(required=False, type="str"), + description=dict(required=False, type="str"), account_id=dict(required=False, type="str"), protocol=dict(required=False, choices=["s3", "swift"]), management=dict(required=False, type="bool", default=True), use_own_identity_source=dict(required=False, type="bool"), allow_platform_services=dict(required=False, type="bool"), + allow_select_object_content=dict(required=False, type="bool"), root_access_group=dict(required=False, type="str"), quota_size=dict(required=False, type="int", default=0), quota_size_unit=dict( @@ -203,9 +220,7 @@ class SgGridAccount(object): type="str", ), password=dict(required=False, type="str", no_log=True), - update_password=dict( - default="on_create", choices=["on_create", "always"] - ), + update_password=dict(default="on_create", choices=["on_create", "always"]), ) ) @@ -232,12 +247,17 @@ class SgGridAccount(object): self.parameters = self.na_helper.set_parameters(self.module.params) # Calling generic SG rest_api class self.rest_api = SGRestAPI(self.module) + # Get API version + self.rest_api.get_sg_product_version() # Checking for the parameters passed and create new parameters list self.data = {} self.data["name"] = self.parameters["name"] self.data["capabilities"] = [self.parameters["protocol"]] + if self.parameters.get("description") is not None: + self.data["description"] = self.parameters["description"] + if self.parameters.get("password") is not None: self.data["password"] = self.parameters["password"] @@ -248,28 +268,19 @@ class SgGridAccount(object): self.data["policy"] = {} if "use_own_identity_source" in self.parameters: - self.data["policy"]["useAccountIdentitySource"] = self.parameters[ - "use_own_identity_source" - ] + self.data["policy"]["useAccountIdentitySource"] = self.parameters["use_own_identity_source"] if "allow_platform_services" in self.parameters: - self.data["policy"]["allowPlatformServices"] = self.parameters[ - "allow_platform_services" - ] + self.data["policy"]["allowPlatformServices"] = self.parameters["allow_platform_services"] if self.parameters.get("root_access_group") is not None: self.data["grantRootAccessToGroup"] = self.parameters["root_access_group"] if self.parameters["quota_size"] > 0: self.parameters["quota_size"] = ( - self.parameters["quota_size"] - * netapp_utils.POW2_BYTE_MAP[ - self.parameters["quota_size_unit"] - ] + self.parameters["quota_size"] * netapp_utils.POW2_BYTE_MAP[self.parameters["quota_size_unit"]] ) - self.data["policy"]["quotaObjectBytes"] = self.parameters[ - "quota_size" - ] + self.data["policy"]["quotaObjectBytes"] = self.parameters["quota_size"] elif self.parameters["quota_size"] == 0: self.data["policy"]["quotaObjectBytes"] = None @@ -277,19 +288,31 @@ class SgGridAccount(object): if self.parameters.get("password") is not None: self.pw_change["password"] = self.parameters["password"] + if "allow_select_object_content" in self.parameters: + self.rest_api.fail_if_not_sg_minimum_version("S3 SelectObjectContent API", 11, 6) + self.data["policy"]["allowSelectObjectContent"] = self.parameters["allow_select_object_content"] + def get_tenant_account_id(self): # Check if tenant account exists # Return tenant account info if found, or None - api = "api/v3/grid/accounts?limit=350" + api = "api/v3/grid/accounts" + params = {"limit": 20} + params["marker"] = "" - list_accounts, error = self.rest_api.get(api) + while params["marker"] is not None: + list_accounts, error = self.rest_api.get(api, params) - if error: - self.module.fail_json(msg=error) + if error: + self.module.fail_json(msg=error) - for account in list_accounts.get("data"): - if account["name"] == self.parameters["name"]: - return account["id"] + if len(list_accounts.get("data")) > 0: + for account in list_accounts["data"]: + if account["name"] == self.parameters["name"]: + return account["id"] + # Set marker to last element + params["marker"] = list_accounts["data"][-1]["id"] + else: + params["marker"] = None return None @@ -351,62 +374,18 @@ class SgGridAccount(object): tenant_account = None if self.parameters.get("account_id"): - tenant_account = self.get_tenant_account( - self.parameters["account_id"] - ) + tenant_account = self.get_tenant_account(self.parameters["account_id"]) else: tenant_account_id = self.get_tenant_account_id() if tenant_account_id: tenant_account = self.get_tenant_account(tenant_account_id) - cd_action = self.na_helper.get_cd_action( - tenant_account, self.parameters - ) + cd_action = self.na_helper.get_cd_action(tenant_account, self.parameters) if cd_action is None and self.parameters["state"] == "present": # let's see if we need to update parameters - update = False - - capability_diff = [ - i - for i in self.data["capabilities"] - + tenant_account["capabilities"] - if i not in self.data["capabilities"] - or i not in tenant_account["capabilities"] - ] - - if self.parameters["quota_size"] > 0: - if ( - tenant_account["policy"]["quotaObjectBytes"] - != self.parameters["quota_size"] - ): - update = True - elif ( - self.parameters["quota_size"] == 0 - and tenant_account["policy"]["quotaObjectBytes"] is not None - ): - update = True - - if ( - "use_own_identity_source" in self.parameters - and tenant_account["policy"]["useAccountIdentitySource"] - != self.parameters["use_own_identity_source"] - ): - update = True - - elif ( - "allow_platform_services" in self.parameters - and tenant_account["policy"]["allowPlatformServices"] - != self.parameters["allow_platform_services"] - ): - update = True - - elif capability_diff: - update = True - - if update: - self.na_helper.changed = True + modify = self.na_helper.get_modified_attributes(tenant_account, self.data) result_message = "" resp_data = tenant_account @@ -423,7 +402,7 @@ class SgGridAccount(object): resp_data = self.create_tenant_account() result_message = "Tenant Account created" - else: + elif modify: resp_data = self.update_tenant_account(tenant_account["id"]) result_message = "Tenant Account updated" @@ -441,9 +420,7 @@ class SgGridAccount(object): results = [result_message, "Tenant Account root password updated"] result_message = "; ".join(filter(None, results)) - self.module.exit_json( - changed=self.na_helper.changed, msg=result_message, resp=resp_data - ) + self.module.exit_json(changed=self.na_helper.changed, msg=result_message, resp=resp_data) def main(): diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_certificate.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_certificate.py index 97f9ab972..4b0aa64bf 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_certificate.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_certificate.py @@ -89,8 +89,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_client_certificate.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_client_certificate.py index aa381b397..a8c36a3df 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_client_certificate.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_client_certificate.py @@ -105,8 +105,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_group.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_group.py index 60592c609..fba212228 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_group.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_group.py @@ -153,7 +153,6 @@ resp: } """ -import json import re import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils @@ -210,7 +209,10 @@ class SgGridGroup(object): "object_metadata": "objectMetadata", "root_access": "rootAccess", } - self.module = AnsibleModule(argument_spec=self.argument_spec, supports_check_mode=True,) + self.module = AnsibleModule( + argument_spec=self.argument_spec, + supports_check_mode=True, + ) self.na_helper = NetAppModule() diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_ha_group.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_ha_group.py index c99719c6d..8420620b4 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_ha_group.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_ha_group.py @@ -150,8 +150,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_identity_federation.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_identity_federation.py index 729cf4545..b1d3292e1 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_identity_federation.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_identity_federation.py @@ -164,9 +164,6 @@ resp: } """ -import json -import re - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule @@ -218,7 +215,10 @@ class SgGridIdentityFederation: "ldap_group_uuid_attribute": "ldapGroupUUIDAttribute", "ca_cert": "caCert", } - self.module = AnsibleModule(argument_spec=self.argument_spec, supports_check_mode=True,) + self.module = AnsibleModule( + argument_spec=self.argument_spec, + supports_check_mode=True, + ) self.na_helper = NetAppModule() diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_traffic_classes.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_traffic_classes.py index 9901a3e00..842148135 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_traffic_classes.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_traffic_classes.py @@ -196,8 +196,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_user.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_user.py index 521d4f566..f93942508 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_user.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_grid_user.py @@ -102,10 +102,8 @@ resp: } """ -import json import re - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_container.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_container.py index da9663184..6ca94e821 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_container.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_container.py @@ -130,8 +130,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_group.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_group.py index d13a7559a..1fd27fda0 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_group.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_group.py @@ -70,7 +70,6 @@ options: s3_policy: description: - StorageGRID S3 Group Policy. - default: "" type: json """ @@ -255,10 +254,16 @@ class SgOrgGroup(object): update = False if self.parameters.get("management_policy"): - if org_group.get("policies") is None or org_group.get("policies", {}).get("management") != self.data["policies"]["management"]: + if ( + org_group.get("policies") is None + or org_group.get("policies", {}).get("management") != self.data["policies"]["management"] + ): update = True if self.parameters.get("s3_policy"): - if org_group.get("policies") is None or org_group.get("policies", {}).get("s3") != self.data["policies"]["s3"]: + if ( + org_group.get("policies") is None + or org_group.get("policies", {}).get("s3") != self.data["policies"]["s3"] + ): update = True if update: diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_identity_federation.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_identity_federation.py index 4b6811cd6..f192b8343 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_identity_federation.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_identity_federation.py @@ -164,9 +164,6 @@ resp: } """ -import json -import re - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule @@ -218,7 +215,10 @@ class SgOrgIdentityFederation: "ldap_group_uuid_attribute": "ldapGroupUUIDAttribute", "ca_cert": "caCert", } - self.module = AnsibleModule(argument_spec=self.argument_spec, supports_check_mode=True,) + self.module = AnsibleModule( + argument_spec=self.argument_spec, + supports_check_mode=True, + ) self.na_helper = NetAppModule() diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user.py index 455ffa345..436e1f2c3 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user.py @@ -102,10 +102,8 @@ resp: } """ -import json import re - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import ( @@ -133,9 +131,7 @@ class SgOrgUser(object): member_of=dict(required=False, type="list", elements="str"), disable=dict(required=False, type="bool"), password=dict(required=False, type="str", no_log=True), - update_password=dict( - default="on_create", choices=["on_create", "always"] - ), + update_password=dict(default="on_create", choices=["on_create", "always"]), ) ) @@ -169,9 +165,7 @@ class SgOrgUser(object): re_local_user.match(self.parameters["unique_name"]) is None and re_fed_user.match(self.parameters["unique_name"]) is None ): - self.module.fail_json( - msg="unique_name must begin with 'user/' or 'federated-user/'" - ) + self.module.fail_json(msg="unique_name must begin with 'user/' or 'federated-user/'") self.pw_change = {} if self.parameters.get("password") is not None: @@ -254,13 +248,9 @@ class SgOrgUser(object): if self.parameters.get("member_of"): org_groups = self.get_org_groups() try: - self.data["memberOf"] = [ - org_groups[x] for x in self.parameters["member_of"] - ] + self.data["memberOf"] = [org_groups[x] for x in self.parameters["member_of"]] except KeyError as e: - self.module.fail_json( - msg="Invalid unique_group supplied: '%s' not found" % e.args[0] - ) + self.module.fail_json(msg="Invalid unique_group supplied: '%s' not found" % e.args[0]) cd_action = self.na_helper.get_cd_action(org_user, self.parameters) @@ -279,9 +269,7 @@ class SgOrgUser(object): if member_of_diff: update = True - if self.parameters.get("disable") is not None and self.parameters[ - "disable" - ] != org_user.get("disable"): + if self.parameters.get("disable") is not None and self.parameters["disable"] != org_user.get("disable"): update = True if update: @@ -318,9 +306,7 @@ class SgOrgUser(object): results = [result_message, "Org User password updated"] result_message = "; ".join(filter(None, results)) - self.module.exit_json( - changed=self.na_helper.changed, msg=result_message, resp=resp_data - ) + self.module.exit_json(changed=self.na_helper.changed, msg=result_message, resp=resp_data) def main(): diff --git a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user_s3_key.py b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user_s3_key.py index 0de396eb7..f04dc9337 100644 --- a/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user_s3_key.py +++ b/ansible_collections/netapp/storagegrid/plugins/modules/na_sg_org_user_s3_key.py @@ -74,8 +74,6 @@ resp: } """ -import json - import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible.module_utils.basic import AnsibleModule from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule @@ -135,7 +133,10 @@ class SgOrgUserS3Key(object): api = "api/v3/org/users/current-user/s3-access-keys/%s" % access_key if user_id: - api = "api/v3/org/users/%s/s3-access-keys/%s" % (user_id, access_key,) + api = "api/v3/org/users/%s/s3-access-keys/%s" % ( + user_id, + access_key, + ) response, error = self.rest_api.get(api) @@ -162,7 +163,10 @@ class SgOrgUserS3Key(object): api = "api/v3/org/users/current-user/s3-access-keys" if user_id: - api = "api/v3/org/users/%s/s3-access-keys/%s" % (user_id, access_key,) + api = "api/v3/org/users/%s/s3-access-keys/%s" % ( + user_id, + access_key, + ) self.data = None response, error = self.rest_api.delete(api, self.data) diff --git a/ansible_collections/netapp/storagegrid/tests/unit/compat/builtins.py b/ansible_collections/netapp/storagegrid/tests/unit/compat/builtins.py index bfc8adfbe..a5b04c088 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/compat/builtins.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/compat/builtins.py @@ -27,6 +27,7 @@ __metaclass__ = type # One unittest needs to import builtins via __import__() so we need to have # the string that represents it try: + # pylint: disable=unused-import import __builtin__ except ImportError: BUILTINS = "builtins" diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_account.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_account.py index e96697381..2e9686538 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_account.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_account.py @@ -9,25 +9,20 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_account import ( SgGridAccount as grid_account_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + + # REST API canned responses when mocking send_request SRR = { # common responses @@ -35,12 +30,15 @@ SRR = { "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), + "version_114": ({"data": {"productVersion": "11.4.0-20200721.1338.d3969b3"}}, None), + "version_116": ({"data": {"productVersion": "11.6.0-20211120.0301.850531e"}}, None), "pw_change_good": ({"code": 204}, None), "grid_accounts": ( { "data": [ { "name": "TestTenantAccount", + "description": "Ansible Test", "capabilities": ["management", "s3"], "policy": { "useAccountIdentitySource": True, @@ -57,6 +55,7 @@ SRR = { { "data": { "name": "TestTenantAccount", + "description": "Ansible Test", "capabilities": ["management", "s3"], "policy": { "useAccountIdentitySource": True, @@ -72,6 +71,7 @@ SRR = { { "data": { "name": "TestTenantAccount", + "description": "Update Account", "capabilities": ["management", "s3"], "policy": { "useAccountIdentitySource": True, @@ -133,12 +133,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -179,6 +177,7 @@ class TestMyModule(unittest.TestCase): { "state": "present", "name": "TestTenantAccount", + "description": "Ansible Test", "protocol": "s3", "management": True, "use_own_identity_source": True, @@ -204,114 +203,95 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_account_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) - def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") + def test_module_fail_when_required_args_present(self, mock_request): + """required arguments are reported as errors""" + mock_request.side_effect = [ + SRR["version_114"], + ] with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_account_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_grid_account_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_account()) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["empty_good"], # get SRR["grid_accounts"], # post SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_tenant_account_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_tenant_account_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_grid_account_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_account()) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get id SRR["grid_account_record"], # get account SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_tenant_account_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_tenant_account_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_account_pass(self, mock_request): args = self.set_args_create_na_sg_grid_account() args["quota_size"] = 10 + args["description"] = "Update Account" set_module_args(args) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get SRR["grid_account_record"], # get SRR["grid_account_record_with_quota"], # put SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_tenant_account_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_tenant_account_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_account_quota_pass(self, mock_request): args = self.set_args_create_na_sg_grid_account() args["quota_size"] = 20480 args["quota_size_unit"] = "mb" set_module_args(args) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get SRR["grid_account_record_with_quota"], # get SRR["grid_account_record_update_quota"], # put SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_tenant_account_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_tenant_account_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # update Tenant Account and set pass - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_account_and_set_password_pass(self, mock_request): args = self.set_args_create_na_sg_grid_account() args["quota_size"] = 20480 @@ -319,62 +299,84 @@ class TestMyModule(unittest.TestCase): args["update_password"] = "always" set_module_args(args) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get SRR["grid_account_record_with_quota"], # get SRR["grid_account_record_update_quota"], # put SRR["pw_change_good"], # post SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_grid_account_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_grid_account_and_set_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # set pass only - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_grid_account_root_password_pass(self, mock_request): args = self.set_args_create_na_sg_grid_account() args["update_password"] = "always" set_module_args(args) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get id SRR["grid_account_record"], # get account SRR["pw_change_good"], # post SRR["end_of_sequence"], ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_grid_account_root_password_pass: %s" % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_grid_account_root_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_grid_account_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_grid_account()) - my_obj = grid_account_module() mock_request.side_effect = [ + SRR["version_114"], # get SRR["grid_accounts"], # get SRR["grid_account_record"], # get SRR["delete_good"], # delete SRR["end_of_sequence"], ] + my_obj = grid_account_module() + with pytest.raises(AnsibleExitJson) as exc: + my_obj.apply() + print("Info: test_create_na_sg_tenant_account_pass: %s" % repr(exc.value.args[0])) + assert exc.value.args[0]["changed"] + + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") + def test_module_fail_minimum_version_not_met(self, mock_request): + args = self.set_args_create_na_sg_grid_account() + args["allow_select_object_content"] = True + set_module_args(args) + mock_request.side_effect = [ + SRR["version_114"], # get + ] + with pytest.raises(AnsibleFailJson) as exc: + grid_account_module() + print("Info: test_module_fail_minimum_version_not_met: %s" % exc.value.args[0]["msg"]) + + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") + def test_create_na_sg_grid_account_with_allow_select_object_content_pass(self, mock_request): + args = self.set_args_create_na_sg_grid_account() + args["allow_select_object_content"] = True + set_module_args(args) + mock_request.side_effect = [ + SRR["version_116"], # get + SRR["empty_good"], # get + SRR["grid_accounts"], # post + SRR["end_of_sequence"], + ] + my_obj = grid_account_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print( - "Info: test_create_na_sg_tenant_account_pass: %s" - % repr(exc.value.args[0]) + "Info: test_create_na_sg_tenant_account_with_allow_select_object_content_pass: %s" % repr(exc.value.args[0]) ) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_certificate.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_certificate.py index 74974abff..5b1208742 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_certificate.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_certificate.py @@ -9,30 +9,27 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_certificate import ( SgGridCertificate as grid_certificate_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses "empty_good": ({"data": []}, None), - "not_found": ({"status": "error", "code": 404, "data": {}}, {"key": "error.404"},), + "not_found": ( + {"status": "error", "code": 404, "data": {}}, + {"key": "error.404"}, + ), "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": (None, None), @@ -127,7 +124,7 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) @@ -264,14 +261,14 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_certificate_module() print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_pass_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_certificate_module() diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_client_certificate.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_client_certificate.py index d21f9da9c..48b740d63 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_client_certificate.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_client_certificate.py @@ -10,25 +10,18 @@ import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") - else: - raise - +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_client_certificate import ( SgGridClientCertificate as grid_client_certificate_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_dns.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_dns.py index 42abde9c8..5246c5dc5 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_dns.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_dns.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_dns import ( SgGridDns as grid_dns_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -39,13 +33,22 @@ SRR = { "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), - "no_dns_servers": ({"data": []}, None,), - "dns_servers": ({"data": ["10.11.12.5", "10.11.12.6"]}, None,), + "no_dns_servers": ( + {"data": []}, + None, + ), + "dns_servers": ( + {"data": ["10.11.12.5", "10.11.12.6"]}, + None, + ), "add_dns_servers": ( {"data": ["10.11.12.5", "10.11.12.6", "10.11.12.7"]}, None, ), - "remove_dns_servers": ({"data": ["10.11.12.5"]}, None,), + "remove_dns_servers": ( + {"data": ["10.11.12.5"]}, + None, + ), } @@ -81,12 +84,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -144,30 +145,22 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_dns_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_dns_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_grid_dns_servers_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_dns_servers()) my_obj = grid_dns_module() @@ -178,15 +171,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_grid_dns_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_grid_dns_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_set_na_sg_grid_dns_servers_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_dns_servers()) my_obj = grid_dns_module() @@ -196,15 +184,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_set_na_sg_grid_dns_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_set_na_sg_grid_dns_servers_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_add_na_sg_grid_dns_servers_pass(self, mock_request): set_module_args(self.set_args_add_na_sg_grid_dns_server()) my_obj = grid_dns_module() @@ -215,15 +198,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_add_na_sg_grid_dns_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_add_na_sg_grid_dns_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_remove_na_sg_grid_dns_servers_pass(self, mock_request): set_module_args(self.set_args_remove_na_sg_grid_dns_server()) my_obj = grid_dns_module() @@ -234,8 +212,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_remove_na_sg_grid_dns_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_remove_na_sg_grid_dns_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_gateway.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_gateway.py index 0a5a7e386..c612aa255 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_gateway.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_gateway.py @@ -10,25 +10,18 @@ import json import pytest import sys -# try: -# from requests import Response -# except ImportError: -# if sys.version_info < (2, 7): -# pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") -# else: -# raise - +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_gateway import ( SgGridGateway as grid_gateway_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -145,7 +138,7 @@ SRR = { }, ], "gatewayCidr": "192.168.14.1/24", - } + }, ] }, None, diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_group.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_group.py index fd9fdf15c..207d73007 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_group.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_group.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_group import ( SgGridGroup as grid_group_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -134,12 +128,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -203,42 +195,31 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_group_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_group_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] def test_module_fail_with_bad_unique_name(self): - """ error returned if unique_name doesn't start with group or federated_group """ + """error returned if unique_name doesn't start with group or federated_group""" with pytest.raises(AnsibleFailJson) as exc: args = self.set_default_args_pass_check() args["unique_name"] = "noprefixgroup" set_module_args(args) grid_group_module() - print( - "Info: test_module_fail_with_bad_unique_name: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"]) - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_grid_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_group()) my_obj = grid_group_module() @@ -249,15 +230,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_grid_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_grid_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_grid_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_group()) my_obj = grid_group_module() @@ -267,15 +243,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_grid_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_grid_group_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_group_pass(self, mock_request): args = self.set_args_create_na_sg_grid_group() args["management_policy"]["tenant_accounts"] = True @@ -291,15 +262,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_grid_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_grid_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_grid_group_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_grid_group()) my_obj = grid_group_module() @@ -310,8 +276,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_delete_na_sg_grid_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_delete_na_sg_grid_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ha_group.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ha_group.py index fbc8fd0ce..c882b74cd 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ha_group.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ha_group.py @@ -10,25 +10,18 @@ import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") - else: - raise - +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_ha_group import ( SgGridHaGroup as grid_ha_group_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_identity_federation.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_identity_federation.py index 058fc609e..be6f5e11c 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_identity_federation.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_identity_federation.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_identity_federation import ( SgGridIdentityFederation as grid_identity_federation_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -160,7 +154,7 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) @@ -262,14 +256,14 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_identity_federation_module() print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_identity_federation_module() diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ntp.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ntp.py index eed83d49b..c9f1f5bed 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ntp.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_ntp.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_ntp import ( SgGridNtp as grid_ntp_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -39,13 +33,22 @@ SRR = { "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), - "ntp_servers": ({"data": ["123.12.3.123", "123.1.23.123"]}, None,), - "update_ntp_servers": ({"data": ["123.12.3.123", "12.3.12.3"]}, None,), + "ntp_servers": ( + {"data": ["123.12.3.123", "123.1.23.123"]}, + None, + ), + "update_ntp_servers": ( + {"data": ["123.12.3.123", "12.3.12.3"]}, + None, + ), "add_ntp_servers": ( {"data": ["123.12.3.123", "123.1.23.123", "12.3.12.3"]}, None, ), - "remove_ntp_servers": ({"data": ["123.12.3.123"]}, None,), + "remove_ntp_servers": ( + {"data": ["123.12.3.123"]}, + None, + ), } @@ -81,12 +84,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -160,30 +161,22 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_ntp_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_ntp_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_grid_ntp_servers_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_ntp_servers()) my_obj = grid_ntp_module() @@ -194,15 +187,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_grid_ntp_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_grid_ntp_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_set_na_sg_grid_ntp_servers_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_ntp_servers()) my_obj = grid_ntp_module() @@ -212,15 +200,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_set_na_sg_grid_ntp_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_set_na_sg_grid_ntp_servers_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_add_na_sg_grid_ntp_servers_pass(self, mock_request): set_module_args(self.set_args_add_na_sg_grid_ntp_servers()) my_obj = grid_ntp_module() @@ -231,15 +214,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_add_na_sg_grid_ntp_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_add_na_sg_grid_ntp_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_remove_na_sg_grid_ntp_servers_pass(self, mock_request): set_module_args(self.set_args_remove_na_sg_grid_ntp_server()) my_obj = grid_ntp_module() @@ -250,8 +228,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_remove_na_sg_grid_ntp_servers_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_remove_na_sg_grid_ntp_servers_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_regions.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_regions.py index 585ba3f45..64ae8ce1b 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_regions.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_regions.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_regions import ( SgGridRegions as grid_regions_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -39,8 +33,14 @@ SRR = { "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), - "default_regions": ({"data": ["us-east-1"]}, None,), - "regions": ({"data": ["us-east-1", "us-west-1"]}, None,), + "default_regions": ( + {"data": ["us-east-1"]}, + None, + ), + "regions": ( + {"data": ["us-east-1", "us-west-1"]}, + None, + ), } @@ -76,12 +76,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -128,30 +126,22 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_regions_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_regions_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_grid_regions_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_regions()) my_obj = grid_regions_module() @@ -162,15 +152,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_grid_regions_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_grid_regions_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_set_na_sg_grid_regions_pass(self, mock_request): set_module_args(self.set_args_set_na_sg_grid_regions()) my_obj = grid_regions_module() @@ -180,15 +165,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_set_na_sg_grid_regions_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_set_na_sg_grid_regions_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_remove_na_sg_grid_regions_pass(self, mock_request): set_module_args(self.set_args_remove_na_sg_grid_regions()) my_obj = grid_regions_module() @@ -199,8 +179,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_remove_na_sg_grid_regions_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_remove_na_sg_grid_regions_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_traffic_classes.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_traffic_classes.py index 42fce0e3b..840a7f601 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_traffic_classes.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_traffic_classes.py @@ -10,25 +10,19 @@ import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_traffic_classes import ( SgGridTrafficClasses as grid_traffic_classes_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_user.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_user.py index c8ec38c09..5b7a858a8 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_user.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_grid_user.py @@ -9,30 +9,27 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_grid_user import ( SgGridUser as grid_user_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses "empty_good": ({"data": []}, None), - "not_found": ({"status": "error", "code": 404, "data": {}}, {"key": "error.404"},), + "not_found": ( + {"status": "error", "code": 404, "data": {}}, + {"key": "error.404"}, + ), "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), @@ -159,12 +156,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -227,37 +222,29 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) grid_user_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) grid_user_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] def test_module_fail_with_bad_unique_name(self): - """ error returned if unique_name doesn't start with user or federated_user """ + """error returned if unique_name doesn't start with user or federated_user""" with pytest.raises(AnsibleFailJson) as exc: args = self.set_default_args_pass_check() args["unique_name"] = "noprefixuser" set_module_args(args) grid_user_module() - print( - "Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"]) def set_args_create_na_sg_grid_user_with_password(self): return dict( @@ -273,9 +260,7 @@ class TestMyModule(unittest.TestCase): } ) - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_grid_user_no_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_user_no_group()) my_obj = grid_user_module() @@ -286,15 +271,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_grid_user_no_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_grid_user_no_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_grid_user_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_user()) my_obj = grid_user_module() @@ -309,9 +289,7 @@ class TestMyModule(unittest.TestCase): print("Info: test_create_na_sg_grid_user_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_grid_user_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_user()) my_obj = grid_user_module() @@ -322,15 +300,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_grid_user_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_grid_user_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_user_pass(self, mock_request): args = self.set_args_create_na_sg_grid_user() args["member_of"] = ["group/testgridgroup1", "group/testgridgroup2"] @@ -348,9 +321,7 @@ class TestMyModule(unittest.TestCase): print("Info: test_update_na_sg_grid_user_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_grid_user_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_grid_user()) my_obj = grid_user_module() @@ -366,9 +337,7 @@ class TestMyModule(unittest.TestCase): assert exc.value.args[0]["changed"] # create user and set pass - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_grid_user_and_set_password_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_user_with_password()) my_obj = grid_user_module() @@ -381,19 +350,12 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_grid_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_grid_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # Idempotent user with password defined - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) - def test_idempotent_create_na_sg_grid_user_and_set_password_pass( - self, mock_request - ): + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") + def test_idempotent_create_na_sg_grid_user_and_set_password_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_grid_user_with_password()) my_obj = grid_user_module() mock_request.side_effect = [ @@ -403,16 +365,11 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_grid_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_grid_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] # update user and set pass - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_grid_user_and_set_password_pass(self, mock_request): args = self.set_args_create_na_sg_grid_user_with_password() args["member_of"] = ["group/testgridgroup1", "group/testgridgroup2"] @@ -429,17 +386,12 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_grid_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_grid_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # set pass only - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_grid_user_password_pass(self, mock_request): args = self.set_args_create_na_sg_grid_user_with_password() args["update_password"] = "always" @@ -454,16 +406,12 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_grid_user_password_pass: %s" % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_grid_user_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # attempt to set password on federated user - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_fail_set_federated_user_password(self, mock_request): with pytest.raises(AnsibleFailJson) as exc: args = self.set_args_create_na_sg_grid_user_with_password() @@ -471,6 +419,4 @@ class TestMyModule(unittest.TestCase): args["update_password"] = "always" set_module_args(args) grid_user_module() - print( - "Info: test_fail_set_federated_user_password: %s" % repr(exc.value.args[0]) - ) + print("Info: test_fail_set_federated_user_password: %s" % repr(exc.value.args[0])) diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_container.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_container.py index 21c49a556..f48d75762 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_container.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_container.py @@ -10,25 +10,19 @@ import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_org_container import ( SgOrgContainer as org_container_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_group.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_group.py index c229130c2..91d02fec3 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_group.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_group.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_org_group import ( SgOrgGroup as org_group_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -164,12 +158,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -279,42 +271,31 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) org_group_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) org_group_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] def test_module_fail_with_bad_unique_name(self): - """ error returned if unique_name doesn't start with group or federated_group """ + """error returned if unique_name doesn't start with group or federated_group""" with pytest.raises(AnsibleFailJson) as exc: args = self.set_default_args_pass_check() args["unique_name"] = "noprefixgroup" set_module_args(args) org_group_module() - print( - "Info: test_module_fail_with_bad_unique_name: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"]) - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_org_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_group()) my_obj = org_group_module() @@ -325,15 +306,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_org_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_org_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_org_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_group()) my_obj = org_group_module() @@ -343,15 +319,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_org_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_org_group_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_org_group_pass(self, mock_request): args = self.set_args_create_na_sg_org_group() args["s3_policy"] = ( @@ -377,15 +348,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_org_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_org_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_org_group_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_org_group()) my_obj = org_group_module() @@ -396,8 +362,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_delete_na_sg_org_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_delete_na_sg_org_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_identity_federation.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_identity_federation.py index b02259005..fb46a59f2 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_identity_federation.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_identity_federation.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_org_identity_federation import ( SgOrgIdentityFederation as org_identity_federation_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -160,7 +154,7 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) @@ -262,14 +256,14 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) org_identity_federation_module() print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) org_identity_federation_module() diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user.py index 8fcec6734..af4303904 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user.py @@ -9,30 +9,27 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_org_user import ( SgOrgUser as org_user_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses "empty_good": ({"data": []}, None), - "not_found": ({"status": "error", "code": 404, "data": {}}, {"key": "error.404"},), + "not_found": ( + {"status": "error", "code": 404, "data": {}}, + {"key": "error.404"}, + ), "end_of_sequence": (None, "Unexpected call to send_request"), "generic_error": (None, "Expected error"), "delete_good": ({"code": 204}, None), @@ -159,12 +156,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -229,37 +224,29 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) org_user_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) org_user_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] def test_module_fail_with_bad_unique_name(self): - """ error returned if unique_name doesn't start with user or federated_user """ + """error returned if unique_name doesn't start with user or federated_user""" with pytest.raises(AnsibleFailJson) as exc: args = self.set_default_args_pass_check() args["unique_name"] = "noprefixuser" set_module_args(args) org_user_module() - print( - "Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_with_bad_unique_name: %s" % exc.value.args[0]["msg"]) def set_args_create_na_sg_org_user_with_password(self): return dict( @@ -275,9 +262,7 @@ class TestMyModule(unittest.TestCase): } ) - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_org_user_no_group_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user_no_group()) my_obj = org_user_module() @@ -288,15 +273,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_org_user_no_group_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_org_user_no_group_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_org_user_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user()) my_obj = org_user_module() @@ -311,9 +291,7 @@ class TestMyModule(unittest.TestCase): print("Info: test_create_na_sg_org_user_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_org_user_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user()) my_obj = org_user_module() @@ -324,15 +302,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_org_user_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_org_user_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_org_user_pass(self, mock_request): args = self.set_args_create_na_sg_org_user() args["member_of"] = ["group/testorggroup1", "group/testorggroup2"] @@ -350,9 +323,7 @@ class TestMyModule(unittest.TestCase): print("Info: test_update_na_sg_org_user_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_org_user_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_org_user()) my_obj = org_user_module() @@ -368,9 +339,7 @@ class TestMyModule(unittest.TestCase): assert exc.value.args[0]["changed"] # create user and set pass - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_org_user_and_set_password_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user_with_password()) my_obj = org_user_module() @@ -383,16 +352,11 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_org_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_org_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # Idempotent user with password defined - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_org_user_and_set_password_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user_with_password()) my_obj = org_user_module() @@ -403,16 +367,11 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_org_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_org_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] # update user and set pass - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_update_na_sg_org_user_and_set_password_pass(self, mock_request): args = self.set_args_create_na_sg_org_user_with_password() args["member_of"] = ["group/testorggroup1", "group/testorggroup2"] @@ -429,17 +388,12 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_update_na_sg_org_user_and_set_password_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_update_na_sg_org_user_and_set_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # set pass only - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_set_na_sg_org_user_password_pass(self, mock_request): args = self.set_args_create_na_sg_org_user_with_password() args["update_password"] = "always" @@ -454,16 +408,12 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_set_na_sg_org_user_password_pass: %s" % repr(exc.value.args[0]) - ) + print("Info: test_set_na_sg_org_user_password_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] # attempt to set password on federated user - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_fail_set_federated_user_password(self, mock_request): with pytest.raises(AnsibleFailJson) as exc: args = self.set_args_create_na_sg_org_user_with_password() @@ -471,6 +421,4 @@ class TestMyModule(unittest.TestCase): args["update_password"] = "always" set_module_args(args) org_user_module() - print( - "Info: test_fail_set_federated_user_password: %s" % repr(exc.value.args[0]) - ) + print("Info: test_fail_set_federated_user_password: %s" % repr(exc.value.args[0])) diff --git a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user_s3_key.py b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user_s3_key.py index 53696bdbf..0e9db2023 100644 --- a/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user_s3_key.py +++ b/ansible_collections/netapp/storagegrid/tests/unit/plugins/modules/test_na_sg_org_user_s3_key.py @@ -9,25 +9,19 @@ __metaclass__ = type import json import pytest import sys -try: - from requests import Response -except ImportError: - if sys.version_info < (2, 7): - pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not be available') - else: - raise +import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils from ansible_collections.netapp.storagegrid.tests.unit.compat import unittest -from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import ( - patch, - Mock, -) +from ansible_collections.netapp.storagegrid.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes from ansible_collections.netapp.storagegrid.plugins.modules.na_sg_org_user_s3_key import ( SgOrgUserS3Key as org_s3_key_module, ) +if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): + pytestmark = pytest.mark.skip("Skipping Unit Tests on 2.6 as requests is not available") + # REST API canned responses when mocking send_request SRR = { # common responses @@ -104,12 +98,10 @@ def fail_json(*args, **kwargs): # pylint: disable=unused-argument class TestMyModule(unittest.TestCase): - """ a group of related Unit Tests """ + """a group of related Unit Tests""" def setUp(self): - self.mock_module_helper = patch.multiple( - basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json - ) + self.mock_module_helper = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) self.mock_module_helper.start() self.addCleanup(self.mock_module_helper.stop) @@ -157,30 +149,22 @@ class TestMyModule(unittest.TestCase): ) def test_module_fail_when_required_args_missing(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleFailJson) as exc: set_module_args(self.set_default_args_fail_check()) org_s3_key_module() - print( - "Info: test_module_fail_when_required_args_missing: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_missing: %s" % exc.value.args[0]["msg"]) def test_module_fail_when_required_args_present(self): - """ required arguments are reported as errors """ + """required arguments are reported as errors""" with pytest.raises(AnsibleExitJson) as exc: set_module_args(self.set_default_args_pass_check()) org_s3_key_module() exit_json(changed=True, msg="Induced arguments check") - print( - "Info: test_module_fail_when_required_args_present: %s" - % exc.value.args[0]["msg"] - ) + print("Info: test_module_fail_when_required_args_present: %s" % exc.value.args[0]["msg"]) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_create_na_sg_org_user_s3_key_pass(self, mock_request): set_module_args(self.set_args_create_na_sg_org_user_s3_keys()) my_obj = org_s3_key_module() @@ -191,15 +175,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_create_na_sg_org_user_s3_key_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_create_na_sg_org_user_s3_key_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_idempotent_create_na_sg_org_user_s3_key_pass(self, mock_request): args = self.set_args_create_na_sg_org_user_s3_keys() args["access_key"] = "ABCDEFabcd1234567890" @@ -212,15 +191,10 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_idempotent_create_na_sg_org_user_s3_key_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_idempotent_create_na_sg_org_user_s3_key_pass: %s" % repr(exc.value.args[0])) assert not exc.value.args[0]["changed"] - @patch( - "ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request" - ) + @patch("ansible_collections.netapp.storagegrid.plugins.module_utils.netapp.SGRestAPI.send_request") def test_delete_na_sg_org_user_s3_keys_pass(self, mock_request): set_module_args(self.set_args_delete_na_sg_org_user_s3_keys()) my_obj = org_s3_key_module() @@ -231,8 +205,5 @@ class TestMyModule(unittest.TestCase): ] with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() - print( - "Info: test_delete_na_sg_org_user_s3_keys_pass: %s" - % repr(exc.value.args[0]) - ) + print("Info: test_delete_na_sg_org_user_s3_keys_pass: %s" % repr(exc.value.args[0])) assert exc.value.args[0]["changed"] |