blob: 23ef7cef6e1517898ff9c15ef760f12f51e0edb3 [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', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030044{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040045{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
46
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040047# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020048{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040049
Dennis Dmitriev492813e2017-08-09 15:08:58 +030050
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020051{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
52{#####################################################}
53
54- description: 'Configure key on nodes and install packages'
55 cmd: |
56 rm -rf trusted* ;
57 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020058 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020059 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
60 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
61 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
62 wget -O - "{{ SALT_GPG }}" | apt-key add -;
63 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
64 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
65 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050066 eatmydata apt-get clean;
67 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020068 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020069 node_name: {{ NODE_NAME }}
70 retry: {count: 1, delay: 5}
71 skip_fail: false
72
73{%- endmacro %}
74
75
Dennis Dmitriev492813e2017-08-09 15:08:58 +030076{%- macro MACRO_INSTALL_SALT_MASTER() %}
77{######################################}
78- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020079 cmd: |
80 which wget >/dev/null || (apt-get update; apt-get install -y wget);
81 # Configure ubuntu and salt repositories
82 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
83 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
84 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
85 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
86
87 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
88 wget -O - {{ FORMULA_GPG }} | apt-key add -;
89 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
90 wget -O - {{ SALT_GPG }} | apt-key add -;
91
92 apt-get clean
93 apt-get update
94
95 # Install salt-master and reclass
96 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
97 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +020098 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 +020099 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300100 node_name: {{ HOSTNAME_CFG01 }}
101 retry: {count: 1, delay: 1}
102 skip_fail: false
103
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200104- description: Remove any existing minion keys
105 cmd: salt-key -y -D || true
106 node_name: {{ HOSTNAME_CFG01 }}
107 retry: {count: 1, delay: 1}
108 skip_fail: false
109
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300110- description: Configure salt-master on cfg01
111 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200112 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300113 file_roots:
114 base:
115 - /usr/share/salt-formulas/env
116 pillar_opts: False
117 open_mode: True
118 reclass: &reclass
119 storage_type: yaml_fs
120 inventory_base_uri: /srv/salt/reclass
121 ext_pillar:
122 - reclass: *reclass
123 master_tops:
124 reclass: *reclass
125 EOF
126 node_name: {{ HOSTNAME_CFG01 }}
127 retry: {count: 1, delay: 1}
128 skip_fail: false
129
130- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300131 cmd: |
132 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200133 #touch /root/.git_trusted_certs.pem;
134 #for server in github.com; do \
135 # openssl s_client -showcerts -connect $server:443 </dev/null \
136 # | openssl x509 -outform PEM \
137 # >> /root/.git_trusted_certs.pem;
138 #done;
139 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
140 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
141 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 1, delay: 1}
144 skip_fail: false
145{%- endmacro %}
146
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300147{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
148{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300149{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
150
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300151- description: Clone reclass models with submodules
152 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300153 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200154 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200155 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200156
157 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
158 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 +0200159 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200160
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200161 pushd /srv/salt/reclass;
162 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
163 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200164 {%- if SALT_MODELS_REF_CHANGE != '' %}
165 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200166 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200167 {%- endfor %}
168 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200169 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200170 {%- endif %}
171 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200172 pushd classes/system/;
173 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
174 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200175 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300176 pushd classes/system/ && \
177 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200178 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300179 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200180 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200181 {%- endif %}
182 popd;
183 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300184 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200185
186 # Replace firstly to an intermediate value to avoid intersection between
187 # already replaced and replacing networks.
188 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
189 # 192.168.10 -> 10.16.0 (generated network for admin)
190 # 10.16.0 -> <external network>
191 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300192 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200193 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
194 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
195 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
196 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200197
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200198 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
199 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
200 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
201 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 +0200202
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300203 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 +0200204
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300205 {%- if IS_CONTRAIL_LAB %}
206 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300207 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 +0300208 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 +0300209 {%- endif %}
210
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200211 # Override some context parameters
212 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
213 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
214 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
215
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200216 # Create the cfg01 inventory file or use existing
217 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
218 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300219 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400220 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300221 parameters:
222 _param:
223 linux_system_codename: xenial
224 reclass_data_revision: master
225 linux:
226 system:
227 name: cfg01
228 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200229 reclass:
230 storage:
231 data_source:
232 engine: local
233 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300234
235 # Show the changes to the console
236 cd /srv/salt/reclass/; git diff
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 1, delay: 1}
239 skip_fail: false
240{%- endmacro %}
241
242
sgudz160b7302017-12-22 17:01:10 +0200243{%- 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 +0300244{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300245{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200246- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300247 upload:
248 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
249 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300250 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300251 node_name: {{ HOSTNAME_CFG01 }}
252
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300253- description: Create cluster model from cookiecutter templates
254 cmd: |
255 set -e;
Tatyana Leontovichb92a53d2018-04-17 14:15:38 +0300256 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300257 pip install cookiecutter
258 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 +0200259
sgudza399dc72018-01-18 17:13:48 +0200260 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
261 pushd /tmp/cookiecutter-templates
262 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
263 popd
264 {%- endif %}
265
sgudz4d816eb2017-11-13 11:58:05 +0200266 {%- if COOKIECUTTER_REF_CHANGE != '' %}
267 pushd /tmp/cookiecutter-templates
268 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
269 popd
270 {%- endif %}
271
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300272 mkdir -p /srv/salt/reclass/classes/cluster/
273 mkdir -p /srv/salt/reclass/classes/system/
274 mkdir -p /srv/salt/reclass/classes/service/
275 mkdir -p /srv/salt/reclass/nodes/_generated
276
277 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200278 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
279 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200280 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300281 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200282 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300283 {%- endif %}
284 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200285 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300286 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300287
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300288 # Replace firstly to an intermediate value to avoid intersection between
289 # already replaced and replacing networks.
290 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
291 # 192.168.10 -> 10.16.0 (generated network for admin)
292 # 10.16.0 -> <external network>
293 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
294 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
295 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
296 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200297 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300298
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300299 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
300 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
301 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200302 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300303
sgudz160b7302017-12-22 17:01:10 +0200304 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
305 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300306 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200307 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300308 --config-file {{ CLUSTER_CONTEXT_PATH }} \
309 --output-dir /srv/salt/reclass/classes/cluster/;
310 done
311
312 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
313
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200314 # Create the cfg01 inventory file or use existing
315 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
316 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300317 classes:
318 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200319 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300320 EOF
321
322 node_name: {{ HOSTNAME_CFG01 }}
323 retry: {count: 1, delay: 1}
324 skip_fail: false
325
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300326- description: Modify generated model and reclass-system if necessary
327 cmd: |
328 set -e;
329 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
330 pushd /srv/salt/reclass/classes/system/
331 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
332 popd
sgudz4d816eb2017-11-13 11:58:05 +0200333 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300334 pushd /srv/salt/reclass/classes/system/
335 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
336 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
337 {%- endfor %}
338 popd
339 {%- endif %}
340
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300341 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200342 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300343 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
344 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
345 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
346 {%- endif %}
347
348 node_name: {{ HOSTNAME_CFG01 }}
349 retry: {count: 1, delay: 1}
350 skip_fail: false
351{%- endmacro %}
352
353
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300354{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
355{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300356
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200357- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300358 cmd: |
359 set -e;
360 mkdir -p /tmp/environment/;
361 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 +0300362 node_name: {{ HOSTNAME_CFG01 }}
363 skip_fail: false
364
sgudzcced67d2017-10-11 15:56:09 +0300365{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
366- description: Fetch changes for environment templates
367 cmd: |
368 set -e;
369 pushd /tmp/environment/environment_template &&
370 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
371 git checkout FETCH_HEAD &&
372 popd
373 node_name: {{ HOSTNAME_CFG01 }}
374 skip_fail: false
375{%- endif %}
376
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300377{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200378- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300379 upload:
380 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
381 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
382 remote_path: /tmp/environment/
383 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300384{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300385
386- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
387 cmd: |
388 set -e;
389 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200390 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
391 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300392 pip install git+https://github.com/dis-xcom/reclass-tools;
393 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
394 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
395 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
396
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500397 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
398 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
399 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 +0300400 fi;
401
402 node_name: {{ HOSTNAME_CFG01 }}
403 retry: {count: 1, delay: 5}
404 skip_fail: false
405
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200406- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300407 cmd: |
408 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200409 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 +0300410
411 node_name: {{ HOSTNAME_CFG01 }}
412 retry: {count: 1, delay: 5}
413 skip_fail: false
414
415- description: "[EXPERIMENTAL] Create environment model for virtual environment"
416 cmd: |
417 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200418 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300419 reclass-tools render --template-dir /tmp/environment/environment_template/ \
420 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300421 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300422 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
423 node_name: {{ HOSTNAME_CFG01 }}
424 retry: {count: 1, delay: 5}
425 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300426
427- description: Modify generated model and reclass-system
428 cmd: |
429 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
430 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
431 node_name: {{ HOSTNAME_CFG01 }}
432 retry: {count: 1, delay: 1}
433 skip_fail: false
434
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300435{%- endmacro %}
436
437
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300438{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
439{#######################################################}
440- description: Configure reclass
441 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300442 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300443 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300444 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200445 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200446 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
447 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300448 apt-get clean; apt-get update;
449 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
450 declare -a formula_services=({{ FORMULA_SERVICES }});
451 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200452 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300453 for formula_service in "${formula_services[@]}"; do
454 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
455 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
456 done;
457 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
458 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
459 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
460
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200461 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300462 storage_type: yaml_fs
463 pretty_print: True
464 output: yaml
465 inventory_base_uri: /srv/salt/reclass
466 EOF
467 node_name: {{ HOSTNAME_CFG01 }}
468 retry: {count: 1, delay: 1}
469 skip_fail: false
470
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200471- 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 +0300472 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200473 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
474 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300475 node_name: {{ HOSTNAME_CFG01 }}
476 retry: {count: 1, delay: 5}
477 skip_fail: false
478
479- description: Configure salt adoptors on cfg01
480 cmd: |
481 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
482 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
483 node_name: {{ HOSTNAME_CFG01 }}
484 retry: {count: 1, delay: 1}
485 skip_fail: false
486
487- description: Show reclass-salt --top for cfg01 node
488 cmd: reclass-salt --top
489 node_name: {{ HOSTNAME_CFG01 }}
490 retry: {count: 1, delay: 5}
491 skip_fail: false
492
493- description: Restart salt-master service
494 cmd: systemctl restart salt-master;
495 node_name: {{ HOSTNAME_CFG01 }}
496 retry: {count: 1, delay: 5}
497 skip_fail: false
498{%- endmacro %}
499
500
501{%- macro MACRO_INSTALL_SALT_MINIONS() %}
502{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200503{%- for ssh in config.underlay.ssh %}
504 {%- set salt_roles = [] %}
505 {%- for role in ssh['roles'] %}
506 {%- if role in config.salt_deploy.salt_roles %}
507 {%- set _ = salt_roles.append(role) %}
508 {%- endif %}
509 {%- endfor %}
510
511 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300512- description: Configure salt-minion on {{ ssh['node_name'] }}
513 cmd: |
514 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200515 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300516 id: {{ ssh['node_name'] }}
517 master: {{ config.salt.salt_master_host }}
518 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200519
520 # Configure ubuntu and salt repositories
521 which wget >/dev/null || (apt-get update; apt-get install -y wget);
522
523 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
524 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
525 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
526 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
527
528 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
529 wget -O - {{ SALT_GPG }} | apt-key add -;
530
531 apt-get clean
532 apt-get update
533
534 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300535 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200536 # Install common packages
537 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200538 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200539 # Restart salt-minion if it was already installed
540 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300541 node_name: {{ ssh['node_name'] }}
542 retry: {count: 1, delay: 1}
543 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200544 {%- else %}
545- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
546 cmd: echo "SSH to $(hostname -f) passed"
547 node_name: {{ ssh['node_name'] }}
548 retry: {count: 1, delay: 1}
549 skip_fail: false
550 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300551
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200552{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300553
554- description: Accept salt keys from all the nodes
555 cmd: salt-key -A -y
556 node_name: {{ HOSTNAME_CFG01 }}
557 retry: {count: 1, delay: 5}
558 skip_fail: true
559{%- endmacro %}
560
561
562{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
563{##################################################}
564
565{# Prepare salt services and nodes settings #}
566
567- description: Run 'linux' formula on cfg01
568 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
569 node_name: {{ HOSTNAME_CFG01 }}
570 retry: {count: 3, delay: 5}
571 skip_fail: false
572
573- description: Run 'openssh' formula on cfg01
574 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300575 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300576 salt --hard-crash --state-output=mixed --state-verbose=False
577 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300578 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300579 node_name: {{ HOSTNAME_CFG01 }}
580 retry: {count: 3, delay: 5}
581 skip_fail: false
582
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300583- description: '*Workaround* of harcoded host from day01 grains'
584 cmd: salt-key -d cfg01.mcp-day01.local -y
585 node_name: {{ HOSTNAME_CFG01 }}
586 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400587 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300588
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300589- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
590 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
591 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
592 node_name: {{ HOSTNAME_CFG01 }}
593 retry: {count: 1, delay: 1}
594 skip_fail: false
595
596- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300597 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 +0300598 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300599 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300600 skip_fail: false
601
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400602{%- if SALT_FORMULAS_REFS != '' %}
603- description: Replace needed formulas to desired version
604 cmd: |
605 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400606 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
607 {% set formula = formula_set.split(':') %}
608 {% set formula_name = formula[0] %}
609 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300610 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400611 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
612 pushd {{ formula_dir }} &&
613 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
614 git checkout FETCH_HEAD &&
615 popd &&
616 if [ -d "{{ formula_dir }}" ]; then
617 echo "Going to replace packaged formula {{ formula_name }}" &&
618 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400619 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
620 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400621 else
622 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
623 fi
624 {%- endfor %}
625 node_name: {{ HOSTNAME_CFG01 }}
626 retry: {count: 1, delay: 10}
627 skip_fail: false
628{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300629
630- description: Refresh pillars on salt-master minion
631 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
632 node_name: {{ HOSTNAME_CFG01 }}
633 retry: {count: 1, delay: 5}
634 skip_fail: false
635
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300636- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300637 cmd: reclass-salt --top
638 node_name: {{ HOSTNAME_CFG01 }}
639 retry: {count: 1, delay: 5}
640 skip_fail: false
641
642- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300643 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 +0300644 node_name: {{ HOSTNAME_CFG01 }}
645 retry: {count: 1, delay: 5}
646 skip_fail: false
647
648- description: Configure linux on master
649 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
650 node_name: {{ HOSTNAME_CFG01 }}
651 retry: {count: 1, delay: 5}
652 skip_fail: false
653
654- description: Configure salt.minion on master
655 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
656 -C 'I@salt:master' state.sls salt.minion && sleep 10
657 node_name: {{ HOSTNAME_CFG01 }}
658 retry: {count: 3, delay: 10}
659 skip_fail: false
660
661- description: Run state 'salt' on master (for salt.api, etc)
662 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
663 -C 'I@salt:master' state.sls salt
664 node_name: {{ HOSTNAME_CFG01 }}
665 retry: {count: 3, delay: 10}
666 skip_fail: false
667{%- endmacro %}
668
Dennis Dmitriev85559962018-01-30 15:35:51 +0200669{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
670{#################################################################}
671
672- description: Refresh pillars before generating nodes
673 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
674 node_name: {{ HOSTNAME_CFG01 }}
675 retry: {count: 1, delay: 5}
676 skip_fail: false
677
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200678- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200679 cmd: |
680 set -e
681 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
682 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 +0200683 node_name: {{ HOSTNAME_CFG01 }}
684 retry: {count: 1, delay: 5}
685 skip_fail: false
686
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300687- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
688 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
689 -C 'I@salt:master' state.sls reclass
690 node_name: {{ HOSTNAME_CFG01 }}
691 retry: {count: 1, delay: 5}
692 skip_fail: false
693
Dennis Dmitriev85559962018-01-30 15:35:51 +0200694{%- if RERUN_SALTMASTER_STATE %}
695- description: Regenerate salt.master states for the newly uploaded/created model
696 cmd: |
697 # Need to refresh installed formulas that are required in the model
698 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
699 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
700 node_name: {{ HOSTNAME_CFG01 }}
701 retry: {count: 1, delay: 5}
702 skip_fail: false
703{%- endif %}
704
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300705- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200706 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300707 node_name: {{ HOSTNAME_CFG01 }}
708 retry: {count: 1, delay: 5}
709 skip_fail: false
710
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300711- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300712 cmd: |
713 set -e
714 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
715 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
716 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300717 node_name: {{ HOSTNAME_CFG01 }}
718 retry: {count: 1, delay: 5}
719 skip_fail: false
720
721- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300722 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300723 node_name: {{ HOSTNAME_CFG01 }}
724 retry: {count: 1, delay: 5}
725 skip_fail: false
726{%- endmacro %}
727
728
729{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
730{########################################}
731# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200732
733- description: Get linux kernel version from all minions
734 cmd: |
735 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
736 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
737 node_name: {{ HOSTNAME_CFG01 }}
738 retry: {count: 5, delay: 10}
739 skip_fail: false
740
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300741- description: Configure linux on other nodes
742 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
743 node_name: {{ HOSTNAME_CFG01 }}
744 retry: {count: 5, delay: 10}
745 skip_fail: false
746
747- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300748 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 +0300749 salt --hard-crash --state-output=mixed --state-verbose=False
750 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
751 yes/' /etc/ssh/sshd_config && service ssh reload"
752 node_name: {{ HOSTNAME_CFG01 }}
753 retry: {count: 1, delay: 5}
754 skip_fail: false
755
756- description: Configure salt.minion on other nodes
757 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 +0400758 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300759 node_name: {{ HOSTNAME_CFG01 }}
760 retry: {count: 3, delay: 15}
761 skip_fail: false
762
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400763- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400764 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400765 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400766 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400767 skip_fail: false
768
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400769- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200770 cmd: |
771 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
772 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400773 node_name: {{ HOSTNAME_CFG01 }}
774 retry: {count: 1, delay: 10}
775 skip_fail: false
776
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200777- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
778 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
779 node_name: {{ HOSTNAME_CFG01 }}
780 retry: {count: 1, delay: 10}
781 skip_fail: false
782
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300783- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400784 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300785 node_name: {{ HOSTNAME_CFG01 }}
786 retry: {count: 3, delay: 15}
787 skip_fail: false
788
789- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400790 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300791 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400792 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300793 skip_fail: false
794
795- description: Configure ntp and rsyslog on nodes
796 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
797 node_name: {{ HOSTNAME_CFG01 }}
798 retry: {count: 1, delay: 10}
799 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200800{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300801
802
803{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
804{#########################################}
805
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300806- description: '*Workaround: Load bonding module before call state.linux'
807 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
808 node_name: {{ HOSTNAME_CFG01 }}
809 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300810 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300811
812- description: '*Workaround* install bridge-utils before running linux formula'
813 # The formula removes default route and then tries to install the package, fails.
814 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
815 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
816 node_name: {{ HOSTNAME_CFG01 }}
817 retry: {count: 1, delay: 5}
818 skip_fail: false
819
820{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400821
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200822
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400823{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200824{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400825
826- description: Set k8s deploy parameters
827 cmd: |
828 {% for k8s_opt, value in config.k8s_deploy.items() %}
829 {% if value|string() %}
830 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
831 {% endif %}
832 {% endfor %}
833 node_name: {{ HOSTNAME_CFG01 }}
834 retry: {count: 1, delay: 1}
835 skip_fail: false
836
837{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400838
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200839
840{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
841{#############################################}
842- description: Set SL docker images deploy parameters
843 cmd: |
844 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
845 {%- for sl_opt, value in config.sl_deploy.items() %}
846 {%- if value|string() %}
847 {%- if OVERRIDES_FILENAME %}
848 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
849 {%- else %}
850 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
851 {%- endif %}
852 {%- endif %}
853 {%- endfor %}
854 salt '*' saltutil.refresh_pillar;
855 sleep 10
856 node_name: {{ HOSTNAME_CFG01 }}
857 retry: {count: 1, delay: 1}
858 skip_fail: false
859{%- endmacro %}
860
861
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400862{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200863{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400864
865{% for ssh in config.underlay.ssh %}
866{% if ssh["node_name"].startswith("cmp") %}
867{% set node_hostname = ssh["node_name"].split('.')[0] %}
868- description: Register compute {{ ssh['node_name'] }}
869 cmd: |
870 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
871 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
872 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400873 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400874 export config_host={{ config.salt.salt_master_host }}
875 export node_domain={{ DOMAIN_NAME }}
876 export nodes_os="xenial"
877 export node_hostname={{ node_hostname }}
878 set -xe
879 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
880 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
881 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
882 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
883
884 # Add wrapper to apt-get to avoid race conditions
885 # with cron jobs running 'unattended-upgrades' script
886 aptget_wrapper() {
887 local apt_wrapper_timeout=300
888 local start_time=$(date '+%s')
889 local fin_time=$((start_time + apt_wrapper_timeout))
890 while true; do
891 if (( "$(date '+%s')" > fin_time )); then
892 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
893 fi
894 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
895 echo "Waiting while another apt/dpkg process releases locks ..."
896 sleep 30
897 continue
898 else
899 apt-get $@
900 break
901 fi
902 done
903 }
904
905 # Set default salt version
906 if [ -z "$saltversion" ]; then
907 saltversion="2016.3"
908 fi
909 echo "Using Salt version $saltversion"
910
911 echo "Preparing base OS ..."
912
913 case "$node_os" in
914 trusty)
915 # workaround for old cloud-init only configuring the first iface
916 iface_config_dir="/etc/network/interfaces"
917 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
918
919 for iface in $ifaces; do
920 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
921 done
922
923 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
924
925 # SUGGESTED UPDATE:
926 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
927 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
928 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
929 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
930 #install_salt_minion_pkg
931
932 # DEPRECATED:
933 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
934 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
935
936 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
937 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
938
939 aptget_wrapper clean
940 aptget_wrapper update
941 aptget_wrapper install -y salt-common
942 aptget_wrapper install -y salt-minion
943 ;;
944 xenial)
945
946 # workaround for new cloud-init setting all interfaces statically
947 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
948
949 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
950
951 # SUGGESTED UPDATE:
952 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
953 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
954 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
955 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
956 #install_salt_minion_pkg
957
958 # DEPRECATED:
959 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
960 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
961
962 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
963 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
964
965 aptget_wrapper clean
966 aptget_wrapper update
967 aptget_wrapper install -y salt-minion
968 ;;
969 rhel|centos|centos7|centos7|rhel6|rhel7)
970 yum install -y git
971 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
972 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
973 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
974 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
975 install_salt_minion_pkg
976 ;;
977 *)
978 msg="OS '$node_os' is not supported."
979 esac
980
981 echo "Configuring Salt minion ..."
982 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
983 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
984
985 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
986
987 sleep 1
988
989 echo "Classifying node ..."
990 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
991 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
992 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
993 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
994 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
995 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
996
997 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
998 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
999 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1000 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1001 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1002
1003 if [ "$node_network05_iface" != "" ]; then
1004 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1005 fi
1006
1007 # find more parameters (every env starting param_)
1008 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1009 if [ "$more_params" != "" ]; then
1010 echo "Additional params: $more_params"
1011 more_params=", $more_params"
1012 fi
1013
1014 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}}"
1015
1016 sleep 5
1017
1018 salt-call saltutil.sync_all
1019 salt-call mine.flush
1020 salt-call mine.update
1021 node_name: {{ ssh['node_name'] }}
1022 retry: {count: 1, delay: 1}
1023 skip_fail: false
1024{%- endif %}
1025{%- endfor %}
1026
1027- description: Refresh pillars on all minions
1028 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1029 node_name: {{ HOSTNAME_CFG01 }}
1030 retry: {count: 1, delay: 5}
1031 skip_fail: false
1032
1033- description: Sync all salt resources
1034 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1035 node_name: {{ HOSTNAME_CFG01 }}
1036 retry: {count: 1, delay: 5}
1037 skip_fail: false
1038
sgudz160b7302017-12-22 17:01:10 +02001039{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001040
1041{%- macro RUN_NEW_TEMPEST() %}
1042{###################################}
1043
1044- description: Upload tempest template
1045 upload:
1046 local_path: {{ config.salt_deploy.templates_dir }}
1047 local_filename: runtest.yml
1048 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1049 node_name: {{ HOSTNAME_CFG01 }}
1050 skip_fail: False
1051
1052- description: Include class with tempest template into cfg node
1053 cmd: |
1054 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1055 salt 'cfg01*' saltutil.refresh_pillar;
1056 salt 'cfg01*' saltutil.sync_all;
1057 node_name: {{ HOSTNAME_CFG01 }}
1058 retry: {count: 1, delay: 10}
1059 skip_fail: false
1060
1061- description: Create flavors for tests
1062 cmd: |
1063 salt 'cfg01*' state.sls nova.client;
1064 node_name: {{ HOSTNAME_CFG01 }}
1065 retry: {count: 1, delay: 5}
1066 skip_fail: false
1067
1068- description: Create networks for tests
1069 cmd: |
1070 salt 'cfg01*' state.sls neutron.client;
1071 node_name: {{ HOSTNAME_CFG01 }}
1072 retry: {count: 1, delay: 5}
1073 skip_fail: false
1074
1075- description: Upload cirros image
1076 cmd: |
1077 salt 'cfg01*' state.sls glance.client;
1078 node_name: {{ HOSTNAME_CFG01 }}
1079 retry: {count: 1, delay: 5}
1080 skip_fail: false
1081
1082- description: Generate tempest config
1083 cmd: |
1084 salt 'cfg01*' state.sls runtest;
1085 node_name: {{ HOSTNAME_CFG01 }}
1086 retry: {count: 1, delay: 5}
1087 skip_fail: false
1088
1089- description: Run tempest from new docker image
1090 cmd: |
Tatyana Leontovich1c101312018-04-18 20:33:08 +03001091 docker run -e ARGS="-r {{TEMPEST_PATTERN }} -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"
sgudz09e9aa92018-04-12 12:31:53 +03001092 node_name: {{ HOSTNAME_GTW01 }}
1093 retry: {count: 1, delay: 30}
1094 skip_fail: true
1095
1096- description: Download xml results
1097 download:
1098 remote_path: /root/test/
1099 remote_filename: "report_*.xml"
1100 local_path: {{ os_env('PWD') }}
1101 node_name: {{ HOSTNAME_GTW01 }}
1102 skip_fail: true
1103
1104{%- endmacro %}