i.create()  # should create and set peer on far host

        self.assertTrue(h2.cli.grep_cmd('ip l', 'testp'))
        self.assertTrue(LinuxCLI().grep_cmd('ip l', 'testi'))
        self.assertFalse(LinuxCLI().grep_cmd('ip l', 'testi.p'))

        i.config_addr()

        # the far iface should be controllable on its own just like any interface
        p.add_ip('192.168.1.2')
        p.up()

        self.assertTrue(h2.cli.grep_cmd('ip a | grep testp | grep inet | sed -e "s/^ *//" | cut -f 2 -d " "',
                                        '192.168.1.2'))

        i.remove()  # should remove both interfaces

        self.assertFalse(h2.cli.grep_cmd('ip l', 'testp'))
        self.assertFalse(LinuxCLI().grep_cmd('ip l', 'testi'))

        h2.remove()


    def tearDown(self):
        LinuxCLI().cmd('ip l del testi')
        LinuxCLI().cmd('ip netns del test2')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(VirtualInterfaceTest)
            cfg = json.load(f)
            ptc = PhysicalTopologyConfig.make_physical_topology(cfg)

        self.assertTrue('root' in ptc.hosts)
        self.assertTrue('zoo1eth0' in ptc.hosts['root'].interfaces)
        self.assertTrue('zoo1' in ptc.hosts)
        self.assertTrue('eth0' in ptc.hosts['zoo1'].interfaces)
        #self.assertTrue('cass1' in ptc.hosts)
        self.assertTrue('cmp1' in ptc.hosts)
        self.assertTrue('root' in ptc.implementation)
        self.assertTrue(ptc.implementation['root'].impl == 'PTM.RootHost')
        self.assertTrue('zoo1' in ptc.implementation)
        self.assertTrue(ptc.implementation['zoo1'].impl == 'PTM.ZookeeperHost')
        self.assertTrue(len(ptc.wiring) > 0)
        self.assertEquals(ptc.wiring['root']['zoo1eth0'].host, 'zoo1')
        self.assertEquals(ptc.wiring['root']['zoo1eth0'].interface, 'eth0')
        self.assertEquals(ptc.wiring['edge1']['eth0'].host, 'cmp1')
        self.assertEquals(ptc.wiring['edge1']['eth0'].interface, 'eth1')

        self.assertTrue('root' in ptc.host_start_order)
        self.assertTrue('external1' in ptc.host_start_order)
        self.assertTrue('test-host1' in ptc.host_start_order)
        self.assertTrue('test-host2' in ptc.host_start_order)
        self.assertTrue('zoo1' in ptc.host_start_order)
        #self.assertTrue('cass1' in ptc.host_start_order)
        self.assertTrue('cmp1' in ptc.host_start_order)
        self.assertTrue('edge1' in ptc.host_start_order)

from CBT.UnitTestRunner import run_unit_test
run_unit_test(PhysicalTopologyConfigTest)
Esempio n. 3
0
            port1 = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
            port2 = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"

            virtual_host1 = Guest(vm1)
            virtual_host1.plugin_vm('eth0', port1)

            virtual_host2 = Guest(vm2)
            virtual_host2.plugin_vm('eth0', port2)

            # No virtual bridge between VMs means they should NOT talk to each other yet.
            self.assertFalse(virtual_host1.ping('eth0', '10.55.55.55'))

            virtual_host1.unplug_vm(port1)
            virtual_host2.unplug_vm(port2)

        finally:
            vm1.net_down()
            vm2.net_down()
            vm1.shutdown()
            vm2.shutdown()
            vm1.remove()
            vm2.remove()

    @classmethod
    def tearDownClass(cls):
        cls.ptm.shutdown()
        LinuxCLI().cmd('ip netns del vm1')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(GuestTest)
