blob: 653eef9691d0079de6cd99f74767ebeed847192b [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') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030018#{% 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_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-2016.3/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %}
Dennis Dmitrievcf777802018-02-14 18:09:55 +020020{% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %}
21{% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %}
22{% 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") %}
23{% set UBUNTU_SECURITY_REPOSITORY = os_env('UBUNTU_SECURITY_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME}-security main restricted universe") %}
Dennis Dmitriev9a532a52018-05-07 13:55:27 +030024{% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %}
Tatyana Leontovich908ab932018-04-27 01:25:09 +030025{% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +030026
Sergii Golovatiuk50f91892017-08-04 18:11:06 +020027{# Address pools for reclass cluster model are taken in the following order:
28 # 1. environment variables,
29 # 2. config.underlay.address_pools based on fuel-devops address pools
30 # (see generated '.ini' file after underlay is created),
31 # 3. defaults #}
32{% set address_pools = config.underlay.address_pools %}
33{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
34{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
35{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
36{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
37{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
38{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
39{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
40{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
41
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040042{# Format for formula replacement:
43 # space separated string:
44 # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #}
45
46{% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %}
Tatyana Leontovich1c101312018-04-18 20:33:08 +030047{% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %}
Tatyana Leontovich69700712018-04-23 12:26:57 +030048{% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +040049{% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %}
50
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040051# Needed for using different models in different templates
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +020052{% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +040053
Dennis Dmitriev492813e2017-08-09 15:08:58 +030054
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020055{%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %}
56{#####################################################}
57
58- description: 'Configure key on nodes and install packages'
59 cmd: |
60 rm -rf trusted* ;
61 rm -rf /etc/apt/sources.list ;
Dennis Dmitrievcf777802018-02-14 18:09:55 +020062 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020063 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
64 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
65 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030066 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020067 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list
68 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list
69 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list
Dennis Dmitrievf4e6efc2018-03-26 06:15:10 -050070 eatmydata apt-get clean;
71 apt-get update;
Dennis Dmitriev01d5e372018-03-15 23:29:29 +020072 sync;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +020073 node_name: {{ NODE_NAME }}
74 retry: {count: 1, delay: 5}
75 skip_fail: false
76
77{%- endmacro %}
78
79
Dennis Dmitriev492813e2017-08-09 15:08:58 +030080{%- macro MACRO_INSTALL_SALT_MASTER() %}
81{######################################}
82- description: Installing salt master on cfg01
Dennis Dmitrievcf777802018-02-14 18:09:55 +020083 cmd: |
84 which wget >/dev/null || (apt-get update; apt-get install -y wget);
85 # Configure ubuntu and salt repositories
86 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
87 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
88 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
89 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
90
91 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
92 wget -O - {{ FORMULA_GPG }} | apt-key add -;
93 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +030094 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
95
Dennis Dmitrievcf777802018-02-14 18:09:55 +020096
97 apt-get clean
98 apt-get update
99
100 # Install salt-master and reclass
101 eatmydata apt-get install -y --allow-unauthenticated reclass salt-master
102 # Install common packages
Dennis Dmitrievf88fc7d2018-02-20 15:40:08 +0200103 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 +0200104 sync;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300105 node_name: {{ HOSTNAME_CFG01 }}
106 retry: {count: 1, delay: 1}
107 skip_fail: false
108
Dennis Dmitrievda9be462018-01-24 21:20:09 +0200109- description: Remove any existing minion keys
110 cmd: salt-key -y -D || true
111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 1, delay: 1}
113 skip_fail: false
114
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300115- description: Configure salt-master on cfg01
116 cmd: |
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200117 cat << 'EOF' > /etc/salt/master.d/master.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300118 file_roots:
119 base:
120 - /usr/share/salt-formulas/env
121 pillar_opts: False
122 open_mode: True
123 reclass: &reclass
124 storage_type: yaml_fs
125 inventory_base_uri: /srv/salt/reclass
126 ext_pillar:
127 - reclass: *reclass
128 master_tops:
129 reclass: *reclass
130 EOF
131 node_name: {{ HOSTNAME_CFG01 }}
132 retry: {count: 1, delay: 1}
133 skip_fail: false
134
135- description: Configure GIT settings and certificates
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300136 cmd: |
137 set -e;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200138 #touch /root/.git_trusted_certs.pem;
139 #for server in github.com; do \
140 # openssl s_client -showcerts -connect $server:443 </dev/null \
141 # | openssl x509 -outform PEM \
142 # >> /root/.git_trusted_certs.pem;
143 #done;
144 #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem;
145 HOME=/root git config --global user.email "mcp-integration-qa@example.com";
146 HOME=/root git config --global user.name "MCP Integration QA";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300147 node_name: {{ HOSTNAME_CFG01 }}
148 retry: {count: 1, delay: 1}
149 skip_fail: false
150{%- endmacro %}
151
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300152{%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %}
153{############################################################}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300154{# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #}
155
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300156- description: Clone reclass models with submodules
157 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300158 set -e;
Dennis Dmitriev75776c52017-12-26 18:22:53 +0200159 set -x;
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200160 #ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200161
162 # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory
163 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 +0200164 rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass;
Dennis Dmitrievf00a3842018-01-24 16:44:26 +0200165
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200166 pushd /srv/salt/reclass;
167 git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}";
168 git submodule update --init --recursive;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200169 {%- if SALT_MODELS_REF_CHANGE != '' %}
170 {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200171 git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200172 {%- endfor %}
173 {%- elif SALT_MODELS_COMMIT != 'master' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200174 git checkout {{ SALT_MODELS_COMMIT }};
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200175 {%- endif %}
176 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200177 pushd classes/system/;
178 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }};
179 popd;
sgudz4d816eb2017-11-13 11:58:05 +0200180 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300181 pushd classes/system/ && \
182 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200183 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD;
Dmitry Tyzhnenko778515f2017-08-25 14:52:54 +0300184 {%- endfor %}
Dennis Dmitriev55ddd792017-12-22 16:35:57 +0200185 popd;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200186 {%- endif %}
187 popd;
188 mkdir -p /srv/salt/reclass/classes/service;
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300189 mkdir -p /srv/salt/reclass/nodes/_generated/;
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200190
191 # Replace firstly to an intermediate value to avoid intersection between
192 # already replaced and replacing networks.
193 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
194 # 192.168.10 -> 10.16.0 (generated network for admin)
195 # 10.16.0 -> <external network>
196 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300197 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200198 find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} +
199 find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} +
200 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} +
201 find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200202
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200203 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} +
204 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} +
205 find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} +
206 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 +0200207
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300208 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 +0200209
Tatyana Leontovicha4a96b22018-04-25 14:30:24 +0300210 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300211 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
Dennis Dmitriev9d9ba9f2017-09-13 17:34:03 +0300212 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 +0300213 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 +0300214 {%- endif %}
215
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200216 # Override some context parameters
217 {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %}
218 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} +
219 find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} +
220
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200221 # Create the cfg01 inventory file or use existing
222 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
223 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300224 classes:
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400225 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrievb2e78be2017-09-26 23:25:24 +0300226 parameters:
227 _param:
228 linux_system_codename: xenial
229 reclass_data_revision: master
230 linux:
231 system:
232 name: cfg01
233 domain: {{ DOMAIN_NAME }}
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200234 reclass:
235 storage:
236 data_source:
237 engine: local
238 EOF
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300239
240 # Show the changes to the console
241 cd /srv/salt/reclass/; git diff
242 node_name: {{ HOSTNAME_CFG01 }}
243 retry: {count: 1, delay: 1}
244 skip_fail: false
245{%- endmacro %}
246
247
sgudz160b7302017-12-22 17:01:10 +0200248{%- 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 +0300249{###################################################################}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300250{%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200251- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300252 upload:
253 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
254 local_filename: {{ CLUSTER_CONTEXT_NAME }}
Dennis Dmitriev1c1352a2017-09-28 21:45:27 +0300255 remote_path: /tmp/
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300256 node_name: {{ HOSTNAME_CFG01 }}
257
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300258- description: Create cluster model from cookiecutter templates
259 cmd: |
260 set -e;
Tatyana Leontovichb92a53d2018-04-17 14:15:38 +0300261 sudo apt-get install python-setuptools -y
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300262 pip install cookiecutter
263 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 +0200264
sgudza399dc72018-01-18 17:13:48 +0200265 {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %}
266 pushd /tmp/cookiecutter-templates
267 git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }}
268 popd
269 {%- endif %}
270
sgudz4d816eb2017-11-13 11:58:05 +0200271 {%- if COOKIECUTTER_REF_CHANGE != '' %}
272 pushd /tmp/cookiecutter-templates
273 git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD
274 popd
275 {%- endif %}
276
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300277 mkdir -p /srv/salt/reclass/classes/cluster/
278 mkdir -p /srv/salt/reclass/classes/system/
279 mkdir -p /srv/salt/reclass/classes/service/
280 mkdir -p /srv/salt/reclass/nodes/_generated
281
282 # Override some context parameters
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200283 sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
284 sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200285 sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300286 {%- if CONTROL_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200287 sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300288 {%- endif %}
289 {%- if TENANT_VLAN %}
Dennis Dmitrievf5bef572017-12-24 17:52:41 +0200290 sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }}
sgudz8c888ec2017-10-02 15:29:23 +0300291 {%- endif %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300292
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300293 # Replace firstly to an intermediate value to avoid intersection between
294 # already replaced and replacing networks.
295 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
296 # 192.168.10 -> 10.16.0 (generated network for admin)
297 # 10.16.0 -> <external network>
298 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
299 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
300 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
301 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200302 sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300303
Dennis Dmitriev39e64bd2017-09-21 22:37:40 +0300304 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
305 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
306 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitriev806f3b52018-02-26 18:04:24 +0200307 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300308
sgudz160b7302017-12-22 17:01:10 +0200309 {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %}
310 for item in {{ items }}; do
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300311 python /tmp/cookiecutter-templates/generate.py \
sgudz160b7302017-12-22 17:01:10 +0200312 --template /tmp/cookiecutter-templates/cluster_product/$item \
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300313 --config-file {{ CLUSTER_CONTEXT_PATH }} \
314 --output-dir /srv/salt/reclass/classes/cluster/;
315 done
316
317 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
318
Dennis Dmitriev97e78e22018-02-23 21:51:49 +0200319 # Create the cfg01 inventory file or use existing
320 export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml"
321 [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300322 classes:
323 - system.openssh.server.team.all
Dennis Dmitrievbdb2b9b2017-12-22 18:00:18 +0200324 - cluster.{{ CLUSTER_NAME }}.infra.config
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300325 EOF
326
327 node_name: {{ HOSTNAME_CFG01 }}
328 retry: {count: 1, delay: 1}
329 skip_fail: false
330
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300331- description: Modify generated model and reclass-system if necessary
332 cmd: |
333 set -e;
334 {%- if SALT_MODELS_SYSTEM_COMMIT != '' %}
335 pushd /srv/salt/reclass/classes/system/
336 git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \
337 popd
sgudz4d816eb2017-11-13 11:58:05 +0200338 {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %}
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300339 pushd /srv/salt/reclass/classes/system/
340 {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %}
341 git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD
342 {%- endfor %}
343 popd
344 {%- endif %}
345
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300346 {%- if IS_CONTRAIL_LAB %}
Dennis Dmitriev862f7752018-01-19 17:12:11 +0200347 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
Dennis Dmitrieva5f38e42017-09-21 21:52:25 +0300348 # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded
349 find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} +
350 find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} +
351 {%- endif %}
352
353 node_name: {{ HOSTNAME_CFG01 }}
354 retry: {count: 1, delay: 1}
355 skip_fail: false
356{%- endmacro %}
357
358
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300359{%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %}
360{########################################################}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300361
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200362- description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9e18de72017-10-11 18:14:36 +0300363 cmd: |
364 set -e;
365 mkdir -p /tmp/environment/;
366 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 +0300367 node_name: {{ HOSTNAME_CFG01 }}
368 skip_fail: false
369
sgudzcced67d2017-10-11 15:56:09 +0300370{%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %}
371- description: Fetch changes for environment templates
372 cmd: |
373 set -e;
374 pushd /tmp/environment/environment_template &&
375 git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} &&
376 git checkout FETCH_HEAD &&
377 popd
378 node_name: {{ HOSTNAME_CFG01 }}
379 skip_fail: false
380{%- endif %}
381
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300382{%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %}
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200383- description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300384 upload:
385 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
386 local_filename: {{ ENVIRONMENT_CONTEXT_NAME }}
387 remote_path: /tmp/environment/
388 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrievccdc87a2017-09-28 17:43:54 +0300389{%- endfor %}
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300390
391- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
392 cmd: |
393 set -e;
394 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200395 [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools;
396 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300397 pip install git+https://github.com/dis-xcom/reclass-tools;
398 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
399 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
400 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
401
Dennis Dmitriev6368f082018-02-23 13:30:30 -0500402 if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
403 reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ;
404 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 +0300405 fi;
406
407 node_name: {{ HOSTNAME_CFG01 }}
408 retry: {count: 1, delay: 5}
409 skip_fail: false
410
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200411- description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'"
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300412 cmd: |
413 set -e;
Dennis Dmitriev222ba8e2017-11-11 00:06:02 +0200414 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 +0300415
416 node_name: {{ HOSTNAME_CFG01 }}
417 retry: {count: 1, delay: 5}
418 skip_fail: false
419
420- description: "[EXPERIMENTAL] Create environment model for virtual environment"
421 cmd: |
422 set -e;
Dennis Dmitrievd96ace12018-01-26 14:46:21 +0200423 . /root/venv-reclass-tools/bin/activate;
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300424 reclass-tools render --template-dir /tmp/environment/environment_template/ \
425 --output-dir /srv/salt/reclass/classes/environment/ \
Dennis Dmitrievd55a8562017-09-28 22:12:09 +0300426 {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300427 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
428 node_name: {{ HOSTNAME_CFG01 }}
429 retry: {count: 1, delay: 5}
430 skip_fail: false
sgudz8c888ec2017-10-02 15:29:23 +0300431
432- description: Modify generated model and reclass-system
433 cmd: |
434 export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/"
435 find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} +
436 node_name: {{ HOSTNAME_CFG01 }}
437 retry: {count: 1, delay: 1}
438 skip_fail: false
439
Dennis Dmitriev9f141af2017-09-28 17:21:01 +0300440{%- endmacro %}
441
442
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300443{%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %}
444{#######################################################}
445- description: Configure reclass
446 cmd: |
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300447 set -e;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300448 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300449 which wget > /dev/null || (apt-get update; apt-get install -y wget);
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200450 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
Dennis Dmitriev3fbbc7f2017-12-21 15:42:14 +0200451 echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list;
452 wget -O - "{{ FORMULA_GPG }}" | apt-key add -;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300453 apt-get clean; apt-get update;
454 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
455 declare -a formula_services=({{ FORMULA_SERVICES }});
456 echo -e "\nInstalling all required salt formulas\n";
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200457 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300458 for formula_service in "${formula_services[@]}"; do
459 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
460 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
461 done;
462 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
463 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
464 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
465
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200466 cat << 'EOF' > /etc/reclass/reclass-config.yml
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300467 storage_type: yaml_fs
468 pretty_print: True
469 output: yaml
470 inventory_base_uri: /srv/salt/reclass
471 EOF
472 node_name: {{ HOSTNAME_CFG01 }}
473 retry: {count: 1, delay: 1}
474 skip_fail: false
475
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200476- 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 +0300477 cmd: |
Dennis Dmitriev92295c02018-02-02 13:18:25 +0200478 # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top'
479 find /srv/salt/reclass/nodes/ -type f -not -name cfg01.{{ DOMAIN_NAME }}.yml -delete
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300480 node_name: {{ HOSTNAME_CFG01 }}
481 retry: {count: 1, delay: 5}
482 skip_fail: false
483
484- description: Configure salt adoptors on cfg01
485 cmd: |
486 ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt;
487 chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py
488 node_name: {{ HOSTNAME_CFG01 }}
489 retry: {count: 1, delay: 1}
490 skip_fail: false
491
492- description: Show reclass-salt --top for cfg01 node
493 cmd: reclass-salt --top
494 node_name: {{ HOSTNAME_CFG01 }}
495 retry: {count: 1, delay: 5}
496 skip_fail: false
497
498- description: Restart salt-master service
ibumarskov712a6872018-04-25 09:22:15 +0400499 cmd: service salt-master restart;
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300500 node_name: {{ HOSTNAME_CFG01 }}
501 retry: {count: 1, delay: 5}
502 skip_fail: false
503{%- endmacro %}
504
505
506{%- macro MACRO_INSTALL_SALT_MINIONS() %}
507{#######################################}
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200508{%- for ssh in config.underlay.ssh %}
509 {%- set salt_roles = [] %}
510 {%- for role in ssh['roles'] %}
511 {%- if role in config.salt_deploy.salt_roles %}
512 {%- set _ = salt_roles.append(role) %}
513 {%- endif %}
514 {%- endfor %}
515
516 {%- if salt_roles %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300517- description: Configure salt-minion on {{ ssh['node_name'] }}
518 cmd: |
519 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
Dennis Dmitrieva578c772018-01-24 21:02:15 +0200520 cat << "EOF" > /etc/salt/minion.d/minion.conf
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300521 id: {{ ssh['node_name'] }}
522 master: {{ config.salt.salt_master_host }}
523 EOF
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200524
525 # Configure ubuntu and salt repositories
526 which wget >/dev/null || (apt-get update; apt-get install -y wget);
527
528 . /etc/lsb-release; # Get DISTRIB_CODENAME variable
529 echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list
530 echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list
531 echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list
532
533 echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list;
Tatyana Leontovich908ab932018-04-27 01:25:09 +0300534 apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}"
535
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200536
537 apt-get clean
538 apt-get update
539
540 # Install salt-minion
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300541 eatmydata apt-get install -y salt-minion;
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200542 # Install common packages
543 eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
Dennis Dmitriev01d5e372018-03-15 23:29:29 +0200544 sync
Dennis Dmitrievcf777802018-02-14 18:09:55 +0200545 # Restart salt-minion if it was already installed
546 service salt-minion restart
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300547 node_name: {{ ssh['node_name'] }}
548 retry: {count: 1, delay: 1}
549 skip_fail: false
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200550 {%- else %}
551- description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }}
552 cmd: echo "SSH to $(hostname -f) passed"
553 node_name: {{ ssh['node_name'] }}
554 retry: {count: 1, delay: 1}
555 skip_fail: false
556 {%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300557
Dennis Dmitriev5bcbdc52018-03-23 18:05:10 +0200558{%- endfor %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300559
560- description: Accept salt keys from all the nodes
561 cmd: salt-key -A -y
562 node_name: {{ HOSTNAME_CFG01 }}
563 retry: {count: 1, delay: 5}
564 skip_fail: true
565{%- endmacro %}
566
567
568{%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %}
569{##################################################}
570
571{# Prepare salt services and nodes settings #}
572
573- description: Run 'linux' formula on cfg01
574 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux;
575 node_name: {{ HOSTNAME_CFG01 }}
576 retry: {count: 3, delay: 5}
577 skip_fail: false
578
579- description: Run 'openssh' formula on cfg01
580 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300581 -C 'I@salt:master' state.sls openssh &&
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300582 salt --hard-crash --state-output=mixed --state-verbose=False
583 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovicha14fef42018-05-21 15:30:25 +0300584 yes/' /etc/ssh/sshd_config && sed -i 's/ClientAliveInterval 300/ClientAliveInterval 3000/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300585 node_name: {{ HOSTNAME_CFG01 }}
586 retry: {count: 3, delay: 5}
587 skip_fail: false
588
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300589- description: '*Workaround* of harcoded host from day01 grains'
590 cmd: salt-key -d cfg01.mcp-day01.local -y
591 node_name: {{ HOSTNAME_CFG01 }}
592 retry: {count: 1, delay: 1}
Victor Ryzhenkin01040942018-04-17 15:45:58 +0400593 skip_fail: true
Tatyana Leontovich907757f2018-04-17 12:29:33 +0300594
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300595- description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962'
596 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
597 '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config"
598 node_name: {{ HOSTNAME_CFG01 }}
599 retry: {count: 1, delay: 1}
600 skip_fail: false
601
602- description: Run 'salt.master' formula on cfg01
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300603 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 +0300604 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieve575e982017-10-21 21:50:45 +0300605 retry: {count: 2, delay: 30}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300606 skip_fail: false
607
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400608{%- if SALT_FORMULAS_REFS != '' %}
609- description: Replace needed formulas to desired version
610 cmd: |
611 set -e;
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400612 {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %}
613 {% set formula = formula_set.split(':') %}
614 {% set formula_name = formula[0] %}
615 {% set formula_ref = formula[1] %}
Dennis Dmitrievbc57b802017-08-16 18:10:57 +0300616 {% set formula_dir = '/tmp/salt-formula-' + formula_name %}
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400617 git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} &&
618 pushd {{ formula_dir }} &&
619 git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} &&
620 git checkout FETCH_HEAD &&
621 popd &&
622 if [ -d "{{ formula_dir }}" ]; then
623 echo "Going to replace packaged formula {{ formula_name }}" &&
624 rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} &&
Victor Ryzhenkinc7913682017-10-11 15:14:40 +0400625 ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" &&
626 ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}";
Victor Ryzhenkin4e077ad2017-08-10 13:42:11 +0400627 else
628 echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!";
629 fi
630 {%- endfor %}
631 node_name: {{ HOSTNAME_CFG01 }}
632 retry: {count: 1, delay: 10}
633 skip_fail: false
634{%- endif %}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300635
636- description: Refresh pillars on salt-master minion
637 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar
638 node_name: {{ HOSTNAME_CFG01 }}
639 retry: {count: 1, delay: 5}
640 skip_fail: false
641
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300642- description: Show reclass-salt --top for salt-master node
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300643 cmd: reclass-salt --top
644 node_name: {{ HOSTNAME_CFG01 }}
645 retry: {count: 1, delay: 5}
646 skip_fail: false
647
648- description: Sync all salt resources on salt-master minion
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300649 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 +0300650 node_name: {{ HOSTNAME_CFG01 }}
651 retry: {count: 1, delay: 5}
652 skip_fail: false
653
654- description: Configure linux on master
655 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system'
656 node_name: {{ HOSTNAME_CFG01 }}
657 retry: {count: 1, delay: 5}
658 skip_fail: false
659
660- description: Configure salt.minion on master
661 cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False
662 -C 'I@salt:master' state.sls salt.minion && sleep 10
663 node_name: {{ HOSTNAME_CFG01 }}
664 retry: {count: 3, delay: 10}
665 skip_fail: false
666
667- description: Run state 'salt' on master (for salt.api, etc)
668 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
669 -C 'I@salt:master' state.sls salt
670 node_name: {{ HOSTNAME_CFG01 }}
671 retry: {count: 3, delay: 10}
672 skip_fail: false
673{%- endmacro %}
674
Dennis Dmitriev85559962018-01-30 15:35:51 +0200675{%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %}
676{#################################################################}
677
678- description: Refresh pillars before generating nodes
679 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
680 node_name: {{ HOSTNAME_CFG01 }}
681 retry: {count: 1, delay: 5}
682 skip_fail: false
683
Dennis Dmitrieve1160fe2018-03-01 01:20:27 +0200684- description: Validate pillar on salt master node
Dennis Dmitriev54a13002018-03-01 11:37:04 +0200685 cmd: |
686 set -e
687 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
688 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 +0200689 node_name: {{ HOSTNAME_CFG01 }}
690 retry: {count: 1, delay: 5}
691 skip_fail: false
692
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300693- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
694 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
695 -C 'I@salt:master' state.sls reclass
696 node_name: {{ HOSTNAME_CFG01 }}
697 retry: {count: 1, delay: 5}
698 skip_fail: false
699
Dennis Dmitriev85559962018-01-30 15:35:51 +0200700{%- if RERUN_SALTMASTER_STATE %}
701- description: Regenerate salt.master states for the newly uploaded/created model
702 cmd: |
703 # Need to refresh installed formulas that are required in the model
704 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5;
705 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master;
706 node_name: {{ HOSTNAME_CFG01 }}
707 retry: {count: 1, delay: 5}
708 skip_fail: false
709{%- endif %}
710
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300711- description: Refresh pillars on all minions
Dennis Dmitriev85559962018-01-30 15:35:51 +0200712 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300713 node_name: {{ HOSTNAME_CFG01 }}
714 retry: {count: 1, delay: 5}
715 skip_fail: false
716
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300717- description: Show reclass-salt --top for all generated nodes
Dennis Dmitriev4386a072017-09-04 13:58:02 +0300718 cmd: |
719 set -e
720 if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi
721 if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi
722 reclass-salt --top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300723 node_name: {{ HOSTNAME_CFG01 }}
724 retry: {count: 1, delay: 5}
725 skip_fail: false
726
727- description: Sync all salt resources
Dennis Dmitriev9a6cacc2017-08-14 00:08:41 +0300728 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300729 node_name: {{ HOSTNAME_CFG01 }}
730 retry: {count: 1, delay: 5}
731 skip_fail: false
732{%- endmacro %}
733
734
735{%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %}
736{########################################}
737# Bootstrap all nodes
Dennis Dmitriev8ed27882018-01-31 23:23:19 +0200738
739- description: Get linux kernel version from all minions
740 cmd: |
741 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort
742 salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort
743 node_name: {{ HOSTNAME_CFG01 }}
744 retry: {count: 5, delay: 10}
745 skip_fail: false
746
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300747- description: Configure linux on other nodes
748 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux
749 node_name: {{ HOSTNAME_CFG01 }}
750 retry: {count: 5, delay: 10}
751 skip_fail: false
752
753- description: Configure openssh on all nodes
Dennis Dmitriev3e731a42017-08-30 17:12:59 +0300754 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 +0300755 salt --hard-crash --state-output=mixed --state-verbose=False
756 -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
Tatyana Leontovichb6896842018-05-21 19:40:49 +0300757 yes/' /etc/ssh/sshd_config && sed -i 's/ClientAliveInterval 300/ClientAliveInterval 18000/' /etc/ssh/sshd_config && service ssh reload"
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300758 node_name: {{ HOSTNAME_CFG01 }}
759 retry: {count: 1, delay: 5}
760 skip_fail: false
761
762- description: Configure salt.minion on other nodes
763 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 +0400764 sleep 30
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300765 node_name: {{ HOSTNAME_CFG01 }}
766 retry: {count: 3, delay: 15}
767 skip_fail: false
768
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400769- description: Wait for salt-minions wake up after restart
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400770 cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400771 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin21bae992018-03-06 17:28:41 +0400772 retry: {count: 25, delay: 30}
Victor Ryzhenkin93b49ff2018-03-06 15:59:51 +0400773 skip_fail: false
774
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400775- description: Update minion information
Dennis Dmitrievea291ee2018-03-16 12:27:43 +0200776 cmd: |
777 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
778 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15
Victor Ryzhenkina06443e2018-03-15 17:25:19 +0400779 node_name: {{ HOSTNAME_CFG01 }}
780 retry: {count: 1, delay: 10}
781 skip_fail: false
782
Dennis Dmitriev14183db2018-03-01 15:14:12 +0200783- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
784 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
785 node_name: {{ HOSTNAME_CFG01 }}
786 retry: {count: 1, delay: 10}
787 skip_fail: false
788
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300789- description: Check salt minion versions on slaves
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400790 cmd: salt --timeout=60 '*' test.version
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300791 node_name: {{ HOSTNAME_CFG01 }}
792 retry: {count: 3, delay: 15}
793 skip_fail: false
794
795- description: Check salt top states on nodes
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400796 cmd: salt --timeout=60 '*' state.show_top
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300797 node_name: {{ HOSTNAME_CFG01 }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400798 retry: {count: 3, delay: 15}
Dennis Dmitriev492813e2017-08-09 15:08:58 +0300799 skip_fail: false
800
801- description: Configure ntp and rsyslog on nodes
802 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog
803 node_name: {{ HOSTNAME_CFG01 }}
804 retry: {count: 1, delay: 10}
805 skip_fail: false
Sergii Golovatiuk50f91892017-08-04 18:11:06 +0200806{%- endmacro %}
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300807
808
809{%- macro MACRO_NETWORKING_WORKAROUNDS() %}
810{#########################################}
811
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300812- description: '*Workaround: Load bonding module before call state.linux'
813 cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding'
814 node_name: {{ HOSTNAME_CFG01 }}
815 retry: {count: 1, delay: 5}
Dennis Dmitriev0496eb72017-09-05 21:42:10 +0300816 skip_fail: true
Dennis Dmitriev9dada8a2017-08-30 17:38:55 +0300817
818- description: '*Workaround* install bridge-utils before running linux formula'
819 # The formula removes default route and then tries to install the package, fails.
820 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
821 cfg01*' cmd.run 'sudo apt-get install -y bridge-utils'
822 node_name: {{ HOSTNAME_CFG01 }}
823 retry: {count: 1, delay: 5}
824 skip_fail: false
825
826{%- endmacro %}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400827
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200828
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400829{%- macro ADJUST_K8S_OPTS() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200830{############################}
Victor Ryzhenkin9cc824c2017-10-12 19:02:23 +0400831
832- description: Set k8s deploy parameters
833 cmd: |
834 {% for k8s_opt, value in config.k8s_deploy.items() %}
835 {% if value|string() %}
836 salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }};
837 {% endif %}
838 {% endfor %}
839 node_name: {{ HOSTNAME_CFG01 }}
840 retry: {count: 1, delay: 1}
841 skip_fail: false
842
843{%- endmacro %}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400844
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200845
846{%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %}
847{#############################################}
848- description: Set SL docker images deploy parameters
849 cmd: |
850 {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #}
851 {%- for sl_opt, value in config.sl_deploy.items() %}
852 {%- if value|string() %}
853 {%- if OVERRIDES_FILENAME %}
854 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }};
855 {%- else %}
856 salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }};
857 {%- endif %}
858 {%- endif %}
859 {%- endfor %}
860 salt '*' saltutil.refresh_pillar;
861 sleep 10
862 node_name: {{ HOSTNAME_CFG01 }}
863 retry: {count: 1, delay: 1}
864 skip_fail: false
865{%- endmacro %}
866
867
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400868{%- macro REGISTER_COMPUTE_NODES() %}
Dennis Dmitriev257a9382018-02-15 04:00:46 +0200869{###################################}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400870
871{% for ssh in config.underlay.ssh %}
872{% if ssh["node_name"].startswith("cmp") %}
873{% set node_hostname = ssh["node_name"].split('.')[0] %}
874- description: Register compute {{ ssh['node_name'] }}
875 cmd: |
876 exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
877 export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
878 export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
Victor Ryzhenkin66593e92017-11-28 19:38:33 +0400879 export cluster_name={{ CLUSTER_NAME }}
Victor Ryzhenkin42e24232017-11-15 08:01:20 -0400880 export config_host={{ config.salt.salt_master_host }}
881 export node_domain={{ DOMAIN_NAME }}
882 export nodes_os="xenial"
883 export node_hostname={{ node_hostname }}
884 set -xe
885 export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
886 export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
887 export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
888 export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
889
890 # Add wrapper to apt-get to avoid race conditions
891 # with cron jobs running 'unattended-upgrades' script
892 aptget_wrapper() {
893 local apt_wrapper_timeout=300
894 local start_time=$(date '+%s')
895 local fin_time=$((start_time + apt_wrapper_timeout))
896 while true; do
897 if (( "$(date '+%s')" > fin_time )); then
898 msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
899 fi
900 if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
901 echo "Waiting while another apt/dpkg process releases locks ..."
902 sleep 30
903 continue
904 else
905 apt-get $@
906 break
907 fi
908 done
909 }
910
911 # Set default salt version
912 if [ -z "$saltversion" ]; then
913 saltversion="2016.3"
914 fi
915 echo "Using Salt version $saltversion"
916
917 echo "Preparing base OS ..."
918
919 case "$node_os" in
920 trusty)
921 # workaround for old cloud-init only configuring the first iface
922 iface_config_dir="/etc/network/interfaces"
923 ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
924
925 for iface in $ifaces; do
926 grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
927 done
928
929 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
930
931 # SUGGESTED UPDATE:
932 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
933 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
934 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
935 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
936 #install_salt_minion_pkg
937
938 # DEPRECATED:
939 echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
940 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
941
942 echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
943 wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
944
945 aptget_wrapper clean
946 aptget_wrapper update
947 aptget_wrapper install -y salt-common
948 aptget_wrapper install -y salt-minion
949 ;;
950 xenial)
951
952 # workaround for new cloud-init setting all interfaces statically
953 which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
954
955 which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
956
957 # SUGGESTED UPDATE:
958 #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
959 #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
960 ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
961 #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
962 #install_salt_minion_pkg
963
964 # DEPRECATED:
965 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
966 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
967
968 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
969 wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
970
971 aptget_wrapper clean
972 aptget_wrapper update
973 aptget_wrapper install -y salt-minion
974 ;;
975 rhel|centos|centos7|centos7|rhel6|rhel7)
976 yum install -y git
977 export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
978 source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
979 # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
980 BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
981 install_salt_minion_pkg
982 ;;
983 *)
984 msg="OS '$node_os' is not supported."
985 esac
986
987 echo "Configuring Salt minion ..."
988 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
989 echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
990
991 service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
992
993 sleep 1
994
995 echo "Classifying node ..."
996 os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
997 node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
998 node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
999 node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1000 node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1001 node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
1002
1003 node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1004 node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1005 node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1006 node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1007 node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
1008
1009 if [ "$node_network05_iface" != "" ]; then
1010 node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
1011 fi
1012
1013 # find more parameters (every env starting param_)
1014 more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
1015 if [ "$more_params" != "" ]; then
1016 echo "Additional params: $more_params"
1017 more_params=", $more_params"
1018 fi
1019
1020 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}}"
1021
1022 sleep 5
1023
1024 salt-call saltutil.sync_all
1025 salt-call mine.flush
1026 salt-call mine.update
1027 node_name: {{ ssh['node_name'] }}
1028 retry: {count: 1, delay: 1}
1029 skip_fail: false
1030{%- endif %}
1031{%- endfor %}
1032
1033- description: Refresh pillars on all minions
1034 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
1035 node_name: {{ HOSTNAME_CFG01 }}
1036 retry: {count: 1, delay: 5}
1037 skip_fail: false
1038
1039- description: Sync all salt resources
1040 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
1041 node_name: {{ HOSTNAME_CFG01 }}
1042 retry: {count: 1, delay: 5}
1043 skip_fail: false
1044
sgudz160b7302017-12-22 17:01:10 +02001045{%- endmacro %}
sgudz09e9aa92018-04-12 12:31:53 +03001046
1047{%- macro RUN_NEW_TEMPEST() %}
1048{###################################}
1049
1050- description: Upload tempest template
1051 upload:
1052 local_path: {{ config.salt_deploy.templates_dir }}
1053 local_filename: runtest.yml
1054 remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/
1055 node_name: {{ HOSTNAME_CFG01 }}
1056 skip_fail: False
1057
1058- description: Include class with tempest template into cfg node
1059 cmd: |
1060 sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml;
1061 salt 'cfg01*' saltutil.refresh_pillar;
1062 salt 'cfg01*' saltutil.sync_all;
1063 node_name: {{ HOSTNAME_CFG01 }}
1064 retry: {count: 1, delay: 10}
1065 skip_fail: false
1066
1067- description: Create flavors for tests
1068 cmd: |
1069 salt 'cfg01*' state.sls nova.client;
1070 node_name: {{ HOSTNAME_CFG01 }}
1071 retry: {count: 1, delay: 5}
1072 skip_fail: false
1073
1074- description: Create networks for tests
1075 cmd: |
1076 salt 'cfg01*' state.sls neutron.client;
1077 node_name: {{ HOSTNAME_CFG01 }}
1078 retry: {count: 1, delay: 5}
1079 skip_fail: false
1080
1081- description: Upload cirros image
1082 cmd: |
1083 salt 'cfg01*' state.sls glance.client;
1084 node_name: {{ HOSTNAME_CFG01 }}
1085 retry: {count: 1, delay: 5}
1086 skip_fail: false
1087
1088- description: Generate tempest config
1089 cmd: |
1090 salt 'cfg01*' state.sls runtest;
1091 node_name: {{ HOSTNAME_CFG01 }}
1092 retry: {count: 1, delay: 5}
1093 skip_fail: false
1094
1095- description: Run tempest from new docker image
1096 cmd: |
Oleksii Butenkoa99fe662018-05-24 17:30:20 +03001097 docker run -e ARGS="-r {{TEMPEST_PATTERN }} -w 2 {{ EXCLUDE_TEST_ARGS }}" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest /bin/bash -c "run-tempest"
sgudz09e9aa92018-04-12 12:31:53 +03001098 node_name: {{ HOSTNAME_GTW01 }}
1099 retry: {count: 1, delay: 30}
1100 skip_fail: true
1101
1102- description: Download xml results
1103 download:
1104 remote_path: /root/test/
1105 remote_filename: "report_*.xml"
1106 local_path: {{ os_env('PWD') }}
1107 node_name: {{ HOSTNAME_GTW01 }}
1108 skip_fail: true
1109
1110{%- endmacro %}