## © University of Southampton IT Innovation Centre, 2018
##
## Copyright in this software belongs to University of Southampton
## IT Innovation Centre of Gamma House, Enterprise Road,
## Chilworth Science Park, Southampton, SO16 7NS, UK.
##
## This software may not be used, sold, licensed, transferred, copied
## or reproduced in whole or in part in any manner or form or in or
## on any media by any person other than in accordance with the terms
## of the Licence Agreement supplied with the software, or otherwise
## without the prior written consent of the copyright owners.
##
## This software is distributed WITHOUT ANY WARRANTY, without even the
## implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE, except where stated in the Licence Agreement supplied with
## the software.
##
##      Created By :            Michael Boniface
##      Created Date :          21-03-2018
##      Created for Project :   FLAME
stages:
  - build
  - test
  - clean

build:tests:
  stage: build
  only:
    - schedules
  script:
    - echo $CI_PROJECT_DIR
    - cd $CI_PROJECT_DIR/src/test
    - python setup.py sdist --dist-dir=$CI_PROJECT_DIR/build
    - cd $CI_PROJECT_DIR/src/service
    - python setup.py sdist --dist-dir=$CI_PROJECT_DIR/build
  artifacts:
    paths:
    - build/clmctest-1.3.0.tar.gz
    - build/clmcservice-1.3.0.tar.gz
    expire_in: 1 day

test:all:
  stage: test
  only:
    - schedules
  dependencies:
    - build:tests
  script:
    - echo "REPO_USER=${REPO_USER}" > $CI_PROJECT_DIR/reporc
    - echo "REPO_PASS=${REPO_PASS}" >> $CI_PROJECT_DIR/reporc
    - sudo scripts/test/fixture.sh create -f src/test/clmctest/rspec.json -r $CI_PROJECT_DIR -c all
    - sudo mkdir /var/lib/lxd/containers/test-runner/rootfs/opt/clmc/build
    - sudo cp build/clmctest-1.3.0.tar.gz /var/lib/lxd/containers/test-runner/rootfs/opt/clmc/build
    - sudo cp build/clmcservice-1.3.0.tar.gz /var/lib/lxd/containers/test-runner/rootfs/opt/clmc/build
    - sudo lxc exec test-runner -- pip3 install /opt/clmc/build/clmctest-1.3.0.tar.gz
    - sudo lxc exec test-runner -- pip3 install /opt/clmc/build/clmcservice-1.3.0.tar.gz
    - sudo lxc exec test-runner -- pytest -s --tb=short -rfp --pyargs clmctest
  when: on_success      
  
clean:
  stage: clean
  only:
    - schedules    
  script: 
    - sudo scripts/test/fixture.sh destroy -f src/test/clmctest/rspec.json -r $CI_PROJECT_DIR -c all
  when: always