Example #1
0
 def setUp(self):
     super(TestCommonDbOps, self).setUp()
     name = utils.get_rand_device_name()
     self.switch = self.useFixture(fixtures.LogicalSwitchFixture(name)).obj
     self.lsps = [
         self.api.lsp_add(
             self.switch.uuid,
             utils.get_rand_device_name()).execute(check_error=True)
         for _ in range(3)
     ]
     self.api.db_set('Logical_Switch', self.switch.uuid, ('external_ids', {
         'one': '1',
         'two': '2'
     })).execute(check_error=True)
Example #2
0
 def test_lb_add_exists(self):
     name = utils.get_rand_device_name()
     vip = '192.0.2.1'
     ips = ['10.0.0.1', '10.0.0.2', '10.0.0.3']
     self._lb_add(name, vip, ips)
     cmd = self.api.lb_add(name, vip, ips)
     self.assertRaises(RuntimeError, cmd.execute, check_error=True)
Example #3
0
 def setUp(self):
     super(TestOvsdbIdl, self).setUp()
     self.api = impl_idl.OvsdbIdl(self.connection)
     self.brname = utils.get_rand_device_name()
     # Destroying the bridge cleans up most things created by tests
     cleanup_cmd = self.api.del_br(self.brname)
     self.addCleanup(cleanup_cmd.execute)
Example #4
0
 def test_chassis_add_may_exist(self):
     chassis = utils.get_rand_device_name()
     self._chassis_add(['vxlan'], '192.0.2.1', chassis=chassis)
     self._chassis_add(['vxlan'],
                       '192.0.2.1',
                       chassis=chassis,
                       may_exist=True)
Example #5
0
 def _lr_nat_add(self, *args, **kwargs):
     lr = kwargs.pop('router', self._lr_add(utils.get_rand_device_name()))
     nat = self.api.lr_nat_add(lr.uuid, *args,
                               **kwargs).execute(check_error=True)
     self.assertIn(nat, lr.nat)
     nat.router = lr
     return nat
Example #6
0
 def test_lrp_add_may_exist_different_router(self):
     name = utils.get_rand_device_name()
     args = (name, 'de:ad:be:ef:4d:ad', ['192.0.2.0/24'])
     lr2 = self.useFixture(fixtures.LogicalRouterFixture()).obj
     self._lrp_add(*args)
     cmd = self.api.lrp_add(lr2.uuid, *args, may_exist=True)
     self.assertRaises(RuntimeError, cmd.execute, check_error=True)
Example #7
0
 def test_lb_add_columns(self):
     ext_ids = {'one': 'two'}
     name = utils.get_rand_device_name()
     lb = self._lb_add(name,
                       '192.0.2.1', ['10.0.0.1', '10.0.0.2'],
                       external_ids=ext_ids)
     self.assertEqual(ext_ids, lb.external_ids)
Example #8
0
 def test_lsp_list_no_switch(self):
     ports = {self._lsp_add(self.switch, None) for _ in range(3)}
     other_switch = self.useFixture(
         fixtures.LogicalSwitchFixture(
             name=utils.get_rand_device_name())).obj
     other_port = self._lsp_add(other_switch, None)
     all_ports = set(self.api.lsp_list().execute(check_error=True))
     self.assertTrue((ports.union(set([other_port]))).issubset(all_ports))
Example #9
0
 def setUp(self):
     super(TestObLbOps, self).setUp()
     self.add_fn = getattr(self.api, self._add_fn)
     self.del_fn = getattr(self.api, self._del_fn)
     self.list_fn = getattr(self.api, self._list_fn)
     # They must be in this order because the load balancer
     # can't be deleted when there is a reference in the router
     self.lb = self.useFixture(
         fixtures.LoadBalancerFixture(utils.get_rand_device_name(),
                                      '192.0.2.1',
                                      ['10.0.0.1', '10.0.0.2'])).obj
     self.lb2 = self.useFixture(
         fixtures.LoadBalancerFixture(utils.get_rand_device_name(),
                                      '192.0.2.2',
                                      ['10.1.0.1', '10.1.0.2'])).obj
     self.lr = self.useFixture(self.fixture(
         utils.get_rand_device_name())).obj
