Moves keypair_info from cloud to proxy object

This makes keypair_info compatible with new sdk version

Change-Id: I09c75717a620272904b023179c726a19c4bca000
This commit is contained in:
anbanerj
2022-02-01 17:43:52 +05:30
parent 86b573883a
commit 595f7d1093
3 changed files with 85 additions and 64 deletions

View File

@@ -1 +1,11 @@
keypair_name: shade_keypair keypair_name: shade_keypair
expected_fields:
- created_at
- fingerprint
- id
- is_deleted
- name
- private_key
- public_key
- type
- user_id

View File

@@ -4,10 +4,14 @@
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
name: "{{ keypair_name }}" name: "{{ keypair_name }}"
state: present state: present
register: register: keypair
keypair
- name: Get list of keypairs - name: Get list of all keypairs
openstack.cloud.keypair_info:
cloud: "{{ cloud }}"
register: keypairs_all
- name: Get list of keypairs with filter
openstack.cloud.keypair_info: openstack.cloud.keypair_info:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
name: "{{ keypair_name }}" name: "{{ keypair_name }}"
@@ -16,15 +20,33 @@
- name: Ensure that list of keypairs contains single element - name: Ensure that list of keypairs contains single element
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 1 - keypairs['keypairs']|length == 1
- name: Assert fields
assert:
that:
- item in keypairs.keypairs.0.keys()
loop: "{{ expected_fields }}"
# This assert verifies that Ansible is capable serializing data returned by SDK # This assert verifies that Ansible is capable serializing data returned by SDK
- name: Ensure private key is returned - name: Ensure public key is returned
assert: assert:
that: that:
- keypair.key.public_key is defined and keypair.key.public_key - keypair.key.public_key is defined and keypair.key.public_key
- name: Create another keypair
openstack.cloud.keypair:
cloud: "{{ cloud }}"
name: "{{ keypair_name }}-2"
state: present
- name: Delete keypair (non-existing) - name: Delete keypair (non-existing)
openstack.cloud.keypair:
cloud: "{{ cloud }}"
name: "non-existing"
state: absent
- name: Delete keypair
openstack.cloud.keypair: openstack.cloud.keypair:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
name: "{{ keypair_name }}" name: "{{ keypair_name }}"
@@ -39,7 +61,13 @@
- name: Ensure that list of keypairs is empty - name: Ensure that list of keypairs is empty
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 0 - keypairs['keypairs']|length == 0
- name: Delete another keypair
openstack.cloud.keypair:
cloud: "{{ cloud }}"
name: "{{ keypair_name }}-2"
state: absent
- name: Generate test key file - name: Generate test key file
user: user:
@@ -63,7 +91,7 @@
- name: Ensure that list of keypairs contains single element - name: Ensure that list of keypairs contains single element
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 1 - keypairs['keypairs']|length == 1
- name: Delete keypair (file) - name: Delete keypair (file)
openstack.cloud.keypair: openstack.cloud.keypair:
@@ -80,7 +108,7 @@
- name: Ensure that list of keypairs is empty - name: Ensure that list of keypairs is empty
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 0 - keypairs['keypairs']|length == 0
- name: Create keypair (key) - name: Create keypair (key)
openstack.cloud.keypair: openstack.cloud.keypair:
@@ -98,7 +126,7 @@
- name: Ensure that list of keypairs contains single element - name: Ensure that list of keypairs contains single element
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 1 - keypairs['keypairs']|length == 1
- name: Delete keypair (key) - name: Delete keypair (key)
openstack.cloud.keypair: openstack.cloud.keypair:
@@ -115,7 +143,7 @@
- name: Ensure that list of keypairs is empty - name: Ensure that list of keypairs is empty
assert: assert:
that: that:
- keypairs['openstack_keypairs']|length == 0 - keypairs['keypairs']|length == 0
- name: Delete test key pub file - name: Delete test key pub file
file: file:

View File

@@ -51,10 +51,11 @@ EXAMPLES = '''
''' '''
RETURN = ''' RETURN = '''
openstack_keypairs: keypairs:
description: description:
- Lists keypairs that are associated with the account. - Lists keypairs that are associated with the account.
type: complex type: list
elements: dict
returned: always returned: always
contains: contains:
created_at: created_at:
@@ -120,31 +121,13 @@ class KeyPairInfoModule(OpenStackModule):
) )
def run(self): def run(self):
name = self.params['name'] filters = {k: self.params[k] for k in
user_id = self.params['user_id'] ['user_id', 'name', 'limit', 'marker']
limit = self.params['limit'] if self.params[k] is not None}
marker = self.params['marker'] keypairs = self.conn.search_keypairs(name_or_id=self.params['name'],
filters = {}
data = []
if user_id:
filters['user_id'] = user_id
if limit:
filters['limit'] = limit
if marker:
filters['marker'] = marker
result = self.conn.search_keypairs(name_or_id=name,
filters=filters) filters=filters)
raws = [raw if isinstance(raw, dict) else raw.to_dict() result = [raw.to_dict(computed=False) for raw in keypairs]
for raw in result] self.exit(changed=False, keypairs=result)
for raw in raws:
raw.pop('location')
data.append(raw)
self.exit(changed=False, openstack_keypairs=data)
def main(): def main():