Fix collect to use the subcloud name also

The collect script uses the standard prompt with the
substring "controller-" within expect, when running
"collect -sc ${subcloud}".
When a subcloud is properly provisioned and configured
the active controller's login prompt is 'controller-0'
or 1.

However, if the subcloud bootstrapping stage fails and
the login prompt never changes to controller-# (like
controller-0, controller-1, etc) then collect from
that subcloud will fail.

Test Plan:

PASS: Verify single subcloud collect

PASS: Verify that collect works after manually modifying
      PS1 on the subcloud.

PASS: Verify named subcloud collect (-sc -a -n <name>)

PASS: Verify collect from all subclouds

PASS: Verify Collect list of hosts

PASS: Verify collect from all hosts in the system

PASS: Verify subcloud and subclouds clean

PASS: Verify local host and hosts clean

Closes-Bug: 1948992
Change-Id: I20523bce76bc3c15f003ff4924299b58513bc57f
Signed-off-by: Shrikumar Sharma <shrikumar.sharma@windriver.com>
This commit is contained in:
Shrikumar Sharma
2021-10-27 16:46:59 -04:00
parent ecf93c7605
commit f12e28755d

View File

@@ -658,10 +658,11 @@ while [[ ${#} -gt 0 ]] ; do
-a|--all|all) -a|--all|all)
if [ "${ACTIVE}" = false ] ; then if [ "${ACTIVE}" = false ] ; then
report_error "can only run collect for remote hosts on active controller" ${FAIL_INACTIVE} wlog "collect with '${key}' option is only supported on an active controller ; defaulting to local collect"
collect_exit ${FAIL_INACTIVE} else
fi
ALLHOSTS=true ALLHOSTS=true
fi
HOSTLIST=(${HOSTNAME}) HOSTLIST=(${HOSTNAME})
HOSTS=1 HOSTS=1
clear_variable_args clear_variable_args
@@ -977,7 +978,17 @@ if [ ! -z ${COLLECT_NAME} ] ; then
if [ "${DCROLE}" == "${DCROLE_SUBCLOUD}" -a "${pw}" != "" ] ; then if [ "${DCROLE}" == "${DCROLE_SUBCLOUD}" -a "${pw}" != "" ] ; then
dlog "date override ${NOWDATE} to ${COLLECT_NAME: -15}" dlog "date override ${NOWDATE} to ${COLLECT_NAME: -15}"
NOWDATE=${COLLECT_NAME: -15} NOWDATE=${COLLECT_NAME: -15}
ilog "Orchestrated collect"
ORCHESTRATED_COLLECT=true ORCHESTRATED_COLLECT=true
elif [ "${DCROLE}" == "" -a "${ACTIVE}" == false -a "${pw}" != "" ]; then
wlog "Subcloud has not been properly configured."
ERROR_DCROLE=$(cat /etc/platform/platform.conf | grep distributed_cloud_role | cut -d '=' -f 2)
if [ "${ERROR_DCROLE}" = "subcloud" ]; then
dlog "date override ${NOWDATE} to ${COLLECT_NAME: -15}"
NOWDATE=${COLLECT_NAME: -15}
ilog "Orchestrated Collect"
ORCHESTRATED_COLLECT=true
fi
fi fi
elif [ "${ALLHOSTS}" = true ] ; then elif [ "${ALLHOSTS}" = true ] ; then
@@ -1240,6 +1251,8 @@ EOF
# #
# Parameters: $1 - remote hostname # Parameters: $1 - remote hostname
# $2 - dir or file with full path # $2 - dir or file with full path
# $3 - expected login prompt
# $4 - alternative login prompt (optional)
# #
########################################################################### ###########################################################################
@@ -1249,6 +1262,15 @@ function delete_remote_dir_or_file()
local dir_or_file=${2} local dir_or_file=${2}
local login_prompt="${3}" local login_prompt="${3}"
# alt_login_prompt is optional. Used when the actual prompt does not
# match the expected login_prompt (as contained in $login_prompt)
local alt_login_prompt="${4}"
# if ${4} is empty, use $login_prompt instead.
if test -z "${4}";
then
alt_login_prompt=${login_prompt};
fi
/usr/bin/expect << EOF /usr/bin/expect << EOF
log_user ${USER_LOG_MODE} log_user ${USER_LOG_MODE}
@@ -1260,7 +1282,10 @@ function delete_remote_dir_or_file()
"assword:" { "assword:" {
send "${pw}\r" send "${pw}\r"
expect { expect {
"${login_prompt}" { timeout { exit ${FAIL_TIMEOUT1} }
"${login_prompt}" {}
"${alt_login_prompt}" {}
}
set timeout 10 set timeout 10
expect -re $ expect -re $
send "sudo rm -rf ${dir_or_file} ; cat ${cmd_done_file}\n" send "sudo rm -rf ${dir_or_file} ; cat ${cmd_done_file}\n"
@@ -1274,9 +1299,6 @@ function delete_remote_dir_or_file()
timeout { exit ${FAIL_TIMEOUT3} } timeout { exit ${FAIL_TIMEOUT3} }
} }
} }
timeout { exit ${FAIL_TIMEOUT1} }
}
}
"(yes/no)?" { "(yes/no)?" {
send "yes\r" send "yes\r"
exp_continue exp_continue
@@ -1863,7 +1885,12 @@ function collect_subcloud_run()
"assword:" { "assword:" {
send "${pw}\r" send "${pw}\r"
expect { expect {
"${SUBCLOUD_LOGIN_PROMPT}" { "${pw_error}" { exit ${FAIL_PASSWORD} }
"${ac_error}" { exit ${FAIL_PERMISSION_SKIP}}
timeout { exit ${FAIL_TIMEOUT3} }
"${SUBCLOUD_LOGIN_PROMPT}" {}
"${subcloud}:" {}
}
set timeout ${TIMEOUT} set timeout ${TIMEOUT}
send "${collect} ${collect_cmd[@]}\n" send "${collect} ${collect_cmd[@]}\n"
expect { expect {
@@ -1926,11 +1953,6 @@ function collect_subcloud_run()
timeout { exit ${FAIL_TIMEOUT5} } timeout { exit ${FAIL_TIMEOUT5} }
} }
} }
"${pw_error}" { exit ${FAIL_PASSWORD} }
"${ac_error}" { exit ${FAIL_PERMISSION_SKIP}}
timeout { exit ${FAIL_TIMEOUT3} }
}
}
"(yes/no)?" { "(yes/no)?" {
send "yes\r" send "yes\r"
exp_continue exp_continue
@@ -2055,7 +2077,7 @@ function collect_host_complete_remote ()
# login to subclouds does not show the subcloud name # login to subclouds does not show the subcloud name
# in the login prompt. It will always be one of the controllers # in the login prompt. It will always be one of the controllers
# so set login prompt to SUBCLOUD_LOGIN_PROMPT # so set login prompt to SUBCLOUD_LOGIN_PROMPT
delete_remote_dir_or_file "${host}" "${COLLECT_BASE_DIR}/${tarname}*" "${SUBCLOUD_LOGIN_PROMPT}" delete_remote_dir_or_file "${host}" "${COLLECT_BASE_DIR}/${tarname}*" "${SUBCLOUD_LOGIN_PROMPT}" "${host}:"
else else
# hosts always login as host name, use that hostname as login prompt # hosts always login as host name, use that hostname as login prompt
delete_remote_dir_or_file "${host}" "${COLLECT_BASE_DIR}/${tarname}*" "${host}" delete_remote_dir_or_file "${host}" "${COLLECT_BASE_DIR}/${tarname}*" "${host}"
@@ -2354,7 +2376,12 @@ function collect_subcloud_clean()
"assword:" { "assword:" {
send "${pw}\r" send "${pw}\r"
expect { expect {
"${SUBCLOUD_LOGIN_PROMPT}" { "${pw_error}" { exit ${FAIL_PASSWORD} }
"${ac_error}" { exit ${FAIL_PERMISSION_SKIP}}
timeout { exit ${FAIL_TIMEOUT3} }
"${SUBCLOUD_LOGIN_PROMPT}" {}
"${subcloud}:" {}
}
send "${collect} ${collect_cmd[@]}\n" send "${collect} ${collect_cmd[@]}\n"
expect { expect {
"${collect_done}" { "${collect_done}" {
@@ -2386,11 +2413,6 @@ function collect_subcloud_clean()
} }
} }
} }
"${pw_error}" { exit ${FAIL_PASSWORD} }
"${ac_error}" { exit ${FAIL_PERMISSION_SKIP}}
timeout { exit ${FAIL_TIMEOUT3} }
}
}
"(yes/no)?" { "(yes/no)?" {
send "yes\r" send "yes\r"
exp_continue exp_continue