Esempio n. 4
0
        self.assertTrue(h1.cli.grep_cmd('ip a | grep testi', '192.168.1.1'))
        self.assertTrue(h2.cli.grep_cmd('ip a | grep testp', '192.168.1.3'))

        h1.net_down()
        h2.net_down()

        h2.shutdown()
        h2.remove()

        self.assertFalse(h1.cli.grep_cmd('ip netns', 'test2'))

        h1.shutdown()
        h1.remove()

    #def test_send_packet(self):
        #h1.send_packet('eth0', 'icmp', '10.0.1.3')
        #self.assertEqual(True, False)

    #def test_connect_iface_to_port(self):
        #self.assertEqual(True, False)

    def tearDown(self):
        LinuxCLI().cmd('ip netns del test')
        LinuxCLI().cmd('ip netns del test2')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(NetNSHostTest)
        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'))

    def tearDown(self):
        #LinuxCLI().cmd('ip netns del cass1')
        LinuxCLI().cmd('ip netns del cmp1')
        LinuxCLI().cmd('ip netns del zoo1')
        LinuxCLI().cmd('ip netns del edge1')
        LinuxCLI().cmd('ip netns del external1')
        LinuxCLI().cmd('ip netns del test-host1')
        LinuxCLI().cmd('ip netns del test-host2')
        LinuxCLI().cmd('ip l set dev br0 down')
        LinuxCLI().cmd('ip l set dev brv0 down')
        LinuxCLI().cmd('ip l del zoo1eth0')
        LinuxCLI().cmd('ip l del cmp1eth0')
        #LinuxCLI().cmd('ip l del cass1eth0')
        LinuxCLI().cmd('ip l del th1eth0')
        LinuxCLI().cmd('ip l del th1eth1')
        LinuxCLI().cmd('ip l del th2eth0')
        LinuxCLI().cmd('brctl delbr br0')
        LinuxCLI().cmd('brctl delbr brv0')


from CBT.UnitTestRunner import run_unit_test
run_unit_test(PhysicalTopologyManagerTest)
Esempio n. 6
0
        self.assertFalse(True)
        pass


class TestCaseTest(unittest.TestCase):
    def test_test_case_scenarios(self):
        tc = SampleTestCase()
        self.assertEquals('SampleTestCase', tc._get_name())
        self.assertIn(SampleScenario, tc.supported_scenarios())

    def test_test_case_run(self):
        tc = SampleTestCase('test_basic')
        tc._prepare_class(SampleScenario(None, None))
        tr = unittest.TestResult()
        tc.run(tr)
        self.assertEquals(0, len(tr.errors))
        self.assertEquals(1, len(tr.failures))

        tc = SampleTestCase('test_a_failure')
        tc._prepare_class(SampleScenario(None, None))
        tr = unittest.TestResult()
        tc.run(tr)
        self.assertEquals(0, len(tr.errors))
        self.assertEquals(1, len(tr.failures))


from CBT.UnitTestRunner import run_unit_test
run_unit_test(TestCaseTest)


Esempio n. 7
0
        for h in ptm.host_by_start_order:
            h.remove()

    def tearDown(self):
        pass
        LinuxCLI().cmd('ip netns del cmp1')
        #LinuxCLI().cmd('ip netns del cass1')
        LinuxCLI().cmd('ip netns del zoo1')
        LinuxCLI().cmd('ip netns del vm1')
        LinuxCLI().cmd('ip l del cmp1eth0')
        #LinuxCLI().cmd('ip l del cass1eth0')
        LinuxCLI().cmd('ip l del zoo1eth0')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')
        #if LinuxCLI().exists('/var/run/cassandra.1/cassandra.pid'):
        #    pid = LinuxCLI().read_from_file('/var/run/cassandra.1/cassandra.pid')
        #    LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/zookeeper.1/pid'):
            pid = LinuxCLI().read_from_file('/var/run/zookeeper.1/pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/midolman.1/pid'):
            pid = LinuxCLI().read_from_file('/var/run/midolman.1/pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/midolman.1/dnsmasq.pid'):
            pid = LinuxCLI().read_from_file('/var/run/midolman.1/dnsmasq.pid')
            LinuxCLI().cmd('kill ' + str(pid))

from CBT.UnitTestRunner import run_unit_test
run_unit_test(ComputeHostTest)
Esempio n. 8
0
                self.assertTrue(cli.grep_file("/etc/hosts", "13.13.13.13 baz"))
                self.assertTrue(cli.grep_file("/etc/hosts", "6.6.6.6 foobar"))
                self.assertTrue(cli.grep_file("/etc/hosts", "9.9.9.9 bamf blaze"))
                self.assertTrue(cli.grep_file("/etc/hosts", "11.11.11.11 test"))
                self.assertTrue(cli.grep_file("/etc/hosts", "6.6.6.6 baz2"))
                self.assertTrue(cli.grep_file("/etc/hosts", "13.13.13.13 baz"))
                self.assertEqual(1, len(cli.cmd('grep "13.13.13.13 baz" /etc/hosts').splitlines(False)))
                self.assertFalse(cli.grep_file("/etc/hosts", "12.12.12.12 baz"))

            finally:
                cli.copy_file("/etc/hosts", "/tmp/hosts.tested")
                cli.move("/etc/hosts.backup", "/etc/hosts")

    def test_pid_functions(self):
        cli = LinuxCLI()
        root_pids = cli.get_process_pids("root")
        pids = cli.get_running_pids()
        ppids = cli.get_parent_pids("1")

        self.assertTrue(len(root_pids) > 0)
        self.assertTrue(len(pids) > 0)
        self.assertTrue(len(ppids) > 0)

    def tearDown(self):
        LinuxCLI().rm("tmp-test")


from CBT.UnitTestRunner import run_unit_test

run_unit_test(CLITest)
Esempio n. 9
0
            h.shutdown()

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

    def tearDown(self):
        pass
        LinuxCLI().cmd('ip netns del cmp1')
        #LinuxCLI().cmd('ip netns del cass1')
        LinuxCLI().cmd('ip netns del zoo1')
        LinuxCLI().cmd('ip l del cmp1eth0')
        #LinuxCLI().cmd('ip l del cass1eth0')
        LinuxCLI().cmd('ip l del zoo1eth0')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')
        #if LinuxCLI().exists('/var/run/cassandra.1/cassandra.pid'):
        #    pid = LinuxCLI().read_from_file('/var/run/cassandra.1/cassandra.pid')
        #    LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/zookeeper.1/pid'):
            pid = LinuxCLI().read_from_file('/var/run/zookeeper.1/pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/midolman.1/pid'):
            pid = LinuxCLI().read_from_file('/var/run/midolman.1/pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/midolman.1/dnsmasq.pid'):
            pid = LinuxCLI().read_from_file('/var/run/midolman.1/dnsmasq.pid')
            LinuxCLI().cmd('kill ' + str(pid))

from CBT.UnitTestRunner import run_unit_test
run_unit_test(NetworkHostTest)
Esempio n. 10
0
            self.assertAlmostEquals(2, LinuxCLI().wc('./sliced-logs/test3.1.slice')['lines'], delta=1)
            self.assertAlmostEquals(2, LinuxCLI().wc('./sliced-logs/test-log.slice')['lines'], delta=1)
            self.assertAlmostEquals(2, LinuxCLI().wc('./sliced-logs/test-log2.slice')['lines'], delta=1)

        finally:
            LinuxCLI().rm('./logs')
            LinuxCLI().rm('./sliced-logs')
            LinuxCLI().rm('./logs-all')
            LinuxCLI().rm('./logs2')
            LinuxCLI().rm('./logs3')
            LinuxCLI().rm('./logs4')

    @classmethod
    def tearDownClass(cls):
        LinuxCLI().rm('log_file.txt')
        LinuxCLI().rm('log_file2.txt')
        LinuxCLI().rm('log_tee.txt')
        LinuxCLI().rm('log_name_generation.txt')
        LinuxCLI().rm('log_levels.txt')
        LinuxCLI().rm('log_multiple.txt')
        LinuxCLI().rm('log_multiple2.txt')
        LinuxCLI().rm('logs')
        LinuxCLI().rm('logs2')
        LinuxCLI().rm('logs3')
        LinuxCLI().rm('logs4')
        LinuxCLI().rm('logs-all')
        LinuxCLI().rm('sliced-logs')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(LogManagerTest)
Esempio n. 11
0
from common.CLI import LinuxCLI
from PTM.Host import Host
from PTM.Interface import Interface


class InterfaceTest(unittest.TestCase):
    def test_use_active_iface(self):
        cli = LinuxCLI(log_cmd=True)
        h = Host('test', None, cli, lambda name: None, lambda name: None)
        i = Interface('testi', h, ip_addr=['192.168.0.2'])
        cli.cmd('ip l add dev testi type dummy')
        self.assertTrue(cli.grep_cmd('ip l | grep testi', 'state DOWN'))

        i.up()

        time.sleep(1)
        self.assertTrue(cli.grep_cmd('ip l | grep testi', 'UP'))

        i.down()

        self.assertFalse(cli.grep_cmd('ip l | grep testi', 'UP'))

        cli.cmd('ip l del testi')

    def tearDown(self):
        LinuxCLI().cmd('ip l del testi')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(InterfaceTest)
