Merge "[cfg01] salt-master: Sync cfg from reclass"
[fuel.git] / mcp / config / states / onap
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2018 Tieto
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 # Deploy ONAP on top of OPNFV installed by Fuel/MCP
10 # ONAP installation is managed by OPNFV Auto project
11
12 AUTO_INSTALL_DIR=/opt/auto
13 AUTO_REPO='https://gerrit.opnfv.org/gerrit/auto'
14 ONAP_INSTALL_SCRIPT='ci/deploy-onap-fuel.sh'
15
16 echo "Clone Auto Repo"
17 salt -C 'I@nova:controller and *01*' cmd.run "\
18     rm -rf $AUTO_INSTALL_DIR; \
19     git clone $AUTO_REPO $AUTO_INSTALL_DIR"
20
21 echo "ONAP installation starts at $(date)"
22 echo "It can take several hours to finish."
23
24 # detect compute HW configuration, i.e. minimal values available across
25 # all compute nodes
26 CMP_COUNT=$(salt -C 'I@nova:compute' grains.get id --out txt | wc -l)
27 CMP_MIN_MEM=$(salt -C 'I@nova:compute' grains.get mem_total --out txt  |\
28     sed -re 's/^[^:]+: ([0-9]+)$/\1/g' | sort -n | head -n1)
29 CMP_MIN_CPUS=$(salt -C 'I@nova:compute' grains.get num_cpus --out txt  |\
30     sed -re 's/^[^:]+: ([0-9]+)$/\1/g' | sort -n | head -n1)
31 # check disk size for storage of instances; if shared storage is mounted,
32 # then return its size, otherwise sum up avalable space of root disk of all
33 # compute nodes
34 STORAGE_PATH='/var/lib/nova/instances'
35 MOUNT_COUNT=$(salt "cmp*" mount.is_mounted $STORAGE_PATH --out txt |\
36     grep True | wc -l)
37 if [ $MOUNT_COUNT -eq $CMP_COUNT ] ; then
38     CMP_STORAGE_TOTAL=$(salt "cmp*" cmd.run "df -BGB $STORAGE_PATH" --out txt |\
39         grep "$STORAGE_PATH" |\
40         sed -re 's/^.* +([0-9]+)GB +([0-9]+GB +){2}.*$/\1/g' |\
41         sort -n | head -n1)
42 else
43     CMP_STORAGE_TOTAL=0
44     for STORAGE in $(salt "cmp*" cmd.run "df -BGB /" --out txt | grep '/$' |\
45         sed -re 's/^.* +([0-9]+GB +){2}([0-9]+)GB +.*$/\2/g') ; do
46         CMP_STORAGE_TOTAL=$(($CMP_STORAGE_TOTAL+$STORAGE));
47     done
48 fi
49
50 # Deploy ONAP with detected configuration
51 # execute installation from the 1st controller node
52 CTL01=$(salt  -C 'I@nova:controller and *01*' grains.get id --out txt |\
53     head -n1 | cut -d':' -f1)
54 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
55     -i /root/fuel/mcp/scripts/mcp.rsa -l ubuntu $CTL01 "bash -s" <<COMMANDS
56   sudo -i
57   source /root/keystonercv3
58   cd $AUTO_INSTALL_DIR
59   export CMP_COUNT=$CMP_COUNT
60   export CMP_MIN_MEM=$CMP_MIN_MEM
61   export CMP_MIN_CPUS=$CMP_MIN_CPUS
62   export CMP_STORAGE_TOTAL=$CMP_STORAGE_TOTAL
63   export AUTO_INSTALL_DIR=$AUTO_INSTALL_DIR
64   $ONAP_INSTALL_SCRIPT | tee $AUTO_INSTALL_DIR/auto_deploy.log
65 COMMANDS