mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-04-26 02:52:40 +00:00
Merge pull request #12 from sshnaidm/tests
Add tests for podman_container and podman_network_info
This commit is contained in:
commit
2bb6fb36ff
6 changed files with 464 additions and 0 deletions
4
tests/integration/targets/podman_container/aliases
Normal file
4
tests/integration/targets/podman_container/aliases
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
shippable/posix/group2
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
destructive
|
||||
2
tests/integration/targets/podman_container/meta/main.yml
Normal file
2
tests/integration/targets/podman_container/meta/main.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_podman
|
||||
389
tests/integration/targets/podman_container/tasks/main.yml
Normal file
389
tests/integration/targets/podman_container/tasks/main.yml
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
- name: Test podman_container
|
||||
become: true
|
||||
block:
|
||||
- name: Delete all container leftovers from tests
|
||||
podman_container:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "alpine:3.7"
|
||||
- "container"
|
||||
- "container2"
|
||||
|
||||
- name: Test no image with default action
|
||||
podman_container:
|
||||
name: container
|
||||
ignore_errors: true
|
||||
register: no_image
|
||||
|
||||
- name: Test no image with state 'started'
|
||||
podman_container:
|
||||
name: container
|
||||
state: started
|
||||
ignore_errors: true
|
||||
register: no_image1
|
||||
|
||||
- name: Test no image with state 'present'
|
||||
podman_container:
|
||||
name: container
|
||||
state: present
|
||||
ignore_errors: true
|
||||
register: no_image2
|
||||
|
||||
- name: Check no image
|
||||
assert:
|
||||
that:
|
||||
- no_image is failed
|
||||
- no_image1 is failed
|
||||
- no_image2 is failed
|
||||
- no_image.msg == "State 'started' required image to be configured!"
|
||||
- no_image1.msg == "State 'started' required image to be configured!"
|
||||
- no_image2.msg == "State 'present' required image to be configured!"
|
||||
fail_msg: No image test failed!
|
||||
success_msg: No image test passed!
|
||||
|
||||
- name: Ensure image doesn't exist
|
||||
podman_image:
|
||||
name: alpine:3.7
|
||||
state: absent
|
||||
|
||||
- name: Check pulling image
|
||||
podman_container:
|
||||
name: container
|
||||
image: alpine:3.7
|
||||
state: present
|
||||
command: sleep 1d
|
||||
register: image
|
||||
|
||||
- name: Check using already pulled image
|
||||
podman_container:
|
||||
name: container2
|
||||
image: alpine:3.7
|
||||
state: present
|
||||
command: sleep 1d
|
||||
register: image2
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- image is changed
|
||||
- image.container is defined
|
||||
- image.container['State']['Running']
|
||||
- "'pulled image alpine:3.7' in image.actions"
|
||||
- "'started container' in image.actions"
|
||||
- image2 is changed
|
||||
- image2.container is defined
|
||||
- image2.container['State']['Running']
|
||||
- "'pulled image alpine:3.7' not in image2.actions"
|
||||
- "'started container2' in image2.actions"
|
||||
fail_msg: Pulling image test failed!
|
||||
success_msg: Pulling image test passed!
|
||||
|
||||
- name: Check failed image pull
|
||||
podman_container:
|
||||
name: container
|
||||
image: ineverneverneverexist
|
||||
state: present
|
||||
command: sleep 1d
|
||||
register: imagefail
|
||||
ignore_errors: true
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- imagefail is failed
|
||||
- imagefail.msg == "Can't pull image ineverneverneverexist"
|
||||
|
||||
|
||||
- name: Force container recreate
|
||||
podman_container:
|
||||
name: container
|
||||
image: alpine
|
||||
state: present
|
||||
command: sleep 1d
|
||||
recreate: true
|
||||
register: recreated
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- recreated is changed
|
||||
- recreated.container is defined
|
||||
- recreated.container['State']['Running']
|
||||
- "'recreated container' in recreated.actions"
|
||||
fail_msg: Force recreate test failed!
|
||||
success_msg: Force recreate test passed!
|
||||
|
||||
- name: Stop container
|
||||
podman_container:
|
||||
name: container
|
||||
state: stopped
|
||||
register: stopped
|
||||
|
||||
- name: Stop the same container again (idempotency)
|
||||
podman_container:
|
||||
name: container
|
||||
state: stopped
|
||||
register: stopped_again
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- stopped is changed
|
||||
- stopped.container is defined
|
||||
- not stopped.container['State']['Running']
|
||||
- "'stopped container' in stopped.actions"
|
||||
- stopped_again is not changed
|
||||
- stopped_again.container is defined
|
||||
- not stopped_again.container['State']['Running']
|
||||
- stopped_again.actions == []
|
||||
fail_msg: Stopping container test failed!
|
||||
success_msg: Stopping container test passed!
|
||||
|
||||
- name: Delete stopped container
|
||||
podman_container:
|
||||
name: container
|
||||
state: absent
|
||||
register: deleted
|
||||
|
||||
- name: Delete again container (idempotency)
|
||||
podman_container:
|
||||
name: container
|
||||
state: absent
|
||||
register: deleted_again
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- deleted is changed
|
||||
- deleted.container is defined
|
||||
- deleted.container == {}
|
||||
- "'deleted container' in deleted.actions"
|
||||
- deleted_again is not changed
|
||||
- deleted_again.container is defined
|
||||
- deleted_again.container == {}
|
||||
- deleted_again.actions == []
|
||||
fail_msg: Deleting stopped container test failed!
|
||||
success_msg: Deleting stopped container test passed!
|
||||
|
||||
- name: Create container, but don't run
|
||||
podman_container:
|
||||
name: container
|
||||
image: alpine:3.7
|
||||
state: stopped
|
||||
command: sleep 1d
|
||||
register: created
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- created is changed
|
||||
- created.container is defined
|
||||
- created.container != {}
|
||||
- not created.container['State']['Running']
|
||||
- "'created container' in created.actions"
|
||||
fail_msg: "Creating stopped container test failed!"
|
||||
success_msg: "Creating stopped container test passed!"
|
||||
|
||||
- name: Delete created container
|
||||
podman_container:
|
||||
name: container
|
||||
state: absent
|
||||
|
||||
- name: Start container that was deleted
|
||||
podman_container:
|
||||
name: container
|
||||
image: alpine:3.7
|
||||
state: started
|
||||
command: sleep 1d
|
||||
register: started
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- started is changed
|
||||
- started.container is defined
|
||||
- started.container['State']['Running']
|
||||
- "'pulled image alpine:3.7' not in started.actions"
|
||||
|
||||
- name: Delete started container
|
||||
podman_container:
|
||||
name: container
|
||||
state: absent
|
||||
register: deleted
|
||||
|
||||
- name: Delete again container (idempotency)
|
||||
podman_container:
|
||||
name: container
|
||||
state: absent
|
||||
register: deleted_again
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- deleted is changed
|
||||
- deleted.container is defined
|
||||
- deleted.container == {}
|
||||
- "'deleted container' in deleted.actions"
|
||||
- deleted_again is not changed
|
||||
- deleted_again.container is defined
|
||||
- deleted_again.container == {}
|
||||
- deleted_again.actions == []
|
||||
fail_msg: Deleting started container test failed!
|
||||
success_msg: Deleting started container test passed!
|
||||
|
||||
- name: Recreate container with parameters
|
||||
podman_container:
|
||||
name: container
|
||||
image: docker.io/alpine:3.7
|
||||
state: started
|
||||
command: sleep 1d
|
||||
recreate: true
|
||||
etc_hosts:
|
||||
host1: 127.0.0.1
|
||||
host2: 127.0.0.1
|
||||
annotation:
|
||||
this: "annotation_value"
|
||||
dns:
|
||||
- 1.1.1.1
|
||||
- 8.8.4.4
|
||||
dns_search: example.com
|
||||
cap_add:
|
||||
- SYS_TIME
|
||||
- NET_ADMIN
|
||||
publish:
|
||||
- "9000:80"
|
||||
- "9001:8000"
|
||||
workdir: "/bin"
|
||||
env:
|
||||
FOO: bar
|
||||
BAR: foo
|
||||
TEST: 1
|
||||
BOOL: false
|
||||
group_add: "somegroup"
|
||||
label:
|
||||
somelabel: labelvalue
|
||||
otheralbe: othervalue
|
||||
volumes:
|
||||
- /tmp:/data
|
||||
register: test
|
||||
|
||||
- name: Check output is correct
|
||||
assert:
|
||||
that:
|
||||
- test is changed
|
||||
- test.container is defined
|
||||
- test.container != {}
|
||||
- test.container['State']['Running']
|
||||
# test capabilities
|
||||
- "'CAP_SYS_TIME' in test.container['BoundingCaps']"
|
||||
- "'CAP_NET_ADMIN' in test.container['BoundingCaps']"
|
||||
# test annotations
|
||||
- test.container['Config']['Annotations']['this'] is defined
|
||||
- test.container['Config']['Annotations']['this'] == "annotation_value"
|
||||
# test DNS
|
||||
- >-
|
||||
(test.container['HostConfig']['Dns'] is defined and
|
||||
test.container['HostConfig']['Dns'] == ['1.1.1.1', '8.8.4.4']) or
|
||||
(test.container['HostConfig']['DNS'] is defined and
|
||||
test.container['HostConfig']['DNS'] == ['1.1.1.1', '8.8.4.4'])
|
||||
# test ports
|
||||
- test.container['NetworkSettings']['Ports']|length == 2
|
||||
# test working dir
|
||||
- test.container['Config']['WorkingDir'] == "/bin"
|
||||
# test dns search
|
||||
- >-
|
||||
(test.container['HostConfig']['DnsSearch'] is defined and
|
||||
test.container['HostConfig']['DnsSearch'] == ['example.com']) or
|
||||
(test.container['HostConfig']['DNSSearch'] is defined and
|
||||
test.container['HostConfig']['DNSSearch'] == ['example.com'])
|
||||
# test environment variables
|
||||
- "'FOO=bar' in test.container['Config']['Env']"
|
||||
- "'BAR=foo' in test.container['Config']['Env']"
|
||||
- "'TEST=1' in test.container['Config']['Env']"
|
||||
- "'BOOL=False' in test.container['Config']['Env']"
|
||||
# test labels
|
||||
- test.container['Config']['Labels'] | length == 2
|
||||
- test.container['Config']['Labels']['somelabel'] == "labelvalue"
|
||||
- test.container['Config']['Labels']['otheralbe'] == "othervalue"
|
||||
# test mounts
|
||||
- >-
|
||||
(test.container['Mounts'][0]['Destination'] is defined and
|
||||
'/data' in test.container['Mounts'] | map(attribute='Destination') | list) or
|
||||
(test.container['Mounts'][0]['destination'] is defined and
|
||||
'/data' in test.container['Mounts'] | map(attribute='destination') | list)
|
||||
- >-
|
||||
(test.container['Mounts'][0]['Source'] is defined and
|
||||
'/tmp' in test.container['Mounts'] | map(attribute='Source') | list) or
|
||||
(test.container['Mounts'][0]['source'] is defined and
|
||||
'/tmp' in test.container['Mounts'] | map(attribute='source') | list)
|
||||
fail_msg: Parameters container test failed!
|
||||
success_msg: Parameters container test passed!
|
||||
|
||||
- name: Check basic idempotency of running container
|
||||
podman_container:
|
||||
name: testidem
|
||||
image: docker.io/alpine
|
||||
state: present
|
||||
command: sleep 20m
|
||||
|
||||
- name: Check basic idempotency of running container - run it again
|
||||
podman_container:
|
||||
name: testidem
|
||||
image: alpine:latest
|
||||
state: present
|
||||
command: sleep 20m
|
||||
register: idem
|
||||
|
||||
- name: Check that nothing was changed
|
||||
assert:
|
||||
that:
|
||||
- not idem.changed
|
||||
|
||||
- name: Run changed container (with tty enabled)
|
||||
podman_container:
|
||||
name: testidem
|
||||
image: alpine
|
||||
state: present
|
||||
command: sleep 20m
|
||||
tty: true
|
||||
register: idem1
|
||||
|
||||
- name: Check that container is recreated when changed
|
||||
assert:
|
||||
that:
|
||||
- idem1 is changed
|
||||
|
||||
- name: Run changed container without specifying an option, use defaults
|
||||
podman_container:
|
||||
name: testidem
|
||||
image: alpine
|
||||
state: present
|
||||
command: sleep 20m
|
||||
register: idem2
|
||||
|
||||
- name: Check that container is recreated when changed to default value
|
||||
assert:
|
||||
that:
|
||||
- idem2 is changed
|
||||
|
||||
- name: Remove container
|
||||
podman_container:
|
||||
name: testidem
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
- name: Check podman_actions
|
||||
assert:
|
||||
that:
|
||||
- "'podman rm -f testidem' in remove.podman_actions"
|
||||
|
||||
always:
|
||||
- name: Delete all container leftovers from tests
|
||||
podman_container:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "alpine:3.7"
|
||||
- "container"
|
||||
- "container2"
|
||||
4
tests/integration/targets/podman_network_info/aliases
Normal file
4
tests/integration/targets/podman_network_info/aliases
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
shippable/posix/group2
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
destructive
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_podman
|
||||
63
tests/integration/targets/podman_network_info/tasks/main.yml
Normal file
63
tests/integration/targets/podman_network_info/tasks/main.yml
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
- name: Test podman_network_info
|
||||
when:
|
||||
- ansible_facts.virtualization_type != 'docker'
|
||||
- ansible_facts.distribution == 'RedHat'
|
||||
become: true
|
||||
block:
|
||||
|
||||
- name: Print podman version
|
||||
command: podman version
|
||||
|
||||
- name: Generate random value for network name
|
||||
set_fact:
|
||||
network_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}"
|
||||
|
||||
- name: Make sure network doesn't exist
|
||||
command: podman network rm {{ network_name }}
|
||||
ignore_errors: true
|
||||
|
||||
- name: Get missing network info
|
||||
podman_network_info:
|
||||
name: "{{ network_name }}"
|
||||
register: nonexist
|
||||
ignore_errors: true
|
||||
|
||||
- name: Check results
|
||||
assert:
|
||||
that:
|
||||
- "'networks' not in nonexist"
|
||||
- nonexist is failed
|
||||
|
||||
- name: Make sure network exists
|
||||
command: podman network create {{ network_name }}
|
||||
|
||||
- name: Get existing network info
|
||||
podman_network_info:
|
||||
name: "{{ network_name }}"
|
||||
register: existing_network
|
||||
|
||||
- name: Dump podman network inspect result
|
||||
debug: var=existing_network
|
||||
|
||||
- name: Comparison with 'podman network inspect'
|
||||
command: podman network inspect "{{ network_name }}"
|
||||
register: podman_inspect
|
||||
|
||||
- name: Convert podman inspect output to JSON
|
||||
set_fact:
|
||||
podman_inspect_result: "{{ podman_inspect.stdout | from_json }}"
|
||||
|
||||
- name: Cleanup
|
||||
command: podman network rm {{ network_name }}
|
||||
|
||||
- name: Make checks
|
||||
assert:
|
||||
that:
|
||||
- "'networks' in existing_network"
|
||||
- existing_network.networks
|
||||
- "existing_network.networks == podman_inspect_result"
|
||||
always:
|
||||
|
||||
- name: Cleanup
|
||||
command: podman network rm {{ network_name }}
|
||||
ignore_errors: true
|
||||
Loading…
Add table
Add a link
Reference in a new issue