Esempio n. 12
0
        port1 = main_bridge.add_port().create()
        """ :type: Port"""
        port2 = main_bridge.add_port().create()
        """ :type: Port"""

        vm1 = vtm.create_vm(ip='10.1.1.2', preferred_hv_host='cmp1')
        vm2 = vtm.create_vm(ip='10.1.1.3', preferred_hv_host='cmp2')

        try:
            vm1.plugin_vm('eth0', port1.get_id())
            vm2.plugin_vm('eth0', port2.get_id())

            self.assertTrue(vm1.ping(on_iface='eth0', target_ip='10.1.1.3'))
            self.assertTrue(vm2.ping(on_iface='eth0', target_ip='10.1.1.2'))

        finally:
            vm1.terminate()
            vm2.terminate()
            port1.delete()
            port2.delete()
            main_bridge.delete()

    @classmethod
    def tearDownClass(cls):
        cls.ptm.shutdown()
        LinuxCLI().cmd('ip netns del vm1')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(MNAPITest)
Esempio n. 13
0
        self.assertEqual(PCAPIP4, pmap['ethernet'].next_parse_recommendation)

    def test_full_packet_parsing_l3_parse_error2(self):
        full_eii_packet_data = \
            [0x00, 0x04, 0x00, 0x01, 0x00, 0x06, 0x08, 0x00, 0x27, 0xc6, 0x25, 0x01, 0x00, 0x00, 0x08, 0x00,
             0x41, 0x10, 0x00, 0x5c, 0x93, 0x06, 0x40, 0x00, 0x40, 0x06, 0x8f, 0x75, 0x0a, 0x00, 0x02, 0x0f,
             0x0a, 0x00, 0x02, 0x02, 0x00, 0x16, 0xd1, 0xf4, 0x52, 0x1a, 0x58, 0x7c, 0x58, 0x25, 0x2e, 0x9b,
             0x50, 0x18, 0x9f, 0xb0, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00 ]

        packet = PCAPPacket(full_eii_packet_data, '13:00')
        self.assertRaises(PacketParsingException, packet.parse, [PCAPSLL])

        pmap = packet.layer_data
        emap = packet.extra_data

        self.assertEqual(1, len(emap['parse_errors.ip']))
        self.assertRegexpMatches(emap['parse_errors.ip'][0], 'field must be at least')

        self.assertEqual('13:00', packet.timestamp)
        self.assertTrue('ethernet' in pmap)

        self.assertEqual(PCAPSLL, type(pmap['ethernet']))

        self.assertEqual('08:00:27:c6:25:01', pmap['ethernet'].source_mac)
        self.assertEqual('00:00:00:00:00:00', pmap['ethernet'].dest_mac)
        self.assertEqual(PCAPIP4, pmap['ethernet'].next_parse_recommendation)


from CBT.UnitTestRunner import run_unit_test
run_unit_test(PCAPPacketTest)
Esempio n. 14
0
            interface=lo_iface,
            packet_type="tcp",
            count=5,
            source_ip="127.0.0.1",
            dest_ip="127.0.0.1",
            dest_port=6055,
            source_port=6015,
        )

        ret = tcpd.wait_for_packets(count=3, timeout=3)
        self.assertEqual(3, len(ret))
        ret = tcpd.wait_for_packets(count=1, timeout=3)
        self.assertEqual(1, len(ret))

        proc = tcpd.stop_capture()

        ret = tcpd.wait_for_packets(count=1, timeout=3)
        self.assertEqual(1, len(ret))

        self.assertTrue(not proc.is_alive())

    def tearDown(self):
        time.sleep(2)
        LinuxCLI().rm("tcp.callback.out")
        LinuxCLI().rm("tcp.out")


from CBT.UnitTestRunner import run_unit_test

run_unit_test(TCPDumpTest)
        self.assertEqual(api.get_client().get_option('option1'), 'test3')

    def test_subnet(self):
        api = VirtualTopologyManager(physical_topology_manager=None,
                                     client_api_impl=MockClient())
        subnet = {
            'subnet': {
                'name': 'test-l2',
                'enable_dhcp': True,
                'network_id': 'b6c86193-024c-4aeb-bd9c-ffc747bb8a74',
                'tenant_id': 'mdts2-ft2015-03-10 06:03:17',
                'dns_nameservers': [],
                'ipv6_ra_mode': None,
                'allocation_pools': [
                    {
                        'start': '1.1.1.2',
                        'end': '1.1.1.254'}],
                'gateway_ip': '1.1.1.1',
                'ipv6_address_mode': None,
                'ip_version': 4,
                'host_routes': [],
                'cidr': '1.1.1.0/24',
                'id': '6c838ffc-6a40-49ba-b363-6380b0a7dae6'}}

        api.get_client().set_subnet(subnet)
        self.assertEqual(api.get_client().show_subnet(), subnet)


from CBT.UnitTestRunner import run_unit_test
run_unit_test(VirtualTopologyManagerUnitTest)
Esempio n. 16
0
    def test_send_packet_tcp_real(self):
        cli = LinuxCLI(debug=True)
        out = TCPSender.send_packet(cli, interface='eth0', packet_type='tcp',
                                    source_ip='1.1.1.1', dest_ip='2.2.2.2',
                                    source_port=22, dest_port=80)
        self.assertTrue('mz eth0' in out)
        self.assertTrue('"sp=22,dp=80"' in out)
        self.assertTrue('-A 1.1.1.1' in out)
        self.assertTrue('-B 2.2.2.2' in out)
        self.assertTrue('-a' not in out)
        self.assertTrue('-b' not in out)
        self.assertTrue('tcp' in out)

    def test_send_packet_and_receive_packet(self):
        cli = LinuxCLI(debug=True)
        out = TCPSender.send_packet(cli, interface='eth0', packet_type='arp',
                                    source_ip='1.1.1.1', dest_ip='2.2.2.2',
                                    packet_options={'command': 'request', 'sip': '1.1.1.1'})
        self.assertTrue('mz eth0' in out)
        self.assertTrue('-t arp "request, sip=1.1.1.1"' in out)
        self.assertTrue('-A 1.1.1.1' in out)
        self.assertTrue('-B 2.2.2.2' in out)
        self.assertTrue('-a' not in out)
        self.assertTrue('-b' not in out)
        self.assertTrue('icmp' not in out)
        self.assertTrue('targetip' not in out)

from CBT.UnitTestRunner import run_unit_test
run_unit_test(TCPSenderTest)
Esempio n. 17
0
        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()

    def tearDown(self):
        LinuxCLI().cmd('ip netns del edge1')
        LinuxCLI().cmd('ip l del edge1eth0')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')
        if LinuxCLI().exists('/var/run/quagga.1/bgpd.pid'):
            pid = LinuxCLI().read_from_file('/var/run/quagga.1/bgpd.pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/quagga.1/zebra.pid'):
            pid = LinuxCLI().read_from_file('/var/run/quagga.1/zebra.pid')
            LinuxCLI().cmd('kill ' + str(pid))
        if LinuxCLI().exists('/var/run/quagga.1/watchquagga.pid'):
            pid = LinuxCLI().read_from_file('/var/run/quagga.1/watchquagga.pid')
            LinuxCLI().cmd('kill ' + str(pid))

from CBT.UnitTestRunner import run_unit_test
run_unit_test(RouterHostTest)
Esempio n. 18
0
import unittest
from common.FileLocation import *
from common.CLI import LinuxCLI


class FileLocationTest(unittest.TestCase):
    def test_get_file(self):
        try:
            cli = LinuxCLI(priv=False)
            cli.write_to_file('test', 'teststr')
            cli.write_to_file('testdir/test2', 'test2str')
            fl = FileLocation('test')
            self.assertEqual('.', fl.path)
            fl.get_file(FileAccessor(), near_filename='test_copy')
            self.assertTrue(cli.exists('test_copy'))

            fl2 = FileLocation('testdir/test2')
            self.assertEqual('testdir', fl2.path)

            #fl2.get_file(SSHFileAccessor('localhost', LinuxCLI().whoami()), near_filename='test2_copy')
            #self.assertTrue(cli.exists('test2_copy'))

        finally:
            LinuxCLI().rm('test')
            LinuxCLI().rm('testdir')
            LinuxCLI().rm('test_copy')
            LinuxCLI().rm('test2_copy')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(FileLocationTest)
