Пример #1
0
    def test_amphorae_post_vip_plug(self, mock_loadbalancer_repo_update,
                                    mock_driver, mock_generate_uuid, mock_log,
                                    mock_get_session, mock_listener_repo_get,
                                    mock_listener_repo_update,
                                    mock_amphora_repo_update):

        amphorae_net_config_mock = mock.Mock()
        amphora_post_vip_plug_obj = amphora_driver_tasks.AmphoraePostVIPPlug()
        amphora_post_vip_plug_obj.execute(_LB_mock, amphorae_net_config_mock)

        mock_driver.post_vip_plug.assert_called_once_with(
            _amphora_mock, _LB_mock, amphorae_net_config_mock)

        # Test revert
        amp = amphora_post_vip_plug_obj.revert(None, _LB_mock)
        repo.LoadBalancerRepository.update.assert_called_once_with(
            _session_mock, id=LB_ID, provisioning_status=constants.ERROR)

        self.assertIsNone(amp)

        # Test revert with exception
        repo.LoadBalancerRepository.update.reset_mock()
        mock_loadbalancer_repo_update.side_effect = Exception('fail')
        amp = amphora_post_vip_plug_obj.revert(None, _LB_mock)
        repo.LoadBalancerRepository.update.assert_called_once_with(
            _session_mock, id=LB_ID, provisioning_status=constants.ERROR)

        self.assertIsNone(amp)
Пример #2
0
    def get_new_LB_networking_subflow(self):
        """Create a sub-flow to setup networking.

        :returns: The flow to setup networking for a new amphora
        """

        new_LB_net_subflow = linear_flow.Flow(constants.
                                              LOADBALANCER_NETWORKING_SUBFLOW)
        new_LB_net_subflow.add(network_tasks.AllocateVIP(
            requires=constants.LOADBALANCER,
            provides=constants.VIP))
        new_LB_net_subflow.add(database_tasks.UpdateVIPAfterAllocation(
            requires=(constants.LOADBALANCER_ID, constants.VIP),
            provides=constants.LOADBALANCER))
        new_LB_net_subflow.add(network_tasks.PlugVIP(
            requires=constants.LOADBALANCER,
            provides=constants.AMPS_DATA))
        new_LB_net_subflow.add(network_tasks.ApplyQos(
            requires=(constants.LOADBALANCER, constants.AMPS_DATA,
                      constants.UPDATE_DICT)))
        new_LB_net_subflow.add(database_tasks.UpdateAmphoraeVIPData(
            requires=constants.AMPS_DATA))
        new_LB_net_subflow.add(database_tasks.ReloadLoadBalancer(
            name=constants.RELOAD_LB_AFTER_PLUG_VIP,
            requires=constants.LOADBALANCER_ID,
            provides=constants.LOADBALANCER))
        new_LB_net_subflow.add(network_tasks.GetAmphoraeNetworkConfigs(
            requires=constants.LOADBALANCER,
            provides=constants.AMPHORAE_NETWORK_CONFIG))
        new_LB_net_subflow.add(amphora_driver_tasks.AmphoraePostVIPPlug(
            requires=(constants.LOADBALANCER,
                      constants.AMPHORAE_NETWORK_CONFIG)))

        return new_LB_net_subflow
Пример #3
0
    def test_amphorae_post_vip_plug(
            self, mock_lb_get, mock_loadbalancer_repo_update, 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):

        amphorae_net_config_mock = mock.MagicMock()
        mock_amphora_repo_get.return_value = _db_amphora_mock
        vip_subnet = network_data_models.Subnet(
            **amphorae_net_config_mock[AMP_ID]['vip_subnet'])
        vrrp_port = network_data_models.Port(
            **amphorae_net_config_mock[AMP_ID]['vrrp_port'])
        _db_load_balancer_mock.amphorae = [_db_amphora_mock]
        mock_lb_get.return_value = _db_load_balancer_mock
        amphora_post_vip_plug_obj = amphora_driver_tasks.AmphoraePostVIPPlug()
        amphora_post_vip_plug_obj.execute(_LB_mock, amphorae_net_config_mock)

        mock_driver.post_vip_plug.assert_called_once_with(
            _db_amphora_mock,
            _db_load_balancer_mock,
            amphorae_net_config_mock,
            vip_subnet=vip_subnet,
            vrrp_port=vrrp_port)

        # Test revert
        amp = amphora_post_vip_plug_obj.revert(None, _LB_mock)
        repo.LoadBalancerRepository.update.assert_called_once_with(
            _session_mock, id=LB_ID, provisioning_status=constants.ERROR)

        self.assertIsNone(amp)

        # Test revert with exception
        repo.LoadBalancerRepository.update.reset_mock()
        mock_loadbalancer_repo_update.side_effect = Exception('fail')
        amp = amphora_post_vip_plug_obj.revert(None, _LB_mock)
        repo.LoadBalancerRepository.update.assert_called_once_with(
            _session_mock, id=LB_ID, provisioning_status=constants.ERROR)

        self.assertIsNone(amp)

        # Test revert when this task failed
        repo.AmphoraRepository.update.reset_mock()
        amp = amphora_post_vip_plug_obj.revert(
            failure.Failure.from_exception(Exception('boom')), _amphora_mock,
            None)
        repo.AmphoraRepository.update.assert_not_called()