Exemplo n.º 1
0
 def testget_schema_helper_success(self, mock_gsh):
     mock_gsh_helper = mock.Mock()
     mock_gsh.side_effect = [mock_gsh_helper]
     ovn_base_connection = ovsdb_monitor.OvnBaseConnection(
         mock.Mock(), mock.Mock(), mock.Mock())
     helper = ovn_base_connection.get_schema_helper()
     mock_gsh.assert_called_once_with(ovn_base_connection.connection,
                                      ovn_base_connection.schema_name)
     self.assertEqual(mock_gsh_helper, helper)
Exemplo n.º 2
0
 def testget_schema_helper_initial_exception(self, mock_gsh):
     mock_gsh_helper = mock.Mock()
     mock_gsh.side_effect = [Exception, mock_gsh_helper]
     ovn_base_connection = ovsdb_monitor.OvnBaseConnection(
         mock.Mock(), mock.Mock(), mock.Mock())
     helper = ovn_base_connection.get_schema_helper()
     gsh_call = mock.call(ovn_base_connection.connection,
                          ovn_base_connection.schema_name)
     mock_gsh.assert_has_calls([gsh_call, gsh_call])
     self.assertEqual(mock_gsh_helper, helper)
Exemplo n.º 3
0
    def _start_ovsdb_server_and_idls(self):
        self.temp_dir = self.useFixture(fixtures.TempDir()).path
        # Start 2 ovsdb-servers one each for OVN NB DB and OVN SB DB
        # ovsdb-server with OVN SB DB can be used to test the chassis up/down
        # events.
        self.ovsdb_server_mgr = self.useFixture(
            process.OvsdbServer(self.temp_dir, self.OVS_INSTALL_SHARE_PATH,
                                ovn_nb_db=True, ovn_sb_db=True,
                                protocol=self._ovsdb_protocol))
        set_cfg = cfg.CONF.set_override
        set_cfg('ovn_nb_connection',
                self.ovsdb_server_mgr.get_ovsdb_connection_path(), 'ovn')
        set_cfg('ovn_sb_connection',
                self.ovsdb_server_mgr.get_ovsdb_connection_path(
                    db_type='sb'), 'ovn')
        set_cfg('ovn_nb_private_key', self.ovsdb_server_mgr.private_key, 'ovn')
        set_cfg('ovn_nb_certificate', self.ovsdb_server_mgr.certificate, 'ovn')
        set_cfg('ovn_nb_ca_cert', self.ovsdb_server_mgr.ca_cert, 'ovn')
        set_cfg('ovn_sb_private_key', self.ovsdb_server_mgr.private_key, 'ovn')
        set_cfg('ovn_sb_certificate', self.ovsdb_server_mgr.certificate, 'ovn')
        set_cfg('ovn_sb_ca_cert', self.ovsdb_server_mgr.ca_cert, 'ovn')

        num_attempts = 0
        # 5 seconds should be more than enough for the transaction to complete
        # for the test cases.
        # This also fixes the bug #1607639.
        cfg.CONF.set_override(
            'ovsdb_connection_timeout', 5,
            'ovn')

        # Created monitor IDL connection to the OVN NB DB.
        # This monitor IDL connection can be used to
        #   - Verify that the ML2 OVN driver has written to the OVN NB DB
        #     as expected.
        #   - Create and delete resources in OVN NB DB outside of the
        #     ML2 OVN driver scope to test scenarios like ovn_nb_sync.
        while num_attempts < 3:
            try:
                self.monitor_nb_idl_con = ovsdb_monitor.OvnBaseConnection(
                    self.ovsdb_server_mgr.get_ovsdb_connection_path(),
                    60, 'OVN_Northbound')
                self.monitor_nb_idl_con.start()
                self.monitor_nb_db_idl = self.monitor_nb_idl_con.idl
                break
            except Exception:
                LOG.exception("Error connecting to the OVN_Northbound DB")
                num_attempts += 1
                time.sleep(1)

        num_attempts = 0

        # Create monitor IDL connection to the OVN SB DB.
        # This monitor IDL connection can be used to
        #  - Create chassis rows
        #  - Update chassis columns etc.
        while num_attempts < 3:
            try:
                self.monitor_sb_idl_con = ovsdb_monitor.OvnBaseConnection(
                    self.ovsdb_server_mgr.get_ovsdb_connection_path(
                        db_type='sb'),
                    60, 'OVN_Southbound')
                self.monitor_sb_idl_con.start()
                self.monitor_sb_db_idl = self.monitor_sb_idl_con.idl
                break
            except Exception:
                LOG.exception("Error connecting to the OVN_Southbound DB")
                num_attempts += 1
                time.sleep(1)

        trigger = mock.MagicMock()
        if self.ovn_worker:
            trigger.im_class = ovsdb_monitor.OvnWorker
            cfg.CONF.set_override('neutron_sync_mode', 'off', 'ovn')
        trigger.im_class.__name__ = 'trigger'

        # mech_driver.post_fork_initialize creates the IDL connections
        self.mech_driver.post_fork_initialize(mock.ANY, mock.ANY, trigger)
Exemplo n.º 4
0
 def testget_schema_helper_all_exception(self, mock_gsh):
     mock_gsh.side_effect = RuntimeError
     ovn_base_connection = ovsdb_monitor.OvnBaseConnection(
         mock.Mock(), mock.Mock(), mock.Mock())
     self.assertRaises(RuntimeError, ovn_base_connection.get_schema_helper)