示例#1
0
    def test_ovsdb_monitor_lock(self):
        """Test case to test the ovsdb monitor lock used by OvnConnection.

        This test case created another IDL connection to the NB DB using
        the ovsdb_monitor.OvnConnection.

        With this we will have 2 'ovsdb_monitor.OvnConnection's. At the
        start the lock should be with the IDL connection created by the
        'TestOVNFunctionalBase' setup() function.

        The port up/down events should be handled by the first IDL connection.
        Then we will restart the first IDL connection so that the 2nd IDL
        connection created in this test case gets the lock and it should
        handle the port up/down events.

        Please note that the "self.monitor_nb_idl_con" created by the base
        class is created using 'connection.Connection' and hence it will not
        contend for any lock.
        """
        tst_ovn_idl_conn = ovsdb_monitor.OvnConnection(
            self.ovsdb_server_mgr.get_ovsdb_connection_path(), 10,
            'OVN_Northbound')
        fake_driver = mock.MagicMock()
        tst_ovn_idl_conn.start(fake_driver)

        self.mech_driver.set_port_status_up = mock.Mock()
        self.mech_driver.set_port_status_down = mock.Mock()

        with self.port(name='port') as p:
            p = p['port']
            with self.nb_idl_transaction(self.fake_api,
                                         check_error=True) as txn:
                txn.add(
                    cmd.SetLSwitchPortCommand(self.fake_api,
                                              p['id'],
                                              True,
                                              up=False))

            self._test_port_up_down_helper(p, self.mech_driver)
            fake_driver.set_port_status_up.assert_not_called()
            fake_driver.set_port_status_down.assert_not_called()

            # Now restart the mech_driver's IDL connection.
            self.mech_driver._nb_ovn.idl.force_reconnect()
            # Wait till the test_ovn_idl_conn has acquired the lock.
            n_utils.wait_until_true(lambda: tst_ovn_idl_conn.idl.has_lock)

            self.mech_driver.set_port_status_up.reset_mock()
            self.mech_driver.set_port_status_down.reset_mock()
            fake_driver.set_port_status_up.reset_mock()
            fake_driver.set_port_status_down.reset_mock()

            self._test_port_up_down_helper(p, fake_driver)
            self.assertFalse(self.mech_driver.set_port_status_up.called)
            self.assertFalse(self.mech_driver.set_port_status_down.called)
示例#2
0
    def _test_connection_start(self, mock_wfc, mock_gsh,
                               mock_nb_idl, mock_sb_idl,
                               schema=None, table_name=None):
        mock_helper = mock.Mock()
        mock_gsh.side_effect = [Exception, mock_helper]
        self.ovn_connection = ovsdb_monitor.OvnConnection(
            mock.Mock(), mock.Mock(), schema)
        with mock.patch.object(poller, 'Poller'), \
            mock.patch('threading.Thread'):
            if table_name:
                table_name_list = [table_name]
            else:
                table_name_list = None
            self.ovn_connection.start(
                mock.Mock(), table_name_list=table_name_list)
            # A second start attempt shouldn't re-register.
            self.ovn_connection.start(
                mock.Mock(), table_name_list=table_name_list)

        if table_name:
            mock_helper.register_table.assert_called_once_with(table_name)
        else:
            mock_helper.register_all.assert_called_once_with()