2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-06-13 09:50:19 +00:00

Change some code in the python framework so

that it's easier to debug issues in configuration when moving to python for OpenBMC
This commit is contained in:
Victor Hu
2018-02-20 16:20:13 -05:00
parent 79fc3de998
commit f19c936638
3 changed files with 15 additions and 12 deletions

View File

@ -14,8 +14,8 @@ class BaseManager(object):
module_name = 'xcatagent.%s' % name
try:
__import__(module_name)
except ImportError:
return None
except ImportError as err:
raise ImportError(err)
class_name = MODULE_MAP[name]
return utils.class_func(module_name, class_name)

View File

@ -70,19 +70,19 @@ sub acquire_lock {
}
sub start_python_agent {
if (! -e $PYTHON_AGENT_FILE) {
xCAT::MsgUtils->message("S", "'$PYTHON_AGENT_FILE' does not exist");
xCAT::MsgUtils->message("S", "start_python_agent() Error: '$PYTHON_AGENT_FILE' does not exist");
return undef;
}
if (!defined(acquire_lock())) {
xCAT::MsgUtils->message("S", "Error: Faild to require lock");
xCAT::MsgUtils->message("S", "start_python_agent() Error: Failed to acquire lock");
return undef;
}
my $fd;
open($fd, '>', $AGENT_SOCK_PATH) && close($fd);
my $pid = fork;
if (!defined $pid) {
xCAT::MsgUtils->message("S", "Error: Unable to fork process");
xCAT::MsgUtils->message("S", "start_python_agent() Error: Unable to fork process");
return undef;
}
$SIG{CHLD} = 'DEFAULT';
@ -93,7 +93,7 @@ sub start_python_agent {
open(STDERR, '>>&', \*STDOUT) or die("open: $!");
my $ret = exec ($PYTHON_AGENT_FILE);
if (!defined($ret)) {
xCAT::MsgUtils->message("S", "Error: Failed to start python agent");
xCAT::MsgUtils->message("S", "start_python_agent() Error: Failed to start the xCAT Python agent.");
exit(1);
}
}
@ -194,7 +194,7 @@ sub wait_agent {
my ($pid, $callback) = @_;
waitpid($pid, 0);
if ($? >> 8 != 0) {
xCAT::MsgUtils->message("E", { data => ["python agent exited unexpectedly"] }, $callback);
xCAT::MsgUtils->message("E", { data => ["python agent exited unexpectedly. See $PYTHON_LOG_PATH for more details."] }, $callback);
}
}

View File

@ -127,6 +127,14 @@ sub preprocess_request {
sub process_request {
my $request = shift;
$callback = shift;
# If we can't start the python agent, exit immediately
my $pid = xCAT::OPENBMC::start_python_agent();
if (!defined($pid)) {
xCAT::MsgUtils->message("E", { data => ["Failed to start the xCAT Python agent. Check /var/log/xcat/cluster.log for more information."] }, $callback);
return;
}
my $noderange = $request->{node};
my $check = parse_node_info($noderange);
if (&refactor_args($request)) {
@ -135,11 +143,6 @@ sub process_request {
}
$callback->({ errorcode => [$check] }) if ($check);
return unless(%node_info);
my $pid = xCAT::OPENBMC::start_python_agent();
if (!defined($pid)) {
xCAT::MsgUtils->message("E", { data => ["Failed to start python agent"] }, $callback);
return;
}
xCAT::OPENBMC::submit_agent_request($pid, $request, \%node_info, $callback);
xCAT::OPENBMC::wait_agent($pid, $callback);