Beispiel #1
0
    def test_amphora_post_network_plug(self, mock_driver, mock_generate_uuid,
                                       mock_log, mock_get_session,
                                       mock_listener_repo_get,
                                       mock_listener_repo_update,
                                       mock_amphora_repo_update):

        amphora_post_network_plug_obj = (
            amphora_driver_tasks.AmphoraPostNetworkPlug())
        amphora_post_network_plug_obj.execute(_amphora_mock, _ports_mock)

        (mock_driver.post_network_plug.assert_called_once_with)(_amphora_mock,
                                                                _port_mock)

        # Test revert
        amp = amphora_post_network_plug_obj.revert(None, _amphora_mock)
        repo.AmphoraRepository.update.assert_called_once_with(
            _session_mock, id=AMP_ID, status=constants.ERROR)

        self.assertIsNone(amp)

        # Test revert with exception
        repo.AmphoraRepository.update.reset_mock()
        mock_amphora_repo_update.side_effect = Exception('fail')
        amp = amphora_post_network_plug_obj.revert(None, _amphora_mock)
        repo.AmphoraRepository.update.assert_called_once_with(
            _session_mock, id=AMP_ID, status=constants.ERROR)

        self.assertIsNone(amp)
    def test_amphora_post_network_plug(self, mock_driver, mock_generate_uuid,
                                       mock_log, mock_get_session,
                                       mock_listener_repo_get,
                                       mock_listener_repo_update,
                                       mock_amphora_repo_get,
                                       mock_amphora_repo_update):

        amphora_post_network_plug_obj = (
            amphora_driver_tasks.AmphoraPostNetworkPlug())
        mock_amphora_repo_get.return_value = _db_amphora_mock
        port_mock = {
            constants.NETWORK: mock.MagicMock(),
            constants.FIXED_IPS: [mock.MagicMock()],
            constants.ID: uuidutils.generate_uuid()
        }
        amphora_post_network_plug_obj.execute(_amphora_mock, [port_mock])

        (mock_driver.post_network_plug.assert_called_once_with)(
            _db_amphora_mock, network_data_models.Port(**port_mock))

        # Test revert
        amp = amphora_post_network_plug_obj.revert(None, _amphora_mock)
        repo.AmphoraRepository.update.assert_called_once_with(
            _session_mock, id=AMP_ID, status=constants.ERROR)

        self.assertIsNone(amp)

        # Test revert with exception
        repo.AmphoraRepository.update.reset_mock()
        mock_amphora_repo_update.side_effect = Exception('fail')
        amp = amphora_post_network_plug_obj.revert(None, _amphora_mock)
        repo.AmphoraRepository.update.assert_called_once_with(
            _session_mock, id=AMP_ID, status=constants.ERROR)

        self.assertIsNone(amp)