Merge "Bugfix: yardstick always report 'PASS' to DB"
[yardstick.git] / docker / exec_tests.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -e
12
13 : ${YARDSTICK_REPO:='https://gerrit.opnfv.org/gerrit/yardstick'}
14 : ${YARDSTICK_REPO_DIR:='/home/opnfv/repos/yardstick'}
15 : ${YARDSTICK_BRANCH:='master'} # branch, tag, sha1 or refspec
16
17 : ${RELENG_REPO:='https://gerrit.opnfv.org/gerrit/releng'}
18 : ${RELENG_REPO_DIR:='/home/opnfv/repos/releng'}
19 # TEMP HACK to freeze releng version to workaround fetch_os_creds.sh problem
20 : ${RELENG_BRANCH:='master'} # branch, tag, sha1 or refspec
21
22 # git update using reference as a branch.
23 # git_update_branch ref
24 function git_update_branch {
25     local git_branch=$1
26
27     git checkout -f origin/${git_branch}
28     # a local branch might not exist
29     git branch -D ${git_branch} || true
30     git checkout -b ${git_branch}
31 }
32
33 # git update using reference as a branch.
34 # git_update_remote_branch ref
35 function git_update_remote_branch {
36     local git_branch=$1
37
38     git checkout -b ${git_branch} -t origin/${git_branch}
39 }
40
41 # git update using reference as a tag. Be careful editing source at that repo
42 # as working copy will be in a detached mode
43 # git_update_tag ref
44 function git_update_tag {
45     local git_tag=$1
46
47     git tag -d ${git_tag}
48     # fetching given tag only
49     git fetch origin tag ${git_tag}
50     git checkout -f ${git_tag}
51 }
52
53
54 # OpenStack Functions
55
56 git_checkout()
57 {
58     local git_ref=$1
59     if [[ -n "$(git show-ref refs/tags/${git_ref})" ]]; then
60         git_update_tag "${git_ref}"
61     elif [[ -n "$(git show-ref refs/heads/${git_ref})" ]]; then
62         git_update_branch "${git_ref}"
63     elif [[ -n "$(git show-ref refs/remotes/origin/${git_ref})" ]]; then
64         git_update_remote_branch "${git_ref}"
65     # check to see if it is a remote ref
66     elif git fetch --tags origin "${git_ref}"; then
67         # refspec / changeset
68         git checkout FETCH_HEAD
69     else
70         # if we are a random commit id we have to unshallow
71         # to get all the commits
72         git fetch --unshallow origin
73         git checkout -f "${git_ref}"
74     fi
75 }
76
77 echo
78 echo "INFO: Updating releng -> ${RELENG_BRANCH}"
79 if [ ! -d ${RELENG_REPO_DIR} ]; then
80     git clone ${RELENG_REPO} ${RELENG_REPO_DIR}
81 fi
82 cd ${RELENG_REPO_DIR}
83 # reset remote so we know origin is valid
84 git remote set-url origin ${RELENG_REPO}
85 # fetch the exact ref
86 git fetch --tags origin ${RELENG_BRANCH} || true
87 # purge pyc files
88 find . -name '*.pyc' -delete
89 git_checkout ${RELENG_BRANCH}
90
91 echo
92 echo "INFO: Updating yardstick -> ${YARDSTICK_BRANCH}"
93 if [ ! -d ${YARDSTICK_REPO_DIR} ]; then
94     git clone ${YARDSTICK_REPO} ${YARDSTICK_REPO_DIR}
95 fi
96 cd ${YARDSTICK_REPO_DIR}
97 git_checkout ${YARDSTICK_BRANCH}
98
99 # setup the environment
100 source ${YARDSTICK_REPO_DIR}/tests/ci/prepare_env.sh
101
102 # execute tests
103 ${YARDSTICK_REPO_DIR}/tests/ci/yardstick-verify $@