1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

s3 integration tests (#28396)

* Replace pause in integration tests with until.

Use resource prefix instead of generating a random number

Only try to delete keys if they exist

* Add alias to tests
This commit is contained in:
Sloane Hertel 2017-09-15 05:08:09 -04:00 committed by ansibot
parent e0a5b7d7ea
commit bdbe5337c6
4 changed files with 21 additions and 26 deletions

View file

@ -353,7 +353,8 @@ def delete_bucket(module, s3, bucket):
# if there are contents then we need to delete them before we can delete the bucket
for keys in paginated_list(s3, Bucket=bucket):
formatted_keys = [{'Key': key} for key in keys]
s3.delete_objects(Bucket=bucket, Delete={'Objects': formatted_keys})
if formatted_keys:
s3.delete_objects(Bucket=bucket, Delete={'Objects': formatted_keys})
s3.delete_bucket(Bucket=bucket)
return True
except botocore.exceptions.ClientError as e:

View file

@ -1 +1,2 @@
cloud/aws
posix/ci/cloud/aws

View file

@ -1,2 +1,3 @@
---
# defaults file for s3
bucket_name: '{{resource_prefix}}'

View file

@ -1,14 +1,9 @@
---
# tasks file for test_s3
# ============================================================
- name: generate random name for the bucket name
command: bash -c 'echo ansible_test_$RANDOM'
register: bucket
# ============================================================
# ============================================================
- name: test create bucket
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: create
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
@ -21,7 +16,7 @@
# ============================================================
- name: trying to create a bucket name that already exists
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: create
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
@ -51,7 +46,7 @@
# ============================================================
- name: test putting an object in the bucket
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: put
src: "{{ tmp1.path }}"
object: delete.txt
@ -67,16 +62,12 @@
- result.changed == True
- result.msg == "PUT operation complete"
# ============================================================
- name: wait a few seconds before continuing
pause:
seconds: 3
# ============================================================
- name: create a second temp file to download the object from the bucket
tempfile:
register: tmp2
- name: test get object
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: get
dest: "{{ tmp2.path }}"
object: delete.txt
@ -86,6 +77,7 @@
retries: 3
delay: 3
register: result
until: "result.msg == 'GET operation complete'"
- name: get the stat of the file so we can compare the checksums
stat:
path: "{{ tmp2.path }}"
@ -96,13 +88,9 @@
that:
- file1stat.stat.checksum == file2stat.stat.checksum
# ============================================================
- name: wait a few seconds before continuing
pause:
seconds: 3
# ============================================================
- name: test geturl of the object
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: geturl
object: delete.txt
security_token: "{{security_token}}"
@ -111,6 +99,7 @@
retries: 3
delay: 3
register: result
until: result.changed
- name: assert we have the object's url
assert:
that:
@ -119,7 +108,7 @@
# ============================================================
- name: test getstr of the object
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: getstr
object: delete.txt
security_token: "{{security_token}}"
@ -136,7 +125,7 @@
# ============================================================
- name: test list to get all objects in the bucket
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: list
security_token: "{{security_token}}"
aws_access_key: "{{ ec2_access_key }}"
@ -152,7 +141,7 @@
# ============================================================
- name: test delobj to just delete an object in the bucket
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: delobj
object: delete.txt
security_token: "{{security_token}}"
@ -169,12 +158,15 @@
# ============================================================
- name: test delete bucket
s3:
bucket: "{{ bucket.stdout }}"
bucket: "{{ bucket_name }}"
mode: delete
security_token: "{{security_token}}"
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
register: result
retries: 3
delay: 3
until: result.changed
- name: assert that changed is True
assert:
that:
@ -191,7 +183,7 @@
# ============================================================
- name: test create a bucket with a dot in the name
s3:
bucket: "{{ bucket.stdout + '.bucket' }}"
bucket: "{{ bucket_name + '.bucket' }}"
mode: create
security_token: "{{security_token}}"
aws_access_key: "{{ ec2_access_key }}"
@ -204,7 +196,7 @@
# ============================================================
- name: test delete a bucket with a dot in the name
s3:
bucket: "{{ bucket.stdout + '.bucket' }}"
bucket: "{{ bucket_name + '.bucket' }}"
mode: delete
security_token: "{{security_token}}"
aws_access_key: "{{ ec2_access_key }}"
@ -217,7 +209,7 @@
# ============================================================
- name: test delete a nonexistent bucket
s3:
bucket: "{{ bucket.stdout + '.bucket' }}"
bucket: "{{ bucket_name + '.bucket' }}"
mode: delete
security_token: "{{security_token}}"
aws_access_key: "{{ ec2_access_key }}"