blob: 8b6c4b66f2022a3372ba0d18ac795b0b21147e9d [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') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030045{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040046{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
47
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040048# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020049{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040050
Dennis Dmitriev492813e2017-08-09 15:08:58 +030051
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020052{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
53{#####################################################}
54
55- description: 'Configure key on nodes and install packages'
56 cmd: |
57 rm -rf trusted* ;
58 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020059 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020060 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
61 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
62 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
63 wget -O - "{{ SALT_GPG }}" | apt-key add -;
64 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
65 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
66 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050067 eatmydata apt-get clean;
68 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020069 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020070 node_name: {{ NODE_NAME }}
71 retry: {count: 1, delay: 5}
72 skip_fail: false
73
74{%- endmacro %}
75
76
Dennis Dmitriev492813e2017-08-09 15:08:58 +030077{%- macro MACRO_INSTALL_SALT_MASTER() %}
78{######################################}
79- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020080 cmd: |
81 which wget >/dev/null || (apt-get update; apt-get install -y wget);
82 # Configure ubuntu and salt repositories
83 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
84 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
85 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
86 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
87
88 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
89 wget -O - {{ FORMULA_GPG }} | apt-key add -;
90 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
91 wget -O - {{ SALT_GPG }} | apt-key add -;
92
93 apt-get clean
94 apt-get update
95
96 # Install salt-master and reclass
97 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
98 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +020099 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 +0200100 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300101 node_name: {{ HOSTNAME_CFG01 }}
102 retry: {count: 1, delay: 1}
103 skip_fail: false
104
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200105- description: Remove any existing minion keys
106 cmd: salt-key -y -D || true
107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 1}
109 skip_fail: false
110
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300111- description: Configure salt-master on cfg01
112 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200113 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300114 file_roots:
115 base:
116 - /usr/share/salt-formulas/env
117 pillar_opts: False
118 open_mode: True
119 reclass: &reclass
120 storage_type: yaml_fs
121 inventory_base_uri: /srv/salt/reclass
122 ext_pillar:
123 - reclass: *reclass
124 master_tops:
125 reclass: *reclass
126 EOF
127 node_name: {{ HOSTNAME_CFG01 }}
128 retry: {count: 1, delay: 1}
129 skip_fail: false
130
131- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300132 cmd: |
133 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200134 #touch /root/.git_trusted_certs.pem;
135 #for server in github.com; do \
136 # openssl s_client -showcerts -connect $server:443 </dev/null \
137 # | openssl x509 -outform PEM \
138 # >> /root/.git_trusted_certs.pem;
139 #done;
140 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
141 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
142 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300143 node_name: {{ HOSTNAME_CFG01 }}
144 retry: {count: 1, delay: 1}
145 skip_fail: false
146{%- endmacro %}
147
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300148{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
149{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300150{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
151
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300152- description: Clone reclass models with submodules
153 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300154 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200155 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200156 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200157
158 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
159 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 +0200160 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200161
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200162 pushd /srv/salt/reclass;
163 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
164 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200165 {%- if SALT_MODELS_REF_CHANGE != '' %}
166 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200167 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200168 {%- endfor %}
169 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200170 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200171 {%- endif %}
172 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200173 pushd classes/system/;
174 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
175 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200176 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300177 pushd classes/system/ && \
178 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200179 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300180 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200181 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200182 {%- endif %}
183 popd;
184 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300185 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200186
187 # Replace firstly to an intermediate value to avoid intersection between
188 # already replaced and replacing networks.
189 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
190 # 192.168.10 -> 10.16.0 (generated network for admin)
191 # 10.16.0 -> <external network>
192 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300193 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200194 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
195 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
196 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
197 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200198
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200199 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
200 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
201 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
202 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 +0200203
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300204 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 +0200205
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300206 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300207 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300208 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 +0300209 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 +0300210 {%- endif %}
211
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200212 # Override some context parameters
213 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
214 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
215 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
216
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200217 # Create the cfg01 inventory file or use existing
218 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
219 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300220 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400221 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300222 parameters:
223 _param:
224 linux_system_codename: xenial
225 reclass_data_revision: master
226 linux:
227 system:
228 name: cfg01
229 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200230 reclass:
231 storage:
232 data_source:
233 engine: local
234 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300235
236 # Show the changes to the console
237 cd /srv/salt/reclass/; git diff
238 node_name: {{ HOSTNAME_CFG01 }}
239 retry: {count: 1, delay: 1}
240 skip_fail: false
241{%- endmacro %}
242
243
sgudz160b7302017-12-22 17:01:10 +0200244{%- 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 +0300245{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300246{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200247- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300248 upload:
249 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
250 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300251 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300252 node_name: {{ HOSTNAME_CFG01 }}
253
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300254- description: Create cluster model from cookiecutter templates
255 cmd: |
256 set -e;
Tatyana Leontovichb92a53d2018-04-17 14:15:38 +0300257 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300258 pip install cookiecutter
259 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 +0200260
sgudza399dc72018-01-18 17:13:48 +0200261 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
262 pushd /tmp/cookiecutter-templates
263 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
264 popd
265 {%- endif %}
266
sgudz4d816eb2017-11-13 11:58:05 +0200267 {%- if COOKIECUTTER_REF_CHANGE != '' %}
268 pushd /tmp/cookiecutter-templates
269 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
270 popd
271 {%- endif %}
272
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300273 mkdir -p /srv/salt/reclass/classes/cluster/
274 mkdir -p /srv/salt/reclass/classes/system/
275 mkdir -p /srv/salt/reclass/classes/service/
276 mkdir -p /srv/salt/reclass/nodes/_generated
277
278 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200279 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
280 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200281 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300282 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200283 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300284 {%- endif %}
285 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200286 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300287 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300288
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300289 # Replace firstly to an intermediate value to avoid intersection between
290 # already replaced and replacing networks.
291 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
292 # 192.168.10 -> 10.16.0 (generated network for admin)
293 # 10.16.0 -> <external network>
294 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
295 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
296 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
297 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200298 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300299
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300300 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
301 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
302 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200303 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300304
sgudz160b7302017-12-22 17:01:10 +0200305 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
306 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300307 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200308 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300309 --config-file {{ CLUSTER_CONTEXT_PATH }} \
310 --output-dir /srv/salt/reclass/classes/cluster/;
311 done
312
313 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
314
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200315 # Create the cfg01 inventory file or use existing
316 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
317 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300318 classes:
319 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200320 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300321 EOF
322
323 node_name: {{ HOSTNAME_CFG01 }}
324 retry: {count: 1, delay: 1}
325 skip_fail: false
326
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300327- description: Modify generated model and reclass-system if necessary
328 cmd: |
329 set -e;
330 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
331 pushd /srv/salt/reclass/classes/system/
332 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
333 popd
sgudz4d816eb2017-11-13 11:58:05 +0200334 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300335 pushd /srv/salt/reclass/classes/system/
336 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
337 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
338 {%- endfor %}
339 popd
340 {%- endif %}
341
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300342 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200343 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300344 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
345 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
346 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
347 {%- endif %}
348
349 node_name: {{ HOSTNAME_CFG01 }}
350 retry: {count: 1, delay: 1}
351 skip_fail: false
352{%- endmacro %}
353
354
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300355{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
356{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300357
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200358- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300359 cmd: |
360 set -e;
361 mkdir -p /tmp/environment/;
362 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 +0300363 node_name: {{ HOSTNAME_CFG01 }}
364 skip_fail: false
365
sgudzcced67d2017-10-11 15:56:09 +0300366{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
367- description: Fetch changes for environment templates
368 cmd: |
369 set -e;
370 pushd /tmp/environment/environment_template &&
371 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
372 git checkout FETCH_HEAD &&
373 popd
374 node_name: {{ HOSTNAME_CFG01 }}
375 skip_fail: false
376{%- endif %}
377
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300378{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200379- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300380 upload:
381 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
382 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
383 remote_path: /tmp/environment/
384 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300385{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300386
387- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
388 cmd: |
389 set -e;
390 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200391 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
392 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300393 pip install git+https://github.com/dis-xcom/reclass-tools;
394 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
395 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
396 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
397
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500398 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
399 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
400 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 +0300401 fi;
402
403 node_name: {{ HOSTNAME_CFG01 }}
404 retry: {count: 1, delay: 5}
405 skip_fail: false
406
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200407- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300408 cmd: |
409 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200410 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 +0300411
412 node_name: {{ HOSTNAME_CFG01 }}
413 retry: {count: 1, delay: 5}
414 skip_fail: false
415
416- description: "[EXPERIMENTAL] Create environment model for virtual environment"
417 cmd: |
418 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200419 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300420 reclass-tools render --template-dir /tmp/environment/environment_template/ \
421 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300422 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300423 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
424 node_name: {{ HOSTNAME_CFG01 }}
425 retry: {count: 1, delay: 5}
426 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300427
428- description: Modify generated model and reclass-system
429 cmd: |
430 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
431 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
432 node_name: {{ HOSTNAME_CFG01 }}
433 retry: {count: 1, delay: 1}
434 skip_fail: false
435
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300436{%- endmacro %}
437
438
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300439{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
440{#######################################################}
441- description: Configure reclass
442 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300443 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300444 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300445 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200446 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200447 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
448 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300449 apt-get clean; apt-get update;
450 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
451 declare -a formula_services=({{ FORMULA_SERVICES }});
452 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200453 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300454 for formula_service in "${formula_services[@]}"; do
455 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
456 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
457 done;
458 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
459 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
460 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
461
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200462 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300463 storage_type: yaml_fs
464 pretty_print: True
465 output: yaml
466 inventory_base_uri: /srv/salt/reclass
467 EOF
468 node_name: {{ HOSTNAME_CFG01 }}
469 retry: {count: 1, delay: 1}
470 skip_fail: false
471
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200472- 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 +0300473 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200474 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
475 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300476 node_name: {{ HOSTNAME_CFG01 }}
477 retry: {count: 1, delay: 5}
478 skip_fail: false
479
480- description: Configure salt adoptors on cfg01
481 cmd: |
482 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
483 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
484 node_name: {{ HOSTNAME_CFG01 }}
485 retry: {count: 1, delay: 1}
486 skip_fail: false
487
488- description: Show reclass-salt --top for cfg01 node
489 cmd: reclass-salt --top
490 node_name: {{ HOSTNAME_CFG01 }}
491 retry: {count: 1, delay: 5}
492 skip_fail: false
493
494- description: Restart salt-master service
495 cmd: systemctl restart salt-master;
496 node_name: {{ HOSTNAME_CFG01 }}
497 retry: {count: 1, delay: 5}
498 skip_fail: false
499{%- endmacro %}
500
501
502{%- macro MACRO_INSTALL_SALT_MINIONS() %}
503{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200504{%- for ssh in config.underlay.ssh %}
505 {%- set salt_roles = [] %}
506 {%- for role in ssh['roles'] %}
507 {%- if role in config.salt_deploy.salt_roles %}
508 {%- set _ = salt_roles.append(role) %}
509 {%- endif %}
510 {%- endfor %}
511
512 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300513- description: Configure salt-minion on {{ ssh['node_name'] }}
514 cmd: |
515 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200516 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300517 id: {{ ssh['node_name'] }}
518 master: {{ config.salt.salt_master_host }}
519 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200520
521 # Configure ubuntu and salt repositories
522 which wget >/dev/null || (apt-get update; apt-get install -y wget);
523
524 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
525 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
526 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
527 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
528
529 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
530 wget -O - {{ SALT_GPG }} | apt-key add -;
531
532 apt-get clean
533 apt-get update
534
535 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300536 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200537 # Install common packages
538 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200539 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200540 # Restart salt-minion if it was already installed
541 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300542 node_name: {{ ssh['node_name'] }}
543 retry: {count: 1, delay: 1}
544 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200545 {%- else %}
546- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
547 cmd: echo "SSH to $(hostname -f) passed"
548 node_name: {{ ssh['node_name'] }}
549 retry: {count: 1, delay: 1}
550 skip_fail: false
551 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300552
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200553{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300554
555- description: Accept salt keys from all the nodes
556 cmd: salt-key -A -y
557 node_name: {{ HOSTNAME_CFG01 }}
558 retry: {count: 1, delay: 5}
559 skip_fail: true
560{%- endmacro %}
561
562
563{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
564{##################################################}
565
566{# Prepare salt services and nodes settings #}
567
568- description: Run 'linux' formula on cfg01
569 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
570 node_name: {{ HOSTNAME_CFG01 }}
571 retry: {count: 3, delay: 5}
572 skip_fail: false
573
574- description: Run 'openssh' formula on cfg01
575 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300576 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300577 salt --hard-crash --state-output=mixed --state-verbose=False
578 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300579 yes/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300580 node_name: {{ HOSTNAME_CFG01 }}
581 retry: {count: 3, delay: 5}
582 skip_fail: false
583
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300584- description: '*Workaround* of harcoded host from day01 grains'
585 cmd: salt-key -d cfg01.mcp-day01.local -y
586 node_name: {{ HOSTNAME_CFG01 }}
587 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400588 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300589
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300590- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
591 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
592 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
593 node_name: {{ HOSTNAME_CFG01 }}
594 retry: {count: 1, delay: 1}
595 skip_fail: false
596
597- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300598 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 +0300599 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300600 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300601 skip_fail: false
602
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400603{%- if SALT_FORMULAS_REFS != '' %}
604- description: Replace needed formulas to desired version
605 cmd: |
606 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400607 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
608 {% set formula = formula_set.split(':') %}
609 {% set formula_name = formula[0] %}
610 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300611 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400612 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
613 pushd {{ formula_dir }} &&
614 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
615 git checkout FETCH_HEAD &&
616 popd &&
617 if [ -d "{{ formula_dir }}" ]; then
618 echo "Going to replace packaged formula {{ formula_name }}" &&
619 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400620 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
621 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400622 else
623 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
624 fi
625 {%- endfor %}
626 node_name: {{ HOSTNAME_CFG01 }}
627 retry: {count: 1, delay: 10}
628 skip_fail: false
629{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300630
631- description: Refresh pillars on salt-master minion
632 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
633 node_name: {{ HOSTNAME_CFG01 }}
634 retry: {count: 1, delay: 5}
635 skip_fail: false
636
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300637- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300638 cmd: reclass-salt --top
639 node_name: {{ HOSTNAME_CFG01 }}
640 retry: {count: 1, delay: 5}
641 skip_fail: false
642
643- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300644 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 +0300645 node_name: {{ HOSTNAME_CFG01 }}
646 retry: {count: 1, delay: 5}
647 skip_fail: false
648
649- description: Configure linux on master
650 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
651 node_name: {{ HOSTNAME_CFG01 }}
652 retry: {count: 1, delay: 5}
653 skip_fail: false
654
655- description: Configure salt.minion on master
656 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
657 -C 'I@salt:master' state.sls salt.minion && sleep 10
658 node_name: {{ HOSTNAME_CFG01 }}
659 retry: {count: 3, delay: 10}
660 skip_fail: false
661
662- description: Run state 'salt' on master (for salt.api, etc)
663 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
664 -C 'I@salt:master' state.sls salt
665 node_name: {{ HOSTNAME_CFG01 }}
666 retry: {count: 3, delay: 10}
667 skip_fail: false
668{%- endmacro %}
669
Dennis Dmitriev85559962018-01-30 15:35:51 +0200670{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
671{#################################################################}
672
673- description: Refresh pillars before generating nodes
674 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
675 node_name: {{ HOSTNAME_CFG01 }}
676 retry: {count: 1, delay: 5}
677 skip_fail: false
678
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200679- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200680 cmd: |
681 set -e
682 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
683 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 +0200684 node_name: {{ HOSTNAME_CFG01 }}
685 retry: {count: 1, delay: 5}
686 skip_fail: false
687
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300688- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
689 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
690 -C 'I@salt:master' state.sls reclass
691 node_name: {{ HOSTNAME_CFG01 }}
692 retry: {count: 1, delay: 5}
693 skip_fail: false
694
Dennis Dmitriev85559962018-01-30 15:35:51 +0200695{%- if RERUN_SALTMASTER_STATE %}
696- description: Regenerate salt.master states for the newly uploaded/created model
697 cmd: |
698 # Need to refresh installed formulas that are required in the model
699 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
700 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
701 node_name: {{ HOSTNAME_CFG01 }}
702 retry: {count: 1, delay: 5}
703 skip_fail: false
704{%- endif %}
705
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300706- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200707 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300708 node_name: {{ HOSTNAME_CFG01 }}
709 retry: {count: 1, delay: 5}
710 skip_fail: false
711
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300712- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300713 cmd: |
714 set -e
715 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
716 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
717 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300718 node_name: {{ HOSTNAME_CFG01 }}
719 retry: {count: 1, delay: 5}
720 skip_fail: false
721
722- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300723 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300724 node_name: {{ HOSTNAME_CFG01 }}
725 retry: {count: 1, delay: 5}
726 skip_fail: false
727{%- endmacro %}
728
729
730{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
731{########################################}
732# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200733
734- description: Get linux kernel version from all minions
735 cmd: |
736 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
737 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
738 node_name: {{ HOSTNAME_CFG01 }}
739 retry: {count: 5, delay: 10}
740 skip_fail: false
741
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300742- description: Configure linux on other nodes
743 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
744 node_name: {{ HOSTNAME_CFG01 }}
745 retry: {count: 5, delay: 10}
746 skip_fail: false
747
748- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300749 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 +0300750 salt --hard-crash --state-output=mixed --state-verbose=False
751 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
752 yes/' /etc/ssh/sshd_config && service ssh reload"
753 node_name: {{ HOSTNAME_CFG01 }}
754 retry: {count: 1, delay: 5}
755 skip_fail: false
756
757- description: Configure salt.minion on other nodes
758 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 +0400759 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300760 node_name: {{ HOSTNAME_CFG01 }}
761 retry: {count: 3, delay: 15}
762 skip_fail: false
763
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400764- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400765 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400766 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400767 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400768 skip_fail: false
769
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400770- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200771 cmd: |
772 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
773 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400774 node_name: {{ HOSTNAME_CFG01 }}
775 retry: {count: 1, delay: 10}
776 skip_fail: false
777
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200778- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
779 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
780 node_name: {{ HOSTNAME_CFG01 }}
781 retry: {count: 1, delay: 10}
782 skip_fail: false
783
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300784- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400785 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300786 node_name: {{ HOSTNAME_CFG01 }}
787 retry: {count: 3, delay: 15}
788 skip_fail: false
789
790- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400791 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300792 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400793 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300794 skip_fail: false
795
796- description: Configure ntp and rsyslog on nodes
797 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
798 node_name: {{ HOSTNAME_CFG01 }}
799 retry: {count: 1, delay: 10}
800 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200801{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300802
803
804{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
805{#########################################}
806
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300807- description: '*Workaround: Load bonding module before call state.linux'
808 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
809 node_name: {{ HOSTNAME_CFG01 }}
810 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300811 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300812
813- description: '*Workaround* install bridge-utils before running linux formula'
814 # The formula removes default route and then tries to install the package, fails.
815 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
816 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
817 node_name: {{ HOSTNAME_CFG01 }}
818 retry: {count: 1, delay: 5}
819 skip_fail: false
820
821{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400822
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200823
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400824{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200825{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400826
827- description: Set k8s deploy parameters
828 cmd: |
829 {% for k8s_opt, value in config.k8s_deploy.items() %}
830 {% if value|string() %}
831 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
832 {% endif %}
833 {% endfor %}
834 node_name: {{ HOSTNAME_CFG01 }}
835 retry: {count: 1, delay: 1}
836 skip_fail: false
837
838{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400839
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200840
841{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
842{#############################################}
843- description: Set SL docker images deploy parameters
844 cmd: |
845 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
846 {%- for sl_opt, value in config.sl_deploy.items() %}
847 {%- if value|string() %}
848 {%- if OVERRIDES_FILENAME %}
849 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
850 {%- else %}
851 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
852 {%- endif %}
853 {%- endif %}
854 {%- endfor %}
855 salt '*' saltutil.refresh_pillar;
856 sleep 10
857 node_name: {{ HOSTNAME_CFG01 }}
858 retry: {count: 1, delay: 1}
859 skip_fail: false
860{%- endmacro %}
861
862
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400863{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200864{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400865
866{% for ssh in config.underlay.ssh %}
867{% if ssh["node_name"].startswith("cmp") %}
868{% set node_hostname = ssh["node_name"].split('.')[0] %}
869- description: Register compute {{ ssh['node_name'] }}
870 cmd: |
871 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
872 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
873 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400874 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400875 export config_host={{ config.salt.salt_master_host }}
876 export node_domain={{ DOMAIN_NAME }}
877 export nodes_os="xenial"
878 export node_hostname={{ node_hostname }}
879 set -xe
880 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
881 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
882 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
883 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
884
885 # Add wrapper to apt-get to avoid race conditions
886 # with cron jobs running 'unattended-upgrades' script
887 aptget_wrapper() {
888 local apt_wrapper_timeout=300
889 local start_time=$(date '+%s')
890 local fin_time=$((start_time + apt_wrapper_timeout))
891 while true; do
892 if (( "$(date '+%s')" > fin_time )); then
893 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
894 fi
895 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
896 echo "Waiting while another apt/dpkg process releases locks ..."
897 sleep 30
898 continue
899 else
900 apt-get $@
901 break
902 fi
903 done
904 }
905
906 # Set default salt version
907 if [ -z "$saltversion" ]; then
908 saltversion="2016.3"
909 fi
910 echo "Using Salt version $saltversion"
911
912 echo "Preparing base OS ..."
913
914 case "$node_os" in
915 trusty)
916 # workaround for old cloud-init only configuring the first iface
917 iface_config_dir="/etc/network/interfaces"
918 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
919
920 for iface in $ifaces; do
921 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
922 done
923
924 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
925
926 # SUGGESTED UPDATE:
927 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
928 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
929 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
930 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
931 #install_salt_minion_pkg
932
933 # DEPRECATED:
934 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
935 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
936
937 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
938 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
939
940 aptget_wrapper clean
941 aptget_wrapper update
942 aptget_wrapper install -y salt-common
943 aptget_wrapper install -y salt-minion
944 ;;
945 xenial)
946
947 # workaround for new cloud-init setting all interfaces statically
948 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
949
950 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
951
952 # SUGGESTED UPDATE:
953 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
954 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
955 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
956 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
957 #install_salt_minion_pkg
958
959 # DEPRECATED:
960 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
961 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
962
963 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
964 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
965
966 aptget_wrapper clean
967 aptget_wrapper update
968 aptget_wrapper install -y salt-minion
969 ;;
970 rhel|centos|centos7|centos7|rhel6|rhel7)
971 yum install -y git
972 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
973 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
974 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
975 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
976 install_salt_minion_pkg
977 ;;
978 *)
979 msg="OS '$node_os' is not supported."
980 esac
981
982 echo "Configuring Salt minion ..."
983 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
984 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
985
986 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
987
988 sleep 1
989
990 echo "Classifying node ..."
991 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
992 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
993 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
994 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
995 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
996 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
997
998 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
999 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1000 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1001 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1002 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1003
1004 if [ "$node_network05_iface" != "" ]; then
1005 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1006 fi
1007
1008 # find more parameters (every env starting param_)
1009 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1010 if [ "$more_params" != "" ]; then
1011 echo "Additional params: $more_params"
1012 more_params=", $more_params"
1013 fi
1014
1015 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}}"
1016
1017 sleep 5
1018
1019 salt-call saltutil.sync_all
1020 salt-call mine.flush
1021 salt-call mine.update
1022 node_name: {{ ssh['node_name'] }}
1023 retry: {count: 1, delay: 1}
1024 skip_fail: false
1025{%- endif %}
1026{%- endfor %}
1027
1028- description: Refresh pillars on all minions
1029 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1030 node_name: {{ HOSTNAME_CFG01 }}
1031 retry: {count: 1, delay: 5}
1032 skip_fail: false
1033
1034- description: Sync all salt resources
1035 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1036 node_name: {{ HOSTNAME_CFG01 }}
1037 retry: {count: 1, delay: 5}
1038 skip_fail: false
1039
sgudz160b7302017-12-22 17:01:10 +02001040{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001041
1042{%- macro RUN_NEW_TEMPEST() %}
1043{###################################}
1044
1045- description: Upload tempest template
1046 upload:
1047 local_path: {{ config.salt_deploy.templates_dir }}
1048 local_filename: runtest.yml
1049 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1050 node_name: {{ HOSTNAME_CFG01 }}
1051 skip_fail: False
1052
1053- description: Include class with tempest template into cfg node
1054 cmd: |
1055 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1056 salt 'cfg01*' saltutil.refresh_pillar;
1057 salt 'cfg01*' saltutil.sync_all;
1058 node_name: {{ HOSTNAME_CFG01 }}
1059 retry: {count: 1, delay: 10}
1060 skip_fail: false
1061
1062- description: Create flavors for tests
1063 cmd: |
1064 salt 'cfg01*' state.sls nova.client;
1065 node_name: {{ HOSTNAME_CFG01 }}
1066 retry: {count: 1, delay: 5}
1067 skip_fail: false
1068
1069- description: Create networks for tests
1070 cmd: |
1071 salt 'cfg01*' state.sls neutron.client;
1072 node_name: {{ HOSTNAME_CFG01 }}
1073 retry: {count: 1, delay: 5}
1074 skip_fail: false
1075
1076- description: Upload cirros image
1077 cmd: |
1078 salt 'cfg01*' state.sls glance.client;
1079 node_name: {{ HOSTNAME_CFG01 }}
1080 retry: {count: 1, delay: 5}
1081 skip_fail: false
1082
1083- description: Generate tempest config
1084 cmd: |
1085 salt 'cfg01*' state.sls runtest;
1086 node_name: {{ HOSTNAME_CFG01 }}
1087 retry: {count: 1, delay: 5}
1088 skip_fail: false
1089
Oleksii Butenkoa3026ae2018-04-20 18:28:58 +03001090- description: Temp WR for PROD-19442
1091 cmd: |
1092 apt-get install crudini -y;
obutenko9652b992018-04-22 20:38:35 +03001093 crudini --verbose --set /root/test/tempest.conf validation connect_method floating;
1094 crudini --verbose --set /root/test/tempest.conf validation run_validation True;
1095 crudini --verbose --set /root/test/tempest.conf validation image_ssh_user cirros;
Oleksii Butenkoa3026ae2018-04-20 18:28:58 +03001096 node_name: {{ HOSTNAME_GTW01 }}
1097 retry: {count: 1, delay: 30}
1098 skip_fail: true
1099
sgudz09e9aa92018-04-12 12:31:53 +03001100- description: Run tempest from new docker image
1101 cmd: |
Tatyana Leontovich69700712018-04-23 12:26:57 +03001102 docker run -e ARGS="-r {{TEMPEST_PATTERN }} -w 4 {{ EXCLUDE_TEST_ARGS }}" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest /bin/bash -c "run-tempest"
sgudz09e9aa92018-04-12 12:31:53 +03001103 node_name: {{ HOSTNAME_GTW01 }}
1104 retry: {count: 1, delay: 30}
1105 skip_fail: true
1106
1107- description: Download xml results
1108 download:
1109 remote_path: /root/test/
1110 remote_filename: "report_*.xml"
1111 local_path: {{ os_env('PWD') }}
1112 node_name: {{ HOSTNAME_GTW01 }}
1113 skip_fail: true
1114
1115{%- endmacro %}