def test_boot(self):

        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=dir_path + '/../..', log_manager=lm)

        ptm.configure(dir_path + '/test-config.json')

        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()

        self.assertTrue(LinuxCLI().grep_cmd('ip netns', 'zoo1'))
        self.assertTrue(LinuxCLI().grep_cmd('ip netns', 'test-host1'))
        root_host = ptm.hosts_by_name['root']
        test_host1 = ptm.hosts_by_name['test-host1']

        self.assertTrue(root_host.cli.grep_cmd('ip l', 'th1eth1'))
        self.assertTrue(test_host1.cli.grep_cmd('ip l', 'eth1'))

        for h in reversed(ptm.host_by_start_order):
            h.net_down()
        for h in reversed(ptm.host_by_start_order):
            h.shutdown()
        for h in reversed(ptm.host_by_start_order):
            h.remove()

        self.assertFalse(LinuxCLI().grep_cmd('ip netns', 'zoo1'))
        self.assertFalse(LinuxCLI().grep_cmd('ip netns', 'test-host1'))
    def test_configure(self):
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=dir_path + '/../..', log_manager=lm)

        ptm.configure(dir_path + '/test-config.json')

        self.assertTrue('zoo1' in ptm.hosts_by_name)
        #self.assertTrue('cass1' in ptm.hosts_by_name)
        self.assertTrue('edge1' in ptm.hosts_by_name)

        self.assertEqual(ptm.host_by_start_order[0].name, 'root')
        self.assertEqual(ptm.host_by_start_order[1].name, 'external1')
        self.assertEqual(ptm.host_by_start_order[2].name, 'test-host1')
        self.assertEqual(ptm.host_by_start_order[3].name, 'test-host2')
        self.assertEqual(ptm.host_by_start_order[4].name, 'edge1')
        self.assertEqual(ptm.host_by_start_order[5].name, 'zoo1')
        #self.assertEqual(ptm.host_by_start_order[6].name, 'cass1')
        #self.assertEqual(ptm.host_by_start_order[7].name, 'cmp1')
        self.assertEqual(ptm.host_by_start_order[6].name, 'cmp1')

        zk_host = ptm.hosts_by_name['zoo1']

        self.assertTrue('eth0' in zk_host.interfaces)

        root_host = ptm.hosts_by_name['root']

        self.assertTrue('zoo1eth0' in root_host.interfaces)
    def test_print_config(self):

        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=dir_path + '/../..', log_manager=lm)

        ptm.configure(dir_path + '/test-config.json')

        ptm.print_config()
    def test_startup(self):

        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=dir_path + '/../..', log_manager=lm)

        ptm.configure(dir_path + '/test-config.json')
        ptm.startup()

        self.assertTrue(LinuxCLI().grep_cmd('ip netns', 'zoo1'))
        self.assertTrue(LinuxCLI().grep_cmd('ip netns', 'test-host1'))
        root_host = ptm.hosts_by_name['root']
        test_host1 = ptm.hosts_by_name['test-host1']

        self.assertTrue(root_host.cli.grep_cmd('ip l', 'th1eth1'))
        self.assertTrue(test_host1.cli.grep_cmd('ip l', 'eth1'))

        ptm.shutdown()

        self.assertFalse(LinuxCLI().grep_cmd('ip netns', 'zoo1'))
        self.assertFalse(LinuxCLI().grep_cmd('ip netns', 'test-host1'))
예제 #5
0
    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()
예제 #6
0
    def test_startup(self):
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=os.path.dirname(os.path.abspath(__file__)) + '/../..', log_manager=lm)

        root_cfg = HostDef('root',
                           bridges={'br0': BridgeDef('br0', ip_addresses=[IP('10.0.0.240')])},
                           interfaces={'edge1eth0': InterfaceDef('edge1eth0', linked_bridge='br0')})
        edge1_cfg = HostDef('edge1',
                           interfaces={'eth0': InterfaceDef('eth0', ip_addresses=[IP('10.0.0.2')])})

        edge1_icfg= ImplementationDef('edge1', 'PTM.RouterHost', id='1')
        root_icfg = ImplementationDef('edge1', 'PTM.RootHost')

        root = RootHost('root', ptm)
        edge1 = RouterHost(edge1_cfg.name, ptm)

        log = lm.add_file_logger('test.log', 'test')
        root.set_logger(log)
        edge1.set_logger(log)

        # Now configure the host with the definition and impl configs
        root.config_from_ptc_def(root_cfg, root_icfg)
        edge1.config_from_ptc_def(edge1_cfg, edge1_icfg)

        root.link_interface(root.interfaces['edge1eth0'], edge1, edge1.interfaces['eth0'])

        ptm.hosts_by_name['root'] = root
        ptm.hosts_by_name['edge1'] = edge1
        ptm.host_by_start_order.append(root)
        ptm.host_by_start_order.append(edge1)

        root.create()
        edge1.create()

        root.boot()
        edge1.boot()

        root.net_up()
        edge1.net_up()

        root.net_finalize()
        edge1.net_finalize()

        edge1.prepare_config()

        start_process = ptm.unshare_control('start', edge1)
        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))
        edge1.wait_for_process_start()

        bgpd_pid = LinuxCLI().read_from_file('/run/quagga.1/bgpd.pid').rstrip()
        zebra_pid = LinuxCLI().read_from_file('/run/quagga.1/zebra.pid').rstrip()
        self.assertTrue(bgpd_pid in LinuxCLI().get_running_pids())
        self.assertTrue(zebra_pid in LinuxCLI().get_running_pids())

        stop_process = ptm.unshare_control('stop', edge1)
        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 start failed with: ' + str(stop_process.returncode))

        edge1.wait_for_process_stop()
        time.sleep(1)
        self.assertFalse(bgpd_pid in LinuxCLI().get_running_pids())

        root.net_down()
        edge1.net_down()

        root.shutdown()
        edge1.shutdown()

        root.remove()
        edge1.remove()
예제 #7
0
    client_impl = None
    if client_impl_type == 'neutron':
        client_impl = create_neutron_client(**client_args)
    elif client_impl_type == 'midonet':
        client_impl = create_midonet_client(**client_args)
    else:
        raise ArgMismatchException('Invalid client API implementation:' + client_impl_type)

    print 'Setting up log manager'
    log_manager = LogManager(root_dir=log_dir)
    console_log = log_manager.add_stdout_logger(name='tsm-run-console',
                                                log_level=logging.DEBUG if debug is True else logging.INFO)
    log_manager.rollover_logs_fresh(file_filter='*.log')

    console_log.debug('Setting up PTM')
    ptm = PhysicalTopologyManager(root_dir=root_dir, log_manager=log_manager)
    ptm.configure_logging(debug=debug)

    console_log.debug('Setting up VTM')
    vtm = VirtualTopologyManager(physical_topology_manager=ptm, client_api_impl=client_impl, log_manager=log_manager)

    console_log.debug('Setting up TSM')
    tsm = TestSystemManager(ptm, vtm, log_manager=log_manager)
    tsm.configure_logging(debug=debug)

    scenario_filters = [TestScenario.get_class(s) for s in scenario_filter_list] \
        if len(scenario_filter_list) != 0 else None
    test_cases = map(TestCase.get_class, tests)

    console_log.debug('Test Case Classes = ' + str(test_cases))
예제 #8
0
        else:
            usage(ArgMismatchException('Invalid argument' + arg))

    if host_cmd == '':
        usage(ArgMismatchException('Must specify command to host'))

    if host_json == '':
        usage(ArgMismatchException('Must specify JSON representing host'))

    arg_list = extra_args

    root_dir = LinuxCLI().cmd('pwd').strip()

    log_manager = LogManager(root_dir=log_dir)

    ptm = PhysicalTopologyManager(root_dir=root_dir, log_manager=log_manager)
    ptm.configure_logging(debug=debug)

    ptm.LOG.debug("Setting root dir to: " + root_dir)

    ptm.LOG.debug("ptm-host-ctl starting cmd: " + host_cmd + " for host: " + host_json)
    ptm.ptm_host_control(host_cmd, host_json, arg_list)
    ptm.LOG.debug("ptm-host-ctl finished")

except ExitCleanException:
    exit(1)
except ArgMismatchException as a:
    print 'Argument mismatch: ' + str(a)
    usage(None)
    traceback.print_tb(sys.exc_traceback)
    exit(2)
예제 #9
0
    def test_startup(self):
        lm = LogManager('./test-logs')
        ptm = PhysicalTopologyManager(root_dir=os.path.dirname(os.path.abspath(__file__)) + '/../..', log_manager=lm)

        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')])})
        net_cfg = HostDef('net')

        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="56713727820156410577229101238628035242")
        cmp1_icfg= ImplementationDef('cmp1', 'PTM.ComputeHost', id='1',
                                     zookeeper_ips=['10.0.0.2'],
                                     cassandra_ips=[])#['10.0.0.5'])
        root_icfg = ImplementationDef('cmp1', 'PTM.RootHost')
        net_icfg = ImplementationDef('cmp1', 'PTM.NetworkHost',
                                     zookeeper_ips=['10.0.0.2'])

        root = RootHost('root', ptm)
        zoo1 = ZookeeperHost(zoo1_cfg.name, ptm)
        #cass1 = CassandraHost(cass1_cfg.name, ptm)
        cmp1 = ComputeHost(cmp1_cfg.name, ptm)
        net = NetworkHost(net_cfg.name, ptm)

        log = lm.add_file_logger('test.log', 'test')
        root.set_logger(log)
        zoo1.set_logger(log)
        #cass1.set_logger(log)
        cmp1.set_logger(log)
        net.set_logger(log)

        # 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)
        net.config_from_ptc_def(net_cfg, net_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.hosts_by_name['net'] = net
        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)
        ptm.host_by_start_order.append(net)

        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))

            try:
                h.wait_for_process_start()
            except SubprocessFailedException:
                raw_input("Press Enter to continue...")

        self.assertTrue(LinuxCLI().cmd('midonet-cli --midonet-url="' +
                                       version_config.ConfigMap.get_configured_parameter('param_midonet_api_url') +
                                       '" -A -e "host list"', return_status=True) == 0)


        for h in reversed(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()

        time.sleep(1)
        self.assertFalse(LinuxCLI().cmd('midonet-cli '
                                        '--midonet-url="http://localhost:8080/midonet-api/" '
                                        '-A -e "hosts list"',
                                        return_status=True) == 0)

        for h in reversed(ptm.host_by_start_order):
            h.net_down()

        for h in reversed(ptm.host_by_start_order):
            h.shutdown()

        for h in reversed(ptm.host_by_start_order):
            h.remove()
예제 #10
0
            log_dir = value
        elif arg in ('-p', '--print'):
            command = 'print'
        else:
            usage(ArgMismatchException('Invalid argument' + arg))

    if command == '':
        usage(ArgMismatchException('Must specify at least one command option'))

    root_dir = LinuxCLI().cmd('pwd').strip()

    log_manager = LogManager(root_dir=log_dir)
    if command == 'startup':
        log_manager.rollover_logs_fresh(file_filter='ptm*.log')

    ptm = PhysicalTopologyManager(root_dir=root_dir, log_manager=log_manager)
    ptm.configure_logging(debug=debug)
    ptm.configure(ptm_config_file)

    if command == 'startup':
        ptm.startup()
    elif command == 'shutdown':
        ptm.shutdown()
    elif command == 'print':
        ptm.print_config()
    else:
        usage(ArgMismatchException('Command option not recognized: ' + command))
   
except ExitCleanException:
    exit(1)
except ArgMismatchException as a: