blob: 90846097bdad7e40bb36053385767bb1ce1a406e [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','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030011{% set SALT_MODELS_SYSTEM_TAG = os_env('SALT_MODELS_SYSTEM_TAG','') %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +030012{% set COOKIECUTTER_TEMPLATES_REPOSITORY = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY','https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates') %}
sgudz4d816eb2017-11-13 11:58:05 +020013{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030014{% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %}
sgudza399dc72018-01-18 17:13:48 +020015{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030016{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020017
Dennis Dmitriev492813e2017-08-09 15:08:58 +030018{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020019{% 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 +020020{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030021#{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %}
22{% 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 +020023{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
24{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
25{% 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") %}
26{% 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 +030027{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030028{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030029
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020030{# Address pools for reclass cluster model are taken in the following order:
31 # 1. environment variables,
32 # 2. config.underlay.address_pools based on fuel-devops address pools
33 # (see generated '.ini' file after underlay is created),
34 # 3. defaults #}
35{% set address_pools = config.underlay.address_pools %}
36{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
37{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
38{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
39{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
40{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
41{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
42{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
43{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
44
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040045{# Format for formula replacement:
46 # space separated string:
47 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
48
49{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030050{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030051{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040052{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
53
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040054# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020055{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040056
Dennis Dmitriev492813e2017-08-09 15:08:58 +030057
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020058{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
59{#####################################################}
60
61- description: 'Configure key on nodes and install packages'
62 cmd: |
63 rm -rf trusted* ;
64 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020065 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020066 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
67 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
68 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030069 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020070 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
71 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
72 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050073 eatmydata apt-get clean;
74 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020075 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020076 node_name: {{ NODE_NAME }}
77 retry: {count: 1, delay: 5}
78 skip_fail: false
79
80{%- endmacro %}
81
82
Dennis Dmitriev492813e2017-08-09 15:08:58 +030083{%- macro MACRO_INSTALL_SALT_MASTER() %}
84{######################################}
85- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020086 cmd: |
87 which wget >/dev/null || (apt-get update; apt-get install -y wget);
88 # Configure ubuntu and salt repositories
89 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
90 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
91 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
92 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
93
94 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
95 wget -O - {{ FORMULA_GPG }} | apt-key add -;
96 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030097 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
98
Dennis Dmitrievcf777802018-02-14 18:09:55 +020099
100 apt-get clean
101 apt-get update
102
103 # Install salt-master and reclass
104 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
105 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200106 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 +0200107 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300108 node_name: {{ HOSTNAME_CFG01 }}
109 retry: {count: 1, delay: 1}
110 skip_fail: false
111
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200112- description: Remove any existing minion keys
113 cmd: salt-key -y -D || true
114 node_name: {{ HOSTNAME_CFG01 }}
115 retry: {count: 1, delay: 1}
116 skip_fail: false
117
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300118- description: Configure salt-master on cfg01
119 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200120 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300121 file_roots:
122 base:
123 - /usr/share/salt-formulas/env
124 pillar_opts: False
125 open_mode: True
126 reclass: &reclass
127 storage_type: yaml_fs
128 inventory_base_uri: /srv/salt/reclass
129 ext_pillar:
130 - reclass: *reclass
131 master_tops:
132 reclass: *reclass
133 EOF
134 node_name: {{ HOSTNAME_CFG01 }}
135 retry: {count: 1, delay: 1}
136 skip_fail: false
137
138- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300139 cmd: |
140 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200141 #touch /root/.git_trusted_certs.pem;
142 #for server in github.com; do \
143 # openssl s_client -showcerts -connect $server:443 </dev/null \
144 # | openssl x509 -outform PEM \
145 # >> /root/.git_trusted_certs.pem;
146 #done;
147 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
148 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
149 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 1, delay: 1}
152 skip_fail: false
153{%- endmacro %}
154
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200155
156{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
157{######################################}
158
159- description: Remove /etc/update-motd.d/52-info
160 cmd: rm -vf /etc/update-motd.d/52-info
161 node_name: {{ HOSTNAME_CFG01 }}
162 retry: {count: 1, delay: 10}
163 skip_fail: false
164
165- description: Set up static interface config
166 cmd: |
167 kill $(pidof /sbin/dhclient) || /bin/true
168 cat << 'EOF' > /etc/network/interfaces
169 # This file describes the network interfaces available on your system
170 # and how to activate them. For more information, see interfaces(5).
171
172 # The loopback network interface
173 auto lo
174 iface lo inet loopback
175
176 # The primary network interface
177 auto ens3
178 iface ens3 inet static
179 address {{ IPV4_NET_ADMIN_PREFIX }}.90
180 netmask 255.255.255.0
181 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
182 EOF
183 node_name: {{ HOSTNAME_CFG01 }}
184 retry: {count: 1, delay: 10}
185 skip_fail: false
186
187- description: Install common packages on cfg01
188 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 1}
191 skip_fail: false
192
193- description: Remove any existing minion keys
194 cmd: salt-key -y -D || true
195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 1, delay: 1}
197 skip_fail: false
198
199- description: Configure GIT settings and certificates
200 cmd: |
201 set -e;
202 #touch /root/.git_trusted_certs.pem;
203 #for server in github.com; do \
204 # openssl s_client -showcerts -connect $server:443 </dev/null \
205 # | openssl x509 -outform PEM \
206 # >> /root/.git_trusted_certs.pem;
207 #done;
208 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
209 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
210 HOME=/root git config --global user.name "MCP Integration QA";
211 node_name: {{ HOSTNAME_CFG01 }}
212 retry: {count: 1, delay: 1}
213 skip_fail: false
214{%- endmacro %}
215
216
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300217{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300218{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300219{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
220
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300221- description: Clone reclass models with submodules
222 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300223 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200224 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200225 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200226
227 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
228 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 +0200229 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200230
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200231 pushd /srv/salt/reclass;
232 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
233 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200234 {%- if SALT_MODELS_REF_CHANGE != '' %}
235 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200236 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200237 {%- endfor %}
238 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200239 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200240 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300241
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200242 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200243 pushd classes/system/;
244 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
245 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200246 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300247 pushd classes/system/ && \
248 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200249 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300250 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200251 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300252 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
253 pushd classes/system/;
254 git fetch --all --tags --prune
255 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
256 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200257 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300258
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200259 popd;
260 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300261 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200262
263 # Replace firstly to an intermediate value to avoid intersection between
264 # already replaced and replacing networks.
265 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
266 # 192.168.10 -> 10.16.0 (generated network for admin)
267 # 10.16.0 -> <external network>
268 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300269 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200270 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
271 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
272 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
273 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300274 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
275 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200276
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200277 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
278 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
279 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
280 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 +0200281
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300282 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 +0200283
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300284 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300285 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300286 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 +0300287 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 +0300288 {%- endif %}
289
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200290 # Override some context parameters
291 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
292 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
293 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
294
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200295 # Create the cfg01 inventory file or use existing
296 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
297 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300298 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400299 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300300 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200301 - cluster.{{ CLUSTER_NAME }}.infra.maas
302 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300303 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300304 parameters:
305 _param:
306 linux_system_codename: xenial
307 reclass_data_revision: master
308 linux:
309 system:
310 name: cfg01
311 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200312 reclass:
313 storage:
314 data_source:
315 engine: local
316 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300317
318 # Show the changes to the console
319 cd /srv/salt/reclass/; git diff
320 node_name: {{ HOSTNAME_CFG01 }}
321 retry: {count: 1, delay: 1}
322 skip_fail: false
323{%- endmacro %}
324
325
sgudz160b7302017-12-22 17:01:10 +0200326{%- 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 +0300327{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300328{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200329- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300330 upload:
331 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
332 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300333 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300334 node_name: {{ HOSTNAME_CFG01 }}
335
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300336- description: "Show options enabled in the context file for model generation"
337 cmd: |
338 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
339 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
340 echo "===== Sources for model generation ====="
341 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
342 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
343 {%- if CLUSTER_PRODUCT_MODELS != '' %}
344 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
345 {%- endif %}
346 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
347 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
348 {%- endif %}
349 {%- if COOKIECUTTER_REF_CHANGE != '' %}
350 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
351 {%- endif %}
352 {%- if COOKIECUTTER_TAG != '' %}
353 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
354 {%- endif %}
355 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
356 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
357 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300358 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
359 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300360 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
361 echo "SALT_MODELS_SYSTEM_TAG={{ SALT_MODELS_SYSTEM_TAG }}"
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300362 {%- endif %}
363 echo "======================================="
364 node_name: {{ HOSTNAME_CFG01 }}
365 retry: {count: 1, delay: 1}
366 skip_fail: false
367
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300368- description: Create cluster model from cookiecutter templates
369 cmd: |
370 set -e;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300371 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300372 pip install cookiecutter
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300373 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /tmp/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200374
sgudza399dc72018-01-18 17:13:48 +0200375 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
376 pushd /tmp/cookiecutter-templates
377 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
378 popd
379 {%- endif %}
380
sgudz4d816eb2017-11-13 11:58:05 +0200381 {%- if COOKIECUTTER_REF_CHANGE != '' %}
382 pushd /tmp/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300383 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200384 popd
385 {%- endif %}
386
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300387 {%- if COOKIECUTTER_TAG != '' %}
388 pushd /tmp/cookiecutter-templates
389 git fetch --all --tags --prune
390 git checkout tags/{{ COOKIECUTTER_TAG }}
391 popd
392 {%- endif %}
393
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300394 mkdir -p /srv/salt/reclass/classes/cluster/
395 mkdir -p /srv/salt/reclass/classes/system/
396 mkdir -p /srv/salt/reclass/classes/service/
397 mkdir -p /srv/salt/reclass/nodes/_generated
398
399 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200400 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
401 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200402 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300403 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200404 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300405 {%- endif %}
406 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200407 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300408 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300409
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300410 # Replace firstly to an intermediate value to avoid intersection between
411 # already replaced and replacing networks.
412 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
413 # 192.168.10 -> 10.16.0 (generated network for admin)
414 # 10.16.0 -> <external network>
415 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300416 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /tmp/cookiecutter-templates"
417 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
418 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
419 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
420 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300421
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300422 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
423 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
424 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
425 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 +0300426
sgudz160b7302017-12-22 17:01:10 +0200427 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
428 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300429 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200430 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300431 --config-file {{ CLUSTER_CONTEXT_PATH }} \
432 --output-dir /srv/salt/reclass/classes/cluster/;
433 done
434
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300435 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300436
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200437 # Create the cfg01 inventory file or use existing
438 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
439 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300440 classes:
441 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200442 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300443 EOF
444
445 node_name: {{ HOSTNAME_CFG01 }}
446 retry: {count: 1, delay: 1}
447 skip_fail: false
448
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300449- description: Modify generated model and reclass-system if necessary
450 cmd: |
451 set -e;
452 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
453 pushd /srv/salt/reclass/classes/system/
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300454 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
455 popd;
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300456 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
457 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300458 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300459 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300460 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300461 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300462 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
463 pushd /srv/salt/reclass/classes/system/
464 git fetch --all --tags --prune
465 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
466 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300467 {%- endif %}
468
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300469 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200470 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300471 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
472 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
473 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
474 {%- endif %}
475
476 node_name: {{ HOSTNAME_CFG01 }}
477 retry: {count: 1, delay: 1}
478 skip_fail: false
479{%- endmacro %}
480
481
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300482{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
483{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300484
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200485- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300486 cmd: |
487 set -e;
488 mkdir -p /tmp/environment/;
489 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 +0300490 node_name: {{ HOSTNAME_CFG01 }}
491 skip_fail: false
492
sgudzcced67d2017-10-11 15:56:09 +0300493{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
494- description: Fetch changes for environment templates
495 cmd: |
496 set -e;
497 pushd /tmp/environment/environment_template &&
498 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
499 git checkout FETCH_HEAD &&
500 popd
501 node_name: {{ HOSTNAME_CFG01 }}
502 skip_fail: false
503{%- endif %}
504
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300505{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200506- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300507 upload:
508 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
509 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
510 remote_path: /tmp/environment/
511 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300512{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300513
514- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
515 cmd: |
516 set -e;
517 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200518 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
519 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300520 pip install git+https://github.com/dis-xcom/reclass-tools;
521 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
522 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
523 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
524
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500525 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
526 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
527 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 +0300528 fi;
529
530 node_name: {{ HOSTNAME_CFG01 }}
531 retry: {count: 1, delay: 5}
532 skip_fail: false
533
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200534- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300535 cmd: |
536 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200537 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 +0300538
539 node_name: {{ HOSTNAME_CFG01 }}
540 retry: {count: 1, delay: 5}
541 skip_fail: false
542
543- description: "[EXPERIMENTAL] Create environment model for virtual environment"
544 cmd: |
545 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200546 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300547 reclass-tools render --template-dir /tmp/environment/environment_template/ \
548 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300549 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300550 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
551 node_name: {{ HOSTNAME_CFG01 }}
552 retry: {count: 1, delay: 5}
553 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300554
555- description: Modify generated model and reclass-system
556 cmd: |
557 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
558 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
559 node_name: {{ HOSTNAME_CFG01 }}
560 retry: {count: 1, delay: 1}
561 skip_fail: false
562
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300563{%- endmacro %}
564
565
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300566{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
567{#######################################################}
568- description: Configure reclass
569 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300570 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300571 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300572 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200573 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200574 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
575 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300576 apt-get clean; apt-get update;
577 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
578 declare -a formula_services=({{ FORMULA_SERVICES }});
579 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200580 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300581 for formula_service in "${formula_services[@]}"; do
582 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
583 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
584 done;
585 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
586 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
587 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
588
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200589 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300590 storage_type: yaml_fs
591 pretty_print: True
592 output: yaml
593 inventory_base_uri: /srv/salt/reclass
594 EOF
595 node_name: {{ HOSTNAME_CFG01 }}
596 retry: {count: 1, delay: 1}
597 skip_fail: false
598
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200599- 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 +0300600 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200601 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
602 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300603 node_name: {{ HOSTNAME_CFG01 }}
604 retry: {count: 1, delay: 5}
605 skip_fail: false
606
607- description: Configure salt adoptors on cfg01
608 cmd: |
609 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
610 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
611 node_name: {{ HOSTNAME_CFG01 }}
612 retry: {count: 1, delay: 1}
613 skip_fail: false
614
615- description: Show reclass-salt --top for cfg01 node
616 cmd: reclass-salt --top
617 node_name: {{ HOSTNAME_CFG01 }}
618 retry: {count: 1, delay: 5}
619 skip_fail: false
620
621- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400622 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300623 node_name: {{ HOSTNAME_CFG01 }}
624 retry: {count: 1, delay: 5}
625 skip_fail: false
626{%- endmacro %}
627
628
629{%- macro MACRO_INSTALL_SALT_MINIONS() %}
630{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200631{%- for ssh in config.underlay.ssh %}
632 {%- set salt_roles = [] %}
633 {%- for role in ssh['roles'] %}
634 {%- if role in config.salt_deploy.salt_roles %}
635 {%- set _ = salt_roles.append(role) %}
636 {%- endif %}
637 {%- endfor %}
638
639 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300640- description: Configure salt-minion on {{ ssh['node_name'] }}
641 cmd: |
642 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200643 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300644 id: {{ ssh['node_name'] }}
645 master: {{ config.salt.salt_master_host }}
646 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200647
648 # Configure ubuntu and salt repositories
649 which wget >/dev/null || (apt-get update; apt-get install -y wget);
650
651 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
652 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
653 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
654 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
655
656 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300657 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
658
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200659
660 apt-get clean
661 apt-get update
662
663 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300664 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200665 # Install common packages
666 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200667 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200668 # Restart salt-minion if it was already installed
669 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300670 node_name: {{ ssh['node_name'] }}
671 retry: {count: 1, delay: 1}
672 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200673 {%- else %}
674- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
675 cmd: echo "SSH to $(hostname -f) passed"
676 node_name: {{ ssh['node_name'] }}
677 retry: {count: 1, delay: 1}
678 skip_fail: false
679 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300680
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200681{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300682
683- description: Accept salt keys from all the nodes
684 cmd: salt-key -A -y
685 node_name: {{ HOSTNAME_CFG01 }}
686 retry: {count: 1, delay: 5}
687 skip_fail: true
688{%- endmacro %}
689
690
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200691{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
692{#######################################################}
693- description: Configure reclass
694 cmd: |
695 set -e;
696 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
697 which wget > /dev/null || (apt-get update; apt-get install -y wget);
698 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
699 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
700 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
701 apt-get clean; apt-get update;
702 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
703 declare -a formula_services=({{ FORMULA_SERVICES }});
704 echo -e "\nInstalling all required salt formulas\n";
705 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
706 for formula_service in "${formula_services[@]}"; do
707 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
708 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
709 done;
710 node_name: {{ HOSTNAME_CFG01 }}
711 retry: {count: 1, delay: 1}
712 skip_fail: false
713
714- description: Show reclass-salt --top for cfg01 node
715 cmd: reclass-salt --top
716 node_name: {{ HOSTNAME_CFG01 }}
717 retry: {count: 1, delay: 5}
718 skip_fail: false
719
720- description: Restart salt-master service
721 cmd: systemctl restart salt-master;
722 node_name: {{ HOSTNAME_CFG01 }}
723 retry: {count: 1, delay: 5}
724 skip_fail: false
725{%- endmacro %}
726
727{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
728{#######################################}
729- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
730 cmd: |
731 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
732 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
733 service salt-minion restart
734
735 while true; do
736 salt-key | grep "$SALT_MASTER_MINION_ID" && break
737 sleep 5
738 done
739
740 sleep 5
741
742 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
743 salt-key -d $i -y
744 done
745 node_name: {{ HOSTNAME_CFG01 }}
746 retry: {count: 1, delay: 1}
747 skip_fail: false
748{%- endmacro %}
749
750
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300751{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
752{##################################################}
753
754{# Prepare salt services and nodes settings #}
755
756- description: Run 'linux' formula on cfg01
757 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
758 node_name: {{ HOSTNAME_CFG01 }}
759 retry: {count: 3, delay: 5}
760 skip_fail: false
761
762- description: Run 'openssh' formula on cfg01
763 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300764 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300765 salt --hard-crash --state-output=mixed --state-verbose=False
766 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300767 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300768 node_name: {{ HOSTNAME_CFG01 }}
769 retry: {count: 3, delay: 5}
770 skip_fail: false
771
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300772- description: '*Workaround* of harcoded host from day01 grains'
773 cmd: salt-key -d cfg01.mcp-day01.local -y
774 node_name: {{ HOSTNAME_CFG01 }}
775 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400776 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300777
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300778- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
779 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
780 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
781 node_name: {{ HOSTNAME_CFG01 }}
782 retry: {count: 1, delay: 1}
783 skip_fail: false
784
785- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300786 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 +0300787 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300788 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300789 skip_fail: false
790
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400791{%- if SALT_FORMULAS_REFS != '' %}
792- description: Replace needed formulas to desired version
793 cmd: |
794 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400795 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
796 {% set formula = formula_set.split(':') %}
797 {% set formula_name = formula[0] %}
798 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300799 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400800 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
801 pushd {{ formula_dir }} &&
802 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
803 git checkout FETCH_HEAD &&
804 popd &&
805 if [ -d "{{ formula_dir }}" ]; then
806 echo "Going to replace packaged formula {{ formula_name }}" &&
807 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400808 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
809 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400810 else
811 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
812 fi
813 {%- endfor %}
814 node_name: {{ HOSTNAME_CFG01 }}
815 retry: {count: 1, delay: 10}
816 skip_fail: false
817{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300818
819- description: Refresh pillars on salt-master minion
820 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
821 node_name: {{ HOSTNAME_CFG01 }}
822 retry: {count: 1, delay: 5}
823 skip_fail: false
824
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300825- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300826 cmd: reclass-salt --top
827 node_name: {{ HOSTNAME_CFG01 }}
828 retry: {count: 1, delay: 5}
829 skip_fail: false
830
831- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300832 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 +0300833 node_name: {{ HOSTNAME_CFG01 }}
834 retry: {count: 1, delay: 5}
835 skip_fail: false
836
837- description: Configure linux on master
838 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
839 node_name: {{ HOSTNAME_CFG01 }}
840 retry: {count: 1, delay: 5}
841 skip_fail: false
842
843- description: Configure salt.minion on master
844 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
845 -C 'I@salt:master' state.sls salt.minion && sleep 10
846 node_name: {{ HOSTNAME_CFG01 }}
847 retry: {count: 3, delay: 10}
848 skip_fail: false
849
850- description: Run state 'salt' on master (for salt.api, etc)
851 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
852 -C 'I@salt:master' state.sls salt
853 node_name: {{ HOSTNAME_CFG01 }}
854 retry: {count: 3, delay: 10}
855 skip_fail: false
856{%- endmacro %}
857
Dennis Dmitriev85559962018-01-30 15:35:51 +0200858{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
859{#################################################################}
860
861- description: Refresh pillars before generating nodes
862 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
863 node_name: {{ HOSTNAME_CFG01 }}
864 retry: {count: 1, delay: 5}
865 skip_fail: false
866
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200867- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200868 cmd: |
869 set -e
870 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
871 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 +0200872 node_name: {{ HOSTNAME_CFG01 }}
873 retry: {count: 1, delay: 5}
874 skip_fail: false
875
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300876- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
877 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
878 -C 'I@salt:master' state.sls reclass
879 node_name: {{ HOSTNAME_CFG01 }}
880 retry: {count: 1, delay: 5}
881 skip_fail: false
882
Dennis Dmitriev85559962018-01-30 15:35:51 +0200883{%- if RERUN_SALTMASTER_STATE %}
884- description: Regenerate salt.master states for the newly uploaded/created model
885 cmd: |
886 # Need to refresh installed formulas that are required in the model
887 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
888 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
889 node_name: {{ HOSTNAME_CFG01 }}
890 retry: {count: 1, delay: 5}
891 skip_fail: false
892{%- endif %}
893
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300894- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200895 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300896 node_name: {{ HOSTNAME_CFG01 }}
897 retry: {count: 1, delay: 5}
898 skip_fail: false
899
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300900- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300901 cmd: |
902 set -e
903 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
904 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
905 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300906 node_name: {{ HOSTNAME_CFG01 }}
907 retry: {count: 1, delay: 5}
908 skip_fail: false
909
910- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300911 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300912 node_name: {{ HOSTNAME_CFG01 }}
913 retry: {count: 1, delay: 5}
914 skip_fail: false
915{%- endmacro %}
916
917
918{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
919{########################################}
920# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200921
922- description: Get linux kernel version from all minions
923 cmd: |
924 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
925 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
926 node_name: {{ HOSTNAME_CFG01 }}
927 retry: {count: 5, delay: 10}
928 skip_fail: false
929
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300930- description: Configure linux on other nodes
931 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
932 node_name: {{ HOSTNAME_CFG01 }}
933 retry: {count: 5, delay: 10}
934 skip_fail: false
935
936- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300937 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 +0300938 salt --hard-crash --state-output=mixed --state-verbose=False
939 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300940 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300941 node_name: {{ HOSTNAME_CFG01 }}
942 retry: {count: 1, delay: 5}
943 skip_fail: false
944
945- description: Configure salt.minion on other nodes
946 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 +0400947 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300948 node_name: {{ HOSTNAME_CFG01 }}
949 retry: {count: 3, delay: 15}
950 skip_fail: false
951
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400952- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400953 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400954 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400955 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400956 skip_fail: false
957
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400958- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200959 cmd: |
960 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
961 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400962 node_name: {{ HOSTNAME_CFG01 }}
963 retry: {count: 1, delay: 10}
964 skip_fail: false
965
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200966- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
967 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
968 node_name: {{ HOSTNAME_CFG01 }}
969 retry: {count: 1, delay: 10}
970 skip_fail: false
971
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300972- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400973 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300974 node_name: {{ HOSTNAME_CFG01 }}
975 retry: {count: 3, delay: 15}
976 skip_fail: false
977
978- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400979 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300980 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400981 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300982 skip_fail: false
983
984- description: Configure ntp and rsyslog on nodes
985 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
986 node_name: {{ HOSTNAME_CFG01 }}
987 retry: {count: 1, delay: 10}
988 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200989{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300990
991
992{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
993{#########################################}
994
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300995- description: '*Workaround: Load bonding module before call state.linux'
996 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
997 node_name: {{ HOSTNAME_CFG01 }}
998 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300999 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001000
1001- description: '*Workaround* install bridge-utils before running linux formula'
1002 # The formula removes default route and then tries to install the package, fails.
1003 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1004 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1005 node_name: {{ HOSTNAME_CFG01 }}
1006 retry: {count: 1, delay: 5}
1007 skip_fail: false
1008
1009{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001010
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001011
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001012{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001013{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001014
1015- description: Set k8s deploy parameters
1016 cmd: |
1017 {% for k8s_opt, value in config.k8s_deploy.items() %}
1018 {% if value|string() %}
1019 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1020 {% endif %}
1021 {% endfor %}
1022 node_name: {{ HOSTNAME_CFG01 }}
1023 retry: {count: 1, delay: 1}
1024 skip_fail: false
1025
1026{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001027
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001028
1029{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1030{#############################################}
1031- description: Set SL docker images deploy parameters
1032 cmd: |
1033 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1034 {%- for sl_opt, value in config.sl_deploy.items() %}
1035 {%- if value|string() %}
1036 {%- if OVERRIDES_FILENAME %}
1037 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1038 {%- else %}
1039 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1040 {%- endif %}
1041 {%- endif %}
1042 {%- endfor %}
1043 salt '*' saltutil.refresh_pillar;
1044 sleep 10
1045 node_name: {{ HOSTNAME_CFG01 }}
1046 retry: {count: 1, delay: 1}
1047 skip_fail: false
1048{%- endmacro %}
1049
1050
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001051{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001052{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001053
1054{% for ssh in config.underlay.ssh %}
1055{% if ssh["node_name"].startswith("cmp") %}
1056{% set node_hostname = ssh["node_name"].split('.')[0] %}
1057- description: Register compute {{ ssh['node_name'] }}
1058 cmd: |
1059 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1060 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1061 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001062 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001063 export config_host={{ config.salt.salt_master_host }}
1064 export node_domain={{ DOMAIN_NAME }}
1065 export nodes_os="xenial"
1066 export node_hostname={{ node_hostname }}
1067 set -xe
1068 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1069 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1070 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1071 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1072
1073 # Add wrapper to apt-get to avoid race conditions
1074 # with cron jobs running 'unattended-upgrades' script
1075 aptget_wrapper() {
1076 local apt_wrapper_timeout=300
1077 local start_time=$(date '+%s')
1078 local fin_time=$((start_time + apt_wrapper_timeout))
1079 while true; do
1080 if (( "$(date '+%s')" > fin_time )); then
1081 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1082 fi
1083 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1084 echo "Waiting while another apt/dpkg process releases locks ..."
1085 sleep 30
1086 continue
1087 else
1088 apt-get $@
1089 break
1090 fi
1091 done
1092 }
1093
1094 # Set default salt version
1095 if [ -z "$saltversion" ]; then
1096 saltversion="2016.3"
1097 fi
1098 echo "Using Salt version $saltversion"
1099
1100 echo "Preparing base OS ..."
1101
1102 case "$node_os" in
1103 trusty)
1104 # workaround for old cloud-init only configuring the first iface
1105 iface_config_dir="/etc/network/interfaces"
1106 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1107
1108 for iface in $ifaces; do
1109 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1110 done
1111
1112 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1113
1114 # SUGGESTED UPDATE:
1115 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1116 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1117 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1118 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1119 #install_salt_minion_pkg
1120
1121 # DEPRECATED:
1122 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1123 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1124
1125 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1126 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1127
1128 aptget_wrapper clean
1129 aptget_wrapper update
1130 aptget_wrapper install -y salt-common
1131 aptget_wrapper install -y salt-minion
1132 ;;
1133 xenial)
1134
1135 # workaround for new cloud-init setting all interfaces statically
1136 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1137
1138 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1139
1140 # SUGGESTED UPDATE:
1141 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1142 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1143 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1144 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1145 #install_salt_minion_pkg
1146
1147 # DEPRECATED:
1148 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1149 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1150
1151 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1152 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1153
1154 aptget_wrapper clean
1155 aptget_wrapper update
1156 aptget_wrapper install -y salt-minion
1157 ;;
1158 rhel|centos|centos7|centos7|rhel6|rhel7)
1159 yum install -y git
1160 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1161 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1162 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1163 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1164 install_salt_minion_pkg
1165 ;;
1166 *)
1167 msg="OS '$node_os' is not supported."
1168 esac
1169
1170 echo "Configuring Salt minion ..."
1171 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1172 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1173
1174 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1175
1176 sleep 1
1177
1178 echo "Classifying node ..."
1179 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1180 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1181 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1182 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1183 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1184 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1185
1186 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1187 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1188 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1189 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1190 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1191
1192 if [ "$node_network05_iface" != "" ]; then
1193 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1194 fi
1195
1196 # find more parameters (every env starting param_)
1197 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1198 if [ "$more_params" != "" ]; then
1199 echo "Additional params: $more_params"
1200 more_params=", $more_params"
1201 fi
1202
1203 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}}"
1204
1205 sleep 5
1206
1207 salt-call saltutil.sync_all
1208 salt-call mine.flush
1209 salt-call mine.update
1210 node_name: {{ ssh['node_name'] }}
1211 retry: {count: 1, delay: 1}
1212 skip_fail: false
1213{%- endif %}
1214{%- endfor %}
1215
1216- description: Refresh pillars on all minions
1217 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1218 node_name: {{ HOSTNAME_CFG01 }}
1219 retry: {count: 1, delay: 5}
1220 skip_fail: false
1221
1222- description: Sync all salt resources
1223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1224 node_name: {{ HOSTNAME_CFG01 }}
1225 retry: {count: 1, delay: 5}
1226 skip_fail: false
1227
sgudz160b7302017-12-22 17:01:10 +02001228{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001229
1230{%- macro RUN_NEW_TEMPEST() %}
1231{###################################}
1232
1233- description: Upload tempest template
1234 upload:
1235 local_path: {{ config.salt_deploy.templates_dir }}
1236 local_filename: runtest.yml
1237 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1238 node_name: {{ HOSTNAME_CFG01 }}
1239 skip_fail: False
1240
1241- description: Include class with tempest template into cfg node
1242 cmd: |
1243 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1244 salt 'cfg01*' saltutil.refresh_pillar;
1245 salt 'cfg01*' saltutil.sync_all;
1246 node_name: {{ HOSTNAME_CFG01 }}
1247 retry: {count: 1, delay: 10}
1248 skip_fail: false
1249
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001250- description: Execute salt.minion on config node
1251 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1252 node_name: {{ HOSTNAME_CFG01 }}
1253 retry: {count: 1, delay: 5}
1254 skip_fail: false
1255
1256- description: Test ping
1257 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1258 node_name: {{ HOSTNAME_CFG01 }}
1259 retry: {count: 1, delay: 5}
1260 skip_fail: false
1261
sgudz09e9aa92018-04-12 12:31:53 +03001262- description: Create flavors for tests
1263 cmd: |
1264 salt 'cfg01*' state.sls nova.client;
1265 node_name: {{ HOSTNAME_CFG01 }}
1266 retry: {count: 1, delay: 5}
1267 skip_fail: false
1268
1269- description: Create networks for tests
1270 cmd: |
1271 salt 'cfg01*' state.sls neutron.client;
1272 node_name: {{ HOSTNAME_CFG01 }}
1273 retry: {count: 1, delay: 5}
1274 skip_fail: false
1275
1276- description: Upload cirros image
1277 cmd: |
1278 salt 'cfg01*' state.sls glance.client;
1279 node_name: {{ HOSTNAME_CFG01 }}
1280 retry: {count: 1, delay: 5}
1281 skip_fail: false
1282
1283- description: Generate tempest config
1284 cmd: |
1285 salt 'cfg01*' state.sls runtest;
1286 node_name: {{ HOSTNAME_CFG01 }}
1287 retry: {count: 1, delay: 5}
1288 skip_fail: false
1289
1290- description: Run tempest from new docker image
1291 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001292 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 +03001293 node_name: {{ HOSTNAME_GTW01 }}
1294 retry: {count: 1, delay: 30}
1295 skip_fail: true
1296
1297- description: Download xml results
1298 download:
1299 remote_path: /root/test/
1300 remote_filename: "report_*.xml"
1301 local_path: {{ os_env('PWD') }}
1302 node_name: {{ HOSTNAME_GTW01 }}
1303 skip_fail: true
1304
1305{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001306
1307{%- macro INSTALL_DOCKER_ON_GTW() %}
1308{###################################}
1309
1310- description: Install docker.io on gtw
1311 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1312 node_name: {{ HOSTNAME_GTW01 }}
1313 retry: {count: 1, delay: 30}
1314 skip_fail: false
1315
1316- description: Enable forward policy
1317 cmd: iptables --policy FORWARD ACCEPT
1318 node_name: {{ HOSTNAME_GTW01 }}
1319 retry: {count: 1, delay: 30}
1320 skip_fail: false
1321
1322{%- endmacro %}