Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloud] Bugfix for aws_s3 empty directory creation #32169

Merged
merged 3 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/ansible/modules/cloud/amazon/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/aws_s3/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/aws
posix/ci/cloud/aws
posix/ci/cloud/group1/aws
56 changes: 44 additions & 12 deletions test/integration/targets/aws_s3/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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 }}"
Expand All @@ -66,7 +66,7 @@
tempfile:
register: tmp2
- name: test get object
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: get
dest: "{{ tmp2.path }}"
Expand All @@ -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
Expand All @@ -107,7 +107,7 @@
- result.changed == True
# ============================================================
- name: test getstr of the object
s3:
aws_s3:
bucket: "{{ bucket_name }}"
mode: getstr
object: delete.txt
Expand All @@ -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}}"
Expand All @@ -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
Expand All @@ -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}}"
Expand All @@ -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}}"
Expand All @@ -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}}"
Expand All @@ -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}}"
Expand Down