blob: 330906de0cf14d7cdaa619aca256ebe1c691c8d0 [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') %}
4{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
5{# 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 #}
6{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
7{# Pin to a specified commit in salt-models/reclass-system #}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +03008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/reclass-system') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02009{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +030010{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
sgudz4d816eb2017-11-13 11:58:05 +020011{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
sgudza399dc72018-01-18 17:13:48 +020012{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030013{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020014
Dennis Dmitriev492813e2017-08-09 15:08:58 +030015{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020016{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020017{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030018#{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %}
19{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-2016.3/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020020{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
21{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
22{% 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") %}
23{% 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 +030024{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030025{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030026
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020027{# Address pools for reclass cluster model are taken in the following order:
28 # 1. environment variables,
29 # 2. config.underlay.address_pools based on fuel-devops address pools
30 # (see generated '.ini' file after underlay is created),
31 # 3. defaults #}
32{% set address_pools = config.underlay.address_pools %}
33{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
34{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
35{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
36{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
37{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
38{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
39{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
40{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
41
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040042{# Format for formula replacement:
43 # space separated string:
44 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
45
46{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030047{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030048{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040049{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
50
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040051# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020052{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040053
Dennis Dmitriev492813e2017-08-09 15:08:58 +030054
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020055{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
56{#####################################################}
57
58- description: 'Configure key on nodes and install packages'
59 cmd: |
60 rm -rf trusted* ;
61 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020062 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020063 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
64 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
65 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030066 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020067 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
68 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
69 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050070 eatmydata apt-get clean;
71 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020072 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020073 node_name: {{ NODE_NAME }}
74 retry: {count: 1, delay: 5}
75 skip_fail: false
76
77{%- endmacro %}
78
79
Dennis Dmitriev492813e2017-08-09 15:08:58 +030080{%- macro MACRO_INSTALL_SALT_MASTER() %}
81{######################################}
82- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020083 cmd: |
84 which wget >/dev/null || (apt-get update; apt-get install -y wget);
85 # Configure ubuntu and salt repositories
86 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
87 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
88 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
89 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
90
91 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
92 wget -O - {{ FORMULA_GPG }} | apt-key add -;
93 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030094 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
95
Dennis Dmitrievcf777802018-02-14 18:09:55 +020096
97 apt-get clean
98 apt-get update
99
100 # Install salt-master and reclass
101 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
102 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200103 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 +0200104 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300105 node_name: {{ HOSTNAME_CFG01 }}
106 retry: {count: 1, delay: 1}
107 skip_fail: false
108
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200109- description: Remove any existing minion keys
110 cmd: salt-key -y -D || true
111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 1, delay: 1}
113 skip_fail: false
114
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300115- description: Configure salt-master on cfg01
116 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200117 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300118 file_roots:
119 base:
120 - /usr/share/salt-formulas/env
121 pillar_opts: False
122 open_mode: True
123 reclass: &reclass
124 storage_type: yaml_fs
125 inventory_base_uri: /srv/salt/reclass
126 ext_pillar:
127 - reclass: *reclass
128 master_tops:
129 reclass: *reclass
130 EOF
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 1}
133 skip_fail: false
134
135- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300136 cmd: |
137 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200138 #touch /root/.git_trusted_certs.pem;
139 #for server in github.com; do \
140 # openssl s_client -showcerts -connect $server:443 </dev/null \
141 # | openssl x509 -outform PEM \
142 # >> /root/.git_trusted_certs.pem;
143 #done;
144 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
145 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
146 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300147 node_name: {{ HOSTNAME_CFG01 }}
148 retry: {count: 1, delay: 1}
149 skip_fail: false
150{%- endmacro %}
151
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200152
153{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
154{######################################}
155
156- description: Remove /etc/update-motd.d/52-info
157 cmd: rm -vf /etc/update-motd.d/52-info
158 node_name: {{ HOSTNAME_CFG01 }}
159 retry: {count: 1, delay: 10}
160 skip_fail: false
161
162- description: Set up static interface config
163 cmd: |
164 kill $(pidof /sbin/dhclient) || /bin/true
165 cat << 'EOF' > /etc/network/interfaces
166 # This file describes the network interfaces available on your system
167 # and how to activate them. For more information, see interfaces(5).
168
169 # The loopback network interface
170 auto lo
171 iface lo inet loopback
172
173 # The primary network interface
174 auto ens3
175 iface ens3 inet static
176 address {{ IPV4_NET_ADMIN_PREFIX }}.90
177 netmask 255.255.255.0
178 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
179 EOF
180 node_name: {{ HOSTNAME_CFG01 }}
181 retry: {count: 1, delay: 10}
182 skip_fail: false
183
184- description: Install common packages on cfg01
185 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
186 node_name: {{ HOSTNAME_CFG01 }}
187 retry: {count: 1, delay: 1}
188 skip_fail: false
189
190- description: Remove any existing minion keys
191 cmd: salt-key -y -D || true
192 node_name: {{ HOSTNAME_CFG01 }}
193 retry: {count: 1, delay: 1}
194 skip_fail: false
195
196- description: Configure GIT settings and certificates
197 cmd: |
198 set -e;
199 #touch /root/.git_trusted_certs.pem;
200 #for server in github.com; do \
201 # openssl s_client -showcerts -connect $server:443 </dev/null \
202 # | openssl x509 -outform PEM \
203 # >> /root/.git_trusted_certs.pem;
204 #done;
205 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
206 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
207 HOME=/root git config --global user.name "MCP Integration QA";
208 node_name: {{ HOSTNAME_CFG01 }}
209 retry: {count: 1, delay: 1}
210 skip_fail: false
211{%- endmacro %}
212
213
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300214{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300215{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300216{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
217
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300218- description: Clone reclass models with submodules
219 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300220 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200221 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200222 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200223
224 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
225 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 +0200226 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200227
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200228 pushd /srv/salt/reclass;
229 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
230 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200231 {%- if SALT_MODELS_REF_CHANGE != '' %}
232 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200233 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200234 {%- endfor %}
235 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200236 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200237 {%- endif %}
238 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200239 pushd classes/system/;
240 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
241 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200242 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300243 pushd classes/system/ && \
244 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200245 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300246 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200247 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200248 {%- endif %}
249 popd;
250 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300251 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200252
253 # Replace firstly to an intermediate value to avoid intersection between
254 # already replaced and replacing networks.
255 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
256 # 192.168.10 -> 10.16.0 (generated network for admin)
257 # 10.16.0 -> <external network>
258 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300259 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200260 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
261 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
262 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
263 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200264
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200265 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
266 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
267 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
268 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 +0200269
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300270 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200271
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300272 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300273 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300274 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 +0300275 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 +0300276 {%- endif %}
277
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200278 # Override some context parameters
279 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
280 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
281 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
282
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200283 # Create the cfg01 inventory file or use existing
284 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
285 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300286 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400287 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300288 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200289 - cluster.{{ CLUSTER_NAME }}.infra.maas
290 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300291 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300292 parameters:
293 _param:
294 linux_system_codename: xenial
295 reclass_data_revision: master
296 linux:
297 system:
298 name: cfg01
299 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200300 reclass:
301 storage:
302 data_source:
303 engine: local
304 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300305
306 # Show the changes to the console
307 cd /srv/salt/reclass/; git diff
308 node_name: {{ HOSTNAME_CFG01 }}
309 retry: {count: 1, delay: 1}
310 skip_fail: false
311{%- endmacro %}
312
313
sgudz160b7302017-12-22 17:01:10 +0200314{%- 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 +0300315{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300316{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200317- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300318 upload:
319 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
320 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300321 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300322 node_name: {{ HOSTNAME_CFG01 }}
323
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300324- description: Create cluster model from cookiecutter templates
325 cmd: |
326 set -e;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300327 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300328 pip install cookiecutter
329 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200330
sgudza399dc72018-01-18 17:13:48 +0200331 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
332 pushd /tmp/cookiecutter-templates
333 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
334 popd
335 {%- endif %}
336
sgudz4d816eb2017-11-13 11:58:05 +0200337 {%- if COOKIECUTTER_REF_CHANGE != '' %}
338 pushd /tmp/cookiecutter-templates
339 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
340 popd
341 {%- endif %}
342
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300343 mkdir -p /srv/salt/reclass/classes/cluster/
344 mkdir -p /srv/salt/reclass/classes/system/
345 mkdir -p /srv/salt/reclass/classes/service/
346 mkdir -p /srv/salt/reclass/nodes/_generated
347
348 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200349 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
350 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200351 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300352 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200353 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300354 {%- endif %}
355 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200356 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300357 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300358
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300359 # Replace firstly to an intermediate value to avoid intersection between
360 # already replaced and replacing networks.
361 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
362 # 192.168.10 -> 10.16.0 (generated network for admin)
363 # 10.16.0 -> <external network>
364 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
365 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
366 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
367 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200368 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300369
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300370 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
371 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
372 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200373 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300374
sgudz160b7302017-12-22 17:01:10 +0200375 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
376 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300377 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200378 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300379 --config-file {{ CLUSTER_CONTEXT_PATH }} \
380 --output-dir /srv/salt/reclass/classes/cluster/;
381 done
382
383 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
384
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200385 # Create the cfg01 inventory file or use existing
386 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
387 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300388 classes:
389 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200390 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300391 EOF
392
393 node_name: {{ HOSTNAME_CFG01 }}
394 retry: {count: 1, delay: 1}
395 skip_fail: false
396
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300397- description: Modify generated model and reclass-system if necessary
398 cmd: |
399 set -e;
400 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
401 pushd /srv/salt/reclass/classes/system/
402 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
403 popd
sgudz4d816eb2017-11-13 11:58:05 +0200404 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300405 pushd /srv/salt/reclass/classes/system/
406 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
407 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
408 {%- endfor %}
409 popd
410 {%- endif %}
411
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300412 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200413 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300414 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
415 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
416 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
417 {%- endif %}
418
419 node_name: {{ HOSTNAME_CFG01 }}
420 retry: {count: 1, delay: 1}
421 skip_fail: false
422{%- endmacro %}
423
424
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300425{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
426{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300427
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200428- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300429 cmd: |
430 set -e;
431 mkdir -p /tmp/environment/;
432 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /tmp/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300433 node_name: {{ HOSTNAME_CFG01 }}
434 skip_fail: false
435
sgudzcced67d2017-10-11 15:56:09 +0300436{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
437- description: Fetch changes for environment templates
438 cmd: |
439 set -e;
440 pushd /tmp/environment/environment_template &&
441 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
442 git checkout FETCH_HEAD &&
443 popd
444 node_name: {{ HOSTNAME_CFG01 }}
445 skip_fail: false
446{%- endif %}
447
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300448{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200449- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300450 upload:
451 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
452 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
453 remote_path: /tmp/environment/
454 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300455{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300456
457- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
458 cmd: |
459 set -e;
460 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200461 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
462 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300463 pip install git+https://github.com/dis-xcom/reclass-tools;
464 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
465 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
466 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
467
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500468 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
469 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
470 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 +0300471 fi;
472
473 node_name: {{ HOSTNAME_CFG01 }}
474 retry: {count: 1, delay: 5}
475 skip_fail: false
476
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200477- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300478 cmd: |
479 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200480 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 +0300481
482 node_name: {{ HOSTNAME_CFG01 }}
483 retry: {count: 1, delay: 5}
484 skip_fail: false
485
486- description: "[EXPERIMENTAL] Create environment model for virtual environment"
487 cmd: |
488 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200489 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300490 reclass-tools render --template-dir /tmp/environment/environment_template/ \
491 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300492 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300493 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
494 node_name: {{ HOSTNAME_CFG01 }}
495 retry: {count: 1, delay: 5}
496 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300497
498- description: Modify generated model and reclass-system
499 cmd: |
500 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
501 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
502 node_name: {{ HOSTNAME_CFG01 }}
503 retry: {count: 1, delay: 1}
504 skip_fail: false
505
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300506{%- endmacro %}
507
508
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300509{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
510{#######################################################}
511- description: Configure reclass
512 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300513 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300514 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300515 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200516 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200517 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
518 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300519 apt-get clean; apt-get update;
520 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
521 declare -a formula_services=({{ FORMULA_SERVICES }});
522 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200523 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300524 for formula_service in "${formula_services[@]}"; do
525 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
526 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
527 done;
528 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
529 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
530 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
531
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200532 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300533 storage_type: yaml_fs
534 pretty_print: True
535 output: yaml
536 inventory_base_uri: /srv/salt/reclass
537 EOF
538 node_name: {{ HOSTNAME_CFG01 }}
539 retry: {count: 1, delay: 1}
540 skip_fail: false
541
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200542- 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 +0300543 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200544 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
545 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300546 node_name: {{ HOSTNAME_CFG01 }}
547 retry: {count: 1, delay: 5}
548 skip_fail: false
549
550- description: Configure salt adoptors on cfg01
551 cmd: |
552 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
553 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
554 node_name: {{ HOSTNAME_CFG01 }}
555 retry: {count: 1, delay: 1}
556 skip_fail: false
557
558- description: Show reclass-salt --top for cfg01 node
559 cmd: reclass-salt --top
560 node_name: {{ HOSTNAME_CFG01 }}
561 retry: {count: 1, delay: 5}
562 skip_fail: false
563
564- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400565 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300566 node_name: {{ HOSTNAME_CFG01 }}
567 retry: {count: 1, delay: 5}
568 skip_fail: false
569{%- endmacro %}
570
571
572{%- macro MACRO_INSTALL_SALT_MINIONS() %}
573{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200574{%- for ssh in config.underlay.ssh %}
575 {%- set salt_roles = [] %}
576 {%- for role in ssh['roles'] %}
577 {%- if role in config.salt_deploy.salt_roles %}
578 {%- set _ = salt_roles.append(role) %}
579 {%- endif %}
580 {%- endfor %}
581
582 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300583- description: Configure salt-minion on {{ ssh['node_name'] }}
584 cmd: |
585 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200586 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300587 id: {{ ssh['node_name'] }}
588 master: {{ config.salt.salt_master_host }}
589 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200590
591 # Configure ubuntu and salt repositories
592 which wget >/dev/null || (apt-get update; apt-get install -y wget);
593
594 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
595 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
596 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
597 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
598
599 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300600 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
601
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200602
603 apt-get clean
604 apt-get update
605
606 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300607 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200608 # Install common packages
609 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200610 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200611 # Restart salt-minion if it was already installed
612 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300613 node_name: {{ ssh['node_name'] }}
614 retry: {count: 1, delay: 1}
615 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200616 {%- else %}
617- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
618 cmd: echo "SSH to $(hostname -f) passed"
619 node_name: {{ ssh['node_name'] }}
620 retry: {count: 1, delay: 1}
621 skip_fail: false
622 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300623
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200624{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300625
626- description: Accept salt keys from all the nodes
627 cmd: salt-key -A -y
628 node_name: {{ HOSTNAME_CFG01 }}
629 retry: {count: 1, delay: 5}
630 skip_fail: true
631{%- endmacro %}
632
633
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200634{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
635{#######################################################}
636- description: Configure reclass
637 cmd: |
638 set -e;
639 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
640 which wget > /dev/null || (apt-get update; apt-get install -y wget);
641 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
642 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
643 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
644 apt-get clean; apt-get update;
645 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
646 declare -a formula_services=({{ FORMULA_SERVICES }});
647 echo -e "\nInstalling all required salt formulas\n";
648 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
649 for formula_service in "${formula_services[@]}"; do
650 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
651 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
652 done;
653 node_name: {{ HOSTNAME_CFG01 }}
654 retry: {count: 1, delay: 1}
655 skip_fail: false
656
657- description: Show reclass-salt --top for cfg01 node
658 cmd: reclass-salt --top
659 node_name: {{ HOSTNAME_CFG01 }}
660 retry: {count: 1, delay: 5}
661 skip_fail: false
662
663- description: Restart salt-master service
664 cmd: systemctl restart salt-master;
665 node_name: {{ HOSTNAME_CFG01 }}
666 retry: {count: 1, delay: 5}
667 skip_fail: false
668{%- endmacro %}
669
670{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
671{#######################################}
672- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
673 cmd: |
674 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
675 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
676 service salt-minion restart
677
678 while true; do
679 salt-key | grep "$SALT_MASTER_MINION_ID" && break
680 sleep 5
681 done
682
683 sleep 5
684
685 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
686 salt-key -d $i -y
687 done
688 node_name: {{ HOSTNAME_CFG01 }}
689 retry: {count: 1, delay: 1}
690 skip_fail: false
691{%- endmacro %}
692
693
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300694{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
695{##################################################}
696
697{# Prepare salt services and nodes settings #}
698
699- description: Run 'linux' formula on cfg01
700 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
701 node_name: {{ HOSTNAME_CFG01 }}
702 retry: {count: 3, delay: 5}
703 skip_fail: false
704
705- description: Run 'openssh' formula on cfg01
706 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300707 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300708 salt --hard-crash --state-output=mixed --state-verbose=False
709 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
ibumarskov9218b632018-05-24 12:29:41 +0400710 yes/' /etc/ssh/sshd_config && sed -i 's/ClientAliveInterval 300/ClientAliveInterval 18000/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300711 node_name: {{ HOSTNAME_CFG01 }}
712 retry: {count: 3, delay: 5}
713 skip_fail: false
714
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300715- description: '*Workaround* of harcoded host from day01 grains'
716 cmd: salt-key -d cfg01.mcp-day01.local -y
717 node_name: {{ HOSTNAME_CFG01 }}
718 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400719 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300720
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300721- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
722 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
723 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
724 node_name: {{ HOSTNAME_CFG01 }}
725 retry: {count: 1, delay: 1}
726 skip_fail: false
727
728- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300729 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 +0300730 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300731 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300732 skip_fail: false
733
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400734{%- if SALT_FORMULAS_REFS != '' %}
735- description: Replace needed formulas to desired version
736 cmd: |
737 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400738 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
739 {% set formula = formula_set.split(':') %}
740 {% set formula_name = formula[0] %}
741 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300742 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400743 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
744 pushd {{ formula_dir }} &&
745 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
746 git checkout FETCH_HEAD &&
747 popd &&
748 if [ -d "{{ formula_dir }}" ]; then
749 echo "Going to replace packaged formula {{ formula_name }}" &&
750 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400751 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
752 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400753 else
754 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
755 fi
756 {%- endfor %}
757 node_name: {{ HOSTNAME_CFG01 }}
758 retry: {count: 1, delay: 10}
759 skip_fail: false
760{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300761
762- description: Refresh pillars on salt-master minion
763 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
764 node_name: {{ HOSTNAME_CFG01 }}
765 retry: {count: 1, delay: 5}
766 skip_fail: false
767
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300768- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300769 cmd: reclass-salt --top
770 node_name: {{ HOSTNAME_CFG01 }}
771 retry: {count: 1, delay: 5}
772 skip_fail: false
773
774- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300775 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 +0300776 node_name: {{ HOSTNAME_CFG01 }}
777 retry: {count: 1, delay: 5}
778 skip_fail: false
779
780- description: Configure linux on master
781 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
782 node_name: {{ HOSTNAME_CFG01 }}
783 retry: {count: 1, delay: 5}
784 skip_fail: false
785
786- description: Configure salt.minion on master
787 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
788 -C 'I@salt:master' state.sls salt.minion && sleep 10
789 node_name: {{ HOSTNAME_CFG01 }}
790 retry: {count: 3, delay: 10}
791 skip_fail: false
792
793- description: Run state 'salt' on master (for salt.api, etc)
794 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
795 -C 'I@salt:master' state.sls salt
796 node_name: {{ HOSTNAME_CFG01 }}
797 retry: {count: 3, delay: 10}
798 skip_fail: false
799{%- endmacro %}
800
Dennis Dmitriev85559962018-01-30 15:35:51 +0200801{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
802{#################################################################}
803
804- description: Refresh pillars before generating nodes
805 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
806 node_name: {{ HOSTNAME_CFG01 }}
807 retry: {count: 1, delay: 5}
808 skip_fail: false
809
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200810- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200811 cmd: |
812 set -e
813 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
814 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 +0200815 node_name: {{ HOSTNAME_CFG01 }}
816 retry: {count: 1, delay: 5}
817 skip_fail: false
818
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300819- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
820 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
821 -C 'I@salt:master' state.sls reclass
822 node_name: {{ HOSTNAME_CFG01 }}
823 retry: {count: 1, delay: 5}
824 skip_fail: false
825
Dennis Dmitriev85559962018-01-30 15:35:51 +0200826{%- if RERUN_SALTMASTER_STATE %}
827- description: Regenerate salt.master states for the newly uploaded/created model
828 cmd: |
829 # Need to refresh installed formulas that are required in the model
830 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
831 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
832 node_name: {{ HOSTNAME_CFG01 }}
833 retry: {count: 1, delay: 5}
834 skip_fail: false
835{%- endif %}
836
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300837- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200838 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300839 node_name: {{ HOSTNAME_CFG01 }}
840 retry: {count: 1, delay: 5}
841 skip_fail: false
842
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300843- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300844 cmd: |
845 set -e
846 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
847 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
848 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300849 node_name: {{ HOSTNAME_CFG01 }}
850 retry: {count: 1, delay: 5}
851 skip_fail: false
852
853- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300854 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300855 node_name: {{ HOSTNAME_CFG01 }}
856 retry: {count: 1, delay: 5}
857 skip_fail: false
858{%- endmacro %}
859
860
861{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
862{########################################}
863# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200864
865- description: Get linux kernel version from all minions
866 cmd: |
867 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
868 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
869 node_name: {{ HOSTNAME_CFG01 }}
870 retry: {count: 5, delay: 10}
871 skip_fail: false
872
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300873- description: Configure linux on other nodes
874 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
875 node_name: {{ HOSTNAME_CFG01 }}
876 retry: {count: 5, delay: 10}
877 skip_fail: false
878
879- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300880 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 +0300881 salt --hard-crash --state-output=mixed --state-verbose=False
882 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovichb6896842018-05-21 19:40:49 +0300883 yes/' /etc/ssh/sshd_config && sed -i 's/ClientAliveInterval 300/ClientAliveInterval 18000/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300884 node_name: {{ HOSTNAME_CFG01 }}
885 retry: {count: 1, delay: 5}
886 skip_fail: false
887
888- description: Configure salt.minion on other nodes
889 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 +0400890 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300891 node_name: {{ HOSTNAME_CFG01 }}
892 retry: {count: 3, delay: 15}
893 skip_fail: false
894
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400895- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400896 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400897 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400898 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400899 skip_fail: false
900
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400901- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200902 cmd: |
903 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
904 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400905 node_name: {{ HOSTNAME_CFG01 }}
906 retry: {count: 1, delay: 10}
907 skip_fail: false
908
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200909- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
910 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
911 node_name: {{ HOSTNAME_CFG01 }}
912 retry: {count: 1, delay: 10}
913 skip_fail: false
914
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300915- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400916 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300917 node_name: {{ HOSTNAME_CFG01 }}
918 retry: {count: 3, delay: 15}
919 skip_fail: false
920
921- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400922 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300923 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400924 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300925 skip_fail: false
926
927- description: Configure ntp and rsyslog on nodes
928 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
929 node_name: {{ HOSTNAME_CFG01 }}
930 retry: {count: 1, delay: 10}
931 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200932{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300933
934
935{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
936{#########################################}
937
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300938- description: '*Workaround: Load bonding module before call state.linux'
939 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
940 node_name: {{ HOSTNAME_CFG01 }}
941 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300942 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300943
944- description: '*Workaround* install bridge-utils before running linux formula'
945 # The formula removes default route and then tries to install the package, fails.
946 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
947 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
948 node_name: {{ HOSTNAME_CFG01 }}
949 retry: {count: 1, delay: 5}
950 skip_fail: false
951
952{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400953
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200954
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400955{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200956{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400957
958- description: Set k8s deploy parameters
959 cmd: |
960 {% for k8s_opt, value in config.k8s_deploy.items() %}
961 {% if value|string() %}
962 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
963 {% endif %}
964 {% endfor %}
965 node_name: {{ HOSTNAME_CFG01 }}
966 retry: {count: 1, delay: 1}
967 skip_fail: false
968
969{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400970
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200971
972{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
973{#############################################}
974- description: Set SL docker images deploy parameters
975 cmd: |
976 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
977 {%- for sl_opt, value in config.sl_deploy.items() %}
978 {%- if value|string() %}
979 {%- if OVERRIDES_FILENAME %}
980 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
981 {%- else %}
982 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
983 {%- endif %}
984 {%- endif %}
985 {%- endfor %}
986 salt '*' saltutil.refresh_pillar;
987 sleep 10
988 node_name: {{ HOSTNAME_CFG01 }}
989 retry: {count: 1, delay: 1}
990 skip_fail: false
991{%- endmacro %}
992
993
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400994{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200995{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400996
997{% for ssh in config.underlay.ssh %}
998{% if ssh["node_name"].startswith("cmp") %}
999{% set node_hostname = ssh["node_name"].split('.')[0] %}
1000- description: Register compute {{ ssh['node_name'] }}
1001 cmd: |
1002 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1003 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1004 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001005 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001006 export config_host={{ config.salt.salt_master_host }}
1007 export node_domain={{ DOMAIN_NAME }}
1008 export nodes_os="xenial"
1009 export node_hostname={{ node_hostname }}
1010 set -xe
1011 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1012 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1013 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1014 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1015
1016 # Add wrapper to apt-get to avoid race conditions
1017 # with cron jobs running 'unattended-upgrades' script
1018 aptget_wrapper() {
1019 local apt_wrapper_timeout=300
1020 local start_time=$(date '+%s')
1021 local fin_time=$((start_time + apt_wrapper_timeout))
1022 while true; do
1023 if (( "$(date '+%s')" > fin_time )); then
1024 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1025 fi
1026 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1027 echo "Waiting while another apt/dpkg process releases locks ..."
1028 sleep 30
1029 continue
1030 else
1031 apt-get $@
1032 break
1033 fi
1034 done
1035 }
1036
1037 # Set default salt version
1038 if [ -z "$saltversion" ]; then
1039 saltversion="2016.3"
1040 fi
1041 echo "Using Salt version $saltversion"
1042
1043 echo "Preparing base OS ..."
1044
1045 case "$node_os" in
1046 trusty)
1047 # workaround for old cloud-init only configuring the first iface
1048 iface_config_dir="/etc/network/interfaces"
1049 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1050
1051 for iface in $ifaces; do
1052 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1053 done
1054
1055 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1056
1057 # SUGGESTED UPDATE:
1058 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1059 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1060 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1061 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1062 #install_salt_minion_pkg
1063
1064 # DEPRECATED:
1065 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1066 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1067
1068 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1069 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1070
1071 aptget_wrapper clean
1072 aptget_wrapper update
1073 aptget_wrapper install -y salt-common
1074 aptget_wrapper install -y salt-minion
1075 ;;
1076 xenial)
1077
1078 # workaround for new cloud-init setting all interfaces statically
1079 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1080
1081 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1082
1083 # SUGGESTED UPDATE:
1084 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1085 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1086 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1087 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1088 #install_salt_minion_pkg
1089
1090 # DEPRECATED:
1091 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1092 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1093
1094 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1095 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1096
1097 aptget_wrapper clean
1098 aptget_wrapper update
1099 aptget_wrapper install -y salt-minion
1100 ;;
1101 rhel|centos|centos7|centos7|rhel6|rhel7)
1102 yum install -y git
1103 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1104 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1105 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1106 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1107 install_salt_minion_pkg
1108 ;;
1109 *)
1110 msg="OS '$node_os' is not supported."
1111 esac
1112
1113 echo "Configuring Salt minion ..."
1114 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1115 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1116
1117 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1118
1119 sleep 1
1120
1121 echo "Classifying node ..."
1122 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1123 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1124 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1125 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1126 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1127 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1128
1129 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1130 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1131 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1132 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1133 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1134
1135 if [ "$node_network05_iface" != "" ]; then
1136 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1137 fi
1138
1139 # find more parameters (every env starting param_)
1140 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1141 if [ "$more_params" != "" ]; then
1142 echo "Additional params: $more_params"
1143 more_params=", $more_params"
1144 fi
1145
1146 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}}"
1147
1148 sleep 5
1149
1150 salt-call saltutil.sync_all
1151 salt-call mine.flush
1152 salt-call mine.update
1153 node_name: {{ ssh['node_name'] }}
1154 retry: {count: 1, delay: 1}
1155 skip_fail: false
1156{%- endif %}
1157{%- endfor %}
1158
1159- description: Refresh pillars on all minions
1160 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1161 node_name: {{ HOSTNAME_CFG01 }}
1162 retry: {count: 1, delay: 5}
1163 skip_fail: false
1164
1165- description: Sync all salt resources
1166 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1167 node_name: {{ HOSTNAME_CFG01 }}
1168 retry: {count: 1, delay: 5}
1169 skip_fail: false
1170
sgudz160b7302017-12-22 17:01:10 +02001171{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001172
1173{%- macro RUN_NEW_TEMPEST() %}
1174{###################################}
1175
1176- description: Upload tempest template
1177 upload:
1178 local_path: {{ config.salt_deploy.templates_dir }}
1179 local_filename: runtest.yml
1180 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1181 node_name: {{ HOSTNAME_CFG01 }}
1182 skip_fail: False
1183
1184- description: Include class with tempest template into cfg node
1185 cmd: |
1186 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1187 salt 'cfg01*' saltutil.refresh_pillar;
1188 salt 'cfg01*' saltutil.sync_all;
1189 node_name: {{ HOSTNAME_CFG01 }}
1190 retry: {count: 1, delay: 10}
1191 skip_fail: false
1192
1193- description: Create flavors for tests
1194 cmd: |
1195 salt 'cfg01*' state.sls nova.client;
1196 node_name: {{ HOSTNAME_CFG01 }}
1197 retry: {count: 1, delay: 5}
1198 skip_fail: false
1199
1200- description: Create networks for tests
1201 cmd: |
1202 salt 'cfg01*' state.sls neutron.client;
1203 node_name: {{ HOSTNAME_CFG01 }}
1204 retry: {count: 1, delay: 5}
1205 skip_fail: false
1206
1207- description: Upload cirros image
1208 cmd: |
1209 salt 'cfg01*' state.sls glance.client;
1210 node_name: {{ HOSTNAME_CFG01 }}
1211 retry: {count: 1, delay: 5}
1212 skip_fail: false
1213
1214- description: Generate tempest config
1215 cmd: |
1216 salt 'cfg01*' state.sls runtest;
1217 node_name: {{ HOSTNAME_CFG01 }}
1218 retry: {count: 1, delay: 5}
1219 skip_fail: false
1220
1221- description: Run tempest from new docker image
1222 cmd: |
Oleksii Butenkoa99fe662018-05-24 17:30:20 +03001223 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 /bin/bash -c "run-tempest"
sgudz09e9aa92018-04-12 12:31:53 +03001224 node_name: {{ HOSTNAME_GTW01 }}
1225 retry: {count: 1, delay: 30}
1226 skip_fail: true
1227
1228- description: Download xml results
1229 download:
1230 remote_path: /root/test/
1231 remote_filename: "report_*.xml"
1232 local_path: {{ os_env('PWD') }}
1233 node_name: {{ HOSTNAME_GTW01 }}
1234 skip_fail: true
1235
1236{%- endmacro %}