blob: eacde80ed95f438aa712981c4dd2fb6aca0ff256 [file] [log] [blame]
Richard Felkl4c4829d2017-11-11 00:12:20 +01001#!/bin/bash -xe
alexzd90608b2018-04-12 23:49:03 +02002
Richard Felkl4c4829d2017-11-11 00:12:20 +01003export SALT_MASTER_DEPLOY_IP=172.16.164.15
4export SALT_MASTER_MINION_ID=cfg01.deploy-name.local
5export DEPLOY_NETWORK_GW=172.16.164.1
6export DEPLOY_NETWORK_NETMASK=255.255.255.192
7export DNS_SERVERS=8.8.8.8
Jiri Broulikcee20532018-01-08 13:30:15 +01008export http_proxy=
9export https_proxy=
10export PIPELINES_FROM_ISO=true
11export PIPELINE_REPO_URL=https://github.com/Mirantis
Richard Felkl98b45342018-04-06 13:30:28 +020012export MCP_VERSION=stable
13export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg
14export 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-*"
alexzcd1d47e2018-04-17 12:21:59 +020017# Not avaible in 2018.4 and pre.
Jiri Broulik0173a272018-04-11 10:56:35 +020018export LOCAL_REPOS=false
Jiri Broulikcee20532018-01-08 13:30:15 +010019#for cloning from aptly image use port 8088
20#export PIPELINE_REPO_URL=http://172.16.47.182:8088
Richard Felkl4c4829d2017-11-11 00:12:20 +010021
alexzcd1d47e2018-04-17 12:21:59 +020022function _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
alexzd90608b2018-04-12 23:49:03 +020038function _post_maas_cfg(){
39 local PROFILE=mirantis
alexzcd1d47e2018-04-17 12:21:59 +020040 # 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
alexzd90608b2018-04-12 23:49:03 +020049 # 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.
Pavel Cizinsky1abc0862018-05-30 14:14:33 +020060 else
61 maas ${PROFILE} boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
62 maas ${PROFILE} boot-resources import
alexzd90608b2018-04-12 23:49:03 +020063 fi
Pavel Cizinsky5f8fb092018-05-30 17:27:19 +020064 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
alexzd90608b2018-04-12 23:49:03 +020069}
70
71### Body
Richard Felkl4c4829d2017-11-11 00:12:20 +010072echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030073find /etc/network/interfaces.d/ -type f -delete
74kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010075envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030076ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030077rm -f /var/run/network/ifstate.ens3
78if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
79(ip r s | grep ^default) && ip r d default || /bin/true
80fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030081ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010082
83echo "Preparing metadata model"
84mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010085cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010086chown -R root:root /srv/salt/reclass/*
alexzd90608b2018-04-12 23:49:03 +020087chown -R root:root /srv/salt/reclass/.git* || true
88chmod -R 644 /srv/salt/reclass/classes/cluster/* || true
89chmod -R 644 /srv/salt/reclass/classes/system/* || true
Richard Felkl4c4829d2017-11-11 00:12:20 +010090
Richard Felkl4c4829d2017-11-11 00:12:20 +010091echo "Configuring salt"
92#service salt-master restart
93envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
94service salt-minion restart
95while true; do
96 salt-key | grep "$SALT_MASTER_MINION_ID" && break
97 sleep 5
98done
99sleep 5
alexzd90608b2018-04-12 23:49:03 +0200100for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do
Richard Felkl4c4829d2017-11-11 00:12:20 +0100101 salt-key -d $i -y
102done
103
104find /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'
105
Jiri Broulikcee20532018-01-08 13:30:15 +0100106echo "updating git repos"
alexzd90608b2018-04-12 23:49:03 +0200107if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then
Jiri Broulikcee20532018-01-08 13:30:15 +0100108 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
109 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
alexzd90608b2018-04-12 23:49:03 +0200110 umount /dev/cdrom || true
Jiri Broulikcee20532018-01-08 13:30:15 +0100111 chown -R git:www-data /home/repo/mk/mk-pipelines/*
112 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
113else
alexzd90608b2018-04-12 23:49:03 +0200114 umount /dev/cdrom || true
115 git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/
116 git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/
Jiri Broulikcee20532018-01-08 13:30:15 +0100117 chown -R git:www-data /home/repo/mk/mk-pipelines/*
118 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
119fi
120
Richard Felkl98b45342018-04-06 13:30:28 +0200121echo "installing formulas"
alexzcd1d47e2018-04-17 12:21:59 +0200122_apt_cfg
Richard Felkl98b45342018-04-06 13:30:28 +0200123curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
124echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
125apt-get update
126apt-get install -y $FORMULAS
Jiri Broulik727978e2018-04-17 12:56:02 +0200127rm -rf /srv/salt/reclass/classes/service/*
Richard Felkl58026842018-04-10 11:17:01 +0200128cd /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
Richard Felkl98b45342018-04-06 13:30:28 +0200129
Richard Felkl4c4829d2017-11-11 00:12:20 +0100130salt-call saltutil.refresh_pillar
131salt-call saltutil.sync_all
alexzd90608b2018-04-12 23:49:03 +0200132if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then
133 echo "ERROR: Reclass render failed!"
134 exit 1
Jiri Broulik0173a272018-04-11 10:56:35 +0200135fi
136
alexzd90608b2018-04-12 23:49:03 +0200137salt-call state.sls linux.network,linux,openssh,salt
Jiri Broulik6b7ca672018-04-19 13:16:32 +0200138salt-call -t5 pkg.install salt-master,salt-minion
139sleep 5
alexzd90608b2018-04-12 23:49:03 +0200140salt-call state.sls salt
141# Sometimes, maas can stuck :(
142salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
143salt-call state.sls reclass
Jiri Broulik1261ca32018-01-18 15:30:25 +0100144
alexzd90608b2018-04-12 23:49:03 +0200145_post_maas_cfg
Pavel Cizinsky44d63402018-05-30 18:07:39 +0200146salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
alexzd90608b2018-04-12 23:49:03 +0200147
148ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true
149
150pillar=$(salt-call pillar.data jenkins:client)
Jiri Broulike40813f2018-01-16 13:35:19 +0100151
152if [[ $pillar == *"job"* ]]; then
153 salt-call state.sls jenkins.client
154fi
Richard Felkl4c4829d2017-11-11 00:12:20 +0100155
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +0300156reboot