correct some check, and improve signal action

This commit is contained in:
AleaJactaEst 2018-10-09 17:18:21 +02:00
parent c3d115b970
commit aff822c534
3 changed files with 11 additions and 9 deletions

View file

@ -1425,8 +1425,12 @@ class Manager():
pass pass
if self.serverHttp: if self.serverHttp:
logging.info("send signal to server http") logging.info("send signal to server http")
self.serverHttp.terminate() try:
self.serverHttp.terminate()
except AttributeError:
pass
logging.info("Finalize signal (%d)" % (signum)) logging.info("Finalize signal (%d)" % (signum))
os._exit(0)
def wait_children_commands(self): def wait_children_commands(self):
for child in self.threadCommand: for child in self.threadCommand:

View file

@ -96,18 +96,17 @@ class TestManager(unittest.TestCase):
time.sleep(1) time.sleep(1)
signal.alarm(10) signal.alarm(10)
msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False)
assert msgjson == {'state' : 'stopped'} self.assertEqual(msgjson['state'], 'stopped')
msgjson = client.send_json({'name': 'command:test'}, 'POST', "/START", show_result=False) msgjson = client.send_json({'name': 'command:test'}, 'POST', "/START", show_result=False)
assert msgjson == {'state' : 'started'} self.assertEqual(msgjson['state'], 'started')
msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False)
assert msgjson == {'state' : 'started'} self.assertEqual(msgjson['state'], 'started')
msgjson = client.send_json({'name': 'command:test', 'action': 'test'}, 'POST', "/STDIN", show_result=False) msgjson = client.send_json({'name': 'command:test', 'action': 'test'}, 'POST', "/STDIN", show_result=False)
print(msgjson) self.assertEqual(msgjson['state'], 'ok')
assert msgjson == {'state' : 'ok'}
msgjson = client.send_json({'name': 'command:test'}, 'POST', "/STOP", show_result=False) msgjson = client.send_json({'name': 'command:test'}, 'POST', "/STOP", show_result=False)
assert msgjson == {'state' : 'stopped'} self.assertEqual(msgjson['state'], 'stopped')
msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False) msgjson = client.send_json({'name': 'command:test'}, 'GET', "/STATUS", show_result=False)
assert msgjson == {'state' : 'stopped'} self.assertEqual(msgjson['state'], 'stopped')
manage.receive_signal(15, 1) manage.receive_signal(15, 1)
manage.wait_children_commands() manage.wait_children_commands()

View file

@ -1264,7 +1264,6 @@ class TestManager(unittest.TestCase):
manage.rfile.define_return( '{"name": "test", "first-line" : "1"}' ) manage.rfile.define_return( '{"name": "test", "first-line" : "1"}' )
manage.headers = {'content-length' : '1000', 'content-type' : 'application/json'} manage.headers = {'content-length' : '1000', 'content-type' : 'application/json'}
manage._command_log() manage._command_log()
print(manage.wfile.message)
self.assertEqual(b'"empty"',manage.wfile.message) self.assertEqual(b'"empty"',manage.wfile.message)
signal.alarm(0) signal.alarm(0)