Revert "Revert "Add k8s-ha-calico model support""
This reverts commit 3b1f40e9da7cd4a7a91938f7fe2c66c01cf4d494.
Change-Id: I5871f91c3fa9d6cfa65afb1d4914eea0acabe35c
diff --git a/tcp_tests/templates/shared-salt.yaml b/tcp_tests/templates/shared-salt.yaml
index efd894b..145c57f 100644
--- a/tcp_tests/templates/shared-salt.yaml
+++ b/tcp_tests/templates/shared-salt.yaml
@@ -594,15 +594,15 @@
skip_fail: false
- description: Check salt minion versions on slaves
- cmd: salt '*' test.version
+ cmd: salt --timeout=60 '*' test.version
node_name: {{ HOSTNAME_CFG01 }}
retry: {count: 3, delay: 15}
skip_fail: false
- description: Check salt top states on nodes
- cmd: salt '*' state.show_top
+ cmd: salt --timeout=60 '*' state.show_top
node_name: {{ HOSTNAME_CFG01 }}
- retry: {count: 1, delay: 5}
+ retry: {count: 3, delay: 15}
skip_fail: false
- description: Configure ntp and rsyslog on nodes
@@ -657,3 +657,182 @@
skip_fail: false
{%- endmacro %}
+
+{%- macro REGISTER_COMPUTE_NODES() %}
+{#########################################}
+
+{% for ssh in config.underlay.ssh %}
+{% if ssh["node_name"].startswith("cmp") %}
+{% set node_hostname = ssh["node_name"].split('.')[0] %}
+- description: Register compute {{ ssh['node_name'] }}
+ cmd: |
+ exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
+ export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }}
+ export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }}
+ export cluster_name={{ LAB_CONFIG_NAME }}
+ export config_host={{ config.salt.salt_master_host }}
+ export node_domain={{ DOMAIN_NAME }}
+ export nodes_os="xenial"
+ export node_hostname={{ node_hostname }}
+ set -xe
+ export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url
+ export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh}
+ export DISTRIB_REVISION={{ REPOSITORY_SUITE }}
+ export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly}
+
+ # Add wrapper to apt-get to avoid race conditions
+ # with cron jobs running 'unattended-upgrades' script
+ aptget_wrapper() {
+ local apt_wrapper_timeout=300
+ local start_time=$(date '+%s')
+ local fin_time=$((start_time + apt_wrapper_timeout))
+ while true; do
+ if (( "$(date '+%s')" > fin_time )); then
+ msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..."
+ fi
+ if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then
+ echo "Waiting while another apt/dpkg process releases locks ..."
+ sleep 30
+ continue
+ else
+ apt-get $@
+ break
+ fi
+ done
+ }
+
+ # Set default salt version
+ if [ -z "$saltversion" ]; then
+ saltversion="2016.3"
+ fi
+ echo "Using Salt version $saltversion"
+
+ echo "Preparing base OS ..."
+
+ case "$node_os" in
+ trusty)
+ # workaround for old cloud-init only configuring the first iface
+ iface_config_dir="/etc/network/interfaces"
+ ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev)
+
+ for iface in $ifaces; do
+ grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface)
+ done
+
+ which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
+
+ # SUGGESTED UPDATE:
+ #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
+ #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
+ ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
+ #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
+ #install_salt_minion_pkg
+
+ # DEPRECATED:
+ echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
+ wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
+
+ echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list
+ wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
+
+ aptget_wrapper clean
+ aptget_wrapper update
+ aptget_wrapper install -y salt-common
+ aptget_wrapper install -y salt-minion
+ ;;
+ xenial)
+
+ # workaround for new cloud-init setting all interfaces statically
+ which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf
+
+ which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget)
+
+ # SUGGESTED UPDATE:
+ #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
+ #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
+ ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
+ #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
+ #install_salt_minion_pkg
+
+ # DEPRECATED:
+ echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list
+ wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -
+
+ echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list
+ wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add -
+
+ aptget_wrapper clean
+ aptget_wrapper update
+ aptget_wrapper install -y salt-minion
+ ;;
+ rhel|centos|centos7|centos7|rhel6|rhel7)
+ yum install -y git
+ export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion
+ source <(curl -qL ${BOOTSTRAP_SCRIPT_URL})
+ # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service
+ BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION "
+ install_salt_minion_pkg
+ ;;
+ *)
+ msg="OS '$node_os' is not supported."
+ esac
+
+ echo "Configuring Salt minion ..."
+ [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
+ echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf
+
+ service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service."
+
+ sleep 1
+
+ echo "Classifying node ..."
+ os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}')
+ node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
+ node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
+ node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
+ node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
+ node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')"
+
+ node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
+ node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
+ node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
+ node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
+ node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')"
+
+ if [ "$node_network05_iface" != "" ]; then
+ node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)"
+ fi
+
+ # find more parameters (every env starting param_)
+ more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g')
+ if [ "$more_params" != "" ]; then
+ echo "Additional params: $more_params"
+ more_params=", $more_params"
+ fi
+
+ 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}}"
+
+ sleep 5
+
+ salt-call saltutil.sync_all
+ salt-call mine.flush
+ salt-call mine.update
+ node_name: {{ ssh['node_name'] }}
+ retry: {count: 1, delay: 1}
+ skip_fail: false
+{%- endif %}
+{%- endfor %}
+
+- description: Refresh pillars on all minions
+ cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
+ node_name: {{ HOSTNAME_CFG01 }}
+ retry: {count: 1, delay: 5}
+ skip_fail: false
+
+- description: Sync all salt resources
+ cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
+ node_name: {{ HOSTNAME_CFG01 }}
+ retry: {count: 1, delay: 5}
+ skip_fail: false
+
+{%- endmacro %}
\ No newline at end of file