Skip to content

Commit 90134ec

Browse files
[CI Fix] Remove ansible.module_utils.six imports (#998) (#999)
This is a backport of PR #998 as merged into main (448d3fe). SUMMARY This PR is essentially attempting Option B from issue #996 (Option A is implemented here); this code update accounts for the recent merge of sanity: warn on ansible.module_utils.six imports #85651. Reviewed-by: Bianca Henderson <[email protected]> Reviewed-by: Mandar Kulkarni <[email protected]>
1 parent dcbe52e commit 90134ec

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- Remove ``ansible.module_utils.six`` imports to avoid warnings (https://github.com/ansible-collections/kubernetes.core/pull/998).

plugins/action/k8s_info.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
)
2323
from ansible.module_utils._text import to_bytes, to_native, to_text
2424
from ansible.module_utils.parsing.convert_bool import boolean
25-
from ansible.module_utils.six import iteritems, string_types
2625
from ansible.plugins.action import ActionBase
2726

2827
try:
@@ -100,7 +99,7 @@ def get_template_args(self, template):
10099
"trim_blocks": True,
101100
"lstrip_blocks": False,
102101
}
103-
if isinstance(template, string_types):
102+
if isinstance(template, str):
104103
# treat this as raw_params
105104
template_param["path"] = template
106105
elif isinstance(template, dict):
@@ -120,7 +119,7 @@ def get_template_args(self, template):
120119
):
121120
if s_type in template_args:
122121
value = ensure_type(template_args[s_type], "string")
123-
if value is not None and not isinstance(value, string_types):
122+
if value is not None and not isinstance(value, str):
124123
raise AnsibleActionFail(
125124
"%s is expected to be a string, but got %s instead"
126125
% (s_type, type(value))
@@ -196,7 +195,7 @@ def load_template(self, template, new_module_args, task_vars):
196195
)
197196

198197
template_params = []
199-
if isinstance(template, string_types) or isinstance(template, dict):
198+
if isinstance(template, str) or isinstance(template, dict):
200199
template_params.append(self.get_template_args(template))
201200
elif isinstance(template, list):
202201
for element in template:
@@ -246,7 +245,7 @@ def load_template(self, template, new_module_args, task_vars):
246245
# add ansible 'template' vars
247246
temp_vars = copy.deepcopy(task_vars)
248247
overrides = {}
249-
for key, value in iteritems(template_item):
248+
for key, value in template_item.items():
250249
if hasattr(self._templar.environment, key):
251250
if value is not None:
252251
overrides[key] = value
@@ -303,7 +302,7 @@ def get_file_realpath(self, local_path):
303302
)
304303

305304
def get_kubeconfig(self, kubeconfig, remote_transport, new_module_args):
306-
if isinstance(kubeconfig, string_types):
305+
if isinstance(kubeconfig, str):
307306
# find the kubeconfig in the expected search path
308307
if not remote_transport:
309308
# kubeconfig is local

plugins/module_utils/args_common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from __future__ import absolute_import, division, print_function
22

3-
from ansible.module_utils.six import string_types
4-
53
__metaclass__ = type
64

75

86
def list_dict_str(value):
9-
if isinstance(value, (list, dict, string_types)):
7+
if isinstance(value, (list, dict, str)):
108
return value
119
raise TypeError
1210

plugins/module_utils/helm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import traceback
1616

1717
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
18-
from ansible.module_utils.six import string_types
1918
from ansible_collections.kubernetes.core.plugins.module_utils.version import (
2019
LooseVersion,
2120
)
@@ -113,7 +112,7 @@ def _prepare_helm_environment(self):
113112
kubeconfig_content = None
114113
kubeconfig = self.params.get("kubeconfig")
115114
if kubeconfig:
116-
if isinstance(kubeconfig, string_types):
115+
if isinstance(kubeconfig, str):
117116
with open(os.path.expanduser(kubeconfig)) as fd:
118117
kubeconfig_content = yaml.safe_load(fd)
119118
elif isinstance(kubeconfig, dict):

plugins/module_utils/k8s/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
from typing import Any, Dict, List, Optional
77

8-
from ansible.module_utils.six import iteritems, string_types
98
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
109
AUTH_ARG_MAP,
1110
AUTH_ARG_SPEC,
@@ -115,7 +114,7 @@ def _load_config(auth: Dict) -> None:
115114
"persist_config": auth.get("persist_config"),
116115
}
117116
if kubeconfig:
118-
if isinstance(kubeconfig, string_types):
117+
if isinstance(kubeconfig, str):
119118
kubernetes.config.load_kube_config(config_file=kubeconfig, **optional_arg)
120119
elif isinstance(kubeconfig, dict):
121120
kubernetes.config.load_kube_config_from_dict(
@@ -163,7 +162,7 @@ def auth_set(*names: list) -> bool:
163162
except AttributeError:
164163
configuration = kubernetes.client.Configuration()
165164

166-
for key, value in iteritems(auth):
165+
for key, value in auth.items():
167166
if key in AUTH_ARG_MAP.keys() and value is not None:
168167
if key == "api_key":
169168
setattr(

plugins/module_utils/k8s/resource.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
from typing import Dict, Iterable, List, Optional, Union, cast
66

7-
from ansible.module_utils.six import string_types
87
from ansible.module_utils.urls import Request
98

109
try:
@@ -78,11 +77,11 @@ def create_definitions(params: Dict) -> List[ResourceDefinition]:
7877
def from_yaml(definition: Union[str, List, Dict]) -> Iterable[Dict]:
7978
"""Load resource definitions from a yaml definition."""
8079
definitions: List[Dict] = []
81-
if isinstance(definition, string_types):
80+
if isinstance(definition, str):
8281
definitions += yaml.safe_load_all(definition)
8382
elif isinstance(definition, list):
8483
for item in definition:
85-
if isinstance(item, string_types):
84+
if isinstance(item, str):
8685
definitions += yaml.safe_load_all(item)
8786
else:
8887
definitions.append(item)

tests/unit/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import pytest
1111
from ansible.module_utils._text import to_bytes
1212
from ansible.module_utils.common._collections_compat import MutableMapping
13-
from ansible.module_utils.six import string_types
1413

1514

1615
@pytest.fixture
@@ -20,7 +19,7 @@ def stdin(mocker, request):
2019
old_argv = sys.argv
2120
sys.argv = ["ansible_unittest"]
2221

23-
if isinstance(request.param, string_types):
22+
if isinstance(request.param, str):
2423
args = request.param
2524
elif isinstance(request.param, MutableMapping):
2625
if "ANSIBLE_MODULE_ARGS" not in request.param:

0 commit comments

Comments
 (0)