Example #10
0
 def test_chassis_add_columns(self):
     chassis = utils.get_rand_device_name()
     hostname = "testhostname"
     extids = {'my': 'external_id', 'is': 'set'}
     ch = self._chassis_add(['vxlan'], '192.0.2.1', chassis=chassis,
                            hostname=hostname, external_ids=extids)
     self.assertEqual(hostname, ch.hostname)
     self.assertEqual(extids, ch.external_ids)
Example #11
0
 def test_lb_list(self):
     lbs = {
         self._lb_add(utils.get_rand_device_name(), '192.0.2.1',
                      ['10.0.0.1', '10.0.0.2'])
         for _ in range(3)
     }
     lbset = self.api.lb_list().execute(check_error=True)
     self.assertTrue(lbs.issubset(lbset))
Example #12
0
 def _test_add_port(self):
     pname = utils.get_rand_device_name()
     with self.api.transaction(check_error=True) as txn:
         txn.extend([
             self.api.add_br(self.brname),
             self.api.add_port(self.brname, pname)
         ])
     return pname
Example #13
0
 def test_lb_del_vip(self):
     name = utils.get_rand_device_name()
     lb1 = self._lb_add(name, '192.0.2.1', ['10.0.0.1', '10.0.0.2'])
     lb2 = self._lb_add(name, '192.0.2.2', ['10.1.0.1', '10.1.0.2'])
     self.assertEqual(lb1, lb2)
     self.api.lb_del(lb1.name, '192.0.2.1').execute(check_error=True)
     self.assertNotIn('192.0.2.1', lb1.vips)
     self.assertIn('192.0.2.2', lb1.vips)
Example #14
0
 def test_lr_nat_add_port(self):
     sw = self.useFixture(fixtures.LogicalSwitchFixture()).obj
     lsp = self.api.lsp_add(
         sw.uuid, utils.get_rand_device_name()).execute(check_error=True)
     lport, mac = (lsp.name, 'de:ad:be:ef:4d:ad')
     nat = self._lr_nat_add(const.NAT_BOTH, '10.172.4.1', '192.0.2.1',
                            lport, mac)
     self.assertIn(lport, nat.logical_port)  # because optional
     self.assertIn(mac, nat.external_mac)
Example #15
0
 def test_lrp_add_may_exist_different_peer(self):
     name = utils.get_rand_device_name()
     args = (name, 'de:ad:be:ef:4d:ad', ['192.0.2.0/24'])
     self._lrp_add(*args)
     self.assertRaises(RuntimeError,
                       self._lrp_add,
                       *args,
                       peer='fake',
                       may_exist=True)
Example #16
0
 def test_lrp_add_may_exist_different_networks(self):
     name = utils.get_rand_device_name()
     args = (name, 'de:ad:be:ef:4d:ad')
     self._lrp_add(*args, networks=['192.0.2.0/24'])
     self.assertRaises(RuntimeError,
                       self._lrp_add,
                       *args,
                       networks=['192.2.1.0/24'],
                       may_exist=True)
Example #17
0
 def load_test_data(self):
     with self.api.transaction(check_error=True) as txn:
         for chassis in self.data['chassis']:
             chassis['name'] = utils.get_rand_device_name('chassis')
             chassis['hostname'] = '%s.localdomain.com' % chassis['name']
             txn.add(self.api.chassis_add(
                 chassis['name'], ['geneve'], chassis['hostname'],
                 hostname=chassis['hostname'],
                 external_ids=chassis['external_ids']))
