# Copyright (c) 2018 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- hosts: all
  tasks:
    - name: Shutdown main swift services
      shell: "swift-init stop main"
      become: true
      ignore_errors: true

    - name: Start main swift services
      shell: "swift-init start main"
      become: true

    - name: Clone s3compat repository
      git:
          repo: "https://github.com/tipabu/s3compat.git"
          dest: "{{ ansible_env.HOME }}/s3compat"

    - name: Install s3compat requirements
      pip:
          requirements: "{{ ansible_env.HOME }}/s3compat/requirements.txt"
          virtualenv: "{{ ansible_env.HOME }}/venv"
          virtualenv_python: python2
      become: true

    - name: Run s3compat tests
      shell: '{{ ansible_env.HOME }}/venv/bin/python {{ ansible_env.HOME }}/s3compat/bin/run_ceph_tests.py "$@"'
      ignore_errors: true
      environment:
          S3TEST_CONF: "{{ ansible_env.HOME }}/{{ zuul.project.src_dir }}/tools/playbooks/ceph-s3tests/ceph-s3.conf"
      args:
          chdir: '{{ ansible_env.HOME }}/s3compat'
      tags:
        - tests

    - name: Show report
      shell: |
        set -o pipefail
        "{{ ansible_env.HOME }}/venv/bin/python" ./bin/get_ceph_test_attributes.py
        "{{ ansible_env.HOME }}/venv/bin/python" ./bin/report.py --detailed "{{ ansible_env.HOME }}/s3compat/output/ceph-s3.out.yaml" \
            --known-failures "{{ ansible_env.HOME}}/{{ zuul.project.src_dir }}/doc/s3api/conf/ceph-known-failures-tempauth.yaml" \
            --detailedformat console "{{ ansible_env.HOME }}/s3compat/output/ceph-s3.out.xml" | \
            tee "{{ ansible_env.HOME }}/s3compat/output/ceph-s3-summary.log"
      args:
          chdir:
              "{{ ansible_env.HOME }}/s3compat"
      tags:
        - tests