Esempio n. 19
0
            vm_host1.start_capture('lo', save_dump_file=True, save_dump_filename='tcp.vmhost.out')

            ping_ret = vm_host1.ping('10.50.50.3')
            vm_host1.send_tcp_packet(iface='lo', dest_ip='10.50.50.3', source_port=6015, dest_port=6055)

            ret1 = vm_host1.capture_packets('lo', count=1, timeout=5)
            ret2 = vm_host1.capture_packets('lo', count=1, timeout=5)

            vm_host1.stop_capture('lo')

            self.assertTrue(ping_ret)
            self.assertEquals(1, len(ret1))

        finally:
            vm_host1.shutdown()
            vm_host1.remove()

    def tearDown(self):
        self.root_host.net_down()
        self.hypervisor.net_down()
        self.hypervisor.shutdown()
        self.root_host.shutdown()
        self.hypervisor.remove()
        self.root_host.remove()
        LinuxCLI().cmd('ip netns del test_vm')
        LinuxCLI().rm('tcp.vmhost.out')


from CBT.UnitTestRunner import run_unit_test
run_unit_test(VMHostTest)
Esempio n. 20
0
                PCAP_NotEqual('ip[0] & 0xf', '5'),
                PCAP_LessThanEqual('len', '1500')
            ])
        ])

        expected_str = \
            '( ' \
            '( not ( ether multicast ) ) and ' \
            '( ' \
            '( ether src host bar ) or ' \
            '( net 192.168.0.0 mask 255.255.255.0 ) ' \
            ') and ' \
            '( len > 80 ) ' \
            ') and ' \
            '( dst port 80 ) and ' \
            '( ' \
            '( src portrange 30000-50000 ) or ' \
            '( ip proto tcp ) or ' \
            '( not ( ether broadcast ) ) ' \
            ') and ' \
            '( ' \
            '( ether[0] & 1 != 0 ) and ' \
            '( ip[0] & 0xf != 5 ) and ' \
            '( len <= 1500 ) ' \
            ')'

        self.assertEqual(expected_str, complex_rule.to_str())

from CBT.UnitTestRunner import run_unit_test
run_unit_test(PCAPRulesTest)
Esempio n. 21
0
        b = Bridge('test-bridge', h, ip_addr=['192.168.0.240'], options=['stp'])

        b.create()
        time.sleep(1)

        # Check bridge is present
        self.assertTrue(h.cli.grep_cmd('brctl show | grep test-bridge | cut -f 1', 'test-bridge'))
        # Check STP
        self.assertTrue(h.cli.grep_cmd('brctl show | grep test-bridge | cut -f 4', 'yes'))

        b.link_interface(i)
        time.sleep(1)
        # Check interface has bridge set as link
        self.assertTrue(h.cli.grep_cmd('ip l | grep testi', 'test-bridge'))

        b.remove()
        i.remove()

        self.assertFalse(cli.grep_cmd('ip l', 'testi'))
        self.assertFalse(cli.grep_cmd('brctl show', 'test-bridge'))

    @classmethod
    def tearDownClass(cls):
        LinuxCLI().cmd('ip l del test-bridge')
        LinuxCLI().cmd('brctl delbr test-bridge')
        LinuxCLI().cmd('ip l del testi')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(BridgeTest)
