Esempio 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"
Esempio n. 2
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()
Esempio n. 3
0
def test_Clamp_requirements():
    """Integration tests for Clamp."""
    requests.get("{}/reset".format(Clamp._base_url))
    # no add resource in clamp
    # svc already exists in mock clamp
    Clamp(cert=('LICENSE', ''))
    svc = Service(name="service01")
    template_exists = Clamp.check_loop_template(service=svc)
    assert template_exists
    policy_exists = Clamp.check_policies(policy_name="MinMax", req_policies=2)
    assert policy_exists
def test_check_loop_template_none(mock_send_message_json):
    """Test Clamp's class method."""
    svc = Service(name='test')
    mock_send_message_json.return_value = {}
    with pytest.raises(ValueError):
        template = Clamp.check_loop_template(service=svc)
        assert template is None
Esempio n. 5
0
 def check(self,
           operational_policies: list,
           is_template: bool = False) -> str:
     """Check CLAMP requirements to create a loop."""
     self._logger.info("Check operational policy")
     for policy in operational_policies:
         exist = Clamp.check_policies(policy_name=policy["name"],
                                      req_policies=30)  # 30 required policy
         self._logger.info("Operational policy found.")
         if not exist:
             raise ValueError("Couldn't load the policy %s", policy)
     # retrieve the service..based on service name
     service: Service = Service(self.service_name)
     if is_template:
         loop_template = Clamp.check_loop_template(service=service)
         self._logger.info("Loop template checked.")
         return loop_template
def test_check_policies_none(mock_send_message_json):
    mock_send_message_json.return_value = POLICIES
    exists = Clamp.check_policies(policy_name="Test")
    mock_send_message_json.\
            assert_called_once_with('GET',
                                    'Get stocked policies',
                                    (f"{Clamp.base_url()}/policyToscaModels/"))
    assert not exists
def test_check_loop_template_none(mock_send_message_json):
    """Test Clamp's class method."""
    svc = Service(name='test')
    mock_send_message_json.return_value = {}
    with pytest.raises(ResourceNotFound) as exc:
        template = Clamp.check_loop_template(service=svc)
        assert template is None
    assert exc.type is ResourceNotFound
def test_check_loop_template(mock_send_message_json):
    """Test Clamp's class method."""
    svc = Service(name='test')
    mock_send_message_json.return_value = TEMPLATES
    template = Clamp.check_loop_template(service=svc)
    mock_send_message_json.assert_called_once_with(
        'GET', 'Get Loop Templates', (f"{Clamp.base_url()}/templates/"))
    assert template == "test_template"
Esempio n. 9
0
 def __init__(self, cleanup=False):
     super().__init__(cleanup=cleanup)
     self._yaml_template: dict = None
     self.add_step(OnboardClampStep(cleanup=cleanup))
     Clamp()
     self.loop_instance = None
def test_initialization():
    """Class initialization test."""
    clamp = Clamp()
    assert isinstance(clamp, Clamp)