예제 #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"
예제 #2
0
def test_create_none(mock_send_message_json):
    """Test Loop instance creation."""
    instance = LoopInstance(template="template", name="test", details={})
    mock_send_message_json.return_value = {}
    with pytest.raises(ValueError):
        instance.create()
        mock_send_message_json.assert_called_once_with('POST', 'Create Loop Instance',
            (f"{instance.base_url()}/loop/create/LOOP_test?templateName=template"),
            cert=instance.cert)
예제 #3
0
def test_create(mock_send_message_json):
    """Test Loop instance creation."""
    instance = LoopInstance(template="template", name="test", details={})
    mock_send_message_json.return_value = LOOP_DETAILS
    instance.create()
    mock_send_message_json.assert_called_once_with('POST', 'Create Loop Instance',
         (f"{instance.base_url()}/loop/create/LOOP_test?templateName=template"),
         cert=instance.cert)
    assert instance.name == "LOOP_test"
    assert len(instance.details["microServicePolicies"]) > 0
예제 #4
0
def test_Loop_creation():
    """Integration tests for Loop Instance."""
    requests.get("{}/reset".format(Clamp._base_url))
    Clamp()
    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()
    def instantiate_loop(self):
        """Instantiate the control loop."""
        loop = LoopInstance(template=self.template,
                            name=self.loop_name,
                            details={})
        details = loop.create()
        if details:
            self._logger.info("Loop instance %s successfully created !!",
                              self.loop_name)
        else:
            self._logger.error(
                "An error occured while creating the loop instance")

        self.add_policies(loop=loop)
        self.configure_policies(loop=loop)
        self.deploy(loop=loop)

        loop.details = loop._update_loop_details()
        return loop