diff --git a/.zuul.yaml b/.zuul.yaml index 81f0a81..bdc0e93 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -20,6 +20,9 @@ parent: opendev-build-docker-image allowed-projects: zuul/zuul-storage-proxy provides: zuul-storage-proxy-container-image + run: &image_playbooks + - playbooks/build.yaml + - playbooks/test.yaml vars: &image_vars docker_images: - context: . @@ -35,6 +38,7 @@ parent: opendev-upload-docker-image description: Build and test a Docker image and upload to Docker Hub. allowed-projects: zuul/zuul-storage-proxy + run: *image_playbooks secrets: name: docker_credentials secret: zuul-storage-proxy-dockerhub diff --git a/playbooks/build.yaml b/playbooks/build.yaml new file mode 100644 index 0000000..8239eed --- /dev/null +++ b/playbooks/build.yaml @@ -0,0 +1,11 @@ +- hosts: all + roles: + - build-docker-image + +# If buildset_registry is defined, that means a parent job is running it; +# only if it is not defined does it mean that we are running it. If we +# are running it, pause the job so that child jobs will automatically +# use it. +- hosts: localhost + roles: + - pause-buildset-registry diff --git a/playbooks/files/clouds.yaml b/playbooks/files/clouds.yaml new file mode 100644 index 0000000..f205b5c --- /dev/null +++ b/playbooks/files/clouds.yaml @@ -0,0 +1,7 @@ +clouds: + testcloud: + auth_type: v1password + auth: + username: 'test:tester' + password: 'testing' + auth_url: http://swift:8080/auth/v1.0 diff --git a/playbooks/test.yaml b/playbooks/test.yaml new file mode 100644 index 0000000..7a06e52 --- /dev/null +++ b/playbooks/test.yaml @@ -0,0 +1,138 @@ +- hosts: all + vars: + content: "Hello world!" + proxy_image: docker.io/zuul/zuul-storage-proxy:latest + tasks: + - name: Create clouds.yaml + tempfile: + state: file + register: clouds_tempfile + + - name: Write clouds.yaml + copy: + src: clouds.yaml + mode: "0644" + dest: "{{ clouds_tempfile.path }}" + + - name: Create docker network + command: docker network create --driver bridge swift-net + + - name: Start a swift AIO + command: >- + docker run -d --rm + --name=swift + --network=swift-net + --publish="8080:8080" + docker.io/bouncestorage/swift-aio:latest + + - name: Start the storage proxy + command: >- + docker run -d --rm + --name=zuul-storage-proxy + --network=swift-net + --publish="8000:8000" + --volume="{{ clouds_tempfile.path }}:/etc/openstack/clouds.yaml" + --env CLOUD_NAMES=testcloud + {{ proxy_image }} + + - name: Wait for swift to start + uri: + url: http://127.0.0.1:8080/auth/v1.0 + headers: + X-Storage-User: 'test:tester' + X-Storage-Pass: 'testing' + register: swift_result + until: swift_result.status == 200 + delay: 2 + retries: 120 + + - name: Create swift container + uri: + url: http://127.0.0.1:8080/v1/AUTH_test/testcontainer + headers: + X-Auth-Token: '{{ swift_result.x_auth_token }}' + method: PUT + status_code: [201, 202] + + - name: Verify swift container + uri: + url: http://127.0.0.1:8080/v1/AUTH_test/testcontainer + headers: + X-Auth-Token: '{{ swift_result.x_auth_token }}' + status_code: [200, 204] + register: result + until: result.status in [200, 204] + delay: 2 + retries: 15 + + - name: Create swift object + uri: + url: http://127.0.0.1:8080/v1/AUTH_test/testcontainer/testobject + headers: + X-Auth-Token: '{{ swift_result.x_auth_token }}' + method: PUT + status_code: [201, 202] + body: "{{ content }}" + + - name: Verify swift object + uri: + url: http://127.0.0.1:8080/v1/AUTH_test/testcontainer/testobject + headers: + X-Auth-Token: '{{ swift_result.x_auth_token }}' + register: result + until: result.status == 200 + delay: 2 + retries: 15 + + # The actual test (at mountpoint /): + - name: Get object via proxy from / + uri: + url: http://127.0.0.1:8000/testcontainer/testobject + return_content: true + register: retrieved_object + + - name: Verify content at / + assert: + that: + - retrieved_object.content == content + + # Restart the proxy with a different mount point + - name: Stop storage proxy + command: docker kill zuul-storage-proxy + + - name: Start the storage proxy + command: >- + docker run -d --rm + --name=zuul-storage-proxy + --network=swift-net + --publish="8000:8000" + --volume="{{ clouds_tempfile.path }}:/etc/openstack/clouds.yaml" + --env CLOUD_NAMES=testcloud + --env MOUNTPOINT=/logs + {{ proxy_image }} + + # The actual test (at mountpoint /logs): + - name: Get object via proxy at /logs + uri: + url: http://127.0.0.1:8000/logs/testcontainer/testobject + return_content: true + register: retrieved_object + + - name: Verify content at /logs + assert: + that: + - retrieved_object.content == content + + - name: Stop swift + command: docker kill swift + + - name: Stop storage proxy + command: docker kill zuul-storage-proxy + + - name: Remove docker network + command: docker network rm swift-net + + - name: Delete clouds.yaml + file: + state: absent + path: "{{ clouds_tempfile.path }}" diff --git a/requirements.txt b/requirements.txt index 720dbc3..5b99fae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ openstacksdk +# So that we can use the tempauth KSA plugin +python-swiftclient