Skip to content

Commit

Permalink
Fix #968 and #967
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jan 8, 2020
1 parent 810c796 commit ee03b44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 11 additions & 10 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,6 @@ def check_ctxt_process(self):
self.ctxt_pid = None
self.configured = False

ip = self.getPublicIP()
if not ip:
ip = ip = self.getPrivateIP()
remote_dir = Config.REMOTE_CONF_DIR + "/" + \
str(self.inf.id) + "/" + ip + "_" + str(self.im_id)

initial_count_out = self.cont_out
wait = 0
while self.ctxt_pid:
Expand All @@ -829,8 +823,9 @@ def check_ctxt_process(self):
try:
self.log_info("Getting status of ctxt process with pid: " + str(ctxt_pid))
(_, _, exit_status) = ssh.execute("ps " + str(ctxt_pid))
except:
self.log_warn("Error getting status of ctxt process with pid: " + str(ctxt_pid))
self.ssh_connect_errors = 0
except Exception as ex:
self.log_warn("Error getting status of ctxt process with pid: %s. %s" % (ctxt_pid, ex))
exit_status = 0
self.ssh_connect_errors += 1
if self.ssh_connect_errors > Config.MAX_SSH_ERRORS:
Expand All @@ -844,6 +839,11 @@ def check_ctxt_process(self):
"credentials has been changed.")
return None

ip = self.getPublicIP()
if not ip:
ip = ip = self.getPrivateIP()
remote_dir = "%s/%s/%s_%s" % (Config.REMOTE_CONF_DIR, self.inf.id, ip, self.im_id)

if exit_status != 0:
# The process has finished, get the outputs
self.log_info("The process %s has finished, get the outputs" % ctxt_pid)
Expand Down Expand Up @@ -892,6 +892,7 @@ def get_ctxt_log(self, remote_dir, delete=False):
# Download the contextualization agent log
try:
# Get the messages of the contextualization process
self.log_debug("Get File: " + remote_dir + '/ctxt_agent.log')
ssh.sftp_get(remote_dir + '/ctxt_agent.log', tmp_dir + '/ctxt_agent.log')
with open(tmp_dir + '/ctxt_agent.log') as f:
conf_out = f.read()
Expand Down Expand Up @@ -922,8 +923,8 @@ def get_ctxt_output(self, remote_dir, delete=False):
# Download the contextualization agent log
try:
# Get the JSON output of the ctxt_agent
ssh.sftp_get(remote_dir + '/ctxt_agent.out',
tmp_dir + '/ctxt_agent.out')
self.log_debug("Get File: " + remote_dir + '/ctxt_agent.out')
ssh.sftp_get(remote_dir + '/ctxt_agent.out', tmp_dir + '/ctxt_agent.out')
with open(tmp_dir + '/ctxt_agent.out') as f:
ctxt_agent_out = json.load(f)
try:
Expand Down
4 changes: 3 additions & 1 deletion test/unit/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def test_get_ctxt_log(self, mkdtemp, get_ssh_ansible_master):
with open('/tmp/test_get_ctxt/ctxt_agent.log', 'w+') as f:
f.write("cont_log")

vm = VirtualMachine(None, "1", None, None, None)
inf = MagicMock()
inf.id = "1"
vm = VirtualMachine(inf, "1", None, None, None)
cont_log = vm.get_ctxt_log("", delete=True)
self.assertEqual(cont_log, "cont_log")

Expand Down

0 comments on commit ee03b44

Please sign in to comment.