From 75bdcce07208653ffc182e84fdddb9edfaae4236 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Wed, 31 May 2017 11:48:35 -0400 Subject: [PATCH] s3 integration tests (#22920) * s3 integration tests * Make s3 integration tests work in standard integration setup and with fish as current shell see also https://github.com/ansible/proposals/issues/62 if you don't like this much * test_s3 integration test - substitute command instead of shell where simple * test_s3 integration test - random contents + complete elimination of use of shell module by moving to tempfile * move s3 to integration test targets * Add a couple more test for . in bucket names Tidy syntax remove reference to legacy credentials.yml remove posix/cli/cloud/aws * remove from legacy testing * remove dependencies that aren't used --- test/integration/targets/s3/aliases | 1 + test/integration/targets/s3/defaults/main.yml | 2 + test/integration/targets/s3/meta/main.yml | 0 test/integration/targets/s3/tasks/main.yml | 217 ++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 test/integration/targets/s3/aliases create mode 100644 test/integration/targets/s3/defaults/main.yml create mode 100644 test/integration/targets/s3/meta/main.yml create mode 100644 test/integration/targets/s3/tasks/main.yml diff --git a/test/integration/targets/s3/aliases b/test/integration/targets/s3/aliases new file mode 100644 index 00000000000..4ef4b2067d0 --- /dev/null +++ b/test/integration/targets/s3/aliases @@ -0,0 +1 @@ +cloud/aws diff --git a/test/integration/targets/s3/defaults/main.yml b/test/integration/targets/s3/defaults/main.yml new file mode 100644 index 00000000000..3afd3694e27 --- /dev/null +++ b/test/integration/targets/s3/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for s3 diff --git a/test/integration/targets/s3/meta/main.yml b/test/integration/targets/s3/meta/main.yml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/integration/targets/s3/tasks/main.yml b/test/integration/targets/s3/tasks/main.yml new file mode 100644 index 00000000000..2e6750cecdf --- /dev/null +++ b/test/integration/targets/s3/tasks/main.yml @@ -0,0 +1,217 @@ +--- +# 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 }}" + 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 + s3: + bucket: "{{ bucket.stdout }}" + 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 + s3: + bucket: "{{ bucket.stdout }}" + 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: 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 }}" + 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 +- 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: wait a few seconds before continuing + pause: + seconds: 3 +# ============================================================ +- name: test geturl of the object + s3: + bucket: "{{ bucket.stdout }}" + 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 +- name: assert we have the object's url + assert: + that: + - "'Download url:' in result.msg" + - result.changed == True +# ============================================================ +- name: test getstr of the object + s3: + bucket: "{{ bucket.stdout }}" + 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 + s3: + bucket: "{{ bucket.stdout }}" + 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 + s3: + bucket: "{{ bucket.stdout }}" + 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 +# ============================================================ +- name: test delete bucket + s3: + bucket: "{{ bucket.stdout }}" + 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 +# ============================================================ +- 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 + s3: + bucket: "{{ bucket.stdout + '.bucket' }}" + 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 + s3: + bucket: "{{ bucket.stdout + '.bucket' }}" + 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 +# ============================================================