From 9485d82ecad09070e3675122b37861d3989593de Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 20 Jan 2015 11:41:41 -0600 Subject: [PATCH] Add tests for rax_cdb --- test/integration/cleanup_rax.py | 24 +- test/integration/rackspace.yml | 3 + .../roles/test_rax_cdb/meta/main.yml | 3 + .../roles/test_rax_cdb/tasks/main.yml | 270 ++++++++++++++++++ 4 files changed, 295 insertions(+), 5 deletions(-) create mode 100644 test/integration/roles/test_rax_cdb/meta/main.yml create mode 100644 test/integration/roles/test_rax_cdb/tasks/main.yml diff --git a/test/integration/cleanup_rax.py b/test/integration/cleanup_rax.py index 10e94334f8..f65a96ca68 100644 --- a/test/integration/cleanup_rax.py +++ b/test/integration/cleanup_rax.py @@ -126,17 +126,31 @@ def delete_rax_cbs(args): args.assumeyes) +def delete_rax_cdb(args): + """Function for deleting Cloud Databases""" + print ("--- Cleaning Cloud Databases matching '%s'" % args.match_re) + for region in pyrax.identity.services.database.regions: + cdb = pyrax.connect_to_cloud_databases(region=region) + for db in rax_list_iterator(cdb): + if re.search(args.match_re, db.name): + prompt_and_delete(db, + 'Delete matching %s? [y/n]: ' % db, + args.assumeyes) + + def main(): if not HAS_PYRAX: raise SystemExit('The pyrax python module is required for this script') args = parse_args() authenticate() - delete_rax(args) - delete_rax_clb(args) - delete_rax_keypair(args) - delete_rax_network(args) - delete_rax_cbs(args) + + for func in [delete_rax, delete_rax_clb, delete_rax_keypair, + delete_rax_network, delete_rax_cbs, delete_rax_cdb]: + try: + func(args) + except Exception as e: + print ("---- %s failed (%s)" % (func.__name__, e.message)) if __name__ == '__main__': diff --git a/test/integration/rackspace.yml b/test/integration/rackspace.yml index cdf0da92e0..e572f145e4 100644 --- a/test/integration/rackspace.yml +++ b/test/integration/rackspace.yml @@ -34,3 +34,6 @@ - role: test_rax_identity tags: test_rax_identity + + - role: test_rax_cdb + tags: test_rax_cdb diff --git a/test/integration/roles/test_rax_cdb/meta/main.yml b/test/integration/roles/test_rax_cdb/meta/main.yml new file mode 100644 index 0000000000..a3f85b642e --- /dev/null +++ b/test/integration/roles/test_rax_cdb/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + - prepare_rax_tests diff --git a/test/integration/roles/test_rax_cdb/tasks/main.yml b/test/integration/roles/test_rax_cdb/tasks/main.yml new file mode 100644 index 0000000000..fe4bdd9c0d --- /dev/null +++ b/test/integration/roles/test_rax_cdb/tasks/main.yml @@ -0,0 +1,270 @@ +# ============================================================ +- name: Test rax_cdb with no args + rax_cdb: + ignore_errors: true + register: rax_cdb + +- name: Validate results of rax_cdb with no args + assert: + that: + - rax_cdb|failed + - rax_cdb.msg == 'missing required arguments: name' +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb with name + rax_cdb: + name: fail + ignore_errors: true + register: rax_cdb + +- name: Validate results of rax_cdb with only creds + assert: + that: + - rax_cdb|failed + - rax_cdb.msg == 'No credentials supplied!' +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb with name and credentials + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + name: fail + ignore_errors: true + register: rax_cdb + +- name: Validate results of rax_cdb with only creds + assert: + that: + - rax_cdb|failed + - rax_cdb.msg.startswith('None is not a valid region') +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb with creds and region + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + ignore_errors: true + register: rax_cdb + +- name: Validate rax_cdb creds and region + assert: + that: + - rax_cdb|failed + - rax_cdb.msg == 'missing required arguments: name' +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb with creds, region and name + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-1" + wait: true + register: rax_cdb + +- name: Validate rax_cdb with creds, region and name + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == '{{ resource_prefix }}-1' + - rax_cdb.cdb.hostname + - rax_cdb.cdb.status == 'ACTIVE' + +- name: "Delete integration 1" + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-1" + state: absent + wait: true + register: rax_cdb + +- name: "Validate delete integration 1" + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-1" + +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb idempotent test 1 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-2" + wait: true + register: rax_cdb + +- name: Validate rax_cdb idempotent test 1 + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-2" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: Test rax_cdb idempotent test 2 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-2" + wait: true + register: rax_cdb + +- name: Validate rax_cdb idempotent test 2 + assert: + that: + - rax_cdb|success + - not rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-2" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: "Delete integration 2" + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-2" + state: absent + wait: true + register: rax_cdb + +- name: "Validate delete integration 2" + assert: + that: + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-2" +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb resize volume 1 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-3" + wait: true + register: rax_cdb + +- name: Validate rax_cdb resize volume 1 + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-3" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: Test rax_cdb resize volume 2 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-3" + volume: 3 + wait: true + wait_timeout: 600 + register: rax_cdb + +- name: Validate rax_cdb resize volume 2 + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-3" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: "Delete integration 3" + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-3" + state: absent + wait: true + register: rax_cdb + +- name: "Validate delete integration 3" + assert: + that: + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-3" +# ============================================================ + + + +# ============================================================ +- name: Test rax_cdb resize flavor 1 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-4" + wait: true + register: rax_cdb + +- name: Validate rax_cdb resize flavor 1 + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-4" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: Test rax_cdb resize flavor 2 + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-4" + flavor: 2 + wait: true + wait_timeout: 600 + register: rax_cdb + +- name: Validate rax_cdb resize flavor 2 + assert: + that: + - rax_cdb|success + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-4" + - rax_cdb.cdb.status == 'ACTIVE' + +- name: "Delete integration 4" + rax_cdb: + username: "{{ rackspace_username }}" + api_key: "{{ rackspace_api_key }}" + region: "{{ rackspace_region }}" + name: "{{ resource_prefix }}-4" + state: absent + wait: true + register: rax_cdb + +- name: "Validate delete integration 4" + assert: + that: + - rax_cdb|changed + - rax_cdb.cdb.name == "{{ resource_prefix }}-4" +# ============================================================