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"
def test_restart_policy(mock_send_message, mock_refresh): """Test submit policies to policy engine.""" loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS) action = loop.act_on_loop_policy(loop.restart) mock_send_message.assert_called_once_with( 'PUT', 'restart policy', (f"{loop.base_url()}/loop/restart/LOOP_test")) mock_refresh.assert_called_once() loop.details = SUBMITED_POLICY assert loop.details["components"]["POLICY"]["componentState"][ "stateName"] == "SENT_AND_DEPLOYED"
def test_stop_policy(mock_send_message, mock_refresh): """Test submit policies to policy engine.""" loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS) action = loop.act_on_loop_policy(loop.stop) mock_send_message.assert_called_once_with('PUT', 'stop policy', (f"{loop.base_url()}/loop/stop/LOOP_test"), cert=loop.cert, exception=ValueError) mock_refresh.assert_called_once() loop.details = {"components":{"POLICY":{"componentState":{"stateName":"SENT"}}}} assert loop.details["components"]["POLICY"]["componentState"]["stateName"] == "SENT"
def test_not_submited_policy(mock_send_message, mock_refresh): """Test submit policies to policy engine.""" loop = LoopInstance(template="template", name="test", details=LOOP_DETAILS) mock_refresh.return_value = NOT_SUBMITED_POLICY action = loop.act_on_loop_policy(loop.submit) mock_send_message.assert_called_once_with('PUT', 'submit policy', (f"{loop.base_url()}/loop/submit/LOOP_test"), cert=loop.cert, exception=ValueError) mock_refresh.assert_called_once() loop.details = NOT_SUBMITED_POLICY assert loop.details["components"]["POLICY"]["componentState"]["stateName"] == "SENT"
def deploy(self, loop: LoopInstance) -> None: """Deploy closed loop.""" self._logger.info("******** SUBMIT POLICIES TO PE *******") submit = loop.act_on_loop_policy(loop.submit) self._logger.info("******** CHECK POLICIES SUBMITION *******") if submit: self._logger.info("Policies successfully submited to PE") else: self._logger.error( "An error occured while submitting the loop instance") raise onap_test_exceptions.PolicyException self._logger.info("******** DEPLOY LOOP INSTANCE *******") deploy = loop.deploy_microservice_to_dcae() if deploy: self._logger.info( "Loop instance %s successfully deployed on DCAE !!", self.loop_name) else: self._logger.error( "An error occured while deploying the loop instance") raise onap_test_exceptions.DcaeException