Advertisement
dfarrell07

reproducer-quickstart.sh

Nov 12th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # See documentation for using the reproducer script:
  4. # README-reproducer-quickstart.html
  5. # (in the same top-level logs directory as this reproducer script).
  6.  
  7. : ${WORKSPACE:=$(mktemp -d -t reproduce-tmp.XXXXX)}
  8. : ${CREATE_VIRTUALENV:=false}
  9. : ${REMOVE_STACKS_KEYPAIRS:=false}
  10. : ${NODESTACK_PREFIX:=""}
  11. : ${AUTORUN:=0}
  12. : ${TIMEOUT:=240}
  13. : ${LIBVIRT:=0}
  14. : ${TOCI_JOBTYPE:="multinode-1ctlr-featureset031"}
  15. : ${NODES_FILE:="/config/nodes/1ctlr.yml"}
  16. : ${ZUUL_CHANGES:="openstack/tripleo-quickstart-extras:master:refs/changes/93/610593/1"}
  17. : ${EXTRA_PARAMS:=""}
  18.  
  19. SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
  20.  
  21. usage () {
  22. echo "Usage: $0 [options]"
  23. echo ""
  24. echo "Options:"
  25. echo " -w, --workspace <dir>"
  26. echo " directory where the virtualenv, inventory files, etc."
  27. echo " are created. Defaults to creating a directory in /tmp"
  28. echo " -v, --create-virtualenv"
  29. echo " create a virtualenv to install Ansible and dependencies."
  30. echo " Options to pass true/false. Defaults to true for OVB. "
  31. echo " Defaults to false for other deployment types."
  32. echo " -r, --remove-stacks-keypairs"
  33. echo " delete all Heat stacks (both Multinode and OVB created) "
  34. echo " in the tenant before deployment."
  35. echo " Will also delete associated keypairs if they exist."
  36. echo " Options to pass true/false. Defaults to false."
  37. echo " -p, --nodestack-prefix"
  38. echo " add a unique prefix for multinode and singlenode stacks"
  39. echo " Defaults to empty."
  40. echo " -a, --autorun"
  41. echo " Run job on prepared environment automatically"
  42. echo " Default is to stop after environment is ready"
  43. echo " -t, --timeout"
  44. echo " Timeout in minutes for the deployment"
  45. echo " Default is 240 minutes"
  46. echo " -l, --libvirt"
  47. echo " Runs a 2-node multinode job or singlenode job on a"
  48. echo " single virthost using libvirt to create the nodes."
  49. echo " The script sets the virthost to be 127.0.0.2"
  50. echo " so the reproducer must be run from the virthost."
  51. echo " If a singlenode reproducer is run, two VMs will still be created."
  52. echo " -n, --nodes-file"
  53. echo " Node config file of the topology needed"
  54. echo " default: $NODES_FILE"
  55. echo " -z, --zuul-changes"
  56. echo " Refspecs with changes to test"
  57. echo " default: $ZUUL_CHANGES"
  58. echo " -j, --toci-jobtype"
  59. echo " TOCI description of the job to run"
  60. echo " default: $TOCI_JOBTYPE"
  61. echo " -e, --extra-params"
  62. echo " File or/and parameters used to override default"
  63. echo " parameters for playbooks. Multiple files"
  64. echo " can be passed [-e @file1.yml -e @file2.yml ...]"
  65. echo " and arguments [-e var=value -e var2=value2 ...]"
  66. echo " -h, --help print this help and exit"
  67. }
  68.  
  69. set -e
  70.  
  71. # Input argument assignments
  72. while [ "x$1" != "x" ]; do
  73.  
  74. case "$1" in
  75. --workspace|-w)
  76. # realpath fails if /some/path doesn't exist. It is created later
  77. WORKSPACE=$(realpath $2 || echo -n $2)
  78. shift
  79. ;;
  80.  
  81. --create-virtualenv|-v)
  82. CREATE_VIRTUALENV=$2
  83. shift
  84. ;;
  85.  
  86. --remove-stacks-keypairs|-r)
  87. REMOVE_STACKS_KEYPAIRS=$2
  88. shift
  89. ;;
  90.  
  91. --nodestack-prefix|-p)
  92. NODESTACK_PREFIX=$2
  93. shift
  94. ;;
  95.  
  96. --autorun|-a)
  97. AUTORUN=1
  98. ;;
  99.  
  100. --timeout|-t)
  101. TIMEOUT=$2
  102. shift
  103. ;;
  104.  
  105. --libvirt|-l)
  106. LIBVIRT=1
  107. ;;
  108.  
  109.  
  110. --extra-params|-e)
  111. [[ ${2::1} == "@" ]] && EXTRA_PARAMS+=("-e @$(realpath ${2#@}) ") || EXTRA_PARAMS+=("-e ${2} ")
  112. shift
  113. ;;
  114.  
  115. --nodes-file|-n)
  116. NODES_FILE=$2
  117. shift
  118. ;;
  119.  
  120. --zuul-changes|-z)
  121. ZUUL_CHANGES=$2
  122. shift
  123. ;;
  124.  
  125. --toci-jobtype|-j)
  126. TOCI_JOBTYPE=$2
  127. shift
  128. ;;
  129.  
  130. --help|-h)
  131. usage
  132. exit
  133. ;;
  134.  
  135. --) shift
  136. break
  137. ;;
  138.  
  139. -*) echo "ERROR: unknown option: $1" >&2
  140. usage >&2
  141. exit 2
  142. ;;
  143.  
  144. *) break
  145. ;;
  146. esac
  147.  
  148. shift
  149. done
  150.  
  151.  
  152. function check_installed {
  153. local binary=$1
  154. if ! which $binary >/dev/null ; then
  155. echo "Error: Could not find required binary $binary. Ensure you have
  156. it installed before trying again."
  157. exit 1
  158. fi
  159. }
  160. BOOTSTRAP_DEPENDENCIES=("virtualenv" "ansible" "pip" "openstack" "heat")
  161. function check_bootstrap_dependencies {
  162. for dependency in ${BOOTSTRAP_DEPENDENCIES[@]} ; do
  163. check_installed $dependency
  164. done
  165. }
  166.  
  167. # Check that tenant credentials have been sourced
  168. # when deploying on a host cloud
  169. if [[ (! -v OS_TENANT_NAME) && ("$LIBVIRT" != "1") ]]; then
  170. # TODO(aschultz): work around for LP#1750455
  171. if [[ -v OS_PROJECT_NAME ]]; then
  172. export OS_TENANT_NAME=$OS_PROJECT_NAME
  173. else
  174. echo "Tenant credentials are not sourced."
  175. exit 1;
  176. fi
  177. fi
  178. set -x
  179.  
  180.  
  181. # Exit if running ovb-fakeha-caserver
  182. # This test is not converted to run with tripleo-quickstart
  183. if [[ "$TOCI_JOBTYPE" == *"ovb-fakeha-caserver"* ]]; then
  184. echo "
  185. ovb-fakeha-caserver is not run with tripleo-quickstart.
  186. It can not be reproduced using this script.
  187. "
  188. exit 1;
  189. fi
  190.  
  191. # Exit of the user request a Libvirt reproducer for an OVB job
  192. if [[ "$TOCI_JOBTYPE" == *"ovb"* && "$LIBVIRT" == "1" ]]; then
  193. echo "
  194. The Libvirt reproducer option is only valid for
  195. Multinode and Singlenode jobs."
  196. exit 1;
  197. fi
  198.  
  199. set -x
  200.  
  201. # Export set variables, they make visible to ansible roles
  202. export WORKSPACE
  203. export ZUUL_CHANGES
  204.  
  205. # Start from a clean workspace
  206. mkdir -p $WORKSPACE
  207. cd $WORKSPACE
  208. rm -rf tripleo-quickstart tripleo-quickstart-extras
  209.  
  210. # Clone quickstart and quickstart-extras
  211. git clone https://github.com/openstack/tripleo-quickstart
  212. git clone https://github.com/openstack/tripleo-quickstart-extras
  213.  
  214. # Set up a virtual env if requested
  215. if [ "$CREATE_VIRTUALENV" = "true" ]; then
  216. check_installed virtualenv
  217. virtualenv $WORKSPACE/venv_ansible
  218. source $WORKSPACE/venv_ansible/bin/activate
  219. pip install --upgrade setuptools pip
  220. pip install -Ur $WORKSPACE/tripleo-quickstart/requirements.txt
  221. fi
  222.  
  223. if [ "$REMOVE_STACKS_KEYPAIRS" = "true" ]; then
  224. # The cleanup templates expects there to be in a /bin dir in the workspace # from quickstart setup.
  225. # To use the clients sourced from venv
  226. sed -i "s#{.*/bin/##g" $WORKSPACE/tripleo-quickstart-extras/roles/ovb-manage-stack/templates/cleanup-stacks-keypairs.sh.j2
  227. fi
  228.  
  229. # sanity check the env has ansible/pip/virtualenv/openstack/etc bootstrap dependencies
  230. check_bootstrap_dependencies
  231.  
  232. # Export our roles path so that we can use the roles from our workspace
  233. export ANSIBLE_ROLES_PATH=$ANSIBLE_ROLES_PATH:$WORKSPACE/tripleo-quickstart/roles:$WORKSPACE/tripleo-quickstart-extras/roles
  234. export ANSIBLE_HOST_KEY_CHECKING=False
  235. export ANSIBLE_LIBRARY=$WORKSPACE/tripleo-quickstart/library
  236.  
  237.  
  238.  
  239. if [[ "$LIBVIRT" == "1" ]]; then
  240. echo "Running a libvirt reproducer ..."
  241.  
  242. # Run from the Virthost
  243. export VIRTHOST=127.0.0.2
  244. echo -e "[virthost]\n$VIRTHOST ansible_connection=local" > $WORKSPACE/virthost
  245.  
  246. ansible-playbook $WORKSPACE/tripleo-quickstart/playbooks/libvirt-nodepool.yml \
  247. -i $WORKSPACE/virthost \
  248. -e ansible_python_interpreter="/usr/bin/python" \
  249. -e local_working_dir=$WORKSPACE \
  250. -e working_dir=$WORKSPACE \
  251. -e non_root_user=$USER \
  252. -e non_root_group=$USER \
  253. ${EXTRA_PARAMS[@]}
  254.  
  255. HOSTS_FILE="hosts"
  256. else
  257. # Calculate subnode_count
  258. if [[ -z "$NODES_FILE" ]]; then
  259. SUBNODE_COUNT=1
  260. else
  261. SUBNODE_COUNT=$(( $( awk '/node_count: / {print $2}' $WORKSPACE/tripleo-quickstart/$NODES_FILE ) +1 ))
  262. fi
  263.  
  264. ansible-playbook $WORKSPACE/tripleo-quickstart-extras/playbooks/provision_multinodes.yml \
  265. -e local_working_dir=$WORKSPACE \
  266. -e subnode_count=$SUBNODE_COUNT \
  267. -e ansible_python_interpreter="/usr/bin/python" \
  268. -e prefix=$NODESTACK_PREFIX \
  269. ${EXTRA_PARAMS[@]}
  270.  
  271. HOSTS_FILE="multinode_hosts"
  272. fi
  273.  
  274. # Run the playbook to setup the undercloud/subnodes to look like nodepool nodes
  275. ansible-playbook $WORKSPACE/tripleo-quickstart-extras/playbooks/nodepool-setup.yml \
  276. -i $WORKSPACE/$HOSTS_FILE \
  277. ${EXTRA_PARAMS[@]}
  278.  
  279. # Get ansible_host
  280. export $(awk '/subnode-0/ {print $2}' $WORKSPACE/$HOSTS_FILE)
  281.  
  282. EXTRA_VARS="$EXTRA_VARS --extra-vars dlrn_hash_tag_newest=e3c1633ea871cac1af5c9515752c3632edfcb476_4d4946bc "
  283.  
  284. # Create the env_vars_to_source file and copy it to the undercloud
  285. cat >"env_vars_to_src.sh" <<EOF
  286. export ZUUL_CHANGES="${ZUUL_CHANGES}"
  287. export NODES_FILE="${NODES_FILE}"
  288. export TOCI_JOBTYPE="${TOCI_JOBTYPE}"
  289. export EXTRA_VARS="\$EXTRA_VARS --extra-vars dlrn_hash_tag=3ed8ac0e93367a02ad53d9fa93467057724b6621_fd8eb74b "
  290. export REMAINING_TIME="$TIMEOUT"
  291. export PLAYBOOKS="$PLAYBOOKS"
  292. EOF
  293.  
  294.  
  295.  
  296. if [[ "$LIBVIRT" == "1" ]]; then
  297. cat >>"env_vars_to_src.sh" <<EOF
  298. # Uncomment this if you have established docker proxy on virthost
  299. # export NODEPOOL_DOCKER_REGISTRY_PROXY=$NODEPOOL_DOCKER_REGISTRY_PROXY
  300. export NODEPOOL_CENTOS_MIRROR=$NODEPOOL_CENTOS_MIRROR
  301. export NODEPOOL_MIRROR_HOST=mirror.mtl01.inap.openstack.org
  302. EOF
  303. fi
  304.  
  305. scp ${SSH_OPTS} "$WORKSPACE/env_vars_to_src.sh" zuul@$ansible_host:/home/zuul/
  306. if [[ "$AUTORUN" == "1" ]]; then
  307. ssh ${SSH_OPTS} zuul@$ansible_host -tt \
  308. "screen -LS ci -h 25000 -dm bash -c 'set -m; source ~/env_vars_to_src.sh; ANSIBLE_FORCE_COLOR=true /opt/stack/tripleo-ci/toci_gate_test.sh 2>&1 | tee ~/console.log; exec bash' && screen -RD"
  309. else
  310. # Remove -x so that the instructions don't print twice
  311. set +x
  312.  
  313. # Instruct the user to execute toci_gate_test.sh on the undercloud
  314. echo "
  315. # Now complete the test execution on the undercloud:
  316. # ssh to the undercloud:
  317. ssh ${SSH_OPTS} zuul@$ansible_host
  318. # Source the environment settings file and run the toci gate script
  319. source /home/zuul/env_vars_to_src.sh
  320. /opt/stack/tripleo-ci/toci_gate_test.sh 2>&1 | tee console.log
  321.  
  322. # To avoid timeouts, you can start a screen session before executing the commands:
  323. screen -S ci
  324. "
  325. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement