def test_tee(self): lm = LogManager() lm.add_format('test', logging.Formatter('%(asctime)s TEST - %(levelname)s - %(message)s')) logger = lm.add_tee_logger('log_tee.txt', name='tee', file_overwrite=True, file_log_level=logging.DEBUG, stdout_log_level=logging.WARNING, file_format_name='test', stdout_format_name='test') logger.error("Test1") logger.warning("Test2") logger.debug("Test3") with open('log_tee.txt', 'r') as f: line = f.readlines() self.assertEquals(len(line), 3) self.assertTrue(line[0].find("TEST - ERROR - Test1") != -1) self.assertTrue(line[1].find("TEST - WARNING - Test2") != -1) self.assertTrue(line[2].find("TEST - DEBUG - Test3") != -1)
def test_startup(self): lm = LogManager('./test-logs') ptm = PhysicalTopologyManager(root_dir=os.path.dirname(os.path.abspath(__file__)) + '/../..', log_manager=lm) ptm.configure_logging(debug=True) root_cfg = HostDef('root', bridges={'br0': BridgeDef('br0', ip_addresses=[IP('10.0.0.240')])}, interfaces={'zoo1eth0': InterfaceDef('zoo1eth0', linked_bridge='br0'), #'cass1eth0': InterfaceDef('cass1eth0', linked_bridge='br0'), 'cmp1eth0': InterfaceDef('cmp1eth0', linked_bridge='br0')}) zoo1_cfg = HostDef('zoo1', interfaces={'eth0': InterfaceDef('eth0', ip_addresses=[IP('10.0.0.2')])}) #cass1_cfg = HostDef('cass1', # interfaces={'eth0': InterfaceDef('eth0', ip_addresses=[IP('10.0.0.5')])}) cmp1_cfg = HostDef('cmp1', interfaces={'eth0': InterfaceDef('eth0', ip_addresses=[IP('10.0.0.8')])}) zoo1_icfg= ImplementationDef('zoo1', 'PTM.ZookeeperHost', id='1', zookeeper_ips=['10.0.0.2']) #cass1_icfg= ImplementationDef('cass1', 'PTM.CassandraHost', id='1', # cassandra_ips=['10.0.0.5'], # init_token="") cmp1_icfg= ImplementationDef('cmp1', 'PTM.ComputeHost', id='1', zookeeper_ips=['10.0.0.2'], cassandra_ips=[])#['10.0.0.5']) root_icfg = ImplementationDef('root', 'PTM.RootHost') root = RootHost('root', ptm) zoo1 = ZookeeperHost(zoo1_cfg.name, ptm) #cass1 = CassandraHost(cass1_cfg.name, ptm) cmp1 = ComputeHost(cmp1_cfg.name, ptm) root.set_logger(lm.add_tee_logger('test.log', name='test-root', file_log_level=logging.DEBUG, stdout_log_level=logging.DEBUG)) zoo1.set_logger(lm.add_tee_logger('test.log', name='test-zoo1', file_log_level=logging.DEBUG, stdout_log_level=logging.DEBUG)) #cass1.set_logger(lm.add_tee_logger('test.log', name='test-cass1', file_log_level=logging.DEBUG, # stdout_log_level=logging.DEBUG)) cmp1.set_logger(lm.add_tee_logger('test.log', name='test-cmp1', file_log_level=logging.DEBUG, stdout_log_level=logging.DEBUG)) # Now configure the host with the definition and impl configs root.config_from_ptc_def(root_cfg, root_icfg) zoo1.config_from_ptc_def(zoo1_cfg, zoo1_icfg) #cass1.config_from_ptc_def(cass1_cfg, cass1_icfg) cmp1.config_from_ptc_def(cmp1_cfg, cmp1_icfg) root.link_interface(root.interfaces['zoo1eth0'], zoo1, zoo1.interfaces['eth0']) #root.link_interface(root.interfaces['cass1eth0'], cass1, cass1.interfaces['eth0']) root.link_interface(root.interfaces['cmp1eth0'], cmp1, cmp1.interfaces['eth0']) ptm.hosts_by_name['root'] = root ptm.hosts_by_name['zoo1'] = zoo1 #ptm.hosts_by_name['cass1'] = cass1 ptm.hosts_by_name['cmp1'] = cmp1 ptm.host_by_start_order.append(root) ptm.host_by_start_order.append(zoo1) #ptm.host_by_start_order.append(cass1) ptm.host_by_start_order.append(cmp1) for h in ptm.host_by_start_order: h.create() for h in ptm.host_by_start_order: h.boot() for h in ptm.host_by_start_order: h.net_up() for h in ptm.host_by_start_order: h.net_finalize() for h in ptm.host_by_start_order: h.prepare_config() for h in ptm.host_by_start_order: start_process = ptm.unshare_control('start', h) stdout, stderr = start_process.communicate() start_process.poll() print("Host control process output: ") print stdout print("Host control process error output: ") print stderr if start_process.returncode != 0: raise SubprocessFailedException('Host control start failed with: ' + str(start_process.returncode)) h.wait_for_process_start() pid = LinuxCLI().read_from_file('/run/midolman.1/pid').rstrip() print "PID = " + pid print "PS = " + LinuxCLI().cmd("ps -aef") self.assertTrue(LinuxCLI().is_pid_running(pid)) for h in ptm.host_by_start_order: stop_process = ptm.unshare_control('stop', h) stdout, stderr = stop_process.communicate() stop_process.poll() print("Host control process output: ") print stdout print("Host control process error output: ") print stderr if stop_process.returncode != 0: raise SubprocessFailedException('Host control stop failed with: ' + str(stop_process.returncode)) h.wait_for_process_stop() for h in ptm.host_by_start_order: h.net_down() for h in ptm.host_by_start_order: h.shutdown() for h in ptm.host_by_start_order: h.remove()