Ejemplo n.º 1
0
def test_Loop_customization():
    """Integration tests for Loop Instance."""
    requests.get("{}/reset".format(Clamp._base_url))
    Clamp(cert=('LICENSE', ''))
    svc = Service(name="service01")
    loop_template = Clamp.check_loop_template(service=svc)
    response = requests.post("{}/reset".format(Clamp._base_url))
    response.raise_for_status()
    loop = LoopInstance(template=loop_template, name="instance01", details={})
    loop.create()
    loop.update_microservice_policy()
    #add op policy FrequencyLimiter that already exists in clamp
    loop.add_operational_policy(
        policy_type="onap.policies.controlloop.guard.common.FrequencyLimiter",
        policy_version="1.0.0")
    #only frequency configuration is available in mock clamp
    loop.add_op_policy_config(loop.add_frequency_limiter, limit=1)
    submit = loop.act_on_loop_policy(loop.submit)
    assert submit
    stop = loop.act_on_loop_policy(loop.stop)
    assert stop
    restart = loop.act_on_loop_policy(loop.restart)
    assert restart
    deploy = loop.deploy_microservice_to_dcae()
    assert deploy
    loop.undeploy_microservice_from_dcae()
    new_details = loop._update_loop_details()
    assert new_details["components"]["DCAE"]["componentState"][
        "stateName"] == "MICROSERVICE_UNINSTALLED_SUCCESSFULLY"
Ejemplo n.º 2
0
def test_add_frequency_policy_config(mock_send_message, mock_extract):
    """Test Loop Instance add op policy configuration."""
    loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS)
    mock_send_message.return_value = True
    loop.add_op_policy_config(loop.add_frequency_limiter)
    mock_send_message.assert_called_once()
    method, description, url = mock_send_message.call_args[0]
    assert method == "POST"
    assert description == "ADD operational policy config"
    assert url == (f"{loop.base_url()}/loop/updateOperationalPolicies/{loop.name}")
Ejemplo n.º 3
0
def test_add_two_policies_config(mock_freq, mock_min, mock_send_message):
    """Test Loop Instance add op policy configuration."""
    loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS)
    mock_min.return_value = '[{"test1":"test1"}]'
    mock_freq.return_value = '[{"test2":"test2"}]'
    loop.add_op_policy_config(loop.add_minmax_config)
    mock_min.assert_called_once()
    mock_send_message.assert_called_once()
    loop.add_op_policy_config(loop.add_frequency_limiter)
    mock_freq.assert_called_once()
    assert loop.operational_policies == '[{"test1":"test1"},{"test2":"test2"}]'
Ejemplo n.º 4
0
def test_add_op_policy_config_error(mock_send_message, mock_freq):
    """Test Loop Instance add op policy configuration."""
    loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS)
    mock_send_message.return_value = False
    #if u put a non cong function
    with pytest.raises(ValueError):
        loop.add_op_policy_config(loop.add_frequency_limiter)
        mock_send_message.assert_called_once()
        method, description, url = mock_send_message.call_args[0]
        assert method == "POST"
        assert description == "ADD operational policy config"
        assert url == (f"{loop.base_url()}/loop/updateOperationalPolicies/{loop.name}")
 def configure_policies(self, loop: LoopInstance) -> None:
     """Configure all policies."""
     self._logger.info("******** UPDATE MICROSERVICE POLICY *******")
     loop._update_loop_details()
     loop.update_microservice_policy()
     self._logger.info(
         "******** UPDATE OPERATIONAL POLICIES CONFIG *******")
     for policy in self.operational_policies:
         #loop.add_op_policy_config(loop.LoopInstance.__dict__[policy["config_function"]])
         #possible configurations for the moment
         if policy["name"] == "MinMax":
             loop.add_op_policy_config(loop.add_minmax_config)
         if policy["name"] == "Drools":
             loop.add_op_policy_config(loop.add_drools_conf)
         if policy["name"] == "FrequencyLimiter":
             loop.add_op_policy_config(loop.add_frequency_limiter)
     self._logger.info("Policies are well configured")