blob: 4992858919ee93e7a9cd277110e77559a7e05a38 [file] [log] [blame]
Dennis Dmitriev492813e2017-08-09 15:08:58 +03001{# Collection of common macroses shared across different deployments #}
2
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02003{% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %}
4{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
5{# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12 #}
6{% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %}
7{# Pin to a specified commit in salt-models/reclass-system #}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +03008{% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/reclass-system') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +02009{% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +030010{% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %}
sgudz4d816eb2017-11-13 11:58:05 +020011{% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %}
sgudza399dc72018-01-18 17:13:48 +020012{% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %}
sgudzcced67d2017-10-11 15:56:09 +030013{% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020014
Dennis Dmitriev492813e2017-08-09 15:08:58 +030015{% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020016{% set FORMULA_REPOSITORY = os_env('FORMULA_REPOSITORY', 'deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ' + REPOSITORY_SUITE + ' salt extra') %}
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020017{% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020018{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %}
19{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
20{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
21{% 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") %}
22{% 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 Dmitriev492813e2017-08-09 15:08:58 +030023
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020024{# Address pools for reclass cluster model are taken in the following order:
25 # 1. environment variables,
26 # 2. config.underlay.address_pools based on fuel-devops address pools
27 # (see generated '.ini' file after underlay is created),
28 # 3. defaults #}
29{% set address_pools = config.underlay.address_pools %}
30{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
31{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
32{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
33{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
34{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
35{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
36{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
37{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
38
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040039{# Format for formula replacement:
40 # space separated string:
41 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
42
43{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
44{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
45
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040046# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020047{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040048
Dennis Dmitriev492813e2017-08-09 15:08:58 +030049
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020050{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
51{#####################################################}
52
53- description: 'Configure key on nodes and install packages'
54 cmd: |
55 rm -rf trusted* ;
56 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020057 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020058 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
59 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
60 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
61 wget -O - "{{ SALT_GPG }}" | apt-key add -;
62 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
63 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
64 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050065 eatmydata apt-get clean;
66 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020067 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020068 node_name: {{ NODE_NAME }}
69 retry: {count: 1, delay: 5}
70 skip_fail: false
71
72{%- endmacro %}
73
74
Dennis Dmitriev492813e2017-08-09 15:08:58 +030075{%- macro MACRO_INSTALL_SALT_MASTER() %}
76{######################################}
77- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020078 cmd: |
79 which wget >/dev/null || (apt-get update; apt-get install -y wget);
80 # Configure ubuntu and salt repositories
81 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
82 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
83 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
84 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
85
86 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
87 wget -O - {{ FORMULA_GPG }} | apt-key add -;
88 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
89 wget -O - {{ SALT_GPG }} | apt-key add -;
90
91 apt-get clean
92 apt-get update
93
94 # Install salt-master and reclass
95 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
96 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +020097 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 +020098 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +030099 node_name: {{ HOSTNAME_CFG01 }}
100 retry: {count: 1, delay: 1}
101 skip_fail: false
102
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200103- description: Remove any existing minion keys
104 cmd: salt-key -y -D || true
105 node_name: {{ HOSTNAME_CFG01 }}
106 retry: {count: 1, delay: 1}
107 skip_fail: false
108
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300109- description: Configure salt-master on cfg01
110 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200111 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300112 file_roots:
113 base:
114 - /usr/share/salt-formulas/env
115 pillar_opts: False
116 open_mode: True
117 reclass: &reclass
118 storage_type: yaml_fs
119 inventory_base_uri: /srv/salt/reclass
120 ext_pillar:
121 - reclass: *reclass
122 master_tops:
123 reclass: *reclass
124 EOF
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 1, delay: 1}
127 skip_fail: false
128
129- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300130 cmd: |
131 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200132 #touch /root/.git_trusted_certs.pem;
133 #for server in github.com; do \
134 # openssl s_client -showcerts -connect $server:443 </dev/null \
135 # | openssl x509 -outform PEM \
136 # >> /root/.git_trusted_certs.pem;
137 #done;
138 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
139 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
140 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300141 node_name: {{ HOSTNAME_CFG01 }}
142 retry: {count: 1, delay: 1}
143 skip_fail: false
144{%- endmacro %}
145
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300146{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
147{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300148{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
149
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300150- description: Clone reclass models with submodules
151 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300152 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200153 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200154 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200155
156 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
157 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 +0200158 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200159
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200160 pushd /srv/salt/reclass;
161 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
162 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200163 {%- if SALT_MODELS_REF_CHANGE != '' %}
164 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200165 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200166 {%- endfor %}
167 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200168 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200169 {%- endif %}
170 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200171 pushd classes/system/;
172 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
173 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200174 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300175 pushd classes/system/ && \
176 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200177 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300178 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200179 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200180 {%- endif %}
181 popd;
182 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300183 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200184
185 # Replace firstly to an intermediate value to avoid intersection between
186 # already replaced and replacing networks.
187 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
188 # 192.168.10 -> 10.16.0 (generated network for admin)
189 # 10.16.0 -> <external network>
190 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300191 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200192 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
193 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
194 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
195 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200196
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200197 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
198 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
199 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
200 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 +0200201
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300202 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 +0200203
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300204 {%- if IS_CONTRAIL_LAB %}
205 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300206 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 +0300207 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 +0300208 {%- endif %}
209
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200210 # Override some context parameters
211 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
212 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
213 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
214
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200215 # Create the cfg01 inventory file or use existing
216 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
217 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300218 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400219 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300220 parameters:
221 _param:
222 linux_system_codename: xenial
223 reclass_data_revision: master
224 linux:
225 system:
226 name: cfg01
227 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200228 reclass:
229 storage:
230 data_source:
231 engine: local
232 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300233
234 # Show the changes to the console
235 cd /srv/salt/reclass/; git diff
236 node_name: {{ HOSTNAME_CFG01 }}
237 retry: {count: 1, delay: 1}
238 skip_fail: false
239{%- endmacro %}
240
241
sgudz160b7302017-12-22 17:01:10 +0200242{%- 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 +0300243{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300244{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200245- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300246 upload:
247 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
248 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300249 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300250 node_name: {{ HOSTNAME_CFG01 }}
251
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300252- description: Create cluster model from cookiecutter templates
253 cmd: |
254 set -e;
255 pip install cookiecutter
256 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 +0200257
sgudza399dc72018-01-18 17:13:48 +0200258 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
259 pushd /tmp/cookiecutter-templates
260 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
261 popd
262 {%- endif %}
263
sgudz4d816eb2017-11-13 11:58:05 +0200264 {%- if COOKIECUTTER_REF_CHANGE != '' %}
265 pushd /tmp/cookiecutter-templates
266 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
267 popd
268 {%- endif %}
269
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300270 mkdir -p /srv/salt/reclass/classes/cluster/
271 mkdir -p /srv/salt/reclass/classes/system/
272 mkdir -p /srv/salt/reclass/classes/service/
273 mkdir -p /srv/salt/reclass/nodes/_generated
274
275 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200276 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
277 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200278 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300279 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200280 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300281 {%- endif %}
282 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200283 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300284 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300285
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300286 # Replace firstly to an intermediate value to avoid intersection between
287 # already replaced and replacing networks.
288 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
289 # 192.168.10 -> 10.16.0 (generated network for admin)
290 # 10.16.0 -> <external network>
291 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
292 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
293 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
294 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200295 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300296
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300297 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
298 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
299 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200300 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300301
sgudz160b7302017-12-22 17:01:10 +0200302 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
303 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300304 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200305 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300306 --config-file {{ CLUSTER_CONTEXT_PATH }} \
307 --output-dir /srv/salt/reclass/classes/cluster/;
308 done
309
310 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
311
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200312 # Create the cfg01 inventory file or use existing
313 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
314 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300315 classes:
316 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200317 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300318 EOF
319
320 node_name: {{ HOSTNAME_CFG01 }}
321 retry: {count: 1, delay: 1}
322 skip_fail: false
323
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300324- description: Modify generated model and reclass-system if necessary
325 cmd: |
326 set -e;
327 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
328 pushd /srv/salt/reclass/classes/system/
329 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
330 popd
sgudz4d816eb2017-11-13 11:58:05 +0200331 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300332 pushd /srv/salt/reclass/classes/system/
333 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
334 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
335 {%- endfor %}
336 popd
337 {%- endif %}
338
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300339 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200340 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300341 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
342 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
343 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
344 {%- endif %}
345
346 node_name: {{ HOSTNAME_CFG01 }}
347 retry: {count: 1, delay: 1}
348 skip_fail: false
349{%- endmacro %}
350
351
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300352{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
353{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300354
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200355- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300356 cmd: |
357 set -e;
358 mkdir -p /tmp/environment/;
359 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 +0300360 node_name: {{ HOSTNAME_CFG01 }}
361 skip_fail: false
362
sgudzcced67d2017-10-11 15:56:09 +0300363{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
364- description: Fetch changes for environment templates
365 cmd: |
366 set -e;
367 pushd /tmp/environment/environment_template &&
368 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
369 git checkout FETCH_HEAD &&
370 popd
371 node_name: {{ HOSTNAME_CFG01 }}
372 skip_fail: false
373{%- endif %}
374
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300375{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200376- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300377 upload:
378 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
379 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
380 remote_path: /tmp/environment/
381 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300382{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300383
384- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
385 cmd: |
386 set -e;
387 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200388 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
389 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300390 pip install git+https://github.com/dis-xcom/reclass-tools;
391 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
392 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
393 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
394
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500395 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
396 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
397 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 +0300398 fi;
399
400 node_name: {{ HOSTNAME_CFG01 }}
401 retry: {count: 1, delay: 5}
402 skip_fail: false
403
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200404- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300405 cmd: |
406 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200407 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 +0300408
409 node_name: {{ HOSTNAME_CFG01 }}
410 retry: {count: 1, delay: 5}
411 skip_fail: false
412
413- description: "[EXPERIMENTAL] Create environment model for virtual environment"
414 cmd: |
415 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200416 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300417 reclass-tools render --template-dir /tmp/environment/environment_template/ \
418 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300419 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300420 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
421 node_name: {{ HOSTNAME_CFG01 }}
422 retry: {count: 1, delay: 5}
423 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300424
425- description: Modify generated model and reclass-system
426 cmd: |
427 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
428 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
429 node_name: {{ HOSTNAME_CFG01 }}
430 retry: {count: 1, delay: 1}
431 skip_fail: false
432
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300433{%- endmacro %}
434
435
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300436{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
437{#######################################################}
438- description: Configure reclass
439 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300440 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300441 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300442 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200443 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200444 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
445 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300446 apt-get clean; apt-get update;
447 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
448 declare -a formula_services=({{ FORMULA_SERVICES }});
449 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200450 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300451 for formula_service in "${formula_services[@]}"; do
452 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
453 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
454 done;
455 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
456 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
457 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
458
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200459 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300460 storage_type: yaml_fs
461 pretty_print: True
462 output: yaml
463 inventory_base_uri: /srv/salt/reclass
464 EOF
465 node_name: {{ HOSTNAME_CFG01 }}
466 retry: {count: 1, delay: 1}
467 skip_fail: false
468
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200469- 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 +0300470 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200471 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
472 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300473 node_name: {{ HOSTNAME_CFG01 }}
474 retry: {count: 1, delay: 5}
475 skip_fail: false
476
477- description: Configure salt adoptors on cfg01
478 cmd: |
479 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
480 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
481 node_name: {{ HOSTNAME_CFG01 }}
482 retry: {count: 1, delay: 1}
483 skip_fail: false
484
485- description: Show reclass-salt --top for cfg01 node
486 cmd: reclass-salt --top
487 node_name: {{ HOSTNAME_CFG01 }}
488 retry: {count: 1, delay: 5}
489 skip_fail: false
490
491- description: Restart salt-master service
492 cmd: systemctl restart salt-master;
493 node_name: {{ HOSTNAME_CFG01 }}
494 retry: {count: 1, delay: 5}
495 skip_fail: false
496{%- endmacro %}
497
498
499{%- macro MACRO_INSTALL_SALT_MINIONS() %}
500{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200501{%- for ssh in config.underlay.ssh %}
502 {%- set salt_roles = [] %}
503 {%- for role in ssh['roles'] %}
504 {%- if role in config.salt_deploy.salt_roles %}
505 {%- set _ = salt_roles.append(role) %}
506 {%- endif %}
507 {%- endfor %}
508
509 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300510- description: Configure salt-minion on {{ ssh['node_name'] }}
511 cmd: |
512 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200513 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300514 id: {{ ssh['node_name'] }}
515 master: {{ config.salt.salt_master_host }}
516 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200517
518 # Configure ubuntu and salt repositories
519 which wget >/dev/null || (apt-get update; apt-get install -y wget);
520
521 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
522 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
523 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
524 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
525
526 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
527 wget -O - {{ SALT_GPG }} | apt-key add -;
528
529 apt-get clean
530 apt-get update
531
532 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300533 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200534 # Install common packages
535 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200536 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200537 # Restart salt-minion if it was already installed
538 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300539 node_name: {{ ssh['node_name'] }}
540 retry: {count: 1, delay: 1}
541 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200542 {%- else %}
543- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
544 cmd: echo "SSH to $(hostname -f) passed"
545 node_name: {{ ssh['node_name'] }}
546 retry: {count: 1, delay: 1}
547 skip_fail: false
548 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300549
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200550{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300551
552- description: Accept salt keys from all the nodes
553 cmd: salt-key -A -y
554 node_name: {{ HOSTNAME_CFG01 }}
555 retry: {count: 1, delay: 5}
556 skip_fail: true
557{%- endmacro %}
558
559
560{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
561{##################################################}
562
563{# Prepare salt services and nodes settings #}
564
565- description: Run 'linux' formula on cfg01
566 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
567 node_name: {{ HOSTNAME_CFG01 }}
568 retry: {count: 3, delay: 5}
569 skip_fail: false
570
571- description: Run 'openssh' formula on cfg01
572 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300573 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300574 salt --hard-crash --state-output=mixed --state-verbose=False
575 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300576 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300577 node_name: {{ HOSTNAME_CFG01 }}
578 retry: {count: 3, delay: 5}
579 skip_fail: false
580
581- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
582 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
583 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
584 node_name: {{ HOSTNAME_CFG01 }}
585 retry: {count: 1, delay: 1}
586 skip_fail: false
587
588- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300589 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 +0300590 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300591 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300592 skip_fail: false
593
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400594{%- if SALT_FORMULAS_REFS != '' %}
595- description: Replace needed formulas to desired version
596 cmd: |
597 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400598 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
599 {% set formula = formula_set.split(':') %}
600 {% set formula_name = formula[0] %}
601 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300602 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400603 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
604 pushd {{ formula_dir }} &&
605 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
606 git checkout FETCH_HEAD &&
607 popd &&
608 if [ -d "{{ formula_dir }}" ]; then
609 echo "Going to replace packaged formula {{ formula_name }}" &&
610 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400611 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
612 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400613 else
614 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
615 fi
616 {%- endfor %}
617 node_name: {{ HOSTNAME_CFG01 }}
618 retry: {count: 1, delay: 10}
619 skip_fail: false
620{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300621
622- description: Refresh pillars on salt-master minion
623 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
624 node_name: {{ HOSTNAME_CFG01 }}
625 retry: {count: 1, delay: 5}
626 skip_fail: false
627
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300628- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300629 cmd: reclass-salt --top
630 node_name: {{ HOSTNAME_CFG01 }}
631 retry: {count: 1, delay: 5}
632 skip_fail: false
633
634- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300635 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 +0300636 node_name: {{ HOSTNAME_CFG01 }}
637 retry: {count: 1, delay: 5}
638 skip_fail: false
639
640- description: Configure linux on master
641 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
642 node_name: {{ HOSTNAME_CFG01 }}
643 retry: {count: 1, delay: 5}
644 skip_fail: false
645
646- description: Configure salt.minion on master
647 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
648 -C 'I@salt:master' state.sls salt.minion && sleep 10
649 node_name: {{ HOSTNAME_CFG01 }}
650 retry: {count: 3, delay: 10}
651 skip_fail: false
652
653- description: Run state 'salt' on master (for salt.api, etc)
654 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
655 -C 'I@salt:master' state.sls salt
656 node_name: {{ HOSTNAME_CFG01 }}
657 retry: {count: 3, delay: 10}
658 skip_fail: false
659{%- endmacro %}
660
Dennis Dmitriev85559962018-01-30 15:35:51 +0200661{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
662{#################################################################}
663
664- description: Refresh pillars before generating nodes
665 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
666 node_name: {{ HOSTNAME_CFG01 }}
667 retry: {count: 1, delay: 5}
668 skip_fail: false
669
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200670- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200671 cmd: |
672 set -e
673 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
674 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 +0200675 node_name: {{ HOSTNAME_CFG01 }}
676 retry: {count: 1, delay: 5}
677 skip_fail: false
678
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300679- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
680 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
681 -C 'I@salt:master' state.sls reclass
682 node_name: {{ HOSTNAME_CFG01 }}
683 retry: {count: 1, delay: 5}
684 skip_fail: false
685
Dennis Dmitriev85559962018-01-30 15:35:51 +0200686{%- if RERUN_SALTMASTER_STATE %}
687- description: Regenerate salt.master states for the newly uploaded/created model
688 cmd: |
689 # Need to refresh installed formulas that are required in the model
690 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
691 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
692 node_name: {{ HOSTNAME_CFG01 }}
693 retry: {count: 1, delay: 5}
694 skip_fail: false
695{%- endif %}
696
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300697- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200698 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300699 node_name: {{ HOSTNAME_CFG01 }}
700 retry: {count: 1, delay: 5}
701 skip_fail: false
702
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300703- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300704 cmd: |
705 set -e
706 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
707 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
708 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300709 node_name: {{ HOSTNAME_CFG01 }}
710 retry: {count: 1, delay: 5}
711 skip_fail: false
712
713- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300714 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300715 node_name: {{ HOSTNAME_CFG01 }}
716 retry: {count: 1, delay: 5}
717 skip_fail: false
718{%- endmacro %}
719
720
721{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
722{########################################}
723# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200724
725- description: Get linux kernel version from all minions
726 cmd: |
727 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
728 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
729 node_name: {{ HOSTNAME_CFG01 }}
730 retry: {count: 5, delay: 10}
731 skip_fail: false
732
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300733- description: Configure linux on other nodes
734 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
735 node_name: {{ HOSTNAME_CFG01 }}
736 retry: {count: 5, delay: 10}
737 skip_fail: false
738
739- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300740 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 +0300741 salt --hard-crash --state-output=mixed --state-verbose=False
742 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
743 yes/' /etc/ssh/sshd_config && service ssh reload"
744 node_name: {{ HOSTNAME_CFG01 }}
745 retry: {count: 1, delay: 5}
746 skip_fail: false
747
748- description: Configure salt.minion on other nodes
749 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 +0400750 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300751 node_name: {{ HOSTNAME_CFG01 }}
752 retry: {count: 3, delay: 15}
753 skip_fail: false
754
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400755- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400756 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400757 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400758 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400759 skip_fail: false
760
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400761- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200762 cmd: |
763 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
764 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400765 node_name: {{ HOSTNAME_CFG01 }}
766 retry: {count: 1, delay: 10}
767 skip_fail: false
768
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200769- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
770 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
771 node_name: {{ HOSTNAME_CFG01 }}
772 retry: {count: 1, delay: 10}
773 skip_fail: false
774
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300775- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400776 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300777 node_name: {{ HOSTNAME_CFG01 }}
778 retry: {count: 3, delay: 15}
779 skip_fail: false
780
781- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400782 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300783 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400784 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300785 skip_fail: false
786
787- description: Configure ntp and rsyslog on nodes
788 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
789 node_name: {{ HOSTNAME_CFG01 }}
790 retry: {count: 1, delay: 10}
791 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200792{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300793
794
795{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
796{#########################################}
797
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300798- description: '*Workaround: Load bonding module before call state.linux'
799 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
800 node_name: {{ HOSTNAME_CFG01 }}
801 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300802 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300803
804- description: '*Workaround* install bridge-utils before running linux formula'
805 # The formula removes default route and then tries to install the package, fails.
806 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
807 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
808 node_name: {{ HOSTNAME_CFG01 }}
809 retry: {count: 1, delay: 5}
810 skip_fail: false
811
812{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400813
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200814
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400815{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200816{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400817
818- description: Set k8s deploy parameters
819 cmd: |
820 {% for k8s_opt, value in config.k8s_deploy.items() %}
821 {% if value|string() %}
822 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
823 {% endif %}
824 {% endfor %}
825 node_name: {{ HOSTNAME_CFG01 }}
826 retry: {count: 1, delay: 1}
827 skip_fail: false
828
829{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400830
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200831
832{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
833{#############################################}
834- description: Set SL docker images deploy parameters
835 cmd: |
836 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
837 {%- for sl_opt, value in config.sl_deploy.items() %}
838 {%- if value|string() %}
839 {%- if OVERRIDES_FILENAME %}
840 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
841 {%- else %}
842 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
843 {%- endif %}
844 {%- endif %}
845 {%- endfor %}
846 salt '*' saltutil.refresh_pillar;
847 sleep 10
848 node_name: {{ HOSTNAME_CFG01 }}
849 retry: {count: 1, delay: 1}
850 skip_fail: false
851{%- endmacro %}
852
853
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400854{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200855{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400856
857{% for ssh in config.underlay.ssh %}
858{% if ssh["node_name"].startswith("cmp") %}
859{% set node_hostname = ssh["node_name"].split('.')[0] %}
860- description: Register compute {{ ssh['node_name'] }}
861 cmd: |
862 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
863 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
864 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400865 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400866 export config_host={{ config.salt.salt_master_host }}
867 export node_domain={{ DOMAIN_NAME }}
868 export nodes_os="xenial"
869 export node_hostname={{ node_hostname }}
870 set -xe
871 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
872 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
873 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
874 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
875
876 # Add wrapper to apt-get to avoid race conditions
877 # with cron jobs running 'unattended-upgrades' script
878 aptget_wrapper() {
879 local apt_wrapper_timeout=300
880 local start_time=$(date '+%s')
881 local fin_time=$((start_time + apt_wrapper_timeout))
882 while true; do
883 if (( "$(date '+%s')" > fin_time )); then
884 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
885 fi
886 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
887 echo "Waiting while another apt/dpkg process releases locks ..."
888 sleep 30
889 continue
890 else
891 apt-get $@
892 break
893 fi
894 done
895 }
896
897 # Set default salt version
898 if [ -z "$saltversion" ]; then
899 saltversion="2016.3"
900 fi
901 echo "Using Salt version $saltversion"
902
903 echo "Preparing base OS ..."
904
905 case "$node_os" in
906 trusty)
907 # workaround for old cloud-init only configuring the first iface
908 iface_config_dir="/etc/network/interfaces"
909 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
910
911 for iface in $ifaces; do
912 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
913 done
914
915 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
916
917 # SUGGESTED UPDATE:
918 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
919 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
920 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
921 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
922 #install_salt_minion_pkg
923
924 # DEPRECATED:
925 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
926 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
927
928 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
929 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
930
931 aptget_wrapper clean
932 aptget_wrapper update
933 aptget_wrapper install -y salt-common
934 aptget_wrapper install -y salt-minion
935 ;;
936 xenial)
937
938 # workaround for new cloud-init setting all interfaces statically
939 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
940
941 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
942
943 # SUGGESTED UPDATE:
944 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
945 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
946 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
947 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
948 #install_salt_minion_pkg
949
950 # DEPRECATED:
951 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
952 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
953
954 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
955 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
956
957 aptget_wrapper clean
958 aptget_wrapper update
959 aptget_wrapper install -y salt-minion
960 ;;
961 rhel|centos|centos7|centos7|rhel6|rhel7)
962 yum install -y git
963 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
964 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
965 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
966 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
967 install_salt_minion_pkg
968 ;;
969 *)
970 msg="OS '$node_os' is not supported."
971 esac
972
973 echo "Configuring Salt minion ..."
974 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
975 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
976
977 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
978
979 sleep 1
980
981 echo "Classifying node ..."
982 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
983 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
984 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
985 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
986 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
987 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
988
989 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
990 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
991 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
992 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
993 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
994
995 if [ "$node_network05_iface" != "" ]; then
996 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
997 fi
998
999 # find more parameters (every env starting param_)
1000 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1001 if [ "$more_params" != "" ]; then
1002 echo "Additional params: $more_params"
1003 more_params=", $more_params"
1004 fi
1005
1006 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}}"
1007
1008 sleep 5
1009
1010 salt-call saltutil.sync_all
1011 salt-call mine.flush
1012 salt-call mine.update
1013 node_name: {{ ssh['node_name'] }}
1014 retry: {count: 1, delay: 1}
1015 skip_fail: false
1016{%- endif %}
1017{%- endfor %}
1018
1019- description: Refresh pillars on all minions
1020 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1021 node_name: {{ HOSTNAME_CFG01 }}
1022 retry: {count: 1, delay: 5}
1023 skip_fail: false
1024
1025- description: Sync all salt resources
1026 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1027 node_name: {{ HOSTNAME_CFG01 }}
1028 retry: {count: 1, delay: 5}
1029 skip_fail: false
1030
sgudz160b7302017-12-22 17:01:10 +02001031{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001032
1033{%- macro RUN_NEW_TEMPEST() %}
1034{###################################}
1035
1036- description: Upload tempest template
1037 upload:
1038 local_path: {{ config.salt_deploy.templates_dir }}
1039 local_filename: runtest.yml
1040 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1041 node_name: {{ HOSTNAME_CFG01 }}
1042 skip_fail: False
1043
1044- description: Include class with tempest template into cfg node
1045 cmd: |
1046 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1047 salt 'cfg01*' saltutil.refresh_pillar;
1048 salt 'cfg01*' saltutil.sync_all;
1049 node_name: {{ HOSTNAME_CFG01 }}
1050 retry: {count: 1, delay: 10}
1051 skip_fail: false
1052
1053- description: Create flavors for tests
1054 cmd: |
1055 salt 'cfg01*' state.sls nova.client;
1056 node_name: {{ HOSTNAME_CFG01 }}
1057 retry: {count: 1, delay: 5}
1058 skip_fail: false
1059
1060- description: Create networks for tests
1061 cmd: |
1062 salt 'cfg01*' state.sls neutron.client;
1063 node_name: {{ HOSTNAME_CFG01 }}
1064 retry: {count: 1, delay: 5}
1065 skip_fail: false
1066
1067- description: Upload cirros image
1068 cmd: |
1069 salt 'cfg01*' state.sls glance.client;
1070 node_name: {{ HOSTNAME_CFG01 }}
1071 retry: {count: 1, delay: 5}
1072 skip_fail: false
1073
1074- description: Generate tempest config
1075 cmd: |
1076 salt 'cfg01*' state.sls runtest;
1077 node_name: {{ HOSTNAME_CFG01 }}
1078 retry: {count: 1, delay: 5}
1079 skip_fail: false
1080
1081- description: Run tempest from new docker image
1082 cmd: |
1083 docker run -e ARGS="-w 4" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest /bin/bash -c "run-tempest"
1084 node_name: {{ HOSTNAME_GTW01 }}
1085 retry: {count: 1, delay: 30}
1086 skip_fail: true
1087
1088- description: Download xml results
1089 download:
1090 remote_path: /root/test/
1091 remote_filename: "report_*.xml"
1092 local_path: {{ os_env('PWD') }}
1093 node_name: {{ HOSTNAME_GTW01 }}
1094 skip_fail: true
1095
1096{%- endmacro %}