Пример #1
0
 def test_recv_data_with_empty_data(self):
     """Test case to test _recv_data with empty data."""
     fake_socket = base_test.SocketClass(None, None, None, '')
     with mock.patch.object(socket, 'socket', return_value=fake_socket):
         with mock.patch.object(ovsdb_writer.LOG, 'warning'):
             ovsdb_conf = base_test.FakeConf()
             l2gw_obj = ovsdb_writer.OVSDBWriter(cfg.CONF.ovsdb, ovsdb_conf)
             result = l2gw_obj._recv_data(mock.ANY)
             self.assertIsNone(result)
 def test_recv_data_with_empty_data(self):
     """Test case to test _recv_data with empty data."""
     fake_socket = base_test.SocketClass(None, None, None, '')
     with contextlib.nested(
             mock.patch.object(socket, 'socket', return_value=fake_socket),
             mock.patch.object(ovsdb_writer.LOG,
                               'warning')) as (fake_sock, fake_warn):
         ovsdb_conf = base_test.FakeConf()
         l2gw_obj = ovsdb_writer.OVSDBWriter(cfg.CONF.ovsdb, ovsdb_conf)
         result = l2gw_obj._recv_data()
         self.assertEqual(None, result)
 def test_recv_data(self):
     """Test case to test _recv_data with a valid data."""
     fake_data = {"fake_key": "fake_value"}
     fake_socket = base_test.SocketClass(
         None, None, None,
         base_test.FakeDecodeClass(jsonutils.dumps(fake_data)))
     with mock.patch.object(socket, 'socket', return_value=fake_socket):
         ovsdb_conf = base_test.FakeConf()
         l2gw_obj = ovsdb_writer.OVSDBWriter(cfg.CONF.ovsdb, ovsdb_conf)
         result = l2gw_obj._recv_data()
         self.assertEqual(jsonutils.dumps(fake_data), result)
Пример #4
0
    def test_recv_data_with_socket_error(self):
        """Test case to test _recv_data with socket error."""

        fake_socket = base_test.SocketClass(None, None, socket.error)
        with mock.patch.object(socket, 'socket', return_value=fake_socket):
            with mock.patch.object(ovsdb_writer.LOG, 'warning') as fake_warn:
                ovsdb_conf = base_test.FakeConf()
                l2gw_obj = ovsdb_writer.OVSDBWriter(cfg.CONF.ovsdb, ovsdb_conf)
                result = l2gw_obj._recv_data(mock.ANY)
                self.assertIsNone(result)
                fake_warn.assert_called_with(
                    "Did not receive any reply from the OVSDB server")
    def test_recv_data_with_socket_error(self):
        """Test case to test _recv_data with socket error."""

        fake_socket = base_test.SocketClass(None, None, socket.error)
        with contextlib.nested(
                mock.patch.object(socket, 'socket', return_value=fake_socket),
                mock.patch.object(ovsdb_writer.LOG,
                                  'warning')) as (fake_sock, fake_warn):
            ovsdb_conf = base_test.FakeConf()
            l2gw_obj = ovsdb_writer.OVSDBWriter(cfg.CONF.ovsdb, ovsdb_conf)
            result = l2gw_obj._recv_data()
            self.assertEqual(None, result)
            fake_warn.assert_called_with(
                _LW("Did not receive any reply from the OVSDB "
                    "server"))