Esempio n. 22
0
        print("Host control process error output: ")
        print stderr
        if stop_process.returncode != 0:
            raise SubprocessFailedException('Host control stop failed with: ' + str(stop_process.returncode))

        cass1.wait_for_process_stop()
        time.sleep(1)
        self.assertFalse(LinuxCLI().is_pid_running(pid))

        root.net_down()
        cass1.net_down()

        root.shutdown()
        cass1.shutdown()

        root.remove()
        cass1.remove()
    def tearDown(self):
        pass
        LinuxCLI().cmd('ip netns del cass1')
        LinuxCLI().cmd('ip l del cass1eth0')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')
        if LinuxCLI().exists('/var/run/cassandra.1/cassandra.pid'):
            pid = LinuxCLI().read_from_file('/var/run/cassandra.1/cassandra.pid')
            LinuxCLI().cmd('kill ' + str(pid))
        """

from CBT.UnitTestRunner import run_unit_test
run_unit_test(CassandraHostTest)
            for tc, err in results[s].errors:
                print "------------------------------"
                print "Test Case ERROR: [" + tc._get_name() + "]"
                print "Error Message:"
                print err

    def test_multi_case_multi_scenario_filter_no_topo(self):

        lm = LogManager(root_dir="test-logs")
        tsm = TestSystemManager(None, None, log_manager=lm)
        tsm.configure_logging(debug=True)

        tsm.add_test(SampleTestCase)
        tsm.add_test(SampleOtherTestCase)

        results = tsm.run_all_tests([SampleOtherTestScenario])

        self.assertNotIn(SampleTestScenario, results)
        self.assertIn(SampleOtherTestScenario, results)

        self.assertEqual(2, results[SampleOtherTestScenario].testsRun)
        self.assertEqual(1, len(results[SampleOtherTestScenario].failures))
        self.assertEqual(1, len(results[SampleOtherTestScenario].successes))
        self.assertEqual(0, len(results[SampleOtherTestScenario].errors))


from CBT.UnitTestRunner import run_unit_test
run_unit_test(TestSystemManagerTest)


Esempio n. 24
0
        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))

        zoo1.wait_for_process_stop()
        time.sleep(1)
        self.assertFalse(LinuxCLI().is_pid_running(pid))

        root.net_down()
        zoo1.net_down()

        root.shutdown()
        zoo1.shutdown()

        root.remove()
        zoo1.remove()

    def tearDown(self):
        LinuxCLI().cmd('ip netns del zoo1')
        LinuxCLI().cmd('ip l del zoo1eth0')
        LinuxCLI().cmd('ip l set br0 down')
        LinuxCLI().cmd('brctl delbr br0')

from CBT.UnitTestRunner import run_unit_test
run_unit_test(ZookeeperTest)
Esempio n. 25
0
            self.assertEqual(expected, mn_version)

    def test_version_strings(self):
        linux_dist = version_config.get_linux_dist()
        self.assertTrue(linux_dist == version_config.LINUX_CENTOS or linux_dist == version_config.LINUX_UBUNTU)

        test_list = [
            (("2:5.0", "201509090010.2f5a1d9"), "2:5.0.0-201509090010.2f5a1d9"),
            (("05.02", "0.0.201509011045.80d8d50"), "5.2.0-201509011045.80d8d50"),
            (("1.9.5", "rc3"), "1.9.5-rc3"),
            (("5.0", "0.0.201509011045.80d8d50.el7"), "5.0.0-201509011045.80d8d50"),
            (("1.8.9", "0.1.rc0.el7"), "1.8.9-rc0"),
            (("1.9.4", "rc0"), "1.9.4-rc0"),
        ]

        for args, expected in test_list:
            mn_version = version_config.parse_midolman_version(*args)
            self.assertEqual(expected, str(mn_version))

    def test_vars(self):
        print version_config.ConfigMap.get_configured_parameter("mn_version", config_json=CFG_FILE)
        print version_config.ConfigMap.get_configured_parameter("cmd_list_datapath", config_json=CFG_FILE)
        print version_config.ConfigMap.get_configured_parameter("option_config_mnconf", config_json=CFG_FILE)
        print version_config.ConfigMap.get_configured_parameter("option_use_v2_stack", config_json=CFG_FILE)
        print version_config.get_linux_dist()


from CBT.UnitTestRunner import run_unit_test

run_unit_test(VersionConfigTest)
Esempio n. 26
0
            vm1.plugin_vm('eth0', port1['id'], port1['mac_address'])
            vm2.plugin_vm('eth0', port2['id'], port2['mac_address'])

            self.assertTrue(vm1.ping(on_iface='eth0', target_ip=ip2))

        finally:
            if vm1 is not None:
                vm1.terminate()
            if vm2 is not None:
                vm2.terminate()

            if port1 is not None:
                self.api.delete_port(port1['id'])
            if port2 is not None:
                self.api.delete_port(port2['id'])

    @classmethod
    def tearDownClass(cls):
        log = logging.getLogger("neutronclient")
        log.setLevel(logging.DEBUG)

        try:
            cls.ptm.shutdown()
            LinuxCLI().cmd('ip netns del vm1')
        finally:
            clean_neutron(cls.api, log=log)


from CBT.UnitTestRunner import run_unit_test
run_unit_test(NeutronAPITest)