Merge "Enable ansible module test for keypair to check return data"
This commit is contained in:
commit
46459f3ab4
|
@ -630,6 +630,22 @@ class Resource(dict):
|
||||||
# remotes or "unknown"
|
# remotes or "unknown"
|
||||||
return self._attributes()
|
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):
|
def _update(self, **attrs):
|
||||||
"""Given attributes, update them on this instance
|
"""Given attributes, update them on this instance
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,14 @@
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
name: "{{ keypair_name }}"
|
name: "{{ keypair_name }}"
|
||||||
state: present
|
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)
|
- name: Delete keypair (non-existing)
|
||||||
os_keypair:
|
os_keypair:
|
||||||
|
|
|
@ -896,6 +896,24 @@ class TestResource(base.TestCase):
|
||||||
actual = json.dumps(res, sort_keys=True)
|
actual = json.dumps(res, sort_keys=True)
|
||||||
self.assertEqual(expected, actual)
|
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):
|
def test_access_by_aka(self):
|
||||||
class Test(resource.Resource):
|
class Test(resource.Resource):
|
||||||
foo = resource.Header('foo_remote', aka='foo_alias')
|
foo = resource.Header('foo_remote', aka='foo_alias')
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -69,7 +69,7 @@ commands =
|
||||||
|
|
||||||
[testenv:ansible]
|
[testenv:ansible]
|
||||||
# Need to pass some env vars for the Ansible playbooks
|
# Need to pass some env vars for the Ansible playbooks
|
||||||
basepython = {env:OPENSTACKSDK_TOX_PYTHON:python2}
|
basepython = {env:OPENSTACKSDK_TOX_PYTHON:python3}
|
||||||
passenv = HOME USER ANSIBLE_VAR_*
|
passenv = HOME USER ANSIBLE_VAR_*
|
||||||
deps =
|
deps =
|
||||||
{[testenv]deps}
|
{[testenv]deps}
|
||||||
|
|
Loading…
Reference in New Issue