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

[cloud] Bugfix for aws_s3 empty directory creation (#32169)

* [cloud] Bugfix for aws_s3 empty directory creation

* Update integration tests
This commit is contained in:
Ryan Brown 2017-10-26 08:17:13 -04:00 committed by Sloane Hertel
parent 0b357ba223
commit 838c1ba6c7
3 changed files with 47 additions and 17 deletions

View file

@ -408,12 +408,10 @@ def create_dirkey(module, s3, bucket, obj):
if module.check_mode:
module.exit_json(msg="PUT operation skipped - running in check mode", changed=True)
try:
bucket = s3.Bucket(bucket)
key = bucket.new_key(obj)
key.set_contents_from_string('')
s3.put_object(Bucket=bucket, Key=obj, Body=b'')
for acl in module.params.get('permission'):
s3.put_object_acl(ACL=acl, Bucket=bucket, Key=obj)
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket.name), changed=True)
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket), changed=True)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed while creating object %s." % obj, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))

View file

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

View file

@ -2,7 +2,7 @@
# tasks file for test_s3
# ============================================================
- name: test create bucket
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: create
aws_access_key: "{{ ec2_access_key }}"
@ -15,7 +15,7 @@
- result.changed == True
# ============================================================
- name: trying to create a bucket name that already exists
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: create
aws_access_key: "{{ ec2_access_key }}"
@ -45,7 +45,7 @@
register: file1stat
# ============================================================
- name: test putting an object in the bucket
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: put
src: "{{ tmp1.path }}"
@ -66,7 +66,7 @@
tempfile:
register: tmp2
- name: test get object
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: get
dest: "{{ tmp2.path }}"
@ -89,7 +89,7 @@
- file1stat.stat.checksum == file2stat.stat.checksum
# ============================================================
- name: test geturl of the object
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: geturl
object: delete.txt
@ -107,7 +107,7 @@
- result.changed == True
# ============================================================
- name: test getstr of the object
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: getstr
object: delete.txt
@ -124,7 +124,7 @@
- result.contents == content
# ============================================================
- name: test list to get all objects in the bucket
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: list
security_token: "{{security_token}}"
@ -140,7 +140,7 @@
- result.msg == "LIST operation complete"
# ============================================================
- name: test delobj to just delete an object in the bucket
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: delobj
object: delete.txt
@ -155,9 +155,41 @@
that:
- "'Object deleted from bucket' in result.msg"
- result.changed == True
- 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
# ============================================================
- name: test delete bucket
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: delete
security_token: "{{security_token}}"
@ -182,7 +214,7 @@
path: "{{ tmp2.path }}"
# ============================================================
- name: test create a bucket with a dot in the name
s3:
aws_s3:
bucket: "{{ bucket_name + '.bucket' }}"
mode: create
security_token: "{{security_token}}"
@ -195,7 +227,7 @@
- result.changed == True
# ============================================================
- name: test delete a bucket with a dot in the name
s3:
aws_s3:
bucket: "{{ bucket_name + '.bucket' }}"
mode: delete
security_token: "{{security_token}}"
@ -208,7 +240,7 @@
- result.changed == True
# ============================================================
- name: test delete a nonexistent bucket
s3:
aws_s3:
bucket: "{{ bucket_name + '.bucket' }}"
mode: delete
security_token: "{{security_token}}"