class ServerTestCase2(unittest.TestCase): proc = None @classmethod def setUpClass(cls): # starts the IPC server in another(!) process cls.proc = Process(target=ServerTestCase2.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname(os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join(base_dir, 'tests/configs/config_no_vlan') # Join Project Root with config Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_get_routers(self): routers = self.server_proxy.get_routers() assert len(routers) != 0 assert isinstance(routers[0], Router)
def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True)
def connect_to_server(): """ Initiates a connection to the IPC server by creating a client. """ global ipc_client ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() # register console for cli name = subprocess.getoutput('tty') server_proxy.register_tty(name) return server_proxy
def tearDownClass(cls): time.sleep(2) print("Shutdown server") ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = server_proxy.get_routers() for router in routers: while server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) server_proxy.stop()
class ServerAlive(unittest.TestCase): """ Little test which tests if it is possible to connect as a client to the test server. If you are running this module standalone it will try to connect to an all ready started server. If not it creates his own server instance. """"" proc = None @classmethod def setUpClass(cls): if not server_already_started: # starts the IPC server in another(!) process cls.proc = Process(target=ServerAlive.serverStartWithParams, args=()).start() block_until_server_is_online() @classmethod def tearDownClass(cls): if not server_already_started: ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): Server.start(config_path='framework_unittests/configs/config_no_vlan') def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() if not server_already_started: # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = self.server_proxy.get_routers() for router in routers: while not not self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) def test_get_version(self): version = self.server_proxy.get_server_version() assert version == Server.VERSION
def test_proxy_object(self): ipc_client = IPC() ipc_client.connect(False) server_proxy = ipc_client.get_server_proxy() rep = server_proxy.get_test_results() # print(rep) assert rep[1].text == "test" DummyServer.testList.append("test1") server_proxy.start_test("", "") # print(DummyServer.testList) testss = server_proxy.get_tests() # print(testss) assert len(testss) == 3 assert testss[0] == "test1" # wäre der Server in einem anderen Prozess gestartet, wäre 'test1' nicht vorhanden assert testss[1] == "test2" assert testss[2] == "test3"
class ServerAlive(unittest.TestCase): """ Little test which tests if he can connect as a client to the server. If you are running this module standalone it will try to connect to an all ready started server. If not it creates his own server instance. """ "" # TODO This test seems to be broken proc = None @classmethod def setUpClass(cls): if not server_all_ready_started: # starts the IPC server in another(!) process cls.proc = Process(target=ServerAlive.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): if not server_all_ready_started: ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname( os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join( base_dir, 'tests/configs/config_no_vlan') # Join Project Root with config Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_get_version(self): version = self.server_proxy.get_server_version() assert len(version) != 0
class TestCLItoServerConnection(unittest.TestCase): path_cli = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli.py') proc = None @classmethod def setUpClass(cls): # starts the IPC server in another(!) process cls.proc = Process( target=TestCLItoServerConnection.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname( os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join( base_dir, 'tests/configs/config_no_vlan') # Join Project Root with config Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_cli_connected(self): response = os.system(self.path_cli) assert response == 0 def test_get_version(self): version = self.server_proxy.get_server_version() assert len(version) != 0
def connect_to_server(): """ Initiates connection to the IPC server by creating a client """ if verbose: Logger().info("Setting up IPC client") global ipc_client ipc_client = IPC() ipc_client.connect() # Wait for connection time.sleep(1) if verbose: Logger().info("Client successfully connected") server_proxy = ipc_client.get_server_proxy() return server_proxy
def connect_to_server(): """ Initiates connection to the IPC server by creating a client """ if verbose: Logger().info("Setting up IPC client") global ipc_client """Global Variable for the IPC Client""" ipc_client = IPC() ipc_client.connect() # Wait for connection time.sleep(1) if verbose: Logger().info("Client succesfully setup") global server_proxy """global variable for the proxy server""" server_proxy = ipc_client.get_server_proxy()
def connect_to_server(): """ Initiates connection to the IPC server by creating a client """ if verbose: logging.info("Setting up IPC client") global ipc_client ipc_client = IPC() ipc_client.connect() if verbose: logging.info("Client successfully connected") server_proxy = ipc_client.get_server_proxy() # register console for cli name = subprocess.getoutput('tty') server_proxy.register_tty(name) return server_proxy
class ServerAlive(unittest.TestCase): """ Little test which tests if he can connect as a client to the server. If you are running this module standalone it will try to connect to an all ready started server. If not it creates his own server instance. """"" # TODO This test seems to be broken proc = None @classmethod def setUpClass(cls): if not server_all_ready_started: # starts the IPC server in another(!) process cls.proc = Process(target=ServerAlive.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): if not server_all_ready_started: ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname(os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join(base_dir, 'tests/configs/config_no_vlan') # Join Project Root with config Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_get_version(self): version = self.server_proxy.get_server_version() assert len(version) != 0
class ServerAlive(unittest.TestCase): """ Little test which tests if he can connect as a client to the server. If you are running this module standalone it will try to connect to an all ready started server. If not it creates his own server instance. """"" proc = None @classmethod def setUpClass(cls): if not server_all_ready_started: # starts the IPC server in another(!) process cls.proc = Process(target=ServerAlive.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): if not server_all_ready_started: ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): Server.start(debug_mode=True, config_path="../tests/config", vlan_activate=False) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_get_version(self): version = self.server_proxy.get_server_version() assert len(version) != 0
class TestCLItoServerConnection(unittest.TestCase): path_cli = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli.py') proc = None @classmethod def setUpClass(cls): # starts the IPC server in another(!) process cls.proc = Process(target=TestCLItoServerConnection.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname(os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join(base_dir, 'tests/configs/config_no_vlan') # Join Project Root with config Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_cli_connected(self): response = os.system(self.path_cli) assert response == 0 def test_get_version(self): version = self.server_proxy.get_server_version() assert len(version) != 0
def tearDownClass(cls): if not server_all_ready_started: ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop()
def start_ipc_server(): TestIPC.ipc_server = IPC() TestIPC.ipc_server.start_ipc_server(DummyServer, True)
class ServerCore(object): @classmethod def tearDownClass(cls): time.sleep(2) print("Shutdown server") ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = server_proxy.get_routers() for router in routers: while server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) server_proxy.stop() def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) def test_get_routers(self): routers = self.server_proxy.get_routers() assert len(routers) != 0 assert isinstance(routers[0], Router) def test_test_set(self): started = self.server_proxy.start_test_set(0, "set_2") assert started # wait until tests are done, assumes that exactly two tests are already finished while not len(self.server_proxy.get_test_results()) == 2: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() assert len(reports) == 2 assert len(reports[-1][2].errors) == 0 # check last report started = self.server_proxy.start_test_set(0, "set_1") assert started # wait until tests are done, assumes that exactly two tests are already finished while not len(self.server_proxy.get_test_results()) == 3: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() assert len(reports) == 3 assert len(reports[2][-1].errors) == 0 # check last report def test_test_results(self): self.server_proxy.delete_test_results() started = self.server_proxy.start_test_set(0, "set_2") assert started while not len(self.server_proxy.get_test_results()) == 2: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() for report in reports: assert report[0] == 0 assert report[1] != "" assert len(report[2].errors) == 0 removed_results = self.server_proxy.delete_test_results() assert len(reports) == removed_results time.sleep(0.5) assert not len(self.server_proxy.get_test_results()) def test_blocked_execution(self): self.server_proxy.delete_test_results() start = datetime.datetime.now() started = self.server_proxy.start_test_set(0, "set_2", 300) assert started stop = datetime.datetime.now() # magic value - we assume that non-blocking execution of the method would be faster assert stop - start > datetime.timedelta(seconds=2)
def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy()
def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop()
class TestCLItoServerConnection(unittest.TestCase): path_cli = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli.py') proc = None @classmethod def setUpClass(cls): # starts the IPC server in another(!) process cls.proc = Process(target=TestCLItoServerConnection.serverStartWithParams, args=()).start() block_until_server_is_online() @classmethod def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname(os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join(base_dir, 'framework_unittests/configs/config_no_vlan') Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_cli_connected(self): response = os.system(self.path_cli) assert response == 0 def test_test_sets(self): response = os.system(self.path_cli + " sets") assert response == 0 response = os.system(self.path_cli + " sets -s set_0") assert response == 0 def test_cli_start_test_set(self): response = os.system(self.path_cli + " start -s set_0 -r 0") assert response == 0 # assumes that there is only one test in the set while self.server_proxy.get_routers_task_queue_size(0): time.sleep(2) print('.', end="", flush=True) assert len(self.server_proxy.get_test_results()) os.system(self.path_cli + " results -d") response = os.system(self.path_cli + " start -s set_0") assert response == 0 routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) assert len(self.server_proxy.get_test_results()) == len(routers) os.system(self.path_cli + " results -d") response = os.system(self.path_cli + " start -s set_0 -r 0 -b") assert response == 0 assert len(self.server_proxy.get_test_results()) == 1 def test_cli_test_results(self): assert not os.system(self.path_cli + " results -d") os.system(self.path_cli + " start -s set_0") routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) response = os.system(self.path_cli + " results -r 0") assert response == 0 response = os.system(self.path_cli + " results") assert response == 0 response = os.system(self.path_cli + " results -d") assert response == 0 response = os.system(self.path_cli + " results -d") assert response == 0 response = os.system(self.path_cli + " results -d -r 0") assert response == 0 assert not len(self.server_proxy.get_test_results()) def test_get_version(self): version = self.server_proxy.get_server_version() assert version == Server.VERSION
class ServerCore(object): @classmethod def tearDownClass(cls): time.sleep(2) print("Shutdown server") ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = server_proxy.get_routers() for router in routers: while server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) server_proxy.stop() def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() # wait until server has all tasks before executed for i in range(2): # do it two times to be sure routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) def tearDown(self): assert not len( self.server_proxy.get_task_errors()) # check if an error happens def test_get_routers(self): routers = self.server_proxy.get_routers() assert len(routers) != 0 assert isinstance(routers[0], Router) def test_test_set(self): started = self.server_proxy.start_test_set(0, "set_1") assert started # wait until tests are done, assumes that exactly two tests are already finished while not len(self.server_proxy.get_test_results()) == 2: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() assert len(reports) == 2 assert len(reports[-1][2].errors) == 0 # check last report started = self.server_proxy.start_test_set(0, "set_0") assert started # wait until tests are done, assumes that exactly two tests are already finished while not len(self.server_proxy.get_test_results()) == 3: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() assert len(reports) == 3 assert len(reports[2][-1].errors) == 0 # check last report def test_test_results(self): self.server_proxy.delete_test_results() started = self.server_proxy.start_test_set(0, "set_1") assert started while not len(self.server_proxy.get_test_results()) == 2: time.sleep(2) print('.', end="", flush=True) reports = self.server_proxy.get_test_results() for report in reports: assert report[0] == 0 assert report[1] != "" assert len(report[2].errors) == 0 removed_results = self.server_proxy.delete_test_results() assert len(reports) == removed_results time.sleep(0.5) assert not len(self.server_proxy.get_test_results()) def test_blocked_execution(self): self.server_proxy.delete_test_results() start = datetime.datetime.now() started = self.server_proxy.start_test_set(0, "set_1", 300) assert started stop = datetime.datetime.now() # magic value - we assume that non-blocking execution of the method would be faster assert stop - start > datetime.timedelta(seconds=2)
class TestCLItoServerConnection(unittest.TestCase): path_cli = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli.py') proc = None @classmethod def setUpClass(cls): # starts the IPC server in another(!) process cls.proc = Process(target=TestCLItoServerConnection.serverStartWithParams, args=()).start() time.sleep(2) @classmethod def tearDownClass(cls): ipc_client = IPC() ipc_client.connect() server_proxy = ipc_client.get_server_proxy() server_proxy.stop() @staticmethod def serverStartWithParams(): base_dir = os.path.dirname(os.path.dirname(__file__)) # This is your Project Root config_path = os.path.join(base_dir, 'framework_unittests/configs/config_no_vlan') Server.start(config_path=config_path) def setUp(self): self.ipc_client = IPC() self.ipc_client.connect() self.server_proxy = self.ipc_client.get_server_proxy() def test_cli_connected(self): response = os.system(self.path_cli) assert response == 0 def test_cli_start_test_set(self): response = os.system(self.path_cli + " start -s set_1 -r 0") assert response == 0 # assumes that there is only one test in the set while self.server_proxy.get_routers_task_queue_size(0): time.sleep(2) print('.', end="", flush=True) assert len(self.server_proxy.get_test_results()) response = os.system(self.path_cli + " start -s set_1 -a") assert response == 0 routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) assert len(self.server_proxy.get_test_results()) == len(routers) + 1 os.system(self.path_cli + " results -rm") response = os.system(self.path_cli + " start -s set_1 -r 0 -b") assert response == 0 assert len(self.server_proxy.get_test_results()) == 1 def test_cli_test_results(self): assert not os.system(self.path_cli + " results -rm -a") os.system(self.path_cli + " start -s set_1 -a") routers = self.server_proxy.get_routers() for router in routers: while self.server_proxy.get_routers_task_queue_size(router.id): time.sleep(2) print('.', end="", flush=True) response = os.system(self.path_cli + " results -r 0") assert response == 0 response = os.system(self.path_cli + " results -a") assert response == 0 response = os.system(self.path_cli + " results -rm") assert response == 0 response = os.system(self.path_cli + " results -rm -a") assert response == 0 response = os.system(self.path_cli + " results -rm -r 0") assert response == 0 assert not len(self.server_proxy.get_test_results()) def test_get_version(self): version = self.server_proxy.get_server_version() assert version == Server.VERSION