Clean up and migrate Azure tests. (#28103)

* Remove placeholder Azure test.
* Migrate Azure tests to ansible-test.
* Initial cleanup on remaining legacy Azure tests.
This commit is contained in:
Matt Clay 2017-08-12 01:03:42 -07:00 committed by GitHub
commit 3631163329
23 changed files with 264 additions and 638 deletions

View file

@ -0,0 +1,2 @@
cloud/azure
destructive

View file

@ -0,0 +1,2 @@
dependencies:
- setup_azure

View file

@ -0,0 +1,102 @@
- name: Remove public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
state: absent
- name: Create public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
allocation_method: Static
domain_name: autotest01
tags:
testing: testing
delete: on-exit
register: output
- assert:
that:
- output.state.public_ip_allocation_method == 'Static'
- output.state.dns_settings.domain_name_label == 'autotest01'
- output.state.tags | length == 2
- output.state.tags.testing == 'testing'
- name: Should be idempotent
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
allocation_method: Static
domain_name: autotest01
tags:
testing: testing
delete: on-exit
register: output
- assert:
that: not output.changed
- name: Update tags
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
tags:
testing: testing
delete: never
foo: bar
register: output
- assert:
that:
- output.state.tags | length == 3
- output.state.tags.delete == 'never'
- name: Gather facts, filtering by tag
azure_rm_publicipaddress_facts:
resource_group: "{{ resource_group }}"
tags:
- testing
- foo:bar
- assert:
that: azure_publicipaddresses | length == 1
- name: Purge all tags
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
tags: {}
register: output
- assert:
that:
- output.state.tags | length == 0
- name: Gather facts for a public ip
azure_rm_publicipaddress_facts:
resource_group: "{{ resource_group }}"
name: testing01
- assert:
that: azure_publicipaddresses | length == 1
- name: Gather facts for all public ips
azure_rm_publicipaddress_facts:
resource_group: "{{ resource_group }}"
- assert:
that: azure_publicipaddresses | length > 0
- name: Remove public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
name: testing01
state: absent
- name: Gather facts for a public ip
azure_rm_publicipaddress_facts:
resource_group: "{{ resource_group }}"
name: testing01
- assert:
that: azure_publicipaddresses | length == 0

View file

@ -0,0 +1,2 @@
cloud/azure
destructive

View file

@ -0,0 +1,2 @@
dependencies:
- setup_azure

View file

@ -0,0 +1,122 @@
- name: Create storage account name
set_fact:
storage_account: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
- name: Test invalid account name
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "invalid_char$"
state: present
register: invalid_name
ignore_errors: yes
- name: Assert task failed
assert: { that: "invalid_name['failed'] == True" }
- name: Delete storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
state: absent
- name: Create new storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_LRS
tags:
test: test
galaxy: galaxy
register: output
- name: Assert status succeeded and results include an Id value
assert:
that:
- output.changed
- output.state.id is defined
- name: Gather facts by tags
azure_rm_storageaccount_facts:
resource_group: "{{ resource_group }}"
tags:
- test
- galaxy
- assert:
that: azure_storageaccounts | length >= 1
- name: Change account type
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Premium_LRS
register: change_account
ignore_errors: yes
- name: Assert account type change failed
assert: { that: "change_account['failed'] == True" }
- name: Change account type and add custom domain
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_GRS
custom_domain: { name: ansible.com, use_sub_domain: no }
register: change_account
ignore_errors: yes
- name: Assert CNAME failure
assert: { that: "'custom domain name could not be verified' in change_account['msg']" }
- name: Update account tags
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
tags:
testing: testing
delete: never
galaxy: 'no'
register: output
- assert:
that:
- "output.state.tags | length == 3"
- "output.state.tags.galaxy == 'no'"
- name: Update account tags
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
tags:
testing: testing
delete: never
register: output
- assert:
that:
- "output.state.tags | length == 2"
- "output.state.tags.testing == 'testing'"
- "output.state.tags.delete == 'never'"
- name: Gather facts
azure_rm_storageaccount_facts:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
- assert:
that:
- "azure_storageaccounts| length == 1"
- name: Gather facts
azure_rm_storageaccount_facts:
resource_group: "{{ resource_group }}"
- assert:
that:
- "azure_storageaccounts | length > 0"
- name: Delete acccount
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
state: absent

View file

@ -0,0 +1,2 @@
cloud/azure
destructive

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -0,0 +1,2 @@
dependencies:
- setup_azure

View file

@ -0,0 +1,116 @@
- name: Create storage account name
set_fact:
storage_account: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
- name: Create storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_LRS
state: present
- name: Create container
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
- name: Force upload blob
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
blob: 'Ratings.png'
src: './targets/azure_rm_storageblob/files/Ratings.png'
content_type: image/png
tags:
val1: foo
val2: bar
force: yes
- name: Upload blob idempotence
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
blob: 'Ratings.png'
src: './targets/azure_rm_storageblob/files/Ratings.png'
content_type: image/png
tags:
val1: foo
val2: bar
register: upload_facts
- assert:
that: "not upload_facts.changed"
- name: Download file idempotence
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
blob: 'Ratings.png'
dest: './targets/azure_rm_storageblob/files/Ratings.png'
register: download_results
- assert:
that: not download_results.changed
- file: path="/tmp/Ratings.png" state=absent
- name: Download file
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
blob: 'Ratings.png'
dest: '/tmp/Ratings.png'
register: download_results
- assert:
that: "download_results.changed"
- find: paths='/tmp' patterns="Ratings.png"
register: find_results
- assert: { that: "find_results['matched'] == 1" }
- name: Do not delete container that has blobs
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
state: absent
register: output
- assert:
that: "not output.changed"
- name: Delete blob object
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
blob: "Ratings.png"
state: absent
register: output
- assert:
that: "output.changed"
- name: Delete container
azure_rm_storageblob:
resource_group: "{{ resource_group }}"
account_name: "{{ storage_account }}"
container_name: my-blobs
state: absent
register: output
- assert:
that: "output.changed"
- name: Delete storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
state: absent

View file

@ -0,0 +1,2 @@
cloud/azure
destructive

View file

@ -0,0 +1,2 @@
dependencies:
- setup_azure

View file

@ -0,0 +1,95 @@
- name: Create virtual network
azure_rm_virtualnetwork:
name: My_Virtual_Network
address_prefixes_cidr:
- 10.1.0.0/16
- 172.100.0.0/16
dns_servers:
- 127.0.0.1
- 127.0.0.3
tags:
testing: testing
delete: on-exit
resource_group: "{{ resource_group }}"
- name: Remove subnet
azure_rm_subnet:
state: absent
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
- name: Catch invalid cidr
azure_rm_subnet:
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0/24"
register: output
ignore_errors: yes
- assert:
that: output.failed
- name: Add the subnet back
azure_rm_subnet:
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/24"
register: output
- assert:
that: output.changed
- name: Create network security group
azure_rm_securitygroup:
name: secgroupfoo
resource_group: "{{ resource_group }}"
tags:
testing: testing
- name: Update the subnet
azure_rm_subnet:
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/16"
security_group: secgroupfoo
tags:
testing: testing
delete: on-fini
- name: Should be idempotent
azure_rm_subnet:
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/16"
security_group: secgroupfoo
tags:
testing: testing
delete: on-fini
register: output
- assert:
that: not output.changed
- name: Remove subnet
azure_rm_subnet:
state: absent
name: foobar
virtual_network_name: My_Virtual_Network
resource_group: "{{ resource_group }}"
- name: Remove security group
azure_rm_securitygroup:
resource_group: "{{ resource_group }}"
name: secgroupfoo
state: absent
- name: Remove virtual network
azure_rm_virtualnetwork:
name: My_Virtual_Network
resource_group: "{{ resource_group }}"
state: absent

View file

@ -1,7 +1,148 @@
- block:
- name: create a virtual network
azure_rm_virtualnetwork:
resource_group: '{{ resource_group }}'
name: test
address_prefixes_cidr:
- "10.1.0.0/16"
- name: Delete virtual network, if it exists
azure_rm_virtualnetwork:
name: my_test_network
resource_group: "{{ resource_group }}"
state: absent
- name: Create virtual network
azure_rm_virtualnetwork:
name: my_test_network
address_prefixes_cidr:
- 10.1.0.0/16
- 172.100.0.0/16
dns_servers:
- 127.0.0.1
- 127.0.0.3
tags:
testing: testing
delete: on-exit
resource_group: "{{ resource_group }}"
register: output
- assert:
that:
- "output.state.address_prefixes | length == 2"
- "output.state.dns_servers | length == 2"
- "output.state.tags.delete == 'on-exit'"
- "output.state.tags | length == 2"
- name: Gather facts by name, tags
azure_rm_virtualnetwork_facts:
resource_group: "{{ resource_group }}"
name: my_test_network
tags:
- testing
- assert:
that: "azure_virtualnetworks | length == 1"
- name: Gather facts by resource group, tags
azure_rm_virtualnetwork_facts:
resource_group: "{{ resource_group }}"
tags:
- testing
- assert:
that: "azure_virtualnetworks | length == 1"
- name: Gather facts by tags
azure_rm_virtualnetwork_facts:
tags:
- testing
- assert:
that: "azure_virtualnetworks | length >= 1"
- name: Should be idempotent
azure_rm_virtualnetwork:
name: my_test_network
address_prefixes_cidr:
- 10.1.0.0/16
- 172.100.0.0/16
dns_servers:
- 127.0.0.1
- 127.0.0.3
tags:
testing: testing
delete: on-exit
resource_group: "{{ resource_group }}"
register: output
- assert:
that: not output.changed
- name: Update tags
azure_rm_virtualnetwork:
name: my_test_network
tags:
testing: 'no'
delete: never
foo: bar
resource_group: "{{ resource_group }}"
register: output
- assert:
that: output.state.tags | length == 3
- name: Purge tags
azure_rm_virtualnetwork:
name: my_test_network
tags:
testing: 'always'
resource_group: "{{ resource_group }}"
register: output
- assert:
that:
- output.state.tags | length == 1
- output.state.tags.testing == 'always'
- name: Should require address_prefixes_cidr when purge_address_prefixes
azure_rm_virtualnetwork:
name: my_test_network
purge_address_prefixes: true
resource_group: "{{ resource_group }}"
register: output
ignore_errors: yes
- assert:
that: output.failed
- name: Purge address prefixes
azure_rm_virtualnetwork:
name: my_test_network
address_prefixes_cidr: 10.1.0.0/16
purge_address_prefixes: true
resource_group: "{{ resource_group }}"
register: output
- assert:
that:
- output.state.address_prefixes | length == 1
- output.state.address_prefixes[0] == '10.1.0.0/16'
- output.state.dns_servers | length == 2
- output.state.dns_servers[0] == '127.0.0.1'
- name: Purge DNS servers
azure_rm_virtualnetwork:
name: my_test_network
purge_dns_servers: true
resource_group: "{{ resource_group }}"
register: output
- assert:
that: output.state['dns_servers'] is undefined
- name: Gather facts
azure_rm_virtualnetwork_facts:
resource_group: "{{ resource_group }}"
name: my_test_network
- assert:
that: "azure_virtualnetworks | length == 1"
- name: Delete virtual network
azure_rm_virtualnetwork:
name: my_test_network
resource_group: "{{ resource_group }}"
state: absent