Skip to content

Commit 51e2d8a

Browse files
Run ansible sanity with all python versions and with latest ansible versions (#573)
1 parent d6e75e7 commit 51e2d8a

16 files changed

+46
-161
lines changed

.github/workflows/ansible-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ jobs:
1919
- name: Set up Python 3.x (latest)
2020
uses: actions/setup-python@v2
2121
with:
22-
python-version: 3.9
22+
python-version: 3.x
2323
- name: Run ansible-lint
2424
uses: ansible/ansible-lint@main

.github/workflows/unit_testing.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ on:
1212
- pull_request
1313
jobs:
1414
sanity1:
15-
name: Sanity tests with ansible-core==2.15.0
16-
runs-on: ubuntu-20.04
15+
name: Sanity tests
16+
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: ["3.9"]
19+
python-version: ["3.11"]
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Set up Python ${{ matrix.python-version }}
@@ -27,7 +27,7 @@ jobs:
2727
uses: docker-practice/actions-setup-docker@master
2828
- name: Install ansible
2929
run: |
30-
pip install -r requirements.txt
30+
pip install -r tests/integration/requirements.txt
3131
- name: Build and install the collection
3232
run: |
3333
NAMESPACE=$(cat galaxy.yml | shyaml get-value namespace)
@@ -40,12 +40,12 @@ jobs:
4040
- name: Run tests
4141
run: |
4242
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
43-
ansible-test sanity --docker default --python ${{ matrix.python-version }} -v
43+
ansible-test sanity --docker default -v
4444
unit_testing:
45-
runs-on: ubuntu-20.04
45+
runs-on: ubuntu-latest
4646
strategy:
4747
matrix:
48-
python-version: ["3.9"]
48+
python-version: ["3.11"]
4949
steps:
5050
- uses: actions/checkout@v2
5151
- name: Set up Python ${{ matrix.python-version }}
@@ -56,7 +56,7 @@ jobs:
5656
uses: docker-practice/actions-setup-docker@master
5757
- name: Install ansible
5858
run: |
59-
pip install -r requirements.txt
59+
pip install -r tests/integration/requirements.txt
6060
- name: Build and install the collection
6161
run: |
6262
NAMESPACE=$(cat galaxy.yml | shyaml get-value namespace)

galaxy.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ authors:
88
- "Prem Karat (@premkarat)"
99
- "Gevorg Khachatryan (@Gevorg-Khachatryan-97)"
1010
- "Alaa Bishtawi (@alaa-bish)"
11-
description: Ansible collection for v3 Nutanix APIs https://www.nutanix.dev/api-reference-v3/
11+
- "Abhinav Bansal (@abhinavbansal29)"
12+
- "George Ghawali (@george-ghawali)"
13+
description: Nutanix Ansible Collection
1214
license_file: 'LICENSE'
1315
tags: [nutanix, prism, ahv, cloud, infrastructure]
1416
repository: https://github.com/nutanix/nutanix.ansible
15-
documentation: https://nutanix.github.io/nutanix.ansible/
17+
documentation: https://galaxy.ansible.com/ui/repo/published/nutanix/ncp/
1618
homepage: https://nutanix.github.io/nutanix.ansible/
1719
issues: https://github.com/nutanix/nutanix.ansible/issues
1820
build_ignore: []

plugins/module_utils/v3/entity.py

+5-109
Original file line numberDiff line numberDiff line change
@@ -20,110 +20,6 @@
2020
from urlparse import urlparse # python2
2121

2222

23-
class EntityV4(object):
24-
module = None
25-
26-
def __init__(self, module):
27-
self.module = module
28-
29-
# old_spec is used for updating entity, where there is already spec object present.
30-
def get_spec(self, module_args, params=None, obj=None, old_spec=None):
31-
"""
32-
For given module parameters input, it will create new spec object or update old_spec object.
33-
It will pick module.params if 'params' is not given.
34-
Args:
35-
module_args (dict): module argument spec for reference
36-
obj (object): spec class from sdk
37-
params (dict): input for creating spec
38-
old_spec (object): Old state obj of entity
39-
Returns:
40-
spec (object): spec object
41-
"""
42-
43-
if not params:
44-
params = copy.deepcopy(self.module.params)
45-
46-
if not old_spec and not obj:
47-
return (
48-
None,
49-
"Either 'old_spec' or 'obj' is required to create/update spec object",
50-
)
51-
52-
# create spec obj or shallow copy of old spec as per entity spec - new or existing
53-
spec = copy.copy(old_spec) if old_spec else obj()
54-
55-
# Resolve each input param w.r.t its module argument spec
56-
for attr, schema in module_args.items():
57-
58-
if attr in params:
59-
60-
type = schema.get("type")
61-
if not type:
62-
return (
63-
None,
64-
"Invalid module argument: 'type' is required parameter for attribute {0}".format(
65-
attr
66-
),
67-
)
68-
69-
options = schema.get("options")
70-
_obj = schema.get("obj")
71-
elements = schema.get("elements")
72-
73-
# for dict type attribute, recursively create spec objects
74-
if type == "dict" and options is not None and _obj is not None:
75-
s, err = self.get_spec(
76-
module_args=options,
77-
obj=_obj,
78-
params=params[attr],
79-
old_spec=getattr(spec, attr),
80-
)
81-
if err:
82-
return None, err
83-
setattr(spec, attr, s)
84-
85-
# for list type attribute, create list of spec objects recursively
86-
elif (
87-
type == "list"
88-
and elements == "dict"
89-
and options is not None
90-
and _obj is not None
91-
):
92-
lst = []
93-
for item in params[attr]:
94-
s, err = self.get_spec(
95-
module_args=options, obj=_obj, params=item
96-
)
97-
if err:
98-
return None, err
99-
lst.append(s)
100-
setattr(spec, attr, lst)
101-
102-
# for other types directly assign
103-
else:
104-
setattr(spec, attr, params[attr])
105-
106-
return spec, None
107-
108-
def get_info_spec(self, params=None):
109-
110-
if not params:
111-
params = copy.deepcopy(self.module.params)
112-
spec = {}
113-
all_params = ["page", "limit", "filter", "orderby", "select"]
114-
if params.get("name"):
115-
_filter = params.get("filter")
116-
if _filter:
117-
_filter += f"""and name eq '{params["name"]}'"""
118-
else:
119-
_filter = f"""name eq '{params["name"]}'"""
120-
params["filter"] = _filter
121-
for key, val in params.items():
122-
if key in all_params:
123-
spec[f"_{key}"] = val
124-
return spec
125-
126-
12723
class Entity(object):
12824
entities_limitation = 20
12925
entity_type = "entities"
@@ -172,7 +68,7 @@ def read(
17268
no_response=False,
17369
timeout=30,
17470
method="GET",
175-
**kwargs,
71+
**kwargs # fmt: skip
17672
):
17773
url = self.base_url + "/{0}".format(uuid) if uuid else self.base_url
17874
if endpoint:
@@ -185,7 +81,7 @@ def read(
18581
raise_error=raise_error,
18682
no_response=no_response,
18783
timeout=timeout,
188-
**kwargs,
84+
**kwargs # fmt: skip
18985
)
19086

19187
def update(
@@ -198,7 +94,7 @@ def update(
19894
no_response=False,
19995
timeout=30,
20096
method="PUT",
201-
**kwargs,
97+
**kwargs # fmt: skip
20298
):
20399
url = self.base_url + "/{0}".format(uuid) if uuid else self.base_url
204100
if endpoint:
@@ -212,7 +108,7 @@ def update(
212108
raise_error=raise_error,
213109
no_response=no_response,
214110
timeout=timeout,
215-
**kwargs,
111+
**kwargs # fmt: skip
216112
)
217113

218114
# source is the file path of resource where ansible yaml runs
@@ -458,7 +354,7 @@ def _fetch_url(
458354
raise_error=True,
459355
no_response=False,
460356
timeout=30,
461-
**kwargs,
357+
**kwargs # fmt: skip
462358
):
463359
# only jsonify if content-type supports, added to avoid incase of form-url-encodeded type data
464360
if self.headers["Content-Type"] == "application/json" and data is not None:

plugins/module_utils/v3/foundation/discover_nodes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def discover(self, include_configured=False):
2222
result_nodes = []
2323
for n in nodes:
2424
configured = n.get("configured")
25-
if include_configured or (type(configured) == bool and not configured):
25+
if include_configured or (
26+
isinstance(configured, bool) and not configured
27+
):
2628

2729
# handle datatype corner cases for cluster_id & current_cvm_vlan_tag
2830
if n.get("cluster_id"):

plugins/module_utils/v4/spec_generator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def get_info_spec(self, attr=None, extra_params=None):
115115
if attr.get("name"):
116116
_filter = attr.get("filter")
117117
if _filter:
118-
_filter += f"""and name eq '{attr["name"]}'"""
118+
_filter += "and name eq '{0}'".format(attr["name"])
119119
else:
120-
_filter = f"""name eq '{attr["name"]}'"""
120+
_filter = "name eq '{0}'".format(attr["name"])
121121
attr["filter"] = _filter
122122
for key, val in attr.items():
123123
if key in all_params:
124-
spec[f"_{key}"] = val
124+
spec["_{0}".format(key)] = val
125125
return spec, None
126126

127127
def get_stats_spec(self, attr=None):

plugins/modules/ntnx_authorization_policies_v2.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,8 @@ def update_authorization_policy(module, result):
386386

387387
if getattr(resp.data, "severity", None) == "ERROR":
388388
result["error"] = resp.data.message
389-
module.fail_json(
390-
msg="Failed to update authorization policy",
391-
**result,
392-
)
389+
msg = "Failed to update authorization policy"
390+
module.fail_json(msg=msg, **result)
393391

394392
resp = get_authorization_policy(module, authorization_policies, ext_id=ext_id)
395393
result["response"] = strip_internal_attributes(resp.to_dict())

plugins/modules/ntnx_discover_unconfigured_nodes_v2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def discover_unconfigured_cluster_node(module, cluster_node_api, result):
239239
result["error"] = err
240240
module.fail_json(
241241
msg="Failed generating spec for fetching prism central cluster",
242-
**result,
242+
**result # fmt: skip
243243
)
244244
try:
245245
pc_cluster = cluster_node_api.list_clusters(**kwargs)

plugins/modules/ntnx_gpus_v2.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ def detach_gpu(module, vms, result):
235235
kwargs = {"if_match": etag}
236236

237237
try:
238-
resp = vms.delete_gpu_by_id(
239-
vmExtId=vm_ext_id,
240-
extId=ext_id,
241-
**kwargs,
242-
)
238+
resp = vms.delete_gpu_by_id(vmExtId=vm_ext_id, extId=ext_id, **kwargs)
243239
except Exception as e:
244240
raise_api_exception(
245241
module=module,

plugins/modules/ntnx_image_placement_policies_v2.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,8 @@ def update_policy_state(module, result, policies, ext_id):
390390
policy = get_policy(module, policies, ext_id)
391391
etag = get_etag(data=policy)
392392
if not etag:
393-
return module.fail_json(
394-
"unable to fetch etag for updating Placement Policy enforcement state",
395-
**result,
396-
)
393+
msg = "unable to fetch etag for updating Placement Policy enforcement state"
394+
return module.fail_json(msg, **result)
397395

398396
kwargs = {"if_match": etag}
399397
resp = None

plugins/modules/ntnx_nodes_network_info_v2.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,8 @@ def get_nodes_network_information(module, cluster_node_api, result):
382382
spec, err = sg.generate_spec(default_spec)
383383
if err:
384384
result["error"] = err
385-
module.fail_json(
386-
msg="Failed generating spec for getting network information for cluster nodes",
387-
**result,
388-
)
385+
msg = "Failed generating spec for getting network information for cluster nodes"
386+
module.fail_json(msg=msg, **result)
389387
cluster_ext_id = module.params.get("cluster_ext_id")
390388
result["cluster_ext_id"] = cluster_ext_id
391389
if module.check_mode:

plugins/modules/ntnx_pbrs_v2.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,8 @@ def get_routing_policy_ext_id(module, result, api_instance, vpc_ext_id, priority
812812
kwargs, err = sg.get_info_spec(attr=params)
813813
if err:
814814
result["error"] = err
815-
module.fail_json(
816-
msg="Failed generating spec for fetching routing policy using priority and vpc_ext_id",
817-
**result,
818-
)
815+
msg = "Failed generating spec for fetching routing policy using priority and vpc_ext_id"
816+
module.fail_json(msg=msg, **result)
819817

820818
try:
821819
resp = api_instance.list_routing_policies(**kwargs)
@@ -834,10 +832,8 @@ def get_routing_policy_ext_id(module, result, api_instance, vpc_ext_id, priority
834832

835833
def create_pbr(module, result):
836834
if not module.params.get("vpc_ext_id") and module.params.get("priority"):
837-
module.fail_json(
838-
msg="vpc_ext_id and priority are required for creating routing policy",
839-
**result,
840-
)
835+
msg = "vpc_ext_id and priority are required for creating routing policy"
836+
module.fail_json(msg=msg, **result)
841837

842838
pbrs = get_routing_policies_api_instance(module)
843839

plugins/modules/ntnx_recovery_points_v2.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,8 @@ def update_expiry_date_recovery_point(module, result):
405405
old_spec.to_dict(), update_spec.to_dict()
406406
):
407407
result["skipped"] = True
408-
module.exit_json(
409-
msg="Update of other operations is not supported. Only updation of Expiration time is allowed.",
410-
**result,
411-
)
408+
msg = "Update of other operations is not supported. Only updation of Expiration time is allowed."
409+
module.exit_json(msg=msg, **result)
412410
else:
413411
result["skipped"] = True
414412
module.exit_json(msg="Nothing to change.", **result)

plugins/modules/ntnx_templates_deploy_v2.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,10 @@ def deploy_template(module, result):
473473
version_ext_id = module.params.get("version_id")
474474
result[
475475
"msg"
476-
] = f"Template ({ext_id}) with given version ({version_ext_id}) will be deployed."
476+
] = "Template ({0}) with given version ({1}) will be deployed.".format(
477+
ext_id,
478+
version_ext_id # fmt: skip
479+
)
477480
return
478481

479482
etag = get_etag(data=current_spec)

plugins/modules/ntnx_vms_stage_guest_customization_v2.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,8 @@ def stage_customize_guest(module, result):
283283

284284
if err:
285285
result["error"] = err
286-
module.fail_json(
287-
msg="Failed generating stage guest customization configuration spec",
288-
**result,
289-
)
286+
msg = "Failed generating stage guest customization configuration spec"
287+
module.fail_json(msg=msg, **result)
290288

291289
if module.check_mode:
292290
result["response"] = strip_internal_attributes(spec.to_dict())

tests/integration/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
pip~=21.3.1
22
ipaddress~=1.0.23
33
setuptools~=44.1.1
4-
ansible-core==2.15.0
4+
ansible-core==2.16.0
55
requests~=2.26.0
66
black==22.8.0
77
flake8==4.0.1
88
isort==5.9.3
9-
coverage==6.5.0
9+
coverage==7.3.2
1010
shyaml==0.6.2
1111
markupsafe==2
1212
ntnx-clustermgmt-py-client==4.0.1

0 commit comments

Comments
 (0)