Enable ansible module test for keypair to check return data
With a change in cloud layer to use proxy/resource layer for keypair Ansible got borked and is not capable in resolving data we return it back. Add test for it searching for the cause. Investigation resulted in the fact, that when invoked by Ansible native implementation of the Resoure.items was not suddifient under Py3, while under Py2 it is fine. An attempt to integrate all invoked functions into SDK from Ansible has not brought any success. Change-Id: I60dec9ba26176efc5b8ad8378b0ef414754a857c
This commit is contained in:
parent
7f2ca8179e
commit
4c0071916d
@ -630,6 +630,22 @@ class Resource(dict):
|
||||
# remotes or "unknown"
|
||||
return self._attributes()
|
||||
|
||||
def items(self):
|
||||
# This method is critically required for Ansible "jsonify"
|
||||
# NOTE(gtema) For some reason when running from SDK itself the native
|
||||
# implementation of the method is absolutely sifficient, when called
|
||||
# from Ansible - the values are often empty. Even integrating all
|
||||
# Ansible internal methods did not help to find the root cause. Another
|
||||
# fact is that under Py2 everything is fine, while under Py3 it fails.
|
||||
# There is currently no direct test for Ansible-SDK issue. It is tested
|
||||
# implicitely in the keypair role for ansible module, where an assert
|
||||
# verifies presence of attributes.
|
||||
res = []
|
||||
for attr in self._attributes():
|
||||
# Append key, value tuple to result list
|
||||
res.append((attr, self[attr]))
|
||||
return res
|
||||
|
||||
def _update(self, **attrs):
|
||||
"""Given attributes, update them on this instance
|
||||
|
||||
|
@ -4,6 +4,14 @@
|
||||
cloud: "{{ cloud }}"
|
||||
name: "{{ keypair_name }}"
|
||||
state: present
|
||||
register:
|
||||
keypair
|
||||
|
||||
# This assert verifies that Ansible is capable serializing data returned by SDK
|
||||
- name: Ensure private key is returned
|
||||
assert:
|
||||
that:
|
||||
- keypair.key.public_key is defined and keypair.key.public_key
|
||||
|
||||
- name: Delete keypair (non-existing)
|
||||
os_keypair:
|
||||
|
@ -896,6 +896,24 @@ class TestResource(base.TestCase):
|
||||
actual = json.dumps(res, sort_keys=True)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_items(self):
|
||||
class Test(resource.Resource):
|
||||
foo = resource.Body('foo')
|
||||
bar = resource.Body('bar')
|
||||
foot = resource.Body('foot')
|
||||
|
||||
data = {
|
||||
'foo': 'bar',
|
||||
'bar': 'foo\n',
|
||||
'foot': 'a:b:c:d'
|
||||
}
|
||||
|
||||
res = Test(**data)
|
||||
for k, v in res.items():
|
||||
expected = data.get(k)
|
||||
if expected:
|
||||
self.assertEqual(v, expected)
|
||||
|
||||
def test_access_by_aka(self):
|
||||
class Test(resource.Resource):
|
||||
foo = resource.Header('foo_remote', aka='foo_alias')
|
||||
|
Loading…
Reference in New Issue
Block a user