blob: 95bab7b23945e9a3b75000ddb6b49284bd43f8dc [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','') %}
sgudz4d816eb2017-11-13 11:58:05 +020012{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
Tatyana Leontovich819a6c82018-06-04 12:05:16 +030013{% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %}
sgudza399dc72018-01-18 17:13:48 +020014{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030015{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020016
Dennis Dmitriev492813e2017-08-09 15:08:58 +030017{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020018{% 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 +020019{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030020#{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %}
21{% 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 +020022{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
23{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
24{% 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") %}
25{% 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 +030026{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030027{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030028
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020029{# Address pools for reclass cluster model are taken in the following order:
30 # 1. environment variables,
31 # 2. config.underlay.address_pools based on fuel-devops address pools
32 # (see generated '.ini' file after underlay is created),
33 # 3. defaults #}
34{% set address_pools = config.underlay.address_pools %}
35{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
36{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
37{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
38{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
39{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
40{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
41{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
42{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
43
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040044{# Format for formula replacement:
45 # space separated string:
46 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
47
48{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030049{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030050{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040051{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
52
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040053# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020054{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040055
Dennis Dmitriev492813e2017-08-09 15:08:58 +030056
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020057{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
58{#####################################################}
59
60- description: 'Configure key on nodes and install packages'
61 cmd: |
62 rm -rf trusted* ;
63 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020064 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020065 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
66 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
67 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030068 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020069 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
70 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
71 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050072 eatmydata apt-get clean;
73 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020074 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020075 node_name: {{ NODE_NAME }}
76 retry: {count: 1, delay: 5}
77 skip_fail: false
78
79{%- endmacro %}
80
81
Dennis Dmitriev492813e2017-08-09 15:08:58 +030082{%- macro MACRO_INSTALL_SALT_MASTER() %}
83{######################################}
84- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020085 cmd: |
86 which wget >/dev/null || (apt-get update; apt-get install -y wget);
87 # Configure ubuntu and salt repositories
88 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
89 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
90 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
91 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
92
93 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
94 wget -O - {{ FORMULA_GPG }} | apt-key add -;
95 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030096 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
97
Dennis Dmitrievcf777802018-02-14 18:09:55 +020098
99 apt-get clean
100 apt-get update
101
102 # Install salt-master and reclass
103 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
104 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200105 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 +0200106 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 1}
109 skip_fail: false
110
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200111- description: Remove any existing minion keys
112 cmd: salt-key -y -D || true
113 node_name: {{ HOSTNAME_CFG01 }}
114 retry: {count: 1, delay: 1}
115 skip_fail: false
116
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300117- description: Configure salt-master on cfg01
118 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200119 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300120 file_roots:
121 base:
122 - /usr/share/salt-formulas/env
123 pillar_opts: False
124 open_mode: True
125 reclass: &reclass
126 storage_type: yaml_fs
127 inventory_base_uri: /srv/salt/reclass
128 ext_pillar:
129 - reclass: *reclass
130 master_tops:
131 reclass: *reclass
132 EOF
133 node_name: {{ HOSTNAME_CFG01 }}
134 retry: {count: 1, delay: 1}
135 skip_fail: false
136
137- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300138 cmd: |
139 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200140 #touch /root/.git_trusted_certs.pem;
141 #for server in github.com; do \
142 # openssl s_client -showcerts -connect $server:443 </dev/null \
143 # | openssl x509 -outform PEM \
144 # >> /root/.git_trusted_certs.pem;
145 #done;
146 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
147 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
148 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300149 node_name: {{ HOSTNAME_CFG01 }}
150 retry: {count: 1, delay: 1}
151 skip_fail: false
152{%- endmacro %}
153
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200154
155{%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %}
156{######################################}
157
158- description: Remove /etc/update-motd.d/52-info
159 cmd: rm -vf /etc/update-motd.d/52-info
160 node_name: {{ HOSTNAME_CFG01 }}
161 retry: {count: 1, delay: 10}
162 skip_fail: false
163
164- description: Set up static interface config
165 cmd: |
166 kill $(pidof /sbin/dhclient) || /bin/true
167 cat << 'EOF' > /etc/network/interfaces
168 # This file describes the network interfaces available on your system
169 # and how to activate them. For more information, see interfaces(5).
170
171 # The loopback network interface
172 auto lo
173 iface lo inet loopback
174
175 # The primary network interface
176 auto ens3
177 iface ens3 inet static
178 address {{ IPV4_NET_ADMIN_PREFIX }}.90
179 netmask 255.255.255.0
180 gateway {{ IPV4_NET_ADMIN_PREFIX }}.1
181 EOF
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 10}
184 skip_fail: false
185
186- description: Install common packages on cfg01
187 cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 1, delay: 1}
190 skip_fail: false
191
192- description: Remove any existing minion keys
193 cmd: salt-key -y -D || true
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 1, delay: 1}
196 skip_fail: false
197
198- description: Configure GIT settings and certificates
199 cmd: |
200 set -e;
201 #touch /root/.git_trusted_certs.pem;
202 #for server in github.com; do \
203 # openssl s_client -showcerts -connect $server:443 </dev/null \
204 # | openssl x509 -outform PEM \
205 # >> /root/.git_trusted_certs.pem;
206 #done;
207 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
208 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
209 HOME=/root git config --global user.name "MCP Integration QA";
210 node_name: {{ HOSTNAME_CFG01 }}
211 retry: {count: 1, delay: 1}
212 skip_fail: false
213{%- endmacro %}
214
215
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300216{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300217{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300218{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
219
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300220- description: Clone reclass models with submodules
221 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300222 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200223 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200224 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200225
226 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
227 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 +0200228 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200229
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200230 pushd /srv/salt/reclass;
231 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
232 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200233 {%- if SALT_MODELS_REF_CHANGE != '' %}
234 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200235 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200236 {%- endfor %}
237 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200238 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200239 {%- endif %}
240 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200241 pushd classes/system/;
242 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
243 popd;
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300244 {%- if SALT_MODELS_SYSTEM_TAG != '' %}
245 pushd classes/system/;
246 git fetch --all --tags --prune
247 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
248 popd;
249 {%- endif %}
sgudz4d816eb2017-11-13 11:58:05 +0200250 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300251 pushd classes/system/ && \
252 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200253 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300254 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200255 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200256 {%- endif %}
257 popd;
258 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300259 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200260
261 # Replace firstly to an intermediate value to avoid intersection between
262 # already replaced and replacing networks.
263 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
264 # 192.168.10 -> 10.16.0 (generated network for admin)
265 # 10.16.0 -> <external network>
266 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300267 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200268 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
269 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
270 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
271 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Tatyana Leontovich26756912018-06-06 20:11:05 +0300272 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} +
273 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200274
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200275 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
276 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
277 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
278 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 +0200279
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300280 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 +0200281
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300282 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300283 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300284 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 +0300285 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 +0300286 {%- endif %}
287
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200288 # Override some context parameters
289 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
290 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
291 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
292
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200293 # Create the cfg01 inventory file or use existing
294 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
295 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300296 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400297 - cluster.{{ CLUSTER_NAME }}.infra.config
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300298 {%- if WITH_MAAS %}
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200299 - cluster.{{ CLUSTER_NAME }}.infra.maas
300 - cluster.{{ CLUSTER_NAME }}.infra.maas-machines
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300301 {%- endif %}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300302 parameters:
303 _param:
304 linux_system_codename: xenial
305 reclass_data_revision: master
306 linux:
307 system:
308 name: cfg01
309 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200310 reclass:
311 storage:
312 data_source:
313 engine: local
314 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300315
316 # Show the changes to the console
317 cd /srv/salt/reclass/; git diff
318 node_name: {{ HOSTNAME_CFG01 }}
319 retry: {count: 1, delay: 1}
320 skip_fail: false
321{%- endmacro %}
322
323
sgudz160b7302017-12-22 17:01:10 +0200324{%- 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 +0300325{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300326{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200327- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300328 upload:
329 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
330 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300331 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300332 node_name: {{ HOSTNAME_CFG01 }}
333
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300334- description: Create cluster model from cookiecutter templates
335 cmd: |
336 set -e;
Dmitry Tyzhnenko1fe62a82018-06-01 12:54:26 +0300337 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300338 pip install cookiecutter
339 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
sgudz4d816eb2017-11-13 11:58:05 +0200340
sgudza399dc72018-01-18 17:13:48 +0200341 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
342 pushd /tmp/cookiecutter-templates
343 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
344 popd
345 {%- endif %}
346
sgudz4d816eb2017-11-13 11:58:05 +0200347 {%- if COOKIECUTTER_REF_CHANGE != '' %}
348 pushd /tmp/cookiecutter-templates
349 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
350 popd
351 {%- endif %}
352
Tatyana Leontovich819a6c82018-06-04 12:05:16 +0300353 {%- if COOKIECUTTER_TAG != '' %}
354 pushd /tmp/cookiecutter-templates
355 git fetch --all --tags --prune
356 git checkout tags/{{ COOKIECUTTER_TAG }}
357 popd
358 {%- endif %}
359
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300360 mkdir -p /srv/salt/reclass/classes/cluster/
361 mkdir -p /srv/salt/reclass/classes/system/
362 mkdir -p /srv/salt/reclass/classes/service/
363 mkdir -p /srv/salt/reclass/nodes/_generated
364
365 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200366 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
367 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200368 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300369 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200370 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300371 {%- endif %}
372 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200373 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300374 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300375
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300376 # Replace firstly to an intermediate value to avoid intersection between
377 # already replaced and replacing networks.
378 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
379 # 192.168.10 -> 10.16.0 (generated network for admin)
380 # 10.16.0 -> <external network>
381 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300382 export REPLACE_DIRS="{{ CLUSTER_CONTEXT_PATH }} /tmp/cookiecutter-templates"
383 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {} +
384 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {} +
385 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {} +
386 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300387
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300388 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
389 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
390 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
391 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 +0300392
sgudz160b7302017-12-22 17:01:10 +0200393 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
394 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300395 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200396 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300397 --config-file {{ CLUSTER_CONTEXT_PATH }} \
398 --output-dir /srv/salt/reclass/classes/cluster/;
399 done
400
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300401 export GIT_SSL_NO_VERIFY=true; git clone {{ SALT_MODELS_SYSTEM_REPOSITORY }} /srv/salt/reclass/classes/system/
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300402
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200403 # Create the cfg01 inventory file or use existing
404 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
405 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300406 classes:
407 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200408 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300409 EOF
410
411 node_name: {{ HOSTNAME_CFG01 }}
412 retry: {count: 1, delay: 1}
413 skip_fail: false
414
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300415- description: Modify generated model and reclass-system if necessary
416 cmd: |
417 set -e;
418 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
419 pushd /srv/salt/reclass/classes/system/
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300420 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
421 popd;
422 {%- if SALT_MODELS_SYSTEM_TAG != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300423 pushd /srv/salt/reclass/classes/system/
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300424 git fetch --all --tags --prune
425 git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }};
426 popd;
427 {%- endif %}
428 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
429 pushd /srv/salt/reclass/classes/system/ && \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300430 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300431 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300432 {%- endfor %}
Dennis Dmitriev96e10202018-07-03 09:55:56 +0300433 popd;
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300434 {%- endif %}
435
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300436 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200437 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300438 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
439 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
440 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
441 {%- endif %}
442
443 node_name: {{ HOSTNAME_CFG01 }}
444 retry: {count: 1, delay: 1}
445 skip_fail: false
446{%- endmacro %}
447
448
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300449{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
450{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300451
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200452- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300453 cmd: |
454 set -e;
455 mkdir -p /tmp/environment/;
456 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 +0300457 node_name: {{ HOSTNAME_CFG01 }}
458 skip_fail: false
459
sgudzcced67d2017-10-11 15:56:09 +0300460{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
461- description: Fetch changes for environment templates
462 cmd: |
463 set -e;
464 pushd /tmp/environment/environment_template &&
465 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
466 git checkout FETCH_HEAD &&
467 popd
468 node_name: {{ HOSTNAME_CFG01 }}
469 skip_fail: false
470{%- endif %}
471
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300472{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200473- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300474 upload:
475 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
476 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
477 remote_path: /tmp/environment/
478 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300479{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300480
481- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
482 cmd: |
483 set -e;
484 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200485 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
486 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300487 pip install git+https://github.com/dis-xcom/reclass-tools;
488 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
489 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
490 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
491
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500492 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
493 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
494 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 +0300495 fi;
496
497 node_name: {{ HOSTNAME_CFG01 }}
498 retry: {count: 1, delay: 5}
499 skip_fail: false
500
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200501- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300502 cmd: |
503 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200504 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 +0300505
506 node_name: {{ HOSTNAME_CFG01 }}
507 retry: {count: 1, delay: 5}
508 skip_fail: false
509
510- description: "[EXPERIMENTAL] Create environment model for virtual environment"
511 cmd: |
512 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200513 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300514 reclass-tools render --template-dir /tmp/environment/environment_template/ \
515 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300516 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300517 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
518 node_name: {{ HOSTNAME_CFG01 }}
519 retry: {count: 1, delay: 5}
520 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300521
522- description: Modify generated model and reclass-system
523 cmd: |
524 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
525 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
526 node_name: {{ HOSTNAME_CFG01 }}
527 retry: {count: 1, delay: 1}
528 skip_fail: false
529
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300530{%- endmacro %}
531
532
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300533{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
534{#######################################################}
535- description: Configure reclass
536 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300537 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300538 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300539 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200540 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200541 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
542 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300543 apt-get clean; apt-get update;
544 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
545 declare -a formula_services=({{ FORMULA_SERVICES }});
546 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200547 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300548 for formula_service in "${formula_services[@]}"; do
549 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
550 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
551 done;
552 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
553 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
554 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
555
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200556 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300557 storage_type: yaml_fs
558 pretty_print: True
559 output: yaml
560 inventory_base_uri: /srv/salt/reclass
561 EOF
562 node_name: {{ HOSTNAME_CFG01 }}
563 retry: {count: 1, delay: 1}
564 skip_fail: false
565
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200566- 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 +0300567 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200568 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
569 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300570 node_name: {{ HOSTNAME_CFG01 }}
571 retry: {count: 1, delay: 5}
572 skip_fail: false
573
574- description: Configure salt adoptors on cfg01
575 cmd: |
576 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
577 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
578 node_name: {{ HOSTNAME_CFG01 }}
579 retry: {count: 1, delay: 1}
580 skip_fail: false
581
582- description: Show reclass-salt --top for cfg01 node
583 cmd: reclass-salt --top
584 node_name: {{ HOSTNAME_CFG01 }}
585 retry: {count: 1, delay: 5}
586 skip_fail: false
587
588- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400589 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300590 node_name: {{ HOSTNAME_CFG01 }}
591 retry: {count: 1, delay: 5}
592 skip_fail: false
593{%- endmacro %}
594
595
596{%- macro MACRO_INSTALL_SALT_MINIONS() %}
597{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200598{%- for ssh in config.underlay.ssh %}
599 {%- set salt_roles = [] %}
600 {%- for role in ssh['roles'] %}
601 {%- if role in config.salt_deploy.salt_roles %}
602 {%- set _ = salt_roles.append(role) %}
603 {%- endif %}
604 {%- endfor %}
605
606 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300607- description: Configure salt-minion on {{ ssh['node_name'] }}
608 cmd: |
609 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200610 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300611 id: {{ ssh['node_name'] }}
612 master: {{ config.salt.salt_master_host }}
613 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200614
615 # Configure ubuntu and salt repositories
616 which wget >/dev/null || (apt-get update; apt-get install -y wget);
617
618 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
619 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
620 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
621 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
622
623 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300624 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
625
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200626
627 apt-get clean
628 apt-get update
629
630 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300631 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200632 # Install common packages
633 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200634 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200635 # Restart salt-minion if it was already installed
636 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300637 node_name: {{ ssh['node_name'] }}
638 retry: {count: 1, delay: 1}
639 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200640 {%- else %}
641- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
642 cmd: echo "SSH to $(hostname -f) passed"
643 node_name: {{ ssh['node_name'] }}
644 retry: {count: 1, delay: 1}
645 skip_fail: false
646 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300647
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200648{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300649
650- description: Accept salt keys from all the nodes
651 cmd: salt-key -A -y
652 node_name: {{ HOSTNAME_CFG01 }}
653 retry: {count: 1, delay: 5}
654 skip_fail: true
655{%- endmacro %}
656
657
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200658{%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %}
659{#######################################################}
660- description: Configure reclass
661 cmd: |
662 set -e;
663 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
664 which wget > /dev/null || (apt-get update; apt-get install -y wget);
665 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
666 # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
667 # wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
668 apt-get clean; apt-get update;
669 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
670 declare -a formula_services=({{ FORMULA_SERVICES }});
671 echo -e "\nInstalling all required salt formulas\n";
672 eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
673 for formula_service in "${formula_services[@]}"; do
674 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
675 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
676 done;
677 node_name: {{ HOSTNAME_CFG01 }}
678 retry: {count: 1, delay: 1}
679 skip_fail: false
680
681- description: Show reclass-salt --top for cfg01 node
682 cmd: reclass-salt --top
683 node_name: {{ HOSTNAME_CFG01 }}
684 retry: {count: 1, delay: 5}
685 skip_fail: false
686
687- description: Restart salt-master service
688 cmd: systemctl restart salt-master;
689 node_name: {{ HOSTNAME_CFG01 }}
690 retry: {count: 1, delay: 5}
691 skip_fail: false
692{%- endmacro %}
693
694{%- macro MACRO_CONFIG_DAY01_SALT_MINION() %}
695{#######################################}
696- description: Configure salt-minion on {{ HOSTNAME_CFG01 }}
697 cmd: |
698 export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }}
699 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
700 service salt-minion restart
701
702 while true; do
703 salt-key | grep "$SALT_MASTER_MINION_ID" && break
704 sleep 5
705 done
706
707 sleep 5
708
709 for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
710 salt-key -d $i -y
711 done
712 node_name: {{ HOSTNAME_CFG01 }}
713 retry: {count: 1, delay: 1}
714 skip_fail: false
715{%- endmacro %}
716
717
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300718{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
719{##################################################}
720
721{# Prepare salt services and nodes settings #}
722
723- description: Run 'linux' formula on cfg01
724 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
725 node_name: {{ HOSTNAME_CFG01 }}
726 retry: {count: 3, delay: 5}
727 skip_fail: false
728
729- description: Run 'openssh' formula on cfg01
730 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300731 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300732 salt --hard-crash --state-output=mixed --state-verbose=False
733 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300734 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300735 node_name: {{ HOSTNAME_CFG01 }}
736 retry: {count: 3, delay: 5}
737 skip_fail: false
738
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300739- description: '*Workaround* of harcoded host from day01 grains'
740 cmd: salt-key -d cfg01.mcp-day01.local -y
741 node_name: {{ HOSTNAME_CFG01 }}
742 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400743 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300744
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300745- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
746 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
747 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
748 node_name: {{ HOSTNAME_CFG01 }}
749 retry: {count: 1, delay: 1}
750 skip_fail: false
751
752- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300753 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 +0300754 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300755 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300756 skip_fail: false
757
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400758{%- if SALT_FORMULAS_REFS != '' %}
759- description: Replace needed formulas to desired version
760 cmd: |
761 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400762 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
763 {% set formula = formula_set.split(':') %}
764 {% set formula_name = formula[0] %}
765 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300766 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400767 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
768 pushd {{ formula_dir }} &&
769 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
770 git checkout FETCH_HEAD &&
771 popd &&
772 if [ -d "{{ formula_dir }}" ]; then
773 echo "Going to replace packaged formula {{ formula_name }}" &&
774 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400775 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
776 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400777 else
778 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
779 fi
780 {%- endfor %}
781 node_name: {{ HOSTNAME_CFG01 }}
782 retry: {count: 1, delay: 10}
783 skip_fail: false
784{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300785
786- description: Refresh pillars on salt-master minion
787 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
788 node_name: {{ HOSTNAME_CFG01 }}
789 retry: {count: 1, delay: 5}
790 skip_fail: false
791
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300792- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300793 cmd: reclass-salt --top
794 node_name: {{ HOSTNAME_CFG01 }}
795 retry: {count: 1, delay: 5}
796 skip_fail: false
797
798- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300799 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 +0300800 node_name: {{ HOSTNAME_CFG01 }}
801 retry: {count: 1, delay: 5}
802 skip_fail: false
803
804- description: Configure linux on master
805 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
806 node_name: {{ HOSTNAME_CFG01 }}
807 retry: {count: 1, delay: 5}
808 skip_fail: false
809
810- description: Configure salt.minion on master
811 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
812 -C 'I@salt:master' state.sls salt.minion && sleep 10
813 node_name: {{ HOSTNAME_CFG01 }}
814 retry: {count: 3, delay: 10}
815 skip_fail: false
816
817- description: Run state 'salt' on master (for salt.api, etc)
818 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
819 -C 'I@salt:master' state.sls salt
820 node_name: {{ HOSTNAME_CFG01 }}
821 retry: {count: 3, delay: 10}
822 skip_fail: false
823{%- endmacro %}
824
Dennis Dmitriev85559962018-01-30 15:35:51 +0200825{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
826{#################################################################}
827
828- description: Refresh pillars before generating nodes
829 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
830 node_name: {{ HOSTNAME_CFG01 }}
831 retry: {count: 1, delay: 5}
832 skip_fail: false
833
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200834- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200835 cmd: |
836 set -e
837 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
838 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 +0200839 node_name: {{ HOSTNAME_CFG01 }}
840 retry: {count: 1, delay: 5}
841 skip_fail: false
842
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300843- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
844 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
845 -C 'I@salt:master' state.sls reclass
846 node_name: {{ HOSTNAME_CFG01 }}
847 retry: {count: 1, delay: 5}
848 skip_fail: false
849
Dennis Dmitriev85559962018-01-30 15:35:51 +0200850{%- if RERUN_SALTMASTER_STATE %}
851- description: Regenerate salt.master states for the newly uploaded/created model
852 cmd: |
853 # Need to refresh installed formulas that are required in the model
854 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
855 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
856 node_name: {{ HOSTNAME_CFG01 }}
857 retry: {count: 1, delay: 5}
858 skip_fail: false
859{%- endif %}
860
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300861- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200862 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300863 node_name: {{ HOSTNAME_CFG01 }}
864 retry: {count: 1, delay: 5}
865 skip_fail: false
866
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300867- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300868 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
872 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300873 node_name: {{ HOSTNAME_CFG01 }}
874 retry: {count: 1, delay: 5}
875 skip_fail: false
876
877- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300878 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300879 node_name: {{ HOSTNAME_CFG01 }}
880 retry: {count: 1, delay: 5}
881 skip_fail: false
882{%- endmacro %}
883
884
885{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
886{########################################}
887# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200888
889- description: Get linux kernel version from all minions
890 cmd: |
891 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
892 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
893 node_name: {{ HOSTNAME_CFG01 }}
894 retry: {count: 5, delay: 10}
895 skip_fail: false
896
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300897- description: Configure linux on other nodes
898 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
899 node_name: {{ HOSTNAME_CFG01 }}
900 retry: {count: 5, delay: 10}
901 skip_fail: false
902
903- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300904 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 +0300905 salt --hard-crash --state-output=mixed --state-verbose=False
906 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitrievd2604512018-06-04 05:34:44 +0300907 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300908 node_name: {{ HOSTNAME_CFG01 }}
909 retry: {count: 1, delay: 5}
910 skip_fail: false
911
912- description: Configure salt.minion on other nodes
913 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 +0400914 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300915 node_name: {{ HOSTNAME_CFG01 }}
916 retry: {count: 3, delay: 15}
917 skip_fail: false
918
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400919- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400920 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400921 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400922 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400923 skip_fail: false
924
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400925- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200926 cmd: |
927 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
928 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400929 node_name: {{ HOSTNAME_CFG01 }}
930 retry: {count: 1, delay: 10}
931 skip_fail: false
932
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200933- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
934 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
935 node_name: {{ HOSTNAME_CFG01 }}
936 retry: {count: 1, delay: 10}
937 skip_fail: false
938
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300939- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400940 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300941 node_name: {{ HOSTNAME_CFG01 }}
942 retry: {count: 3, delay: 15}
943 skip_fail: false
944
945- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400946 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300947 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400948 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300949 skip_fail: false
950
951- description: Configure ntp and rsyslog on nodes
952 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
953 node_name: {{ HOSTNAME_CFG01 }}
954 retry: {count: 1, delay: 10}
955 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200956{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300957
958
959{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
960{#########################################}
961
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300962- description: '*Workaround: Load bonding module before call state.linux'
963 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
964 node_name: {{ HOSTNAME_CFG01 }}
965 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300966 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300967
968- description: '*Workaround* install bridge-utils before running linux formula'
969 # The formula removes default route and then tries to install the package, fails.
970 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
971 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
972 node_name: {{ HOSTNAME_CFG01 }}
973 retry: {count: 1, delay: 5}
974 skip_fail: false
975
976{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400977
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200978
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400979{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200980{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400981
982- description: Set k8s deploy parameters
983 cmd: |
984 {% for k8s_opt, value in config.k8s_deploy.items() %}
985 {% if value|string() %}
986 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
987 {% endif %}
988 {% endfor %}
989 node_name: {{ HOSTNAME_CFG01 }}
990 retry: {count: 1, delay: 1}
991 skip_fail: false
992
993{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400994
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200995
996{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
997{#############################################}
998- description: Set SL docker images deploy parameters
999 cmd: |
1000 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
1001 {%- for sl_opt, value in config.sl_deploy.items() %}
1002 {%- if value|string() %}
1003 {%- if OVERRIDES_FILENAME %}
1004 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
1005 {%- else %}
1006 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
1007 {%- endif %}
1008 {%- endif %}
1009 {%- endfor %}
1010 salt '*' saltutil.refresh_pillar;
1011 sleep 10
1012 node_name: {{ HOSTNAME_CFG01 }}
1013 retry: {count: 1, delay: 1}
1014 skip_fail: false
1015{%- endmacro %}
1016
1017
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001018{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +02001019{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001020
1021{% for ssh in config.underlay.ssh %}
1022{% if ssh["node_name"].startswith("cmp") %}
1023{% set node_hostname = ssh["node_name"].split('.')[0] %}
1024- description: Register compute {{ ssh['node_name'] }}
1025 cmd: |
1026 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
1027 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
1028 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +04001029 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -04001030 export config_host={{ config.salt.salt_master_host }}
1031 export node_domain={{ DOMAIN_NAME }}
1032 export nodes_os="xenial"
1033 export node_hostname={{ node_hostname }}
1034 set -xe
1035 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
1036 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
1037 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
1038 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
1039
1040 # Add wrapper to apt-get to avoid race conditions
1041 # with cron jobs running 'unattended-upgrades' script
1042 aptget_wrapper() {
1043 local apt_wrapper_timeout=300
1044 local start_time=$(date '+%s')
1045 local fin_time=$((start_time + apt_wrapper_timeout))
1046 while true; do
1047 if (( "$(date '+%s')" > fin_time )); then
1048 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
1049 fi
1050 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
1051 echo "Waiting while another apt/dpkg process releases locks ..."
1052 sleep 30
1053 continue
1054 else
1055 apt-get $@
1056 break
1057 fi
1058 done
1059 }
1060
1061 # Set default salt version
1062 if [ -z "$saltversion" ]; then
1063 saltversion="2016.3"
1064 fi
1065 echo "Using Salt version $saltversion"
1066
1067 echo "Preparing base OS ..."
1068
1069 case "$node_os" in
1070 trusty)
1071 # workaround for old cloud-init only configuring the first iface
1072 iface_config_dir="/etc/network/interfaces"
1073 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
1074
1075 for iface in $ifaces; do
1076 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
1077 done
1078
1079 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1080
1081 # SUGGESTED UPDATE:
1082 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1083 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1084 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1085 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1086 #install_salt_minion_pkg
1087
1088 # DEPRECATED:
1089 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1090 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1091
1092 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
1093 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1094
1095 aptget_wrapper clean
1096 aptget_wrapper update
1097 aptget_wrapper install -y salt-common
1098 aptget_wrapper install -y salt-minion
1099 ;;
1100 xenial)
1101
1102 # workaround for new cloud-init setting all interfaces statically
1103 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
1104
1105 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
1106
1107 # SUGGESTED UPDATE:
1108 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1109 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1110 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1111 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1112 #install_salt_minion_pkg
1113
1114 # DEPRECATED:
1115 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
1116 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
1117
1118 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
1119 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
1120
1121 aptget_wrapper clean
1122 aptget_wrapper update
1123 aptget_wrapper install -y salt-minion
1124 ;;
1125 rhel|centos|centos7|centos7|rhel6|rhel7)
1126 yum install -y git
1127 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
1128 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
1129 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
1130 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
1131 install_salt_minion_pkg
1132 ;;
1133 *)
1134 msg="OS '$node_os' is not supported."
1135 esac
1136
1137 echo "Configuring Salt minion ..."
1138 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
1139 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
1140
1141 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
1142
1143 sleep 1
1144
1145 echo "Classifying node ..."
1146 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
1147 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1148 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1149 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1150 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1151 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1152
1153 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1154 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1155 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1156 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1157 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1158
1159 if [ "$node_network05_iface" != "" ]; then
1160 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1161 fi
1162
1163 # find more parameters (every env starting param_)
1164 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1165 if [ "$more_params" != "" ]; then
1166 echo "Additional params: $more_params"
1167 more_params=", $more_params"
1168 fi
1169
1170 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}}"
1171
1172 sleep 5
1173
1174 salt-call saltutil.sync_all
1175 salt-call mine.flush
1176 salt-call mine.update
1177 node_name: {{ ssh['node_name'] }}
1178 retry: {count: 1, delay: 1}
1179 skip_fail: false
1180{%- endif %}
1181{%- endfor %}
1182
1183- description: Refresh pillars on all minions
1184 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1185 node_name: {{ HOSTNAME_CFG01 }}
1186 retry: {count: 1, delay: 5}
1187 skip_fail: false
1188
1189- description: Sync all salt resources
1190 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1191 node_name: {{ HOSTNAME_CFG01 }}
1192 retry: {count: 1, delay: 5}
1193 skip_fail: false
1194
sgudz160b7302017-12-22 17:01:10 +02001195{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001196
1197{%- macro RUN_NEW_TEMPEST() %}
1198{###################################}
1199
1200- description: Upload tempest template
1201 upload:
1202 local_path: {{ config.salt_deploy.templates_dir }}
1203 local_filename: runtest.yml
1204 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1205 node_name: {{ HOSTNAME_CFG01 }}
1206 skip_fail: False
1207
1208- description: Include class with tempest template into cfg node
1209 cmd: |
1210 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1211 salt 'cfg01*' saltutil.refresh_pillar;
1212 salt 'cfg01*' saltutil.sync_all;
1213 node_name: {{ HOSTNAME_CFG01 }}
1214 retry: {count: 1, delay: 10}
1215 skip_fail: false
1216
Oleksii Butenko2e8e8ee2018-06-21 11:10:13 +03001217- description: Execute salt.minion on config node
1218 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False state.sls salt.minion;
1219 node_name: {{ HOSTNAME_CFG01 }}
1220 retry: {count: 1, delay: 5}
1221 skip_fail: false
1222
1223- description: Test ping
1224 cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False test.ping;
1225 node_name: {{ HOSTNAME_CFG01 }}
1226 retry: {count: 1, delay: 5}
1227 skip_fail: false
1228
sgudz09e9aa92018-04-12 12:31:53 +03001229- description: Create flavors for tests
1230 cmd: |
1231 salt 'cfg01*' state.sls nova.client;
1232 node_name: {{ HOSTNAME_CFG01 }}
1233 retry: {count: 1, delay: 5}
1234 skip_fail: false
1235
1236- description: Create networks for tests
1237 cmd: |
1238 salt 'cfg01*' state.sls neutron.client;
1239 node_name: {{ HOSTNAME_CFG01 }}
1240 retry: {count: 1, delay: 5}
1241 skip_fail: false
1242
1243- description: Upload cirros image
1244 cmd: |
1245 salt 'cfg01*' state.sls glance.client;
1246 node_name: {{ HOSTNAME_CFG01 }}
1247 retry: {count: 1, delay: 5}
1248 skip_fail: false
1249
1250- description: Generate tempest config
1251 cmd: |
1252 salt 'cfg01*' state.sls runtest;
1253 node_name: {{ HOSTNAME_CFG01 }}
1254 retry: {count: 1, delay: 5}
1255 skip_fail: false
1256
1257- description: Run tempest from new docker image
1258 cmd: |
Oleksii Butenko71d76f32018-06-05 17:46:34 +03001259 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 +03001260 node_name: {{ HOSTNAME_GTW01 }}
1261 retry: {count: 1, delay: 30}
1262 skip_fail: true
1263
1264- description: Download xml results
1265 download:
1266 remote_path: /root/test/
1267 remote_filename: "report_*.xml"
1268 local_path: {{ os_env('PWD') }}
1269 node_name: {{ HOSTNAME_GTW01 }}
1270 skip_fail: true
1271
1272{%- endmacro %}
Oleksii Butenko5cd0a162018-06-14 18:18:10 +03001273
1274{%- macro INSTALL_DOCKER_ON_GTW() %}
1275{###################################}
1276
1277- description: Install docker.io on gtw
1278 cmd: salt-call cmd.run 'apt-get install docker.io -y'
1279 node_name: {{ HOSTNAME_GTW01 }}
1280 retry: {count: 1, delay: 30}
1281 skip_fail: false
1282
1283- description: Enable forward policy
1284 cmd: iptables --policy FORWARD ACCEPT
1285 node_name: {{ HOSTNAME_GTW01 }}
1286 retry: {count: 1, delay: 30}
1287 skip_fail: false
1288
1289{%- endmacro %}