2017-05-31 17:48:35 +02:00
|
|
|
---
|
|
|
|
# tasks file for test_s3
|
|
|
|
# ============================================================
|
|
|
|
- name: test create bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: create
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
register: result
|
|
|
|
- name: assert changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: trying to create a bucket name that already exists
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: create
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
register: result
|
|
|
|
- name: assert changed is False since the bucket already exists
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == False
|
|
|
|
# ============================================================
|
|
|
|
- name: create temporary file object to put in a bucket
|
|
|
|
tempfile:
|
|
|
|
register: tmp1
|
|
|
|
- name: make random contents
|
|
|
|
set_fact:
|
|
|
|
content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}"
|
|
|
|
|
|
|
|
- name: give temporary file data
|
|
|
|
copy:
|
|
|
|
content: "{{ content }}"
|
|
|
|
dest: "{{ tmp1.path }}"
|
|
|
|
- name: get the stat of the file
|
|
|
|
stat:
|
|
|
|
path: "{{ tmp1.path }}"
|
|
|
|
get_checksum: yes
|
|
|
|
register: file1stat
|
|
|
|
# ============================================================
|
|
|
|
- name: test putting an object in the bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: put
|
|
|
|
src: "{{ tmp1.path }}"
|
|
|
|
object: delete.txt
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert object exists
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
- result.msg == "PUT operation complete"
|
|
|
|
# ============================================================
|
|
|
|
- name: create a second temp file to download the object from the bucket
|
|
|
|
tempfile:
|
|
|
|
register: tmp2
|
|
|
|
- name: test get object
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: get
|
|
|
|
dest: "{{ tmp2.path }}"
|
|
|
|
object: delete.txt
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
2017-09-15 11:08:09 +02:00
|
|
|
until: "result.msg == 'GET operation complete'"
|
2017-05-31 17:48:35 +02:00
|
|
|
- name: get the stat of the file so we can compare the checksums
|
|
|
|
stat:
|
|
|
|
path: "{{ tmp2.path }}"
|
|
|
|
get_checksum: yes
|
|
|
|
register: file2stat
|
|
|
|
- name: assert checksums are the same
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- file1stat.stat.checksum == file2stat.stat.checksum
|
|
|
|
# ============================================================
|
|
|
|
- name: test geturl of the object
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: geturl
|
|
|
|
object: delete.txt
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
2017-09-15 11:08:09 +02:00
|
|
|
until: result.changed
|
2017-05-31 17:48:35 +02:00
|
|
|
- name: assert we have the object's url
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Download url:' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test getstr of the object
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: getstr
|
|
|
|
object: delete.txt
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that we have the object's contents
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.msg == "GET operation complete"
|
|
|
|
- result.contents == content
|
|
|
|
# ============================================================
|
|
|
|
- name: test list to get all objects in the bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: list
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that the keys are correct
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'delete.txt' in result.s3_keys"
|
|
|
|
- result.msg == "LIST operation complete"
|
|
|
|
# ============================================================
|
|
|
|
- name: test delobj to just delete an object in the bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: delobj
|
|
|
|
object: delete.txt
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that delete.txt is no longer an object in the bucket deleteme
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Object deleted from bucket' in result.msg"
|
|
|
|
- result.changed == True
|
2017-10-26 14:17:13 +02:00
|
|
|
- name: assert that delete.txt is no longer an object in the bucket deleteme
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Object deleted from bucket' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test creation of empty path
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: create
|
|
|
|
object: foo/bar/baz/
|
|
|
|
security_token: "{{ security_token }}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that empty path is created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Virtual directory foo/bar/baz/ created' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
- name: test deletion of empty path
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: delobj
|
|
|
|
object: foo/bar/baz/
|
|
|
|
security_token: "{{ security_token }}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
2017-05-31 17:48:35 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test delete bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: delete
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
register: result
|
2017-09-15 11:08:09 +02:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
until: result.changed
|
2017-05-31 17:48:35 +02:00
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: delete temporary file 1
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ tmp1.path }}"
|
|
|
|
- name: delete temporary file 2
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ tmp2.path }}"
|
|
|
|
# ============================================================
|
|
|
|
- name: test create a bucket with a dot in the name
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: create
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
register: result
|
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test delete a bucket with a dot in the name
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-05-31 17:48:35 +02:00
|
|
|
mode: delete
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
register: result
|
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
2017-06-12 19:52:25 +02:00
|
|
|
- name: test delete a nonexistent bucket
|
2017-10-26 14:17:13 +02:00
|
|
|
aws_s3:
|
2017-09-15 11:08:09 +02:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-06-12 19:52:25 +02:00
|
|
|
mode: delete
|
|
|
|
security_token: "{{security_token}}"
|
|
|
|
aws_access_key: "{{ ec2_access_key }}"
|
|
|
|
aws_secret_key: "{{ ec2_secret_key }}"
|
|
|
|
register: result
|
|
|
|
- name: assert that changed is False
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == False
|
|
|
|
# ============================================================
|