blob: 80acaaf08256bcd271ac98e83f95a6a61b7a2d74 [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 #}
Dennis Dmitriev0f272312018-10-01 13:29:40 +03008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.com/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 Dmitriev0f272312018-10-01 13:29:40 +030012{% set COOKIECUTTER_TEMPLATES_REPOSITORY = os_env('COOKIECUTTER_TEMPLATES_REPOSITORY','https://gerrit.mcp.mirantis.com/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','') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030017# Currently we support 2 salt version that can be set over bellow var
Tatyana Leontovich14e201d2018-07-05 13:28:54 +030018{% set SALT_VERSION = os_env('SALT_VERSION','2017.7') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030019{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020020{% 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 +020021{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +030022#{# set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") #}
23# Note repo is changed so new one looks like defined bellow
24{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-" + SALT_VERSION+ "/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020025{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
26{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
27{% 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") %}
28{% 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 +030029{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030030{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030031
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020032{# Address pools for reclass cluster model are taken in the following order:
33 # 1. environment variables,
34 # 2. config.underlay.address_pools based on fuel-devops address pools
35 # (see generated '.ini' file after underlay is created),
36 # 3. defaults #}
37{% set address_pools = config.underlay.address_pools %}
38{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
39{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
40{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
41{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
42{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
43{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
44{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
45{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
46
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040047{# Format for formula replacement:
48 # space separated string:
49 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
50
51{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030052{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030053{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Dennis Dmitriev0f272312018-10-01 13:29:40 +030054{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.com/salt-formulas') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040055
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040056# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020057{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040058
Dennis Dmitriev492813e2017-08-09 15:08:58 +030059
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020060{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
61{#####################################################}
62
63- description: 'Configure key on nodes and install packages'
64 cmd: |
65 rm -rf trusted* ;
66 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020067 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020068 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
69 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
70 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030071 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020072 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
73 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
74 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050075 eatmydata apt-get clean;
76 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020077 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020078 node_name: {{ NODE_NAME }}
79 retry: {count: 1, delay: 5}
80 skip_fail: false
81
82{%- endmacro %}
83
84
Dennis Dmitriev492813e2017-08-09 15:08:58 +030085{%- macro MACRO_INSTALL_SALT_MASTER() %}
86{######################################}
87- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020088 cmd: |
89 which wget >/dev/null || (apt-get update; apt-get install -y wget);
90 # Configure ubuntu and salt repositories
91 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
92 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
93 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
94 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
95
96 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
97 wget -O - {{ FORMULA_GPG }} | apt-key add -;
98 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030099 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
100
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200101
102 apt-get clean
103 apt-get update
104
105 # Install salt-master and reclass
106 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
107 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200108 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 +0200109 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300110 node_name: {{ HOSTNAME_CFG01 }}
111 retry: {count: 1, delay: 1}
112 skip_fail: false
113
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200114- description: Remove any existing minion keys
115 cmd: salt-key -y -D || true
116 node_name: {{ HOSTNAME_CFG01 }}
117 retry: {count: 1, delay: 1}
118 skip_fail: false
119
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300120- description: Configure salt-master on cfg01
121 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200122 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300123 file_roots:
124 base:
125 - /usr/share/salt-formulas/env
126 pillar_opts: False
127 open_mode: True
128 reclass: &reclass
129 storage_type: yaml_fs
130 inventory_base_uri: /srv/salt/reclass
131 ext_pillar:
132 - reclass: *reclass
133 master_tops:
134 reclass: *reclass
135 EOF
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 1, delay: 1}
138 skip_fail: false
139
140- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300141 cmd: |
142 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200143 #touch /root/.git_trusted_certs.pem;
144 #for server in github.com; do \
145 # openssl s_client -showcerts -connect $server:443 </dev/null \
146 # | openssl x509 -outform PEM \
147 # >> /root/.git_trusted_certs.pem;
148 #done;
149 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
150 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
151 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300152 node_name: {{ HOSTNAME_CFG01 }}
153 retry: {count: 1, delay: 1}
154 skip_fail: false
155{%- endmacro %}
156
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200157
158{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
159{######################################}
160
161- description: Remove /etc/update-motd.d/52-info
162 cmd: rm -vf /etc/update-motd.d/52-info
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 10}
165 skip_fail: false
166
167- description: Set up static interface config
168 cmd: |
169 kill $(pidof /sbin/dhclient) || /bin/true
170 cat << 'EOF' > /etc/network/interfaces
171 # This file describes the network interfaces available on your system
172 # and how to activate them. For more information, see interfaces(5).
173
174 # The loopback network interface
175 auto lo
176 iface lo inet loopback
177
178 # The primary network interface
179 auto ens3
180 iface ens3 inet static
181 address {{ IPV4_NET_ADMIN_PREFIX }}.90
182 netmask 255.255.255.0
183 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
184 EOF
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 1, delay: 10}
187 skip_fail: false
188
189- description: Install common packages on cfg01
190 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
191 node_name: {{ HOSTNAME_CFG01 }}
192 retry: {count: 1, delay: 1}
193 skip_fail: false
194
195- description: Remove any existing minion keys
196 cmd: salt-key -y -D || true
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 1}
199 skip_fail: false
200
201- description: Configure GIT settings and certificates
202 cmd: |
203 set -e;
204 #touch /root/.git_trusted_certs.pem;
205 #for server in github.com; do \
206 # openssl s_client -showcerts -connect $server:443 </dev/null \
207 # | openssl x509 -outform PEM \
208 # >> /root/.git_trusted_certs.pem;
209 #done;
210 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
211 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
212 HOME=/root git config --global user.name "MCP Integration QA";
213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 1, delay: 1}
215 skip_fail: false
216{%- endmacro %}
217
218
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300219{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300220{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300221{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
222
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300223- description: Clone reclass models with submodules
224 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300225 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200226 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200227 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200228
229 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
230 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 +0200231 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200232
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200233 pushd /srv/salt/reclass;
234 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
235 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200236 {%- if SALT_MODELS_REF_CHANGE != '' %}
237 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200238 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200239 {%- endfor %}
240 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200241 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200242 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300243
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300244 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300245 pushd classes/system/ && \
246 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200247 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300248 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200249 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300250 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
251 pushd classes/system/;
252 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
253 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300254 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
255 pushd classes/system/;
256 git fetch --all --tags --prune
257 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
258 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200259 {%- endif %}
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300260
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200261 popd;
262 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300263 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200264
265 # Replace firstly to an intermediate value to avoid intersection between
266 # already replaced and replacing networks.
267 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
268 # 192.168.10 -> 10.16.0 (generated network for admin)
269 # 10.16.0 -> <external network>
270 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300271 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200272 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
273 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
274 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
275 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300276 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
277 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200278
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200279 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
280 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
281 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
282 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 +0200283
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300284 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 +0200285
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300286 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300287 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300288 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 +0300289 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 +0300290 {%- endif %}
291
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200292 # Override some context parameters
293 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
294 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
295 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
296
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200297 # Create the cfg01 inventory file or use existing
298 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
299 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300300 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400301 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300302 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200303 - cluster.{{ CLUSTER_NAME }}.infra.maas
304 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300305 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300306 parameters:
307 _param:
308 linux_system_codename: xenial
309 reclass_data_revision: master
310 linux:
311 system:
312 name: cfg01
313 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200314 reclass:
315 storage:
316 data_source:
317 engine: local
318 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300319
320 # Show the changes to the console
321 cd /srv/salt/reclass/; git diff
322 node_name: {{ HOSTNAME_CFG01 }}
323 retry: {count: 1, delay: 1}
324 skip_fail: false
325{%- endmacro %}
326
327
sgudz160b7302017-12-22 17:01:10 +0200328{%- 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 +0300329{###################################################################}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300330{%- set CLUSTER_CONTEXT_PATH = '/root/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200331- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300332 upload:
333 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
334 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300335 remote_path: /root/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300336 node_name: {{ HOSTNAME_CFG01 }}
337
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300338- description: "Show options enabled in the context file for model generation"
339 cmd: |
340 echo "===== Options enabled in the context for generation the model {{ LAB_CONFIG_NAME }} ====="
341 fgrep "True" {{ CLUSTER_CONTEXT_PATH }}
342 echo "===== Sources for model generation ====="
343 echo "# mcp_version: {{ REPOSITORY_SUITE }}"
344 echo "COOKIECUTTER_TEMPLATES_REPOSITORY={{ COOKIECUTTER_TEMPLATES_REPOSITORY }}"
345 {%- if CLUSTER_PRODUCT_MODELS != '' %}
346 echo "CLUSTER_PRODUCT_MODELS={{ CLUSTER_PRODUCT_MODELS }}"
347 {%- endif %}
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300348 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300349 echo "COOKIECUTTER_REF_CHANGE={{ COOKIECUTTER_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300350 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
351 echo "COOKIECUTTER_TEMPLATE_COMMIT={{ COOKIECUTTER_TEMPLATE_COMMIT }}"
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300352 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300353 echo "COOKIECUTTER_TAG={{ COOKIECUTTER_TAG }}"
354 {%- endif %}
355 echo "SALT_MODELS_SYSTEM_REPOSITORY={{ SALT_MODELS_SYSTEM_REPOSITORY }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300356 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300357 echo "SALT_MODELS_SYSTEM_REF_CHANGE={{ SALT_MODELS_SYSTEM_REF_CHANGE }}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300358 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
359 echo "SALT_MODELS_SYSTEM_COMMIT={{ SALT_MODELS_SYSTEM_COMMIT }}"
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;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300371 set -x;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300372 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300373 pip install cookiecutter
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300374 export GIT_SSL_NO_VERIFY=true; git clone {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} /root/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200375
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300376 {%- if COOKIECUTTER_REF_CHANGE != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300377 pushd /root/cookiecutter-templates
Dennis Dmitrievbcf94f82018-07-03 10:06:06 +0300378 git fetch {{ COOKIECUTTER_TEMPLATES_REPOSITORY }} {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
sgudz4d816eb2017-11-13 11:58:05 +0200379 popd
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300380 {%- elif COOKIECUTTER_TEMPLATE_COMMIT != '' %}
381 pushd /root/cookiecutter-templates
382 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
383 popd
Dennis Dmitriev713dce22018-07-03 11:47:46 +0300384 {%- elif COOKIECUTTER_TAG != '' %}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300385 pushd /root/cookiecutter-templates
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300386 git fetch --all --tags --prune
387 git checkout tags/{{ COOKIECUTTER_TAG }}
388 popd
389 {%- endif %}
390
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300391 mkdir -p /srv/salt/reclass/classes/cluster/
392 mkdir -p /srv/salt/reclass/classes/system/
393 mkdir -p /srv/salt/reclass/classes/service/
394 mkdir -p /srv/salt/reclass/nodes/_generated
395
396 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200397 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
398 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200399 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300400 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200401 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300402 {%- endif %}
403 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200404 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300405 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300406
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300407 # Replace firstly to an intermediate value to avoid intersection between
408 # already replaced and replacing networks.
409 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
410 # 192.168.10 -> 10.16.0 (generated network for admin)
411 # 10.16.0 -> <external network>
412 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300413 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /root/cookiecutter-templates"
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300414 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
415 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
416 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
417 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300418
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300419 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
420 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
421 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
422 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 +0300423
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300424 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /root/cookiecutter-templates/cluster_product/)' %}
sgudz160b7302017-12-22 17:01:10 +0200425 for item in {{ items }}; do
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300426 python /root/cookiecutter-templates/generate.py \
427 --template /root/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300428 --config-file {{ CLUSTER_CONTEXT_PATH }} \
429 --output-dir /srv/salt/reclass/classes/cluster/;
430 done
431
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300432 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300433
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200434 # Create the cfg01 inventory file or use existing
435 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
436 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300437 classes:
438 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200439 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300440 EOF
441
442 node_name: {{ HOSTNAME_CFG01 }}
443 retry: {count: 1, delay: 1}
444 skip_fail: false
445
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300446- description: Modify generated model and reclass-system if necessary
447 cmd: |
448 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300449 set -x;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300450 {%- if SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300451 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300452 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300453 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300454 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300455 popd;
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300456 {%- elif SALT_MODELS_SYSTEM_COMMIT != '' %}
457 pushd /srv/salt/reclass/classes/system/
458 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
459 popd;
Dennis Dmitriev5f9cf2e2018-07-03 10:36:00 +0300460 {%- elif SALT_MODELS_SYSTEM_TAG != '' %}
461 pushd /srv/salt/reclass/classes/system/
462 git fetch --all --tags --prune
463 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
464 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300465 {%- endif %}
466
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300467 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200468 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300469 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
470 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
471 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
472 {%- endif %}
473
474 node_name: {{ HOSTNAME_CFG01 }}
475 retry: {count: 1, delay: 1}
476 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300477
478- description: Restart salt-api
479 cmd: |
480 set -e;
481 systemctl restart salt-api
482
483 node_name: {{ HOSTNAME_CFG01 }}
484 retry: {count: 1, delay: 1}
485 skip_fail: false
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300486{%- endmacro %}
487
488
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300489{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
490{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300491
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200492- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300493 cmd: |
494 set -e;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300495 mkdir -p /root/environment/;
496 export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /root/environment/environment_template
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300497 node_name: {{ HOSTNAME_CFG01 }}
498 skip_fail: false
499
sgudzcced67d2017-10-11 15:56:09 +0300500{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
501- description: Fetch changes for environment templates
502 cmd: |
503 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300504 set -x;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300505 pushd /root/environment/environment_template &&
sgudzcced67d2017-10-11 15:56:09 +0300506 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
507 git checkout FETCH_HEAD &&
508 popd
509 node_name: {{ HOSTNAME_CFG01 }}
510 skip_fail: false
511{%- endif %}
512
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300513{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200514- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300515 upload:
516 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
517 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300518 remote_path: /root/environment/
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300519 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300520{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300521
522- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
523 cmd: |
524 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300525 set -x;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300526 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200527 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
528 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300529 pip install git+https://github.com/dis-xcom/reclass-tools;
530 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
531 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
532 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
533
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500534 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
535 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
536 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 +0300537 fi;
538
539 node_name: {{ HOSTNAME_CFG01 }}
540 retry: {count: 1, delay: 5}
541 skip_fail: false
542
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200543- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300544 cmd: |
545 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200546 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 +0300547
548 node_name: {{ HOSTNAME_CFG01 }}
549 retry: {count: 1, delay: 5}
550 skip_fail: false
551
552- description: "[EXPERIMENTAL] Create environment model for virtual environment"
553 cmd: |
554 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300555 set -x;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200556 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300557 reclass-tools render --template-dir /root/environment/environment_template/ \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300558 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitriev30841c32018-07-19 20:12:07 +0300559 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /root/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300560 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
561 node_name: {{ HOSTNAME_CFG01 }}
562 retry: {count: 1, delay: 5}
563 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300564
565- description: Modify generated model and reclass-system
566 cmd: |
567 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
568 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
569 node_name: {{ HOSTNAME_CFG01 }}
570 retry: {count: 1, delay: 1}
571 skip_fail: false
572
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300573{%- endmacro %}
574
575
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300576{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
577{#######################################################}
578- description: Configure reclass
579 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300580 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300581 set -x;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300582 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300583 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200584 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200585 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
586 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300587 apt-get clean; apt-get update;
588 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
589 declare -a formula_services=({{ FORMULA_SERVICES }});
590 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200591 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300592 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300593 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
594 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
595 done;
596 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
597 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
598 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
599
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200600 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300601 storage_type: yaml_fs
602 pretty_print: True
603 output: yaml
604 inventory_base_uri: /srv/salt/reclass
605 EOF
606 node_name: {{ HOSTNAME_CFG01 }}
607 retry: {count: 1, delay: 1}
608 skip_fail: false
609
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200610- 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 +0300611 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200612 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
613 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300614 node_name: {{ HOSTNAME_CFG01 }}
615 retry: {count: 1, delay: 5}
616 skip_fail: false
617
618- description: Configure salt adoptors on cfg01
619 cmd: |
620 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
621 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
622 node_name: {{ HOSTNAME_CFG01 }}
623 retry: {count: 1, delay: 1}
624 skip_fail: false
625
626- description: Show reclass-salt --top for cfg01 node
627 cmd: reclass-salt --top
628 node_name: {{ HOSTNAME_CFG01 }}
629 retry: {count: 1, delay: 5}
630 skip_fail: false
631
632- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400633 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300634 node_name: {{ HOSTNAME_CFG01 }}
635 retry: {count: 1, delay: 5}
636 skip_fail: false
637{%- endmacro %}
638
639
640{%- macro MACRO_INSTALL_SALT_MINIONS() %}
641{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200642{%- for ssh in config.underlay.ssh %}
643 {%- set salt_roles = [] %}
644 {%- for role in ssh['roles'] %}
645 {%- if role in config.salt_deploy.salt_roles %}
646 {%- set _ = salt_roles.append(role) %}
647 {%- endif %}
648 {%- endfor %}
649
650 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300651- description: Configure salt-minion on {{ ssh['node_name'] }}
652 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300653 set -ex;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300654 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitriev3fe24dd2018-07-20 18:38:57 +0300655 cat << EOF > /etc/salt/minion.d/minion.conf
656 id: $(hostname -s).{{ DOMAIN_NAME }}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300657 master: {{ config.salt.salt_master_host }}
658 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200659
660 # Configure ubuntu and salt repositories
661 which wget >/dev/null || (apt-get update; apt-get install -y wget);
662
663 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
664 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
665 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
666 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
667
668 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300669 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
670
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200671
672 apt-get clean
673 apt-get update
674
675 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300676 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200677 # Install common packages
678 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200679 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200680 # Restart salt-minion if it was already installed
681 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300682 node_name: {{ ssh['node_name'] }}
683 retry: {count: 1, delay: 1}
684 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200685 {%- else %}
686- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
687 cmd: echo "SSH to $(hostname -f) passed"
688 node_name: {{ ssh['node_name'] }}
689 retry: {count: 1, delay: 1}
690 skip_fail: false
691 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300692
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200693{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300694
695- description: Accept salt keys from all the nodes
696 cmd: salt-key -A -y
697 node_name: {{ HOSTNAME_CFG01 }}
698 retry: {count: 1, delay: 5}
699 skip_fail: true
700{%- endmacro %}
701
702
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200703{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
704{#######################################################}
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300705- description: Install salt formulas
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200706 cmd: |
707 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300708 set -x;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200709 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
710 which wget > /dev/null || (apt-get update; apt-get install -y wget);
711 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
712 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
713 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
714 apt-get clean; apt-get update;
715 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
716 declare -a formula_services=({{ FORMULA_SERVICES }});
717 echo -e "\nInstalling all required salt formulas\n";
718 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev3d28aa32018-07-04 16:14:59 +0300719 for formula_service in $(ls -1 ${FORMULA_PATH}/reclass/service); do
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200720 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
721 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
722 done;
723 node_name: {{ HOSTNAME_CFG01 }}
724 retry: {count: 1, delay: 1}
725 skip_fail: false
Dennis Dmitriev010f0292018-07-28 23:33:48 +0300726
727- description: Sync all salt resources on salt-master minion
728 cmd: salt-call saltutil.sync_all && sleep 5
729 node_name: {{ HOSTNAME_CFG01 }}
730 retry: {count: 1, delay: 5}
731 skip_fail: false
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200732{%- endmacro %}
733
734{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
735{#######################################}
736- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
737 cmd: |
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300738 set -ex;
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200739 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
740 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
741 service salt-minion restart
742
743 while true; do
744 salt-key | grep "$SALT_MASTER_MINION_ID" && break
745 sleep 5
746 done
747
748 sleep 5
749
750 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
751 salt-key -d $i -y
752 done
753 node_name: {{ HOSTNAME_CFG01 }}
754 retry: {count: 1, delay: 1}
755 skip_fail: false
756{%- endmacro %}
757
758
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300759{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
760{##################################################}
761
762{# Prepare salt services and nodes settings #}
763
sgudz6e797562018-10-22 12:27:09 +0300764- description: '*Workaround* of harcoded host from day01 grains'
765 cmd: salt-key -d cfg01.mcp-day01.local -y
766 node_name: {{ HOSTNAME_CFG01 }}
767 retry: {count: 1, delay: 1}
768 skip_fail: true
769
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300770- description: Run 'linux' formula on cfg01
771 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
772 node_name: {{ HOSTNAME_CFG01 }}
773 retry: {count: 3, delay: 5}
774 skip_fail: false
775
776- description: Run 'openssh' formula on cfg01
777 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300778 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300779 salt --hard-crash --state-output=mixed --state-verbose=False
780 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300781 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300782 node_name: {{ HOSTNAME_CFG01 }}
783 retry: {count: 3, delay: 5}
784 skip_fail: false
785
786- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
787 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
788 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
789 node_name: {{ HOSTNAME_CFG01 }}
790 retry: {count: 1, delay: 1}
791 skip_fail: false
792
793- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300794 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 +0300795 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300796 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300797 skip_fail: false
798
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400799{%- if SALT_FORMULAS_REFS != '' %}
800- description: Replace needed formulas to desired version
801 cmd: |
802 set -e;
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300803 set -x;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400804 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
805 {% set formula = formula_set.split(':') %}
806 {% set formula_name = formula[0] %}
807 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300808 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400809 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
810 pushd {{ formula_dir }} &&
811 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
812 git checkout FETCH_HEAD &&
813 popd &&
814 if [ -d "{{ formula_dir }}" ]; then
815 echo "Going to replace packaged formula {{ formula_name }}" &&
816 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400817 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
818 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400819 else
820 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
821 fi
822 {%- endfor %}
823 node_name: {{ HOSTNAME_CFG01 }}
824 retry: {count: 1, delay: 10}
825 skip_fail: false
826{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300827
828- description: Refresh pillars on salt-master minion
829 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
830 node_name: {{ HOSTNAME_CFG01 }}
831 retry: {count: 1, delay: 5}
832 skip_fail: false
833
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300834- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300835 cmd: reclass-salt --top
836 node_name: {{ HOSTNAME_CFG01 }}
837 retry: {count: 1, delay: 5}
838 skip_fail: false
839
840- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300841 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 +0300842 node_name: {{ HOSTNAME_CFG01 }}
843 retry: {count: 1, delay: 5}
844 skip_fail: false
845
846- description: Configure linux on master
847 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
848 node_name: {{ HOSTNAME_CFG01 }}
849 retry: {count: 1, delay: 5}
850 skip_fail: false
851
852- description: Configure salt.minion on master
853 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
854 -C 'I@salt:master' state.sls salt.minion && sleep 10
855 node_name: {{ HOSTNAME_CFG01 }}
856 retry: {count: 3, delay: 10}
857 skip_fail: false
858
859- description: Run state 'salt' on master (for salt.api, etc)
860 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
861 -C 'I@salt:master' state.sls salt
862 node_name: {{ HOSTNAME_CFG01 }}
863 retry: {count: 3, delay: 10}
864 skip_fail: false
Tatyana Leontovich4453dd62018-06-26 18:44:31 +0300865
866- description: Restart salt-api after states
867 cmd: systemctl restart salt-api
868 node_name: {{ HOSTNAME_CFG01 }}
869 retry: {count: 3, delay: 10}
870 skip_fail: false
871
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300872{%- endmacro %}
873
Dennis Dmitriev85559962018-01-30 15:35:51 +0200874{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
875{#################################################################}
876
877- description: Refresh pillars before generating nodes
878 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
879 node_name: {{ HOSTNAME_CFG01 }}
880 retry: {count: 1, delay: 5}
881 skip_fail: false
882
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200883- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200884 cmd: |
885 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300886 set -x;
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200887 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
888 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 +0200889 node_name: {{ HOSTNAME_CFG01 }}
890 retry: {count: 1, delay: 5}
891 skip_fail: false
892
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300893- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
894 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
895 -C 'I@salt:master' state.sls reclass
896 node_name: {{ HOSTNAME_CFG01 }}
897 retry: {count: 1, delay: 5}
898 skip_fail: false
899
Dennis Dmitriev85559962018-01-30 15:35:51 +0200900{%- if RERUN_SALTMASTER_STATE %}
901- description: Regenerate salt.master states for the newly uploaded/created model
902 cmd: |
903 # Need to refresh installed formulas that are required in the model
904 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
905 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
906 node_name: {{ HOSTNAME_CFG01 }}
907 retry: {count: 1, delay: 5}
908 skip_fail: false
909{%- endif %}
910
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300911- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200912 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300913 node_name: {{ HOSTNAME_CFG01 }}
914 retry: {count: 1, delay: 5}
915 skip_fail: false
916
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300917- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300918 cmd: |
919 set -e
Dennis Dmitriev468ce352018-08-14 13:23:31 +0300920 set -x;
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300921 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
922 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
923 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300924 node_name: {{ HOSTNAME_CFG01 }}
925 retry: {count: 1, delay: 5}
926 skip_fail: false
927
928- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300929 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300930 node_name: {{ HOSTNAME_CFG01 }}
931 retry: {count: 1, delay: 5}
932 skip_fail: false
933{%- endmacro %}
934
935
936{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
937{########################################}
938# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200939
940- description: Get linux kernel version from all minions
941 cmd: |
942 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
943 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
944 node_name: {{ HOSTNAME_CFG01 }}
945 retry: {count: 5, delay: 10}
946 skip_fail: false
947
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300948- description: Configure linux on other nodes
949 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
950 node_name: {{ HOSTNAME_CFG01 }}
951 retry: {count: 5, delay: 10}
952 skip_fail: false
953
954- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300955 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 +0300956 salt --hard-crash --state-output=mixed --state-verbose=False
957 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300958 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300959 node_name: {{ HOSTNAME_CFG01 }}
960 retry: {count: 1, delay: 5}
961 skip_fail: false
962
963- description: Configure salt.minion on other nodes
964 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 +0400965 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300966 node_name: {{ HOSTNAME_CFG01 }}
967 retry: {count: 3, delay: 15}
968 skip_fail: false
969
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400970- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400971 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400972 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400973 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400974 skip_fail: false
975
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400976- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200977 cmd: |
978 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300979 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 60
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400980 node_name: {{ HOSTNAME_CFG01 }}
981 retry: {count: 1, delay: 10}
982 skip_fail: false
983
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200984- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
985 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
986 node_name: {{ HOSTNAME_CFG01 }}
987 retry: {count: 1, delay: 10}
988 skip_fail: false
989
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300990- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400991 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300992 node_name: {{ HOSTNAME_CFG01 }}
993 retry: {count: 3, delay: 15}
994 skip_fail: false
995
996- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400997 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300998 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400999 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001000 skip_fail: false
1001
1002- description: Configure ntp and rsyslog on nodes
1003 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
1004 node_name: {{ HOSTNAME_CFG01 }}
1005 retry: {count: 1, delay: 10}
1006 skip_fail: false
Tatyana Leontovich529e4052018-07-09 18:30:48 +03001007
1008- description: Install and configure iptables if it is in pillar
1009 cmd: |
1010 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' match.pillar 'iptables:service' ; then
1011 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@iptables:service' state.sls iptables
1012 fi
1013 node_name: {{ HOSTNAME_CFG01 }}
1014 retry: {count: 1, delay: 10}
1015 skip_fail: false
1016
1017
1018- description: Install and configure logrotate if it is in pillar
1019 cmd: |
1020 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' match.pillar 'logrotate:server' ; then
1021 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@logrotate:server' state.sls logrotate
1022 fi
1023 node_name: {{ HOSTNAME_CFG01 }}
1024 retry: {count: 1, delay: 10}
1025 skip_fail: false
1026
1027- description: Install and configure auditd if it is enabled
1028 cmd: |
1029 if salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" match.pillar 'auditd:service'; then
1030 salt --hard-crash --state-output=mixed --state-verbose=False -C "I@auditd:service" state.sls auditd
1031 fi
1032 node_name: {{ HOSTNAME_CFG01 }}
1033 retry: {count: 1, delay: 10}
1034 skip_fail: false
1035
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02001036{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001037
1038
1039{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
1040{#########################################}
1041
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001042- description: '*Workaround: Load bonding module before call state.linux'
1043 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
1044 node_name: {{ HOSTNAME_CFG01 }}
1045 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +03001046 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +03001047
1048- description: '*Workaround* install bridge-utils before running linux formula'
1049 # The formula removes default route and then tries to install the package, fails.
1050 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
1051 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
1052 node_name: {{ HOSTNAME_CFG01 }}
1053 retry: {count: 1, delay: 5}
1054 skip_fail: false
1055
1056{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001057
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001058
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001059{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001060{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +04001061
1062- description: Set k8s deploy parameters
1063 cmd: |
1064 {% for k8s_opt, value in config.k8s_deploy.items() %}
1065 {% if value|string() %}
1066 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
1067 {% endif %}
1068 {% endfor %}
1069 node_name: {{ HOSTNAME_CFG01 }}
1070 retry: {count: 1, delay: 1}
1071 skip_fail: false
1072
1073{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001074
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001075
1076{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
1077{#############################################}
1078- description: Set SL docker images deploy parameters
1079 cmd: |
1080 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1081 {%- for sl_opt, value in config.sl_deploy.items() %}
1082 {%- if value|string() %}
1083 {%- if OVERRIDES_FILENAME %}
1084 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1085 {%- else %}
1086 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1087 {%- endif %}
1088 {%- endif %}
1089 {%- endfor %}
1090 salt '*' saltutil.refresh_pillar;
1091 sleep 10
1092 node_name: {{ HOSTNAME_CFG01 }}
1093 retry: {count: 1, delay: 1}
1094 skip_fail: false
1095{%- endmacro %}
1096
1097
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001098{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001099{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001100
1101{% for ssh in config.underlay.ssh %}
1102{% if ssh["node_name"].startswith("cmp") %}
1103{% set node_hostname = ssh["node_name"].split('.')[0] %}
1104- description: Register compute {{ ssh['node_name'] }}
1105 cmd: |
1106 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1107 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1108 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001109 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001110 export config_host={{ config.salt.salt_master_host }}
1111 export node_domain={{ DOMAIN_NAME }}
1112 export nodes_os="xenial"
1113 export node_hostname={{ node_hostname }}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001114 export saltversion={{ SALT_VERSION }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001115 set -xe
1116 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1117 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1118 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1119 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1120
1121 # Add wrapper to apt-get to avoid race conditions
1122 # with cron jobs running 'unattended-upgrades' script
1123 aptget_wrapper() {
1124 local apt_wrapper_timeout=300
1125 local start_time=$(date '+%s')
1126 local fin_time=$((start_time + apt_wrapper_timeout))
1127 while true; do
1128 if (( "$(date '+%s')" > fin_time )); then
1129 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1130 fi
1131 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1132 echo "Waiting while another apt/dpkg process releases locks ..."
1133 sleep 30
1134 continue
1135 else
1136 apt-get $@
1137 break
1138 fi
1139 done
1140 }
1141
1142 # Set default salt version
1143 if [ -z "$saltversion" ]; then
Tatyana Leontovich14e201d2018-07-05 13:28:54 +03001144 saltversion="2017.7"
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001145 fi
1146 echo "Using Salt version $saltversion"
1147
1148 echo "Preparing base OS ..."
1149
1150 case "$node_os" in
1151 trusty)
1152 # workaround for old cloud-init only configuring the first iface
1153 iface_config_dir="/etc/network/interfaces"
1154 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1155
1156 for iface in $ifaces; do
1157 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1158 done
1159
1160 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1161
1162 # SUGGESTED UPDATE:
1163 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1164 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1165 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1166 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1167 #install_salt_minion_pkg
1168
1169 # DEPRECATED:
1170 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1171 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1172
1173 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1174 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1175
1176 aptget_wrapper clean
1177 aptget_wrapper update
1178 aptget_wrapper install -y salt-common
1179 aptget_wrapper install -y salt-minion
1180 ;;
1181 xenial)
1182
1183 # workaround for new cloud-init setting all interfaces statically
1184 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1185
1186 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1187
1188 # SUGGESTED UPDATE:
1189 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1190 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1191 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1192 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1193 #install_salt_minion_pkg
1194
1195 # DEPRECATED:
1196 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1197 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1198
1199 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1200 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1201
1202 aptget_wrapper clean
1203 aptget_wrapper update
1204 aptget_wrapper install -y salt-minion
1205 ;;
1206 rhel|centos|centos7|centos7|rhel6|rhel7)
1207 yum install -y git
1208 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1209 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1210 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1211 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1212 install_salt_minion_pkg
1213 ;;
1214 *)
1215 msg="OS '$node_os' is not supported."
1216 esac
1217
1218 echo "Configuring Salt minion ..."
1219 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1220 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1221
1222 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1223
1224 sleep 1
1225
1226 echo "Classifying node ..."
1227 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1228 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1229 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1230 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1231 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1232 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1233
1234 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1235 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1236 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1237 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1238 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1239
1240 if [ "$node_network05_iface" != "" ]; then
1241 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1242 fi
1243
1244 # find more parameters (every env starting param_)
1245 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1246 if [ "$more_params" != "" ]; then
1247 echo "Additional params: $more_params"
1248 more_params=", $more_params"
1249 fi
1250
1251 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}}"
1252
1253 sleep 5
1254
1255 salt-call saltutil.sync_all
1256 salt-call mine.flush
1257 salt-call mine.update
1258 node_name: {{ ssh['node_name'] }}
1259 retry: {count: 1, delay: 1}
1260 skip_fail: false
1261{%- endif %}
1262{%- endfor %}
1263
1264- description: Refresh pillars on all minions
1265 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1266 node_name: {{ HOSTNAME_CFG01 }}
1267 retry: {count: 1, delay: 5}
1268 skip_fail: false
1269
1270- description: Sync all salt resources
1271 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1272 node_name: {{ HOSTNAME_CFG01 }}
1273 retry: {count: 1, delay: 5}
1274 skip_fail: false
1275
sgudz160b7302017-12-22 17:01:10 +02001276{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001277
1278{%- macro RUN_NEW_TEMPEST() %}
1279{###################################}
1280
1281- description: Upload tempest template
1282 upload:
1283 local_path: {{ config.salt_deploy.templates_dir }}
1284 local_filename: runtest.yml
1285 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1286 node_name: {{ HOSTNAME_CFG01 }}
1287 skip_fail: False
1288
1289- description: Include class with tempest template into cfg node
1290 cmd: |
1291 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1292 salt 'cfg01*' saltutil.refresh_pillar;
1293 salt 'cfg01*' saltutil.sync_all;
1294 node_name: {{ HOSTNAME_CFG01 }}
1295 retry: {count: 1, delay: 10}
1296 skip_fail: false
1297
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001298- description: Execute salt.minion on config node
1299 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1300 node_name: {{ HOSTNAME_CFG01 }}
1301 retry: {count: 1, delay: 5}
1302 skip_fail: false
1303
1304- description: Test ping
1305 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1306 node_name: {{ HOSTNAME_CFG01 }}
1307 retry: {count: 1, delay: 5}
1308 skip_fail: false
1309
sgudz09e9aa92018-04-12 12:31:53 +03001310- description: Create flavors for tests
1311 cmd: |
1312 salt 'cfg01*' state.sls nova.client;
1313 node_name: {{ HOSTNAME_CFG01 }}
1314 retry: {count: 1, delay: 5}
1315 skip_fail: false
1316
1317- description: Create networks for tests
1318 cmd: |
1319 salt 'cfg01*' state.sls neutron.client;
1320 node_name: {{ HOSTNAME_CFG01 }}
1321 retry: {count: 1, delay: 5}
1322 skip_fail: false
1323
1324- description: Upload cirros image
1325 cmd: |
1326 salt 'cfg01*' state.sls glance.client;
1327 node_name: {{ HOSTNAME_CFG01 }}
1328 retry: {count: 1, delay: 5}
1329 skip_fail: false
1330
1331- description: Generate tempest config
1332 cmd: |
1333 salt 'cfg01*' state.sls runtest;
1334 node_name: {{ HOSTNAME_CFG01 }}
1335 retry: {count: 1, delay: 5}
1336 skip_fail: false
1337
1338- description: Run tempest from new docker image
1339 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001340 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 +03001341 node_name: {{ HOSTNAME_GTW01 }}
1342 retry: {count: 1, delay: 30}
1343 skip_fail: true
1344
1345- description: Download xml results
1346 download:
1347 remote_path: /root/test/
1348 remote_filename: "report_*.xml"
1349 local_path: {{ os_env('PWD') }}
1350 node_name: {{ HOSTNAME_GTW01 }}
1351 skip_fail: true
1352
1353{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001354
1355{%- macro INSTALL_DOCKER_ON_GTW() %}
1356{###################################}
1357
1358- description: Install docker.io on gtw
1359 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1360 node_name: {{ HOSTNAME_GTW01 }}
1361 retry: {count: 1, delay: 30}
1362 skip_fail: false
1363
1364- description: Enable forward policy
1365 cmd: iptables --policy FORWARD ACCEPT
1366 node_name: {{ HOSTNAME_GTW01 }}
1367 retry: {count: 1, delay: 30}
1368 skip_fail: false
1369
1370{%- endmacro %}
Tatyana Leontovich4453dd62018-06-26 18:44:31 +03001371
1372{%- macro MACRO_CHECK_SALT_VERSION_ON_NODES() %}
1373{#####################################################}
1374
1375{%- for ssh in config.underlay.ssh %}
1376 {%- set salt_roles = [] %}
1377 {%- for role in ssh['roles'] %}
1378 {%- if role in config.salt_deploy.salt_roles %}
1379 {%- set _ = salt_roles.append(role) %}
1380 {%- endif %}
1381 {%- endfor %}
1382
1383 {%- if salt_roles %}
1384- description: 'Check salt version is as expected'
1385 cmd: salt-call test.version | grep {{ SALT_VERSION }}
1386 node_name: {{ ssh['node_name'] }}
1387 retry: {count: 1, delay: 1}
1388 skip_fail: false
1389 {%- endif %}
1390
1391{%- endfor %}
1392{%- endmacro %}
1393
1394{%- macro MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG() %}
1395{#####################################################}
1396
1397- description: 'Check salt-api, salt-master and salt-minion version'
1398 cmd: |
1399 salt-master --version | grep {{ SALT_VERSION }};
1400 salt-minion --version | grep {{ SALT_VERSION }};
1401 salt-api --version | grep {{ SALT_VERSION }};
1402 node_name: {{ HOSTNAME_CFG01 }}
1403 retry: {count: 1, delay: 5}
1404 skip_fail: false
1405
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001406{%- endmacro %}