Example #18
0
 def test_find(self):
     # This test will easily time out if indexing isn't used
     length = 2000
     basename = utils.get_rand_device_name('testswitch')
     with self.api.transaction(check_error=True) as txn:
         for i in range(length):
             txn.add(self.api.ls_add("%s%d" % (basename, i)))
     match = "%s%d" % (basename, length / 2)
     sw = self.api.lookup('Logical_Switch', match)
     self.assertEqual(sw.name, match)
Example #19
0
 def test_lb_add_may_exist(self):
     name = utils.get_rand_device_name()
     vip = '192.0.2.1'
     ips = ['10.0.0.1', '10.0.0.2', '10.0.0.3']
     lb1 = self._lb_add(name, vip, ips)
     ips += ['10.0.0.4']
     lb2 = self.api.lb_add(name, vip, ips,
                           may_exist=True).execute(check_error=True)
     self.assertEqual(lb1, lb2)
     self.assertEqual(",".join(ips), lb1.vips[vip])
Example #20
0
 def test_lrp_add_may_exist_different_mac(self):
     name = utils.get_rand_device_name()
     args = {
         'port': name,
         'mac': 'de:ad:be:ef:4d:ad',
         'networks': ['192.0.2.0/24']
     }
     self._lrp_add(**args)
     args['mac'] = 'da:d4:de:ad:be:ef'
     self.assertRaises(RuntimeError, self._lrp_add, may_exist=True, **args)
Example #21
0
 def test_lsp_bind_may_exist(self):
     chassis, switch, port = self.test_lsp_bind()
     other = self._chassis_add(['vxlan'], '192.0.2.2',
                               chassis=utils.get_rand_device_name())
     self.api.lsp_bind(port.name, other.name, may_exist=True).execute(
         check_error=True)
     binding = idlutils.row_by_value(self.api.idl, 'Port_Binding',
                                     'logical_port', port.name)
     self.assertNotIn(other, binding.chassis)
     self.assertIn(chassis, binding.chassis)
Example #22
0
 def _chassis_add(self, encap_types, encap_ip, *args, **kwargs):
     chassis = kwargs.pop('chassis', utils.get_rand_device_name())
     c = self.useFixture(fixtures.ChassisFixture(
         chassis=chassis, encap_types=encap_types, encap_ip=encap_ip,
         *args, **kwargs)).obj
     self.assertIn(c, self.api.chassis_list().execute(check_error=True))
     self.assertEqual(c.name, chassis)
     self.assertEqual(set(encap_types), {e.type for e in c.encaps})
     self.assertTrue(all(encap_ip == e.ip for e in c.encaps))
     return c
Example #23
0
 def setUp(self):
     super(ImplIdlTestCase, self).setUp()
     self.api = impl_idl.OvsdbIdl(self.connection)
     self.brname = utils.get_rand_device_name()
     # Make sure exceptions pass through by calling do_post_commit directly
     mock.patch.object(
         impl_idl.OvsVsctlTransaction,
         "post_commit",
         side_effect=impl_idl.OvsVsctlTransaction.do_post_commit,
         autospec=True).start()
Example #24
0
    def setUp(self):
        self.bridges = [
            {'name': utils.get_rand_device_name(),
             'datapath_type': 'fake1'},
            {'name': utils.get_rand_device_name(),
             'datapath_type': 'fake1'},
            {'name': utils.get_rand_device_name(),
             'datapath_type': 'fake2'}
        ]

        super(TestBackendDb, self).setUp()
        self.api = impl_idl.OvsdbIdl(self.connection)
        for bridge in self.bridges:
            self.useFixture(fixtures.BridgeFixture(bridge['name']))
            for col, val in bridge.items():
                if col == 'name':
                    continue
                self.api.db_set(
                    'Bridge', bridge['name'], (col, val)).execute(
                        check_error=True)
 def _add_switch_port(self, chassis_name, type='localport'):
     sname, pname = (utils.get_rand_device_name(prefix=p)
                     for p in ('switch', 'port'))
     chassis = self.api.lookup('Chassis', chassis_name)
     row_event = events.WaitForCreatePortBindingEvent(pname)
     self.handler.watch_event(row_event)
     with self.nbapi.transaction(check_error=True) as txn:
         switch = txn.add(self.nbapi.ls_add(sname))
         port = txn.add(self.nbapi.lsp_add(sname, pname, type=type))
     row_event.wait()
     return chassis, switch.result, port.result, row_event.row
