コード例 #1
0
ファイル: test_impl_idl.py プロジェクト: gaozhengwei/ovsdbapp
 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 = event.WaitForPortBindingEvent(pname)
     bogus_event = event.ExceptionalMatchFnEvent(pname)
     # We have to wait for ovn-northd to actually create the port binding
     self.handler.watch_event(bogus_event)
     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))
     self.assertTrue(row_event.wait())
     self.assertFalse(bogus_event.wait())
     return chassis, switch.result, port.result
コード例 #2
0
    def _create_logical_switch_port(self):
        lswitch_name = 'ovn-' + uuidutils.generate_uuid()
        lswitchport_name = 'ovn-port-' + uuidutils.generate_uuid()
        # It may take some time to ovn-northd to translate from OVN NB DB to
        # the OVN SB DB. Wait for port binding event to happen before binding
        # the port to chassis.
        pb_event = test_event.WaitForPortBindingEvent(lswitchport_name)
        self.handler.watch_event(pb_event)

        with self.nb_api.transaction(check_error=True, log_errors=True) as txn:
            txn.add(self.nb_api.ls_add(lswitch_name))
            txn.add(
                self.nb_api.create_lswitch_port(lswitchport_name,
                                                lswitch_name))
            self._create_metadata_port(txn, lswitch_name)
        self.assertTrue(pb_event.wait())

        return lswitchport_name
コード例 #3
0
    def test_agent_resync_on_non_existing_bridge(self, mock_pbinding):
        # The agent has initialized with br-int and above list_br doesn't
        # return it, hence the agent should trigger reconfiguration and store
        # new br-new value to its attribute.
        self.assertEqual(self.OVN_BRIDGE, self.agent.ovn_bridge)
        lswitch_name = 'ovn-' + uuidutils.generate_uuid()
        lswitchport_name = 'ovn-port-' + uuidutils.generate_uuid()

        # It may take some time to ovn-northd to translate from OVN NB DB to
        # the OVN SB DB. Wait for port binding event to happen before binding
        # the port to chassis.
        pb_event = test_event.WaitForPortBindingEvent(lswitchport_name)
        self.handler.watch_event(pb_event)

        with self.nb_api.transaction(check_error=True, log_errors=True) as txn:
            txn.add(self.nb_api.ls_add(lswitch_name))
            txn.add(
                self.nb_api.create_lswitch_port(lswitchport_name,
                                                lswitch_name))
            self._create_metadata_port(txn, lswitch_name)
        self.assertTrue(pb_event.wait())

        # Trigger PortBindingChassisEvent
        self.sb_api.lsp_bind(lswitchport_name,
                             self.chassis_name).execute(check_error=True,
                                                        log_errors=True)
        exc = Exception('PortBindingChassisEvent was not called')

        def check_mock_pbinding():
            if mock_pbinding.call_count < 1:
                return False
            args = mock_pbinding.call_args[0]
            self.assertEqual('update', args[0])
            self.assertEqual(lswitchport_name, args[1].logical_port)
            self.assertEqual(self.chassis_name, args[1].chassis[0].name)
            return True

        n_utils.wait_until_true(check_mock_pbinding, timeout=10, exception=exc)
コード例 #4
0
    def test_agent_resync_on_non_existing_bridge(self):
        BR_NEW = 'br-new'
        self._mock_get_ovn_br.return_value = BR_NEW
        self.agent.ovs_idl.list_br.return_value.execute.return_value = [BR_NEW]
        # The agent has initialized with br-int and above list_br doesn't
        # return it, hence the agent should trigger reconfiguration and store
        # new br-new value to its attribute.
        self.assertEqual(self.OVN_BRIDGE, self.agent.ovn_bridge)
        lswitch_name = 'ovn-' + uuidutils.generate_uuid()
        lswitchport_name = 'ovn-port-' + uuidutils.generate_uuid()

        # It may take some time to ovn-northd to translate from OVN NB DB to
        # the OVN SB DB. Wait for port binding event to happen before binding
        # the port to chassis.

        pb_event = test_event.WaitForPortBindingEvent(lswitchport_name)
        self.handler.watch_event(pb_event)

        with self.nb_api.transaction(check_error=True, log_errors=True) as txn:
            txn.add(self.nb_api.ls_add(lswitch_name))
            txn.add(
                self.nb_api.create_lswitch_port(lswitchport_name,
                                                lswitch_name))
            self._create_metadata_port(txn, lswitch_name)
        self.assertTrue(pb_event.wait())

        # Trigger PortBindingChassisEvent
        self.sb_api.lsp_bind(lswitchport_name,
                             self.chassis_name).execute(check_error=True,
                                                        log_errors=True)
        exc = Exception("Agent bridge hasn't changed from %s to %s "
                        "in 10 seconds after Port_Binding event" %
                        (self.agent.ovn_bridge, BR_NEW))
        n_utils.wait_until_true(lambda: BR_NEW == self.agent.ovn_bridge,
                                timeout=10,
                                exception=exc)