Ejemplo n.º 1
0
def fake_controller_setup(
    enf_controller=None,
    enf_stats_controller=None,
    startup_flow_controller=None,
    check_quota_controller=None,
    setup_flows_request=None,
    check_quota_request=None,
):
    """
    Immitate contoller restart. This is done by manually setting contoller init
    fields back to False, and restarting the startup stats controller(optional)

    If no stats controller is given this means a clean restart, if clean restart
    flag is not set fail the test case.
    """
    if setup_flows_request is None:
        setup_flows_request = SetupPolicyRequest(
            requests=[],
            epoch=global_epoch,
        )
    if startup_flow_controller:
        startup_flow_controller._flows_received = False
        startup_flow_controller._table_flows.clear()
        hub.spawn(startup_flow_controller._poll_startup_flows, 1)
    else:
        TestCase().assertEqual(enf_controller._clean_restart, True)
        if enf_stats_controller:
            TestCase().assertEqual(enf_stats_controller._clean_restart, True)
    enf_controller.init_finished = False
    TestCase().assertEqual(
        setup_controller(
            enf_controller,
            setup_flows_request,
        ),
        SetupFlowsResult.SUCCESS,
    )
    if enf_stats_controller:
        enf_stats_controller.init_finished = False
        enf_stats_controller.cleanup_state()
        TestCase().assertEqual(
            setup_controller(
                enf_stats_controller,
                setup_flows_request,
            ),
            SetupFlowsResult.SUCCESS,
        )
    if check_quota_controller:
        check_quota_controller.init_finished = False
        if check_quota_request is None:
            check_quota_request = UpdateSubscriberQuotaStateRequest(
                requests=[],
                epoch=global_epoch,
            )
        TestCase().assertEqual(
            setup_controller(
                check_quota_controller,
                check_quota_request,
            ),
            SetupFlowsResult.SUCCESS,
        )
Ejemplo n.º 2
0
def fake_inout_setup(inout_controller):
    TestCase().assertEqual(
        setup_controller(
            inout_controller, SetupPolicyRequest(requests=[], epoch=global_epoch),
        ),
        SetupFlowsResult.SUCCESS,
    )
Ejemplo n.º 3
0
    def test_setup_flows_req(self):
        gx_req1 = ActivateFlowsRequest()
        gx_req2 = ActivateFlowsRequest()
        gy_req = ActivateFlowsRequest(
            request_origin=RequestOriginType(type=RequestOriginType.GY), )
        setup_req = SetupPolicyRequest(requests=[gx_req1, gx_req2, gy_req])

        self.pipelined_srv.SetupPolicyFlows(setup_req, MagicMock())
        self._enforcer_app.handle_restart.assert_called_with(
            [gx_req1, gx_req2])
        self._enforcement_stats.handle_restart.assert_called_with(
            [gx_req1, gx_req2])
        self._gy_app.handle_restart.assert_called_with([gy_req])