Example #26
0
 def test_create_index(self, table_lookup):
     self.assertFalse(self.api.tables['Logical_Switch'].rows.indexes)
     self.api.create_index("Logical_Switch", "name")
     self.api.start_connection(self.connection)
     name = utils.get_rand_device_name("testswitch")
     self.api.ls_add(name).execute(check_error=True)
     sw = self.api.lookup('Logical_Switch', name)
     self.assertEqual(sw.name, name)
     self.assertRaises(idlutils.RowNotFound, self.api.lookup,
                       'Logical_Switch', 'nothere')
     table_lookup.assert_not_called()
Example #27
0
 def _add_chassis_switch_port(self):
     cname, sname, pname = (utils.get_rand_device_name(prefix=p)
                            for p in ("chassis", "switch", "port"))
     chassis = self._chassis_add(['vxlan'], '192.0.2.1', chassis=cname)
     row_event = WaitForPortBindingEvent(pname)
     # We have to wait for ovn-northd to actually create the port binding
     self.handler.watch_event(row_event)
     with self.nbapi.transaction(check_error=True) as txn:
         switch = txn.add(self.nbapi.ls_add(sname))
         port = txn.add(self.nbapi.lsp_add(sname, pname))
     row_event.wait()
     return chassis, switch.result, port.result
Example #28
0
 def _three_nats(self):
     lr = self._lr_add(utils.get_rand_device_name())
     for n, nat_type in enumerate(
         (const.NAT_DNAT, const.NAT_SNAT, const.NAT_BOTH)):
         nat_kwargs = {
             'router': lr,
             'nat_type': nat_type,
             'logical_ip': '10.17.4.%s' % (n + 1),
             'external_ip': '192.0.2.%s' % (n + 1)
         }
         self._lr_nat_add(**nat_kwargs)
     return lr
Example #29
0
 def test_lr_nat_add_may_exist_remove_port(self):
     sw = self.useFixture(fixtures.LogicalSwitchFixture()).obj
     lsp = self.api.lsp_add(
         sw.uuid, utils.get_rand_device_name()).execute(check_error=True)
     args = (const.NAT_BOTH, '10.17.4.1', '192.0.2.1')
     lp, mac = (lsp.name, 'de:ad:be:ef:4d:ad')
     nat1 = self._lr_nat_add(*args, logical_port=lp, external_mac=mac)
     nat2 = self.api.lr_nat_add(nat1.router.uuid, *args,
                                may_exist=True).execute(check_error=True)
     self.assertEqual(nat1, nat2)
     self.assertEqual([], nat2.logical_port)  # because optional
     self.assertEqual([], nat2.external_mac)
Example #30
0
 def test_get_network_port_bindings_by_ip_with_unbound_port(self):
     binding, ipaddr, switch = self._create_bound_port_with_ip()
     unbound_port_name = utils.get_rand_device_name(prefix="port")
     mac_ip = "de:ad:be:ef:4d:ab %s" % ipaddr
     with self.nbapi.transaction(check_error=True) as txn:
         txn.add(
             self.nbapi.lsp_add(switch.name, unbound_port_name, type=type))
         txn.add(self.nbapi.lsp_set_addresses(unbound_port_name, [mac_ip]))
     network_id = switch.name.replace('neutron-', '')
     result = self.api.get_network_port_bindings_by_ip(network_id, ipaddr)
     self.assertIn(binding, result)
     self.assertEqual(1, len(result))