blob: 0fc572348bba07b4cada6436dfc61c29a20c266f [file] [log] [blame]
abaraniuk68c7f7c2018-08-06 16:06:29 +03001#!/bin/bash -xe
2
3export SALT_MASTER_DEPLOY_IP=${SALT_MASTER_DEPLOY_IP:-"172.16.49.66"}
4export SALT_MASTER_MINION_ID=${SALT_MASTER_MINION_ID:-"cfg01.cookied-bm-contrail40-nfv.local"}
5export DEPLOY_NETWORK_GW=${DEPLOY_NETWORK_GW:-"172.16.49.65"}
6export DEPLOY_NETWORK_NETMASK=${DEPLOY_NETWORK_NETMASK:-"255.255.255.192"}
7export DNS_SERVERS=${DNS_SERVERS:-"172.18.208.44"}
8export http_proxy=${http_proxy:-""}
9export https_proxy=${https_proxy:-""}
10export PIPELINES_FROM_ISO=${PIPELINES_FROM_ISO:-"false"}
11export PIPELINE_REPO_URL=${PIPELINE_REPO_URL:-"https://github.com/Mirantis"}
12export MCP_VERSION=${MCP_VERSION:-"proposed"}
13export MCP_SALT_REPO_KEY=${MCP_SALT_REPO_KEY:-"http://apt.mirantis.com/public.gpg"}
14export MCP_SALT_REPO_URL=${MCP_SALT_REPO_URL:-"http://apt.mirantis.com/xenial"}
15export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt"
16export FORMULAS="salt-formula-*"
17# Not avaible in 2018.4 and pre.
18export LOCAL_REPOS=false
19#for cloning from aptly image use port 8088
20#export PIPELINE_REPO_URL=http://172.16.47.182:8088
21
22function _apt_cfg(){
23 # TODO remove those function after 2018.4 release
24 echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt
25 echo "Acquire::EnableSrvRecords false;" >/etc/apt/apt.conf.d/99enablesrvrecords-false
26 echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99aws-s3-mirrors-workaround-salt
27 echo "APT::Install-Recommends false;" > /etc/apt/apt.conf.d/99dont_install_recommends-salt
28 echo "APT::Install-Suggests false;" > /etc/apt/apt.conf.d/99dont_install_suggests-salt
29 echo "Acquire::Languages none;" > /etc/apt/apt.conf.d/99dont_acquire_all_languages-salt
30 echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt
31 echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt
32 echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt
33 echo "INFO: cleaning sources lists"
34 rm -rv /etc/apt/sources.list.d/* || true
35 echo > /etc/apt/sources.list || true
36}
37
38function _post_maas_cfg(){
39 local PROFILE=mirantis
40 # TODO: remove those check, and use only new version, adfter 2018.4 release
41 if [[ -f /var/lib/maas/.maas_login.sh ]]; then
42 /var/lib/maas/.maas_login.sh
43 else
44 echo "WARNING: Attempt to use old maas login schema.."
45 TOKEN=$(cat /var/lib/maas/.maas_credentials);
46 maas list | cut -d' ' -f1 | xargs -I{} maas logout {}
47 maas login $PROFILE http://127.0.0.1:5240/MAAS/api/2.0/ "${TOKEN}"
48 fi
49 # disable backports for maas enlist pkg repo
50 maas ${PROFILE} package-repository update 1 "disabled_pockets=backports"
51 maas ${PROFILE} package-repository update 1 "arches=amd64"
52 # Download ubuntu image from MAAS local mirror
53 if [[ "$LOCAL_REPOS" == "true" ]] ; then
54 maas ${PROFILE} boot-source-selections create 2 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
55 echo "WARNING: Removing default MAAS stream:"
56 maas ${PROFILE} boot-source read 1
57 maas ${PROFILE} boot-source delete 1
58 maas ${PROFILE} boot-resources import
59 # TODO wait for finish,and stop import.
60 else
61 maas ${PROFILE} boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
62 maas ${PROFILE} boot-resources import
63 fi
64 while [ ! -d /var/lib/maas/boot-resources/current/ubuntu/amd64/generic/xenial ]
65 do
66 sleep 10
67 echo "WARNING: Image is still not ready"
68 done
69}
70
71### Body
72echo "Preparing metadata model"
73mount /dev/cdrom /mnt/
74cp -rT /mnt/model/model /srv/salt/reclass
75chown -R root:root /srv/salt/reclass/*
76chown -R root:root /srv/salt/reclass/.git* || true
77chmod -R 644 /srv/salt/reclass/classes/cluster/* || true
78chmod -R 644 /srv/salt/reclass/classes/system/* || true
79
80echo "Configuring salt"
81#service salt-master restart
82envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
83service salt-minion restart
84while true; do
85 salt-key | grep "$SALT_MASTER_MINION_ID" && break
86 sleep 5
87done
88sleep 5
89for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do
90 salt-key -d $i -y
91done
92
93find /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml -type f -print0 | xargs -0 sed -i -e 's/10.167.4.15/'$SALT_MASTER_DEPLOY_IP'/g'
94
95echo "updating git repos"
96if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then
97 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
98 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
99 umount /dev/cdrom || true
100 chown -R git:www-data /home/repo/mk/mk-pipelines/*
101 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
102else
103 umount /dev/cdrom || true
104 git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/
105 git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/
106 chown -R git:www-data /home/repo/mk/mk-pipelines/*
107 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
108fi
109
110echo "installing formulas"
111_apt_cfg
112curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
113echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
114apt-get update
115apt-get install -y $FORMULAS
116rm -rf /srv/salt/reclass/classes/service/*
117cd /srv/salt/reclass/classes/service/;ls /usr/share/salt-formulas/reclass/service/ -1 | xargs -I{} ln -s /usr/share/salt-formulas/reclass/service/{};cd /root
118
119salt-call saltutil.refresh_pillar
120salt-call saltutil.sync_all
121if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then
122 echo "ERROR: Reclass render failed!"
123 exit 1
124fi
125
126salt-call state.sls linux.network,linux,openssh,salt
127salt-call -t5 pkg.install salt-master,salt-minion
128sleep 5
129salt-call state.sls salt
130# Sometimes, maas can stuck :(
131salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
132salt-call state.sls reclass,ntp
133
134_post_maas_cfg
135salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
136
137ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true
138
139pillar=$(salt-call pillar.data jenkins:client)
140
141if [[ $pillar == *"job"* ]]; then
142 salt-call state.sls jenkins.client
143fi
144