mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
openshift inventory plugin: fix exception when auth fails (#45826)
* openshift inventory: fix exception when auth fails
Fix 'ForbiddenError' object has no attribute 'message':
[WARNING]: * Failed to parse test.yml with openshift plugin: 'ForbiddenError' object has no attribute 'message'
File "ansible/lib/ansible/inventory/manager.py", line 270, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "ansible/lib/ansible/plugins/inventory/openshift.py", line 122, in parse
self.setup(config_data, cache, cache_key)
File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 58, in setup
self.fetch_objects(connections)
File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 250, in fetch_objects
super(OpenShiftInventoryHelper, self).fetch_objects(connections)
File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 81, in fetch_objects
namespaces = self.get_available_namespaces(client)
File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 95, in get_available_namespaces
raise K8sInventoryException('Error fetching Namespace list: {0}'.format(exc.message))
Don't try to get 'message' attribute from:
- K8sInventoryException instances
- Exception instances
- KubernetesException instances (because KubernetesException can be
Exception)
* move k8s/OpenShift inventory plugin dedicated code
inventory plugin specific code should not be located in
lib/ansible/module_utils directory. Then ansible.utils methods can be
reused (for example Display).
* Remove unused class variables 'helper'
unused since 4d77878654
.
This commit is contained in:
parent
241b04f7e9
commit
2fd18c77ae
5 changed files with 315 additions and 330 deletions
|
@ -70,7 +70,7 @@ class KubernetesAnsibleScaleModule(KubernetesRawModule):
|
|||
existing = resource.get(name=name, namespace=namespace)
|
||||
return_attributes['result'] = existing.to_dict()
|
||||
except KubernetesException as exc:
|
||||
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.message),
|
||||
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc),
|
||||
error=exc.value.get('status'))
|
||||
|
||||
if self.kind == 'job':
|
||||
|
@ -129,7 +129,7 @@ class KubernetesAnsibleScaleModule(KubernetesRawModule):
|
|||
resource.scale.patch(body=scale_obj)
|
||||
except Exception as exc:
|
||||
self.fail_json(
|
||||
msg="Scale request failed: {0}".format(exc.message)
|
||||
msg="Scale request failed: {0}".format(exc)
|
||||
)
|
||||
|
||||
if wait and stream is not None:
|
||||
|
@ -173,7 +173,7 @@ class KubernetesAnsibleScaleModule(KubernetesRawModule):
|
|||
watcher.stop()
|
||||
break
|
||||
except Exception as exc:
|
||||
self.fail_json(msg="Exception reading event stream: {0}".format(exc.message))
|
||||
self.fail_json(msg="Exception reading event stream: {0}".format(exc))
|
||||
|
||||
if not return_obj:
|
||||
self.fail_json(msg="Error fetching the patched object. Try a higher wait_timeout value.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue