Add test_rax_keypair role

pull/10220/head
Matt Martz 10 years ago
parent abac45dafc
commit e54c45ee6d

@ -90,6 +90,18 @@ def delete_rax_clb(args):
args.assumeyes)
def delete_rax_keypair(args):
"""Function for deleting Rackspace Key pairs"""
print ("--- Cleaning Key Pairs matching '%s'" % args.match_re)
for region in pyrax.identity.services.compute.regions:
cs = pyrax.connect_to_cloudservers(region=region)
for keypair in cs.keypairs.list():
if re.search(args.match_re, keypair.name):
prompt_and_delete(keypair,
'Delete matching %s? [y/n]: ' % keypair,
args.assumeyes)
def main():
if not HAS_PYRAX:
raise SystemExit('The pyrax python module is required for this script')
@ -98,7 +110,7 @@ def main():
authenticate()
delete_rax(args)
delete_rax_clb(args)
delete_rax_keypair(args)
if __name__ == '__main__':
main()

@ -19,6 +19,9 @@
- role: test_rax_meta
tags: test_rax_meta
- role: test_rax_keypair
tags: test_rax_keypair
- role: test_rax_clb
tags: test_rax_clb

@ -4,4 +4,7 @@ rackspace_image_human_id: "ubuntu-1404-lts-trusty-tahr-pvhvm"
rackspace_image_id: "753a7703-4960-488b-aab4-a3cdd4b276dc"
rackspace_image_name: "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)"
rackspace_flavor: "performance1-1"
rackspace_keypair_pub: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDymofzvt86DUA6XSSxc7eDHwUNvcOSmUWjB76jFvhYc6PbS5QmTzBtCka1ORdaW0Z2i3EjfFvzA8WvuY3qP/FpIVDL25ZqZHgxSfGN5pbJ2tAeXK165kNPXBuuISrMhmdLFbRZNn6PwKHEmtrtfEQ3w6ay9+MhqlEr0OX2r6bCXLj+f50QnQXamU6Fm4IpkTsb60osvHNi569Dd8cADEv92oLZpNMa8/MPGnlipjauhzNtEDTUeZwtrAQUXe6CzJ0QmIlyKDglDZLuAKU/VRumo1FRsn4AwJnVsbP2CHBPkbNoYt6LhQiQqXypEIWGmIln0dlO6gZTr3dYC4BVGREl"
resource_prefix: ansible-testing

@ -0,0 +1,3 @@
dependencies:
- prepare_tests
- prepare_rax_tests

@ -0,0 +1,245 @@
# ============================================================
- name: Test rax_keypair with no args
rax_keypair:
ignore_errors: true
register: rax_keypair
- name: Validate results of rax_keypair with no args
assert:
that:
- rax_keypair|failed
- rax_keypair.msg == 'missing required arguments: name'
# ============================================================
# ============================================================
- name: Test rax_keypair with name
rax_keypair:
name: fail
ignore_errors: true
register: rax_keypair
- name: Validate results of rax_keypair with no args
assert:
that:
- rax_keypair|failed
- rax_keypair.msg == 'No credentials supplied!'
# ============================================================
# ============================================================
- name: Test rax_keypair with name and credentials
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
name: fail
ignore_errors: true
register: rax_keypair
- name: Validate results of rax_keypair with name and credentials
assert:
that:
- rax_keypair|failed
- rax_keypair.msg.startswith('None is not a valid region')
# ============================================================
# ============================================================
- name: Create public key file for tests
copy:
content: "{{ rackspace_keypair_pub }}"
dest: "{{ output_dir|expanduser }}/{{ resource_prefix }}.pub"
- name: Set variable for public key path
set_fact:
rackspace_keypair_pub_path: "{{ output_dir|expanduser }}/{{ resource_prefix }}.pub"
# ============================================================
# ============================================================
- name: Test rax_keypair with creds, region, name and public_key string
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-1"
public_key: "{{ rackspace_keypair_pub }}"
register: rax_keypair
- name: Validate rax_keypair creds, region, name and public_key string
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-1"
- rax_keypair.keypair.public_key == "{{ rackspace_keypair_pub }}"
- name: Delete integration 1
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-1"
public_key: "{{ rackspace_keypair_pub }}"
state: absent
register: rax_keypair
- name: Validate delete integration 1
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-1"
# ============================================================
# ============================================================
- name: Test rax_keypair with creds, region, name and public_key path
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-2"
public_key: "{{ rackspace_keypair_pub_path }}"
register: rax_keypair
- name: Validate rax_keypair creds, region, name and public_key path
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-2"
- rax_keypair.keypair.public_key == "{{ rackspace_keypair_pub }}"
- name: Delete integration 2
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-2"
public_key: "{{ rackspace_keypair_pub }}"
state: absent
register: rax_keypair
- name: Validate delete integration 2
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-2"
# ============================================================
# ============================================================
- name: Test rax_keypair with idempotency 1
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-3"
public_key: "{{ rackspace_keypair_pub }}"
register: rax_keypair
- name: Validate rax_keypair with idempotency 1
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-3"
- rax_keypair.keypair.public_key == "{{ rackspace_keypair_pub }}"
- name: Test rax_keypair with idempotency 2
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-3"
public_key: "{{ rackspace_keypair_pub }}"
register: rax_keypair
- name: Validate rax_keypair with idempotency 1
assert:
that:
- rax_keypair|success
- not rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-3"
- rax_keypair.keypair.public_key == "{{ rackspace_keypair_pub }}"
- name: Delete integration 3
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-3"
public_key: "{{ rackspace_keypair_pub }}"
state: absent
register: rax_keypair
- name: Validate delete integration 3
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-3"
# ============================================================
# ============================================================
- name: Test rax_keypair with creds, region and name
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-4"
register: rax_keypair
- name: Validate rax_keypair creds, region and name
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-4"
- rax_keypair.keypair.private_key is defined
- rax_keypair.keypair.public_key is defined
- name: Test rax_keypair with creds, region and name idempotency
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-4"
register: rax_keypair
- name: Validate rax_keypair creds, region and name
assert:
that:
- rax_keypair|success
- not rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-4"
- rax_keypair.keypair.private_key is not defined
- rax_keypair.keypair.public_key is defined
- name: Delete integration 4
rax_keypair:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-4"
public_key: "{{ rackspace_keypair_pub }}"
state: absent
register: rax_keypair
- name: Validate delete integration 4
assert:
that:
- rax_keypair|success
- rax_keypair|changed
- rax_keypair.keypair.name == "{{ resource_prefix }}-4"
# ============================================================
Loading…
Cancel
Save