class TestSzig(unittest.TestCase): def setUp(self): self.szig = SZIG("", HandlerMock) def test_get_value(self): self.assertEquals(self.szig.get_value(""), None) self.assertEquals(self.szig.get_value("service"), None) self.assertEquals(self.szig.get_value("info.policy.file"), "/etc/zorp/policy.py") self.assertEquals(self.szig.get_value("stats.thread_number"), 5) self.assertEquals( self.szig.get_value( "service.service_http_transparent.sessions_running"), 0) def test_get_sibling(self): self.assertEquals(self.szig.get_sibling("conns"), "info") self.assertEquals(self.szig.get_sibling("stats.threads_running"), "stats.thread_rate_max") self.assertEquals(self.szig.get_sibling("stats.thread_rate_max"), "stats.audit_number") self.assertEquals(self.szig.get_sibling("stats.thread_number"), None) def test_get_child(self): self.assertEquals(self.szig.get_child(""), "conns") self.assertEquals(self.szig.get_child("info"), "info.policy") self.assertEquals(self.szig.get_child("info.policy"), "info.policy.reload_stamp") self.assertEquals(self.szig.get_child("info.policy.reload_stamp"), None) def test_get_set_loglevel(self): loglevel = 6 self.szig.loglevel = loglevel self.assertEquals(self.szig.loglevel, loglevel) def test_get_set_logspec(self): logspec = "this is a logspec" self.szig.logspec = logspec self.assertEquals(self.szig.logspec, logspec) def test_get_set_deadlockcheck(self): deadlockcheck = False self.szig.deadlockcheck = deadlockcheck self.assertEquals(self.szig.deadlockcheck, deadlockcheck) def test_reload_and_reload_result(self): self.szig.reload() self.assertEquals(self.szig.reload_result(), True) def test_coredump(self): try: self.szig.coredump() self.assertTrue( False, "szig coredump should not work while not repaired") except: self.assertTrue(True, "szig coredump is not working yet")
class TestSzig(unittest.TestCase): def setUp(self): self.szig = SZIG("", HandlerMock) def test_get_value(self): self.assertEquals(self.szig.get_value(""), None) self.assertEquals(self.szig.get_value("service"), None) self.assertEquals(self.szig.get_value("info.policy.file"), "/etc/zorp/policy.py") self.assertEquals(self.szig.get_value("stats.thread_number"), 5) self.assertEquals(self.szig.get_value("service.service_http_transparent.sessions_running"), 0) def test_get_sibling(self): self.assertEquals(self.szig.get_sibling("conns"), "info") self.assertEquals(self.szig.get_sibling("stats.threads_running"), "stats.thread_rate_max") self.assertEquals(self.szig.get_sibling("stats.thread_rate_max"), "stats.audit_number") self.assertEquals(self.szig.get_sibling("stats.thread_number"), None) def test_get_child(self): self.assertEquals(self.szig.get_child(""), "conns") self.assertEquals(self.szig.get_child("info"), "info.policy") self.assertEquals(self.szig.get_child("info.policy"), "info.policy.reload_stamp") self.assertEquals(self.szig.get_child("info.policy.reload_stamp"), None) def test_get_set_loglevel(self): loglevel = 6 self.szig.loglevel = loglevel self.assertEquals(self.szig.loglevel, loglevel) def test_get_set_logspec(self): logspec = "this is a logspec" self.szig.logspec = logspec self.assertEquals(self.szig.logspec, logspec) def test_get_set_deadlockcheck(self): deadlockcheck = False self.szig.deadlockcheck = deadlockcheck self.assertEquals(self.szig.deadlockcheck, deadlockcheck) def test_reload_and_reload_result(self): self.szig.reload() self.assertEquals(self.szig.reload_result(), True) def test_coredump(self): try: self.szig.coredump() self.assertTrue(False, "szig coredump should not work while not repaired") except: self.assertTrue(True, "szig coredump is not working yet")
class SzigWalkAlgorithm(ProcessAlgorithm): def __init__(self, root=""): self.root = root super(SzigWalkAlgorithm, self).__init__() def errorHandling(self): running = self.isRunning(self.instance.process_name) if not running: # Ignore not running process return CommandResultSuccess(running.msg) try: self.szig = SZIG(self.instance.process_name) except IOError as e: return CommandResultFailure(e.message) return None def getChilds(self, node): child = self.szig.get_child(node) if child: result = {} result[child.split('.')[-1]] = self.walk(child) sibling = self.szig.get_sibling(child) while sibling: result[sibling.split('.')[-1]] = self.walk(sibling) sibling = self.szig.get_sibling(sibling) return result else: return None def walk(self, node): value = self.szig.get_value(node) if value != None: return value else: return self.getChilds(node) def execute(self): def _prepend_instance_name(tree): return {self.instance.process_name: tree} error = self.errorHandling() if error != None: return error try: if self.root: szig_dict = _prepend_instance_name( {self.root: self.walk(self.root)}) else: szig_dict = _prepend_instance_name(self.walk(self.root)) return CommandResultSuccess(value=szig_dict) except SZIGError as e: return CommandResultFailure( 'Error while communicating through szig: ' + e.msg)
class SzigWalkAlgorithm(ProcessAlgorithm): def __init__(self, root=""): self.root = root super(SzigWalkAlgorithm, self).__init__() def errorHandling(self): running = self.isRunning(self.instance.process_name) if not running: return running try: self.szig = SZIG(self.instance.process_name) except IOError as e: return CommandResultFailure(e.message) return None def getChilds(self, node): child = self.szig.get_child(node) if child: result = {} result[child.split('.')[-1]] = self.walk(child) sibling = self.szig.get_sibling(child) while sibling: result[sibling.split('.')[-1]] = self.walk(sibling) sibling = self.szig.get_sibling(sibling) return result else: return None def walk(self, node): value = self.szig.get_value(node) if value != None: return value else: return self.getChilds(node) def execute(self): def _prepend_instance_name(tree): return {self.instance.process_name : tree} error = self.errorHandling() if error != None: return error try: if self.root: szig_dict = _prepend_instance_name({self.root : self.walk(self.root)}) else: szig_dict = _prepend_instance_name(self.walk(self.root)) return CommandResultSuccess("", szig_dict) except SZIGError as e: return CommandResultFailure("error while communicating through szig: %s" % e.msg)