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: if module.check_mode:
module.exit_json(msg="PUT operation skipped - running in check mode", changed=True) module.exit_json(msg="PUT operation skipped - running in check mode", changed=True)
try: try:
bucket = s3.Bucket(bucket) s3.put_object(Bucket=bucket, Key=obj, Body=b'')
key = bucket.new_key(obj)
key.set_contents_from_string('')
for acl in module.params.get('permission'): for acl in module.params.get('permission'):
s3.put_object_acl(ACL=acl, Bucket=bucket, Key=obj) 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: 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)) 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 cloud/aws
posix/ci/cloud/aws posix/ci/cloud/group1/aws

View file

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