class TestTunnelConf(TestStartingSingleTunnel): """ Run the same tests as TestStartingSingleTunnel with a tunnel loaded from the configuration file. Also adds a few extra tests. """ def setUp(self): self.executable = 'cal_run_forever' conf = SafeConfigParser() sec1 = 'tunnel:test' conf.add_section(sec1) conf.set(sec1, 'tunnel_type', 'base') conf.set(sec1, 'cmd', self.executable) conf.set(sec1, 'executable', self.executable) self.tm = TunnelManager() self.tm.load_tunnels(conf) self.tm.start_tunnels() self.t = self.tm.tunnels[0] def test_already_loaded(self): conf = SafeConfigParser() self.assertRaises(TunnelsAlreadyLoadedException, self.tm.load_tunnels, *[conf])
class TestInvalidTunnels(unittest.TestCase): def setUp(self): self.tunnel = TunnelBase(['ls'], 'DOESNOTEXIST') self.tm = TunnelManager() self.tm.tunnels.append(self.tunnel) def test_start_bad_exec(self): self.tm.start_tunnels() # No error was raised self.assertFalse(self.tunnel.is_running()) def test_continue_bad_exec(self): self.tm.continue_tunnels() # No error was raised self.assertFalse(self.tunnel.is_running())
class TestBaseParser(TearDownRunForever): def setUp(self): self.executable = 'cal_run_forever' self.conf = SafeConfigParser() self.sec1 = 'tunnel:test' self.conf.add_section(self.sec1) self.conf.set(self.sec1, 'tunnel_type', 'base') self.conf.set(self.sec1, 'cmd', self.executable) self.conf.set(self.sec1, 'executable', self.executable) self.tm = TunnelManager() def test_base_parse(self): self.tm.load_tunnels(self.conf) self.tm.start_tunnels() def test_name(self): self.tm.load_tunnels(self.conf) t = self.tm.tunnels[0] self.assertEqual(t.name, 'test') def test_cmd(self): self.tm.load_tunnels(self.conf) t = self.tm.tunnels[0] self.assertEqual(t.cmd, [self.executable]) def test_executable(self): self.tm.load_tunnels(self.conf) t = self.tm.tunnels[0] self.assertEqual(t.executable, self.executable) def test_runs(self): self.tm.load_tunnels(self.conf) t = self.tm.tunnels[0] self.tm.start_tunnels() self.assertTrue(t.is_running())
class TestStartingSingleTunnel(TearDownRunForever): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) self.tm = TunnelManager() self.tm.tunnels = [self.t] def test_start_success(self): self.tm.start_tunnels() self.assertTrue(self.t.is_running()) def test_continue_not_started(self): """ Calling continue before starting shouldn't error out """ self.tm.continue_tunnels() def test_continue_post_start(self): self.tm.start_tunnels() self.tm.continue_tunnels() self.assertTrue(self.t.is_running()) def test_vanilla_continue(self): self.tm.start_tunnels() self.tm.continue_tunnels() self.assertTrue(self.t.is_running()) def test_close(self): self.tm.start_tunnels() self.t.close(wait=False)
class TestLongRun(TearDownRunForever): def setUp(self): self.executable = 'cal_run_forever' self.cmd = [self.executable] self.t = TunnelBase(self.cmd, self.executable) self.tm = TunnelManager() self.tm.tunnels = [self.t] def tearDown(self): signal.signal(signal.SIGCHLD, signal.SIG_IGN) try: subprocess.call("ps auxww | grep %s | awk '{print $2}' | xargs kill" % self.executable, shell=True) except OSError: pass def test_single_run(self): self.tm.start_tunnels() self.tm.continue_tunnels() time.sleep(1) self.assertTrue(is_really_running(self.t)) def test_close_running_externally_handled(self): self.tm.start_tunnels() proc = self.t.proc os.kill(proc.pid, signal.SIGTERM) # Wait for the process to close _wait_for_condition(lambda : not self.t.is_running(), "Process not closed") self.assertFalse(self.t.is_running()) def test_continue_after_kill(self): self.tm.start_tunnels() self.t.close(wait=False) _wait_for_condition(lambda: not is_really_running(self.t), "Process not stopped") self.tm.continue_tunnels() _wait_for_condition(lambda: is_really_running(self.t), "Process not started") self.assertTrue(is_really_running(self.t))