blob: 1a955b2e8c49ca3e43900cdbf92ae2ca8c9dd718 [file] [log] [blame]
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001{# Collection of common macroses shared across different deployments #}
2
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02003{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +03004{% set JENKINS_PIPELINE_BRANCH = os_env('JENKINS_PIPELINE_BRANCH','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02005{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
6{# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12 #}
7{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
8{# Pin to a specified commit in salt-models/reclass-system #}
Dennis Dmitriev3d0ed0a2018-11-23 11:02:52 +00009{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.com/salt-models/reclass-system') %}
10{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
11{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
12{% set SALT_MODELS_SYSTEM_TAG = os_env('SALT_MODELS_SYSTEM_TAG','') %}
Dennis Dmitriev06979442018-10-24 18:53:49 +030013{% set COOKIECUTTER_TEMPLATES_REPOSITORY_USER = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_USER','mcp-gerrit') %}
14{% set COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH','') %}
15{% set COOKIECUTTER_TEMPLATES_REPOSITORY = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY','ssh://' + COOKIECUTTER_TEMPLATES_REPOSITORY_USER +'@gerrit.mcp.mirantis.com:29418/mk/cookiecutter-templates') %}
sgudz4d816eb2017-11-13 11:58:05 +020016{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030017{% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %}
sgudza399dc72018-01-18 17:13:48 +020018{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
Vladimir Khlyunevf337c902018-12-06 12:29:24 +040019{% set ENVIRONMENT_TEMPLATE_COMMIT = os_env('ENVIRONMENT_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030020{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030021# Currently we support 2 salt version that can be set over bellow var
Tatyana Leontovich14e201d2018-07-05 13:28:54 +030022{% set SALT_VERSION = os_env('SALT_VERSION','2017.7') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030023{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020024{# set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') #}
obutenkob6006352018-12-20 10:46:44 +020025{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas"+"/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020026{# set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020027{% set FORMULA_GPG = os_env('FORMULA_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020028{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030029# Note repo is changed so new one looks like defined bellow
30{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-" + SALT_VERSION+ "/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020031{# set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') #}
obutenkob6006352018-12-20 10:46:44 +020032{% set SALT_GPG = os_env('SALT_GPG', "http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/salt-formulas/xenial/archive-salt-formulas.key") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020033{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
34{% set UBUNTU_UPDATES_REPOSITORY = os_env('UBUNTU_UPDATES_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME}-updates main restricted universe") %}
35{% set UBUNTU_SECURITY_REPOSITORY = os_env('UBUNTU_SECURITY_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME}-security main restricted universe") %}
Dennis Dmitriev9a532a52018-05-07 13:55:27 +030036{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030037{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
sgudzb7953382019-02-18 17:59:30 +020038{% set UPDATE_REPO_CUSTOM_TAG = os_env('UPDATE_REPO_CUSTOM_TAG', '') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030039
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020040{# Address pools for reclass cluster model are taken in the following order:
41 # 1. environment variables,
42 # 2. config.underlay.address_pools based on fuel-devops address pools
43 # (see generated '.ini' file after underlay is created),
44 # 3. defaults #}
45{% set address_pools = config.underlay.address_pools %}
46{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
47{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
48{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
49{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
50{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
51{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
52{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
53{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
54
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040055{# Format for formula replacement:
56 # space separated string:
57 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
58
59{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030060{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030061{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030062{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040063
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040064# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020065{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040066
Dennis Dmitriev492813e2017-08-09 15:08:58 +030067
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020068{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
69{#####################################################}
70
71- description: 'Configure key on nodes and install packages'
72 cmd: |
73 rm -rf trusted* ;
74 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020075 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020076 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
77 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
78 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030079 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020080 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
81 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
82 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050083 eatmydata apt-get clean;
84 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020085 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020086 node_name: {{ NODE_NAME }}
87 retry: {count: 1, delay: 5}
88 skip_fail: false
89
90{%- endmacro %}
91
92
Dennis Dmitriev492813e2017-08-09 15:08:58 +030093{%- macro MACRO_INSTALL_SALT_MASTER() %}
94{######################################}
95- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020096 cmd: |
97 which wget >/dev/null || (apt-get update; apt-get install -y wget);
98 # Configure ubuntu and salt repositories
99 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
100 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
101 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
102 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
103
104 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
105 wget -O - {{ FORMULA_GPG }} | apt-key add -;
106 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300107 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
108
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200109
110 apt-get clean
111 apt-get update
112
113 # Install salt-master and reclass
114 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
115 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200116 eatmydata apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200117 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300118 node_name: {{ HOSTNAME_CFG01 }}
119 retry: {count: 1, delay: 1}
120 skip_fail: false
121
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200122- description: Remove any existing minion keys
123 cmd: salt-key -y -D || true
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 1}
126 skip_fail: false
127
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300128- description: Configure salt-master on cfg01
129 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200130 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300131 file_roots:
132 base:
133 - /usr/share/salt-formulas/env
134 pillar_opts: False
135 open_mode: True
136 reclass: &reclass
137 storage_type: yaml_fs
138 inventory_base_uri: /srv/salt/reclass
139 ext_pillar:
140 - reclass: *reclass
141 master_tops:
142 reclass: *reclass
143 EOF
144 node_name: {{ HOSTNAME_CFG01 }}
145 retry: {count: 1, delay: 1}
146 skip_fail: false
147
148- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300149 cmd: |
150 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200151 #touch /root/.git_trusted_certs.pem;
152 #for server in github.com; do \
153 # openssl s_client -showcerts -connect $server:443 </dev/null \
154 # | openssl x509 -outform PEM \
155 # >> /root/.git_trusted_certs.pem;
156 #done;
157 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
158 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
159 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300160 node_name: {{ HOSTNAME_CFG01 }}
161 retry: {count: 1, delay: 1}
162 skip_fail: false
163{%- endmacro %}
164
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200165
166{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
167{######################################}
168
169- description: Remove /etc/update-motd.d/52-info
170 cmd: rm -vf /etc/update-motd.d/52-info
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 10}
173 skip_fail: false
174
175- description: Set up static interface config
176 cmd: |
177 kill $(pidof /sbin/dhclient) || /bin/true
178 cat << 'EOF' > /etc/network/interfaces
179 # This file describes the network interfaces available on your system
180 # and how to activate them. For more information, see interfaces(5).
181
182 # The loopback network interface
183 auto lo
184 iface lo inet loopback
185
186 # The primary network interface
187 auto ens3
188 iface ens3 inet static
189 address {{ IPV4_NET_ADMIN_PREFIX }}.90
190 netmask 255.255.255.0
191 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
192 EOF
193 node_name: {{ HOSTNAME_CFG01 }}
194 retry: {count: 1, delay: 10}
195 skip_fail: false
196
197- description: Install common packages on cfg01
198 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
199 node_name: {{ HOSTNAME_CFG01 }}
200 retry: {count: 1, delay: 1}
201 skip_fail: false
202
203- description: Remove any existing minion keys
204 cmd: salt-key -y -D || true
205 node_name: {{ HOSTNAME_CFG01 }}
206 retry: {count: 1, delay: 1}
207 skip_fail: false
208
209- description: Configure GIT settings and certificates
210 cmd: |
211 set -e;
212 #touch /root/.git_trusted_certs.pem;
213 #for server in github.com; do \
214 # openssl s_client -showcerts -connect $server:443 </dev/null \
215 # | openssl x509 -outform PEM \
216 # >> /root/.git_trusted_certs.pem;
217 #done;
218 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
219 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
220 HOME=/root git config --global user.name "MCP Integration QA";
221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 1, delay: 1}
223 skip_fail: false
224{%- endmacro %}
225
226
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300227{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300228{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300229{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
230
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300231- description: Clone reclass models with submodules
232 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300233 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200234 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200235 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200236
237 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
238 export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass.tmp;
Dennis Dmitriev70dd3062018-01-24 20:45:49 +0200239 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200240
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200241 pushd /srv/salt/reclass;
242 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
243 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200244 {%- if SALT_MODELS_REF_CHANGE != '' %}
245 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200246 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200247 {%- endfor %}
248 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200249 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200250 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300251
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300252 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300253 pushd classes/system/ && \
254 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200255 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300256 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200257 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300258 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
259 pushd classes/system/;
260 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
261 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300262 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
263 pushd classes/system/;
264 git fetch --all --tags --prune
265 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
266 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200267 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300268
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200269 popd;
270 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300271 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200272
273 # Replace firstly to an intermediate value to avoid intersection between
274 # already replaced and replacing networks.
275 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
276 # 192.168.10 -> 10.16.0 (generated network for admin)
277 # 10.16.0 -> <external network>
278 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300279 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200280 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
281 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
282 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
283 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300284 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
285 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200286
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200287 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
288 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
289 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
290 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200291
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300292 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400293 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200294
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300295 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300296 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300297 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
Tatyana Leontovich3424bf62017-09-15 12:13:54 +0300298 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300299 {%- endif %}
300
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200301 # Override some context parameters
302 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
303 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
304 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
305
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200306 # Create the cfg01 inventory file or use existing
307 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
308 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300309 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400310 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300311 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200312 - cluster.{{ CLUSTER_NAME }}.infra.maas
313 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300314 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300315 parameters:
316 _param:
317 linux_system_codename: xenial
318 reclass_data_revision: master
319 linux:
320 system:
321 name: cfg01
322 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200323 reclass:
324 storage:
325 data_source:
326 engine: local
327 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300328
329 # Show the changes to the console
330 cd /srv/salt/reclass/; git diff
331 node_name: {{ HOSTNAME_CFG01 }}
332 retry: {count: 1, delay: 1}
333 skip_fail: false
334{%- endmacro %}
335
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200336{%- macro MACRO_UPLOAD_AND_IMPORT_GPG_ENCRYPTION_KEY() %}
337{%- set KEY_FILE_NAME = 'encryption-key.asc' %}
338- description: "Upload gpg encruption key"
339 upload:
340 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
341 local_filename: {{ KEY_FILE_NAME }}
342 remote_path: /root/
343 node_name: {{ HOSTNAME_CFG01 }}
344
345- description: Import encryption key
346 cmd: |
Tatyana Leontovich1192aa42019-03-25 14:11:27 +0200347 set -ex;
348 mkdir -p /etc/salt/gpgkeys
349 chmod 0700 /etc/salt/gpgkeys
350 export GNUPGHOME=/etc/salt/gpgkeys
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200351 gpg --import {{ KEY_FILE_NAME }}
352 gpg --list-keys
353 node_name: {{ HOSTNAME_CFG01 }}
354 retry: {count: 1, delay: 1}
355 skip_fail: false
356
357- description: Put encryption key to reclass folder
358 cmd: |
359 set -e;
360 set -x;
361 mkdir -p /srv/salt/reclass
362 cp /root/{{ KEY_FILE_NAME }} /srv/salt/reclass/
363 node_name: {{ HOSTNAME_CFG01 }}
364 retry: {count: 1, delay: 1}
365 skip_fail: false
366
367{%- endmacro %}
368
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300369
sgudz160b7302017-12-22 17:01:10 +0200370{%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None, CLUSTER_PRODUCT_MODELS='') %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300371{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300372{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200373- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300374 upload:
375 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
376 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300377 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300378 node_name: {{ HOSTNAME_CFG01 }}
379
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300380- description: "Show options enabled in the context file for model generation"
381 cmd: |
382 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
383 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
384 echo "===== Sources for model generation ====="
385 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
386 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
387 {%- if CLUSTER_PRODUCT_MODELS != '' %}
388 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
389 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300390 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300391 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300392 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
393 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300394 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300395 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
396 {%- endif %}
397 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300398 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300399 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300400 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
401 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300402 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
403 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300404 {%- endif %}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300405 {%- if JENKINS_PIPELINE_BRANCH != '' %}
406 echo "JENKINS_PIPELINE_BRANCH={{ JENKINS_PIPELINE_BRANCH }}"
407 {%- endif %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300408 echo "======================================="
409 node_name: {{ HOSTNAME_CFG01 }}
410 retry: {count: 1, delay: 1}
411 skip_fail: false
412
Dennis Dmitriev06979442018-10-24 18:53:49 +0300413- description: "Upload {{ COOKIECUTTER_TEMPLATES_REPOSITORY_USER }} key"
414 upload:
415 local_path: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | dirname }}/
416 local_filename: {{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
417 remote_path: /tmp/
418 node_name: {{ HOSTNAME_CFG01 }}
419
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300420- description: Create cluster model from cookiecutter templates
421 cmd: |
422 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300423 set -x;
Tatyana Leontovich1ef60952018-12-19 00:36:50 +0200424 sudo apt-get install virtualenv -y
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300425 sudo apt-get install python-setuptools -y
Dennis Dmitrievb4b74032018-12-18 21:53:23 +0200426
427 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
428 . /root/venv-reclass-tools/bin/activate;
429 pip install -U pip
430
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300431 pip install cookiecutter
Dennis Dmitriev06979442018-10-24 18:53:49 +0300432
433 chmod 0600 /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
434 eval $(ssh-agent)
435 ssh-add /tmp/{{ COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH | basename }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300436 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200437
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300438 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300439 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300440 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200441 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300442 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
443 pushd /root/cookiecutter-templates
444 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
445 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300446 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300447 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300448 git fetch --all --tags --prune
449 git checkout tags/{{ COOKIECUTTER_TAG }}
450 popd
451 {%- endif %}
452
Dennis Dmitrievddcea2f2018-12-18 21:21:11 +0200453 if [ -f /root/cookiecutter-templates/requirements.txt ]; then
454 pip install -r /root/cookiecutter-templates/requirements.txt
455 fi
456
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300457 mkdir -p /srv/salt/reclass/classes/cluster/
458 mkdir -p /srv/salt/reclass/classes/system/
459 mkdir -p /srv/salt/reclass/classes/service/
460 mkdir -p /srv/salt/reclass/nodes/_generated
461
462 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200463 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
464 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200465 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300466 {%- if JENKINS_PIPELINE_BRANCH != '' %}
467 sed -i 's/jenkins_pipelines_branch: .*/jenkins_pipelines_branch: release\/proposed\/{{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
468 {%- endif %}
sgudz8c888ec2017-10-02 15:29:23 +0300469 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200470 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300471 {%- endif %}
472 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200473 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300474 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300475
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300476 # Replace firstly to an intermediate value to avoid intersection between
477 # already replaced and replacing networks.
478 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
479 # 192.168.10 -> 10.16.0 (generated network for admin)
480 # 10.16.0 -> <external network>
481 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300482 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300483 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
484 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
485 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
486 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300487
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300488 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
489 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
490 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
491 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300492
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300493 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200494 mkdir -p /tmp/output /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/
Tatyana Leontovich1192aa42019-03-25 14:11:27 +0200495 # Allow to use encryption keys
496 export GNUPGHOME=/etc/salt/gpgkeys
sgudz160b7302017-12-22 17:01:10 +0200497 for item in {{ items }}; do
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200498 [ "$item" = "stacklight2" ] && continue;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300499 python /root/cookiecutter-templates/generate.py \
500 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300501 --config-file {{ CLUSTER_CONTEXT_PATH }} \
Dmitry Tyzhnenkofcb4dab2019-03-05 20:11:59 +0200502 --output-dir /tmp/output/$item/;
503 mv -v /tmp/output/$item/{{ CLUSTER_NAME }}/$item /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300504 done
505
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300506 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300507
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200508 # Create the cfg01 inventory file or use existing
509 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
510 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300511 classes:
512 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200513 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300514 EOF
515
516 node_name: {{ HOSTNAME_CFG01 }}
517 retry: {count: 1, delay: 1}
518 skip_fail: false
519
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300520- description: Modify generated model and reclass-system if necessary
521 cmd: |
522 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300523 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300524 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300525 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300526 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300527 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300528 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300529 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300530 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
531 pushd /srv/salt/reclass/classes/system/
532 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
533 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300534 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
535 pushd /srv/salt/reclass/classes/system/
536 git fetch --all --tags --prune
537 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
538 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300539 {%- endif %}
540
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300541 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200542 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300543 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
544 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
545 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
546 {%- endif %}
547
548 node_name: {{ HOSTNAME_CFG01 }}
549 retry: {count: 1, delay: 1}
550 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300551
552- description: Restart salt-api
553 cmd: |
554 set -e;
555 systemctl restart salt-api
556
557 node_name: {{ HOSTNAME_CFG01 }}
558 retry: {count: 1, delay: 1}
559 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300560{%- endmacro %}
561
562
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300563{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
564{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300565
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200566- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300567 cmd: |
568 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300569 mkdir -p /root/environment/;
570 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /root/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300571
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400572 {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300573 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300574 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
575 git checkout FETCH_HEAD &&
576 popd
Vladimir Khlyunevf337c902018-12-06 12:29:24 +0400577 {%- elif ENVIRONMENT_TEMPLATE_COMMIT != '' %}
578 pushd /root/environment/environment_template
579 git checkout {{ ENVIRONMENT_TEMPLATE_COMMIT }}
580 popd
581 {%- endif %}
582
sgudzcced67d2017-10-11 15:56:09 +0300583 node_name: {{ HOSTNAME_CFG01 }}
584 skip_fail: false
sgudzcced67d2017-10-11 15:56:09 +0300585
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300586{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200587- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300588 upload:
589 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
590 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300591 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300592 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300593{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300594
Dennis Dmitriev1ddf6472018-11-25 22:30:12 +0200595- description: "Replace template addresses to actual environment addresses"
596 cmd: |
597 set -ex;
598 # Replace firstly to an intermediate value to avoid intersection between
599 # already replaced and replacing networks.
600 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
601 # 192.168.10 -> 10.16.0 (generated network for admin)
602 # 10.16.0 -> <external network>
603 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
604 export REPLACE_DIRS="/root/environment/"
605 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
606 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
607 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
608 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
609
610 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
611 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
612 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
613 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {} +
614 node_name: {{ HOSTNAME_CFG01 }}
615 retry: {count: 1, delay: 5}
616 skip_fail: false
617
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300618- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
619 cmd: |
620 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300621 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300622 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200623 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
624 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300625 pip install git+https://github.com/dis-xcom/reclass-tools;
626 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
627 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
628 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
629
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500630 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
631 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
632 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300633 fi;
634
635 node_name: {{ HOSTNAME_CFG01 }}
636 retry: {count: 1, delay: 5}
637 skip_fail: false
638
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200639- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300640 cmd: |
641 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200642 find /srv/salt/reclass/classes/{system,cluster}/ -name '*.yml' -type f -exec sed -ri '/^ keepalived:/{:1;N;/\n instance:/!b1 {N; /\n [[:graph:]]+:/ { s/\n instance:\n [[:graph:]]+:/\n instance:\n VIP:/ } } }' {} +
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300643
644 node_name: {{ HOSTNAME_CFG01 }}
645 retry: {count: 1, delay: 5}
646 skip_fail: false
647
648- description: "[EXPERIMENTAL] Create environment model for virtual environment"
649 cmd: |
650 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300651 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200652 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300653 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300654 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300655 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300656 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
657 node_name: {{ HOSTNAME_CFG01 }}
658 retry: {count: 1, delay: 5}
659 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300660
661- description: Modify generated model and reclass-system
662 cmd: |
663 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
664 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400665 find ${REPLACE_DIRS} -type f -exec sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {} +
sgudz8c888ec2017-10-02 15:29:23 +0300666 node_name: {{ HOSTNAME_CFG01 }}
667 retry: {count: 1, delay: 1}
668 skip_fail: false
669
sgudzb7953382019-02-18 17:59:30 +0200670{%- if UPDATE_REPO_CUSTOM_TAG != '' %}
671- description: "[EXPERIMENTAL] Change update repos tag acording to defined in job"
672 cmd: |
673 . /root/venv-reclass-tools/bin/activate;
674 reclass-tools add-key parameters._param.linux_system_repo_update_url 'http://mirror.mirantis.com/update/{{ UPDATE_REPO_CUSTOM_TAG }}/' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/openstack/init.yml;
Tatyana Leontovicha5e04c12019-03-07 18:27:13 +0200675 reclass-tools add-key parameters._param.linux_system_repo_update_url 'http://mirror.mirantis.com/update/{{ UPDATE_REPO_CUSTOM_TAG }}/' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/kubernetes/init.yml;
sgudzb7953382019-02-18 17:59:30 +0200676 # Replace ubuntu_updates repo tag independently, because it has another url structure
677 reclass-tools add-key parameters.linux.system.repo.ubuntu_updates.source 'deb [arch=amd64] http://mirror.mirantis.com/{{ UPDATE_REPO_CUSTOM_TAG }}/ubuntu/ ${_param:linux_system_codename}-updates main restricted universe' /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/apt_repos.yml;
678 node_name: {{ HOSTNAME_CFG01 }}
679 retry: {count: 1, delay: 5}
680 skip_fail: false
681{%- endif %}
682
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300683{%- endmacro %}
684
685
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300686{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
687{#######################################################}
688- description: Configure reclass
689 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300690 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300691 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300692 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300693 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200694 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200695 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
696 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300697 apt-get clean; apt-get update;
698 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
699 declare -a formula_services=({{ FORMULA_SERVICES }});
700 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200701 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300702 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300703 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
704 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
705 done;
706 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
707 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
708 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
709
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200710 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300711 storage_type: yaml_fs
712 pretty_print: True
713 output: yaml
714 inventory_base_uri: /srv/salt/reclass
715 EOF
716 node_name: {{ HOSTNAME_CFG01 }}
717 retry: {count: 1, delay: 1}
718 skip_fail: false
719
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200720- description: "*Workaround* remove all cfg01 nodes except cfg01.{{ DOMAIN_NAME }} to not depend on other clusters in 'reclass --top'"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300721 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200722 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
723 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300724 node_name: {{ HOSTNAME_CFG01 }}
725 retry: {count: 1, delay: 5}
726 skip_fail: false
727
728- description: Configure salt adoptors on cfg01
729 cmd: |
730 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
731 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
732 node_name: {{ HOSTNAME_CFG01 }}
733 retry: {count: 1, delay: 1}
734 skip_fail: false
735
736- description: Show reclass-salt --top for cfg01 node
737 cmd: reclass-salt --top
738 node_name: {{ HOSTNAME_CFG01 }}
739 retry: {count: 1, delay: 5}
740 skip_fail: false
741
742- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400743 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300744 node_name: {{ HOSTNAME_CFG01 }}
745 retry: {count: 1, delay: 5}
746 skip_fail: false
747{%- endmacro %}
748
749
750{%- macro MACRO_INSTALL_SALT_MINIONS() %}
751{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200752{%- for ssh in config.underlay.ssh %}
753 {%- set salt_roles = [] %}
754 {%- for role in ssh['roles'] %}
755 {%- if role in config.salt_deploy.salt_roles %}
756 {%- set _ = salt_roles.append(role) %}
757 {%- endif %}
758 {%- endfor %}
759
760 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300761- description: Configure salt-minion on {{ ssh['node_name'] }}
762 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300763 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300764 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300765 cat << EOF > /etc/salt/minion.d/minion.conf
766 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300767 master: {{ config.salt.salt_master_host }}
768 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200769
770 # Configure ubuntu and salt repositories
771 which wget >/dev/null || (apt-get update; apt-get install -y wget);
772
773 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
774 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
775 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
776 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
777
778 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300779 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
780
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200781
782 apt-get clean
783 apt-get update
784
785 # Install salt-minion
Tatyana Leontovich47708552018-12-19 16:36:09 +0200786 apt-get install eatmydata -y;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300787 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200788 # Install common packages
789 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200790 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200791 # Restart salt-minion if it was already installed
792 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300793 node_name: {{ ssh['node_name'] }}
794 retry: {count: 1, delay: 1}
795 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200796 {%- else %}
797- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
798 cmd: echo "SSH to $(hostname -f) passed"
799 node_name: {{ ssh['node_name'] }}
800 retry: {count: 1, delay: 1}
801 skip_fail: false
802 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300803
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200804{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300805
806- description: Accept salt keys from all the nodes
807 cmd: salt-key -A -y
808 node_name: {{ HOSTNAME_CFG01 }}
809 retry: {count: 1, delay: 5}
810 skip_fail: true
811{%- endmacro %}
812
813
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200814{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
815{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300816- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200817 cmd: |
818 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300819 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200820 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
821 which wget > /dev/null || (apt-get update; apt-get install -y wget);
822 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
823 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
824 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
825 apt-get clean; apt-get update;
826 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
827 declare -a formula_services=({{ FORMULA_SERVICES }});
828 echo -e "\nInstalling all required salt formulas\n";
829 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300830 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200831 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
832 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
833 done;
834 node_name: {{ HOSTNAME_CFG01 }}
835 retry: {count: 1, delay: 1}
836 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300837
838- description: Sync all salt resources on salt-master minion
839 cmd: salt-call saltutil.sync_all && sleep 5
840 node_name: {{ HOSTNAME_CFG01 }}
841 retry: {count: 1, delay: 5}
842 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200843{%- endmacro %}
844
845{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
846{#######################################}
847- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
848 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300849 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200850 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
851 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
852 service salt-minion restart
853
854 while true; do
855 salt-key | grep "$SALT_MASTER_MINION_ID" && break
856 sleep 5
857 done
858
859 sleep 5
860
861 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
862 salt-key -d $i -y
863 done
864 node_name: {{ HOSTNAME_CFG01 }}
865 retry: {count: 1, delay: 1}
866 skip_fail: false
867{%- endmacro %}
868
869
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300870{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
871{##################################################}
872
873{# Prepare salt services and nodes settings #}
874
sgudz6e797562018-10-22 12:27:09 +0300875- description: '*Workaround* of harcoded host from day01 grains'
876 cmd: salt-key -d cfg01.mcp-day01.local -y
877 node_name: {{ HOSTNAME_CFG01 }}
878 retry: {count: 1, delay: 1}
879 skip_fail: true
880
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300881- description: Run 'linux' formula on cfg01
882 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
883 node_name: {{ HOSTNAME_CFG01 }}
884 retry: {count: 3, delay: 5}
885 skip_fail: false
886
887- description: Run 'openssh' formula on cfg01
888 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300889 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300890 salt --hard-crash --state-output=mixed --state-verbose=False
891 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300892 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300893 node_name: {{ HOSTNAME_CFG01 }}
894 retry: {count: 3, delay: 5}
895 skip_fail: false
896
897- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
898 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
899 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
900 node_name: {{ HOSTNAME_CFG01 }}
901 retry: {count: 1, delay: 1}
902 skip_fail: false
903
904- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300905 cmd: timeout 600 salt-call -l info --hard-crash --state-output=mixed --state-verbose=False state.sls salt.master;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300906 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300907 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300908 skip_fail: false
909
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400910{%- if SALT_FORMULAS_REFS != '' %}
911- description: Replace needed formulas to desired version
912 cmd: |
913 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300914 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400915 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
916 {% set formula = formula_set.split(':') %}
917 {% set formula_name = formula[0] %}
918 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300919 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400920 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
921 pushd {{ formula_dir }} &&
922 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
923 git checkout FETCH_HEAD &&
924 popd &&
925 if [ -d "{{ formula_dir }}" ]; then
926 echo "Going to replace packaged formula {{ formula_name }}" &&
927 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400928 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
929 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400930 else
931 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
932 fi
933 {%- endfor %}
934 node_name: {{ HOSTNAME_CFG01 }}
935 retry: {count: 1, delay: 10}
936 skip_fail: false
937{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300938
939- description: Refresh pillars on salt-master minion
940 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
941 node_name: {{ HOSTNAME_CFG01 }}
942 retry: {count: 1, delay: 5}
943 skip_fail: false
944
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300945- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300946 cmd: reclass-salt --top
947 node_name: {{ HOSTNAME_CFG01 }}
948 retry: {count: 1, delay: 5}
949 skip_fail: false
950
951- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300952 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300953 node_name: {{ HOSTNAME_CFG01 }}
954 retry: {count: 1, delay: 5}
955 skip_fail: false
956
957- description: Configure linux on master
958 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
959 node_name: {{ HOSTNAME_CFG01 }}
960 retry: {count: 1, delay: 5}
961 skip_fail: false
962
963- description: Configure salt.minion on master
964 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
965 -C 'I@salt:master' state.sls salt.minion && sleep 10
966 node_name: {{ HOSTNAME_CFG01 }}
967 retry: {count: 3, delay: 10}
968 skip_fail: false
969
970- description: Run state 'salt' on master (for salt.api, etc)
971 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
972 -C 'I@salt:master' state.sls salt
973 node_name: {{ HOSTNAME_CFG01 }}
974 retry: {count: 3, delay: 10}
975 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300976
977- description: Restart salt-api after states
978 cmd: systemctl restart salt-api
979 node_name: {{ HOSTNAME_CFG01 }}
980 retry: {count: 3, delay: 10}
981 skip_fail: false
982
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300983{%- endmacro %}
984
Dennis Dmitriev85559962018-01-30 15:35:51 +0200985{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
986{#################################################################}
987
988- description: Refresh pillars before generating nodes
989 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
990 node_name: {{ HOSTNAME_CFG01 }}
991 retry: {count: 1, delay: 5}
992 skip_fail: false
993
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200994- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200995 cmd: |
996 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300997 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200998 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
999 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +02001000 node_name: {{ HOSTNAME_CFG01 }}
1001 retry: {count: 1, delay: 5}
1002 skip_fail: false
1003
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001004- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
1005 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
1006 -C 'I@salt:master' state.sls reclass
1007 node_name: {{ HOSTNAME_CFG01 }}
1008 retry: {count: 1, delay: 5}
1009 skip_fail: false
1010
Dennis Dmitriev85559962018-01-30 15:35:51 +02001011{%- if RERUN_SALTMASTER_STATE %}
1012- description: Regenerate salt.master states for the newly uploaded/created model
1013 cmd: |
1014 # Need to refresh installed formulas that are required in the model
1015 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
1016 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
1017 node_name: {{ HOSTNAME_CFG01 }}
1018 retry: {count: 1, delay: 5}
1019 skip_fail: false
1020{%- endif %}
1021
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001022- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +02001023 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001024 node_name: {{ HOSTNAME_CFG01 }}
1025 retry: {count: 1, delay: 5}
1026 skip_fail: false
1027
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001028- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001029 cmd: |
1030 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +03001031 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +03001032 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
1033 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
1034 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001035 node_name: {{ HOSTNAME_CFG01 }}
1036 retry: {count: 1, delay: 5}
1037 skip_fail: false
1038
1039- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +03001040 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001041 node_name: {{ HOSTNAME_CFG01 }}
1042 retry: {count: 1, delay: 5}
1043 skip_fail: false
1044{%- endmacro %}
1045
1046
1047{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
1048{########################################}
1049# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +02001050
1051- description: Get linux kernel version from all minions
1052 cmd: |
1053 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
1054 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
1055 node_name: {{ HOSTNAME_CFG01 }}
1056 retry: {count: 5, delay: 10}
1057 skip_fail: false
1058
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001059- description: Configure linux on other nodes
1060 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
1061 node_name: {{ HOSTNAME_CFG01 }}
1062 retry: {count: 5, delay: 10}
1063 skip_fail: false
1064
1065- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +03001066 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001067 salt --hard-crash --state-output=mixed --state-verbose=False
1068 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +03001069 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001070 node_name: {{ HOSTNAME_CFG01 }}
1071 retry: {count: 1, delay: 5}
1072 skip_fail: false
1073
1074- description: Configure salt.minion on other nodes
1075 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion &&
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001076 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001077 node_name: {{ HOSTNAME_CFG01 }}
1078 retry: {count: 3, delay: 15}
1079 skip_fail: false
1080
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001081- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001082 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001083 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +04001084 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +04001085 skip_fail: false
1086
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001087- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +02001088 cmd: |
1089 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001090 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +04001091 node_name: {{ HOSTNAME_CFG01 }}
1092 retry: {count: 1, delay: 10}
1093 skip_fail: false
1094
Dennis Dmitriev14183db2018-03-01 15:14:12 +02001095- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
1096 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
1097 node_name: {{ HOSTNAME_CFG01 }}
1098 retry: {count: 1, delay: 10}
1099 skip_fail: false
1100
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001101- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001102 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001103 node_name: {{ HOSTNAME_CFG01 }}
1104 retry: {count: 3, delay: 15}
1105 skip_fail: false
1106
1107- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001108 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001109 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001110 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001111 skip_fail: false
1112
1113- description: Configure ntp and rsyslog on nodes
1114 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1115 node_name: {{ HOSTNAME_CFG01 }}
1116 retry: {count: 1, delay: 10}
1117 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001118
1119- description: Install and configure iptables if it is in pillar
1120 cmd: |
1121 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1122 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1123 fi
1124 node_name: {{ HOSTNAME_CFG01 }}
1125 retry: {count: 1, delay: 10}
1126 skip_fail: false
1127
1128
1129- description: Install and configure logrotate if it is in pillar
1130 cmd: |
1131 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1132 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1133 fi
1134 node_name: {{ HOSTNAME_CFG01 }}
1135 retry: {count: 1, delay: 10}
1136 skip_fail: false
1137
1138- description: Install and configure auditd if it is enabled
1139 cmd: |
1140 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1141 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1142 fi
1143 node_name: {{ HOSTNAME_CFG01 }}
1144 retry: {count: 1, delay: 10}
1145 skip_fail: false
1146
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001147{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001148
1149
1150{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1151{#########################################}
1152
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001153- description: '*Workaround: Load bonding module before call state.linux'
1154 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1155 node_name: {{ HOSTNAME_CFG01 }}
1156 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001157 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001158
1159- description: '*Workaround* install bridge-utils before running linux formula'
1160 # The formula removes default route and then tries to install the package, fails.
1161 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1162 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1163 node_name: {{ HOSTNAME_CFG01 }}
1164 retry: {count: 1, delay: 5}
1165 skip_fail: false
1166
1167{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001168
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001169
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001170{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001171{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001172
1173- description: Set k8s deploy parameters
1174 cmd: |
1175 {% for k8s_opt, value in config.k8s_deploy.items() %}
1176 {% if value|string() %}
1177 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1178 {% endif %}
1179 {% endfor %}
1180 node_name: {{ HOSTNAME_CFG01 }}
1181 retry: {count: 1, delay: 1}
1182 skip_fail: false
1183
1184{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001185
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001186
1187{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1188{#############################################}
1189- description: Set SL docker images deploy parameters
1190 cmd: |
1191 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1192 {%- for sl_opt, value in config.sl_deploy.items() %}
1193 {%- if value|string() %}
1194 {%- if OVERRIDES_FILENAME %}
1195 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1196 {%- else %}
1197 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1198 {%- endif %}
1199 {%- endif %}
1200 {%- endfor %}
1201 salt '*' saltutil.refresh_pillar;
1202 sleep 10
1203 node_name: {{ HOSTNAME_CFG01 }}
1204 retry: {count: 1, delay: 1}
1205 skip_fail: false
1206{%- endmacro %}
1207
1208
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001209{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001210{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001211
1212{% for ssh in config.underlay.ssh %}
1213{% if ssh["node_name"].startswith("cmp") %}
1214{% set node_hostname = ssh["node_name"].split('.')[0] %}
1215- description: Register compute {{ ssh['node_name'] }}
1216 cmd: |
1217 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1218 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1219 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001220 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001221 export config_host={{ config.salt.salt_master_host }}
1222 export node_domain={{ DOMAIN_NAME }}
1223 export nodes_os="xenial"
1224 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001225 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001226 set -xe
1227 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1228 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1229 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1230 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1231
1232 # Add wrapper to apt-get to avoid race conditions
1233 # with cron jobs running 'unattended-upgrades' script
1234 aptget_wrapper() {
1235 local apt_wrapper_timeout=300
1236 local start_time=$(date '+%s')
1237 local fin_time=$((start_time + apt_wrapper_timeout))
1238 while true; do
1239 if (( "$(date '+%s')" > fin_time )); then
1240 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1241 fi
1242 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1243 echo "Waiting while another apt/dpkg process releases locks ..."
1244 sleep 30
1245 continue
1246 else
1247 apt-get $@
1248 break
1249 fi
1250 done
1251 }
1252
1253 # Set default salt version
1254 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001255 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001256 fi
1257 echo "Using Salt version $saltversion"
1258
1259 echo "Preparing base OS ..."
1260
1261 case "$node_os" in
1262 trusty)
1263 # workaround for old cloud-init only configuring the first iface
1264 iface_config_dir="/etc/network/interfaces"
1265 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1266
1267 for iface in $ifaces; do
1268 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1269 done
1270
1271 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1272
1273 # SUGGESTED UPDATE:
1274 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1275 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1276 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1277 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1278 #install_salt_minion_pkg
1279
1280 # DEPRECATED:
1281 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1282 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1283
1284 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1285 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1286
1287 aptget_wrapper clean
1288 aptget_wrapper update
1289 aptget_wrapper install -y salt-common
1290 aptget_wrapper install -y salt-minion
1291 ;;
1292 xenial)
1293
1294 # workaround for new cloud-init setting all interfaces statically
1295 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1296
1297 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1298
1299 # SUGGESTED UPDATE:
1300 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1301 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1302 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1303 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1304 #install_salt_minion_pkg
1305
1306 # DEPRECATED:
1307 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1308 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1309
1310 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1311 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1312
1313 aptget_wrapper clean
1314 aptget_wrapper update
1315 aptget_wrapper install -y salt-minion
1316 ;;
1317 rhel|centos|centos7|centos7|rhel6|rhel7)
1318 yum install -y git
1319 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1320 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1321 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1322 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1323 install_salt_minion_pkg
1324 ;;
1325 *)
1326 msg="OS '$node_os' is not supported."
1327 esac
1328
1329 echo "Configuring Salt minion ..."
1330 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1331 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1332
1333 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1334
1335 sleep 1
1336
1337 echo "Classifying node ..."
1338 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1339 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1340 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1341 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1342 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1343 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1344
1345 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1346 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1347 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1348 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1349 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1350
1351 if [ "$node_network05_iface" != "" ]; then
1352 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1353 fi
1354
1355 # find more parameters (every env starting param_)
1356 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1357 if [ "$more_params" != "" ]; then
1358 echo "Additional params: $more_params"
1359 more_params=", $more_params"
1360 fi
1361
1362 salt-call event.send "reclass/minion/classify" "{\"node_master_ip\": \"$config_host\", \"node_os\": \"${os_codename}\", \"node_deploy_ip\": \"${node_network01_ip}\", \"node_deploy_iface\": \"${node_network01_iface}\", \"node_control_ip\": \"${node_network02_ip}\", \"node_control_iface\": \"${node_network02_iface}\", \"node_tenant_ip\": \"${node_network03_ip}\", \"node_tenant_iface\": \"${node_network03_iface}\", \"node_external_ip\": \"${node_network04_ip}\", \"node_external_iface\": \"${node_network04_iface}\", \"node_baremetal_ip\": \"${node_network05_ip}\", \"node_baremetal_iface\": \"${node_network05_iface}\", \"node_baremetal_hwaddress\": \"${node_network05_hwaddress}\", \"node_domain\": \"$node_domain\", \"node_cluster\": \"$cluster_name\", \"node_hostname\": \"$node_hostname\"${more_params}}"
1363
1364 sleep 5
1365
1366 salt-call saltutil.sync_all
1367 salt-call mine.flush
1368 salt-call mine.update
1369 node_name: {{ ssh['node_name'] }}
1370 retry: {count: 1, delay: 1}
1371 skip_fail: false
1372{%- endif %}
1373{%- endfor %}
1374
1375- description: Refresh pillars on all minions
1376 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1377 node_name: {{ HOSTNAME_CFG01 }}
1378 retry: {count: 1, delay: 5}
1379 skip_fail: false
1380
1381- description: Sync all salt resources
1382 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1383 node_name: {{ HOSTNAME_CFG01 }}
1384 retry: {count: 1, delay: 5}
1385 skip_fail: false
1386
sgudz160b7302017-12-22 17:01:10 +02001387{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001388
1389{%- macro RUN_NEW_TEMPEST() %}
1390{###################################}
1391
1392- description: Upload tempest template
1393 upload:
1394 local_path: {{ config.salt_deploy.templates_dir }}
1395 local_filename: runtest.yml
1396 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1397 node_name: {{ HOSTNAME_CFG01 }}
1398 skip_fail: False
1399
1400- description: Include class with tempest template into cfg node
1401 cmd: |
1402 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1403 salt 'cfg01*' saltutil.refresh_pillar;
1404 salt 'cfg01*' saltutil.sync_all;
1405 node_name: {{ HOSTNAME_CFG01 }}
1406 retry: {count: 1, delay: 10}
1407 skip_fail: false
1408
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001409- description: Execute salt.minion on config node
1410 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1411 node_name: {{ HOSTNAME_CFG01 }}
1412 retry: {count: 1, delay: 5}
1413 skip_fail: false
1414
1415- description: Test ping
1416 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1417 node_name: {{ HOSTNAME_CFG01 }}
1418 retry: {count: 1, delay: 5}
1419 skip_fail: false
1420
sgudz09e9aa92018-04-12 12:31:53 +03001421- description: Create flavors for tests
1422 cmd: |
1423 salt 'cfg01*' state.sls nova.client;
1424 node_name: {{ HOSTNAME_CFG01 }}
1425 retry: {count: 1, delay: 5}
1426 skip_fail: false
1427
1428- description: Create networks for tests
1429 cmd: |
1430 salt 'cfg01*' state.sls neutron.client;
1431 node_name: {{ HOSTNAME_CFG01 }}
1432 retry: {count: 1, delay: 5}
1433 skip_fail: false
1434
1435- description: Upload cirros image
1436 cmd: |
1437 salt 'cfg01*' state.sls glance.client;
1438 node_name: {{ HOSTNAME_CFG01 }}
1439 retry: {count: 1, delay: 5}
1440 skip_fail: false
1441
1442- description: Generate tempest config
1443 cmd: |
1444 salt 'cfg01*' state.sls runtest;
1445 node_name: {{ HOSTNAME_CFG01 }}
1446 retry: {count: 1, delay: 5}
1447 skip_fail: false
1448
1449- description: Run tempest from new docker image
1450 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001451 docker run -e ARGS="-r {{TEMPEST_PATTERN }} -w 2 {{ EXCLUDE_TEST_ARGS }}" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:pike /bin/bash -c "run-tempest"
sgudz09e9aa92018-04-12 12:31:53 +03001452 node_name: {{ HOSTNAME_GTW01 }}
1453 retry: {count: 1, delay: 30}
1454 skip_fail: true
1455
1456- description: Download xml results
1457 download:
1458 remote_path: /root/test/
1459 remote_filename: "report_*.xml"
1460 local_path: {{ os_env('PWD') }}
1461 node_name: {{ HOSTNAME_GTW01 }}
1462 skip_fail: true
1463
1464{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001465
1466{%- macro INSTALL_DOCKER_ON_GTW() %}
1467{###################################}
1468
1469- description: Install docker.io on gtw
1470 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1471 node_name: {{ HOSTNAME_GTW01 }}
1472 retry: {count: 1, delay: 30}
1473 skip_fail: false
1474
1475- description: Enable forward policy
1476 cmd: iptables --policy FORWARD ACCEPT
1477 node_name: {{ HOSTNAME_GTW01 }}
1478 retry: {count: 1, delay: 30}
1479 skip_fail: false
1480
1481{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001482
1483{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1484{#####################################################}
1485
1486{%- for ssh in config.underlay.ssh %}
1487 {%- set salt_roles = [] %}
1488 {%- for role in ssh['roles'] %}
1489 {%- if role in config.salt_deploy.salt_roles %}
1490 {%- set _ = salt_roles.append(role) %}
1491 {%- endif %}
1492 {%- endfor %}
1493
1494 {%- if salt_roles %}
1495- description: 'Check salt version is as expected'
1496 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1497 node_name: {{ ssh['node_name'] }}
1498 retry: {count: 1, delay: 1}
1499 skip_fail: false
1500 {%- endif %}
1501
1502{%- endfor %}
1503{%- endmacro %}
1504
1505{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1506{#####################################################}
1507
1508- description: 'Check salt-api, salt-master and salt-minion version'
1509 cmd: |
1510 salt-master --version | grep {{ SALT_VERSION }};
1511 salt-minion --version | grep {{ SALT_VERSION }};
1512 salt-api --version | grep {{ SALT_VERSION }};
1513 node_name: {{ HOSTNAME_CFG01 }}
1514 retry: {count: 1, delay: 5}
1515 skip_fail: false
1516
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001517{%- endmacro %}