3 # Copyright (c) 2018 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function ansible_host () {
20 # Setup host via ansible playbook.
23 # - ${HOST} - Server production IP address (Linux).
27 pushd "${TOOLS_DIR}"/testbed-setup/ansible || die "Pushd failed!"
28 ssh-copy-id -o StrictHostKeyChecking=no testuser@"${HOST}"
29 ansible-playbook --vault-id vault_pass --extra-vars '@vault.yml' \
30 --inventory production site.yaml --limit ${HOST} || {
31 die "Failed to ansible host!"
33 popd || die "Popd failed!"
37 function installed () {
38 # Check if the given utility is installed. Fail if not installed.
41 # - ${1} - Utility to check.
43 # - 0 - If command is installed.
44 # - 1 - If command is not installed.
52 function pxe_cimc () {
53 # Reboot server with next boot set to PXE, disables PXE after server is UP
54 # to prevent endless loop.
57 # - ${HOST} - Server production IP address (Linux).
58 # - ${MGMT} - Server management IP address (IPMI/CIMC).
59 # - ${USER} - CIMC user.
60 # - ${PASS} - CIMC pass.
64 pushd "${TOOLS_DIR}"/testbed-setup/cimc || die "Pushd failed!"
65 ./cimc.py -u "${USER}" -p "${PASS}" "${MGMT}" --debug -pxe || {
66 die "Failed to send the PXE reboot command!"
68 for i in $(seq 1 500); do
69 warn "Waiting for server to become reachable ... " || die
70 if pingable "${HOST}"; then
71 ./cimc.py -u "${USER}" -p "${PASS}" "${MGMT}" --debug -hdd || {
72 die "Failed to send the HDD command!"
74 ssh-keygen -f "/home/testuser/.ssh/known_hosts" -R "${HOST}" || {
75 die "Failed to remove obsolete SSH key!"
77 warn "Server reachable, PXE running!" || die
81 popd || die "Popd failed!"
85 function pxe_host () {
86 # Reboot host into PXE mode and detect once it is up.
89 # - ${@} - All script arguments from command line.
91 # - ${HOST} - Server production IP address (Linux).
92 # - ${MGMT} - Server management IP address (IPMI/CIMC).
98 if ! installed ipmitool; then
99 die "ipmitool not present. Please install before continue!"
107 ipmi="ipmitool -I lanplus -H ${MGMT} -U ${USER} -P ${PASS} chassis status"
108 cimc="./cimc.py -u ${USER} -p ${PASS} ${MGMT} --mac-table"
109 pushd "${TOOLS_DIR}"/testbed-setup/cimc || die "Pushd failed!"
111 warn "This is IMPI managed server!"
112 pxe_supermicro || die
114 warn "This is CIMC managed server!"
117 die "Unknown management console!"
119 popd || die "Popd failed!"
125 function pxe_supermicro () {
126 # Reboot server with next boot set to PXE.
129 # - ${HOST} - Server production IP address (Linux).
130 # - ${MGMT} - Server management IP address (IPMI/CIMC).
131 # - ${USER} - IPMI user.
132 # - ${PASS} - IPMI pass.
136 if ! installed ipmitool; then
137 die "ipmitool not present. Please install before continue!"
140 cmd="chassis bootdev pxe"
141 ipmitool -I lanplus -H "${MGMT}" -U "${USER}" -P "${PASS}" "${cmd}" || {
142 die "Failed to send the ${cmd} command!"
145 ipmitool -I lanplus -H "${MGMT}" -U "${USER}" -P "${PASS}" "${cmd}" || {
146 die "Failed to send the ${cmd} command!"
148 for i in $(seq 1 500); do
149 warn "Waiting for server to become reachable ... " || die
150 if pingable "${HOST}"; then
151 ssh-keygen -f "/home/testuser/.ssh/known_hosts" -R "${HOST}" || {
152 die "Failed to remove obsolete SSH key!"
154 warn "Server reachable, PXE running!" || die
161 function pingable () {
162 # Check if the host is reachable over ping. Fail if not reachable.
165 # - ${1} - Host to check.
167 # - 0 - If host is reachable over ping.
168 # - 1 - If host is not reachable over ping.
172 ping -q -c 1 "${1}" 2>&1 > /dev/null
176 function wait_for_ssh () {
177 # Check if the host is reachable over SSH. Fail if not reachable.
180 # - ${HOST} - Server production IP address (Linux).
184 while ! ssh "${HOST}"
186 warn "SSH not yet reachable, trying again!"
189 warn "SSH reachable!"