Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tfs/controller
1 result
Show changes
Commits on Source (25)
Showing
with 1378 additions and 253 deletions
......@@ -31,10 +31,6 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
interface = {}
interface_name = xml_interface.find('oci:name', namespaces=NAMESPACES)
if interface_name is None or interface_name.text is None: continue
add_value_from_tag(interface, 'name', interface_name)
#interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
#add_value_from_tag(interface, 'type', interface_type)
......@@ -42,8 +38,11 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
elif xml_interface.find('oci:state/oci:type', namespaces=NAMESPACES) is not None:
interface_type = xml_interface.find('oci:state/oci:type', namespaces=NAMESPACES)
else:
interface_type = ''
else: continue
interface_name = xml_interface.find('oci:name', namespaces=NAMESPACES)
if interface_name is None or interface_name.text is None: continue
add_value_from_tag(interface, 'name', interface_name)
# Get the type of interface according to the vendor's type
if 'ianaift:' in interface_type.text:
......
......@@ -54,7 +54,6 @@ XPATH_PORTS = "//ocp:components/ocp:component"
def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
response = []
LOGGER.debug("InventoryPrueba")
parent_types = {}
for xml_component in xml_data.xpath(XPATH_PORTS, namespaces=NAMESPACES):
LOGGER.info('xml_component inventario = {:s}'.format(str(ET.tostring(xml_component))))
......@@ -78,9 +77,9 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
add_value_from_tag(inventory['attributes'], 'location', component_location)
component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES)
component_type.text = component_type.text.replace('oc-platform-types:','')
if component_type is None: continue
add_value_from_tag(inventory, 'class', component_type)
if component_type is not None:
component_type.text = component_type.text.replace('oc-platform-types:','')
add_value_from_tag(inventory, 'class', component_type)
if inventory['class'] == 'CPU' or inventory['class'] == 'STORAGE': continue
......
......@@ -35,7 +35,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
#LOGGER.info('xml_policy_definition = {:s}'.format(str(ET.tostring(xml_policy_definition))))
policy_definition = {}
statement_name = ''
policy_name = xml_policy_definition.find('ocrp:name', namespaces=NAMESPACES)
if policy_name is None or policy_name.text is None: continue
add_value_from_tag(policy_definition, 'policy_name', policy_name)
......
......@@ -151,6 +151,11 @@ def test_device_ietf_actn_configure(
retrieved_driver_config_rules = sorted(driver.GetConfig(), key=operator.itemgetter(0))
LOGGER.info('driver_config = {:s}'.format(str(retrieved_driver_config_rules)))
assert isinstance(retrieved_driver_config_rules, list)
retrieved_driver_config_rules = [
(resource_key, resource_value)
for resource_key, resource_value in retrieved_driver_config_rules
if resource_key != '/endpoints/endpoint[mgmt]'
]
if len(retrieved_driver_config_rules) > 0:
LOGGER.error('PRE DRIVER CONFIG RULES - Differences:\n{:s}'.format(str(retrieved_driver_config_rules)))
assert len(retrieved_driver_config_rules) == 0
......@@ -186,6 +191,7 @@ def test_device_ietf_actn_configure(
retrieved_driver_config_rules = [
{'action': 1, 'custom': {'resource_key': resource_key, 'resource_value': resource_value}}
for resource_key, resource_value in retrieved_driver_config_rules
if resource_key != '/endpoints/endpoint[mgmt]'
]
with open(DATA_FILE_CONFIG_RULES, 'r', encoding='UTF-8') as f:
expected_driver_config_rules = sorted(json.load(f), key=lambda cr: cr['custom']['resource_key'])
......@@ -231,6 +237,7 @@ def test_device_ietf_actn_deconfigure(
retrieved_driver_config_rules = [
{'action': 1, 'custom': {'resource_key': resource_key, 'resource_value': resource_value}}
for resource_key, resource_value in retrieved_driver_config_rules
if resource_key != '/endpoints/endpoint[mgmt]'
]
with open(DATA_FILE_CONFIG_RULES, 'r', encoding='UTF-8') as f:
expected_driver_config_rules = sorted(json.load(f), key=lambda cr: cr['custom']['resource_key'])
......@@ -266,6 +273,11 @@ def test_device_ietf_actn_deconfigure(
retrieved_driver_config_rules = sorted(driver.GetConfig(), key=operator.itemgetter(0))
LOGGER.info('retrieved_driver_config_rules = {:s}'.format(str(retrieved_driver_config_rules)))
assert isinstance(retrieved_driver_config_rules, list)
retrieved_driver_config_rules = [
(resource_key, resource_value)
for resource_key, resource_value in retrieved_driver_config_rules
if resource_key != '/endpoints/endpoint[mgmt]'
]
if len(retrieved_driver_config_rules) > 0:
LOGGER.error('POST DRIVER CONFIG RULES - Differences:\n{:s}'.format(str(retrieved_driver_config_rules)))
assert len(retrieved_driver_config_rules) == 0
......
......@@ -13,7 +13,7 @@
# limitations under the License.
import logging
from typing import Dict
from typing import Dict, List
from flask import request
from flask.json import jsonify
from flask_restful import Resource
......@@ -36,11 +36,40 @@ class L3VPN_Services(Resource):
request_data : Dict = request.json
LOGGER.debug('Request: {:s}'.format(str(request_data)))
errors = list()
if 'ietf-l3vpn-svc:l3vpn-services' in request_data:
# processing multiple L3VPN service requests formatted as:
#{
# "ietf-l3vpn-svc:l3vpn-services": {
# "l3vpn-svc": [
# {
# "service-id": "vpn1",
# "vpn-services": {
# "vpn-service": [
for l3vpn_svc in request_data['ietf-l3vpn-svc:l3vpn-services']['l3vpn-svc']:
l3vpn_svc.pop('service-id', None)
l3vpn_svc_request_data = {'ietf-l3vpn-svc:l3vpn-svc': l3vpn_svc}
errors.extend(self._process_l3vpn(l3vpn_svc_request_data))
elif 'ietf-l3vpn-svc:l3vpn-svc' in request_data:
# processing single (standard) L3VPN service request formatted as:
#{
# "ietf-l3vpn-svc:l3vpn-svc": {
# "vpn-services": {
# "vpn-service": [
errors.extend(self._process_l3vpn(request_data))
else:
errors.append('unexpected request: {:s}'.format(str(request_data)))
response = jsonify(errors)
response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR
return response
def _process_l3vpn(self, request_data : Dict) -> List[Dict]:
yang_validator = YangValidator('ietf-l3vpn-svc')
request_data = yang_validator.parse_to_dict(request_data)
yang_validator.destroy()
errors = []
errors = list()
for vpn_service in request_data['l3vpn-svc']['vpn-services']['vpn-service']:
process_vpn_service(vpn_service, errors)
......@@ -48,6 +77,4 @@ class L3VPN_Services(Resource):
for site in request_data['l3vpn-svc']['sites']['site']:
process_site(site, errors)
response = jsonify(errors)
response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR
return response
return errors
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy.common;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
public class ApplicationProperties {
public static final String INVALID_MESSAGE = "%s is invalid.";
public static final String VALID_MESSAGE = "%s is valid.";
public static final PolicyRuleState INSERTED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_INSERTED, "Successfully entered to INSERTED state");
public static final PolicyRuleState VALIDATED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_VALIDATED, "Successfully transitioned to VALIDATED state");
public static final PolicyRuleState PROVISIONED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_PROVISIONED,
"Successfully transitioned from VALIDATED to PROVISIONED state");
public static final PolicyRuleState ACTIVE_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_ACTIVE,
"Successfully transitioned from PROVISIONED to ACTIVE state");
public static final PolicyRuleState ENFORCED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_ENFORCED,
"Successfully transitioned from ACTIVE to ENFORCED state");
public static final PolicyRuleState INEFFECTIVE_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_INEFFECTIVE,
"Transitioned from ENFORCED to INEFFECTIVE state");
public static final PolicyRuleState EFFECTIVE_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_EFFECTIVE,
"Successfully transitioned from ENFORCED to EFFECTIVE state");
public static final PolicyRuleState UPDATED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_UPDATED, "Successfully entered to UPDATED state");
public static final PolicyRuleState REMOVED_POLICYRULE_STATE =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_REMOVED, "Successfully entered to REMOVED state");
}
......@@ -64,7 +64,7 @@ public class PolicyRuleBasic {
this.booleanOperator = BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED;
this.policyRuleActions = new ArrayList<PolicyRuleAction>();
this.isValid = false;
this.exceptionMessage = e.toString();
this.exceptionMessage = e.getMessage();
}
}
......
......@@ -40,7 +40,7 @@ public class PolicyRuleDevice {
this.policyRuleBasic = policyRuleBasic;
this.deviceIds = new ArrayList<String>();
this.isValid = false;
this.exceptionMessage = e.toString();
this.exceptionMessage = e.getMessage();
}
}
......
......@@ -50,7 +50,7 @@ public class PolicyRuleService {
this.serviceId = new ServiceId("", "");
this.deviceIds = new ArrayList<String>();
this.isValid = false;
this.exceptionMessage = e.toString();
this.exceptionMessage = e.getMessage();
}
}
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE;
import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.smallrye.mutiny.Uni;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.etsi.tfs.policy.context.ContextService;
import org.etsi.tfs.policy.model.BooleanOperator;
import org.etsi.tfs.policy.model.NumericalOperator;
import org.etsi.tfs.policy.model.PolicyRuleAction;
import org.etsi.tfs.policy.model.PolicyRuleActionConfig;
import org.etsi.tfs.policy.model.PolicyRuleActionEnum;
import org.etsi.tfs.policy.model.PolicyRuleBasic;
import org.etsi.tfs.policy.model.PolicyRuleCondition;
import org.etsi.tfs.policy.model.PolicyRuleDevice;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
import org.etsi.tfs.policy.monitoring.MonitoringService;
import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue;
import org.etsi.tfs.policy.monitoring.model.KpiValue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@QuarkusTest
class PolicyAddDeviceTest {
@Inject PolicyServiceImpl policyService;
@InjectMock PolicyRuleConditionValidator policyRuleConditionValidator;
@InjectMock ContextService contextService;
@InjectMock MonitoringService monitoringService;
static PolicyRuleBasic policyRuleBasic;
static PolicyRuleDevice policyRuleDevice;
@BeforeAll
static void init() {
String policyId = "policyRuleId";
KpiValue kpiValue = new IntegerKpiValue(100);
PolicyRuleCondition policyRuleCondition =
new PolicyRuleCondition(
"kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue);
PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value");
PolicyRuleAction policyRuleAction =
new PolicyRuleAction(
PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION,
Arrays.asList(policyRuleActionConfig));
policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
Arrays.asList(policyRuleCondition),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
Arrays.asList(policyRuleAction));
List<String> deviceIds = Arrays.asList("device1", "device2");
policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, deviceIds);
}
@Test
void deviceListMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Device Ids must not be empty.");
policyService
.addPolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void isPolicyRuleBasicValid() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleBasic policyRuleBasic =
new PolicyRuleBasic(
"policyId",
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
0,
new ArrayList<>(),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
new ArrayList<>());
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, "Policy Rule conditions cannot be empty.");
policyService
.addPolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void isPolicyRuleIdValid() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED,
String.format(
INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId()));
Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(Boolean.FALSE));
policyService
.addPolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void successPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_VALIDATED,
VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage());
Mockito.when(policyRuleConditionValidator.isDeviceIdValid(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(Boolean.TRUE));
policyService
.addPolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.etsi.tfs.policy.common.ApplicationProperties.*;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.smallrye.mutiny.Uni;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.etsi.tfs.policy.context.ContextService;
import org.etsi.tfs.policy.context.model.Service;
import org.etsi.tfs.policy.context.model.ServiceId;
import org.etsi.tfs.policy.context.model.ServiceTypeEnum;
import org.etsi.tfs.policy.model.BooleanOperator;
import org.etsi.tfs.policy.model.NumericalOperator;
import org.etsi.tfs.policy.model.PolicyRule;
import org.etsi.tfs.policy.model.PolicyRuleAction;
import org.etsi.tfs.policy.model.PolicyRuleActionConfig;
import org.etsi.tfs.policy.model.PolicyRuleActionEnum;
import org.etsi.tfs.policy.model.PolicyRuleBasic;
import org.etsi.tfs.policy.model.PolicyRuleCondition;
import org.etsi.tfs.policy.model.PolicyRuleService;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
import org.etsi.tfs.policy.monitoring.MonitoringService;
import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue;
import org.etsi.tfs.policy.monitoring.model.KpiValue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@QuarkusTest
public class PolicyAddServiceTest {
@Inject PolicyServiceImpl policyService;
@InjectMock PolicyRuleConditionValidator policyRuleConditionValidator;
@InjectMock ContextService contextService;
@InjectMock MonitoringService monitoringService;
static PolicyRuleBasic policyRuleBasic;
static PolicyRuleService policyRuleService;
@BeforeAll
static void init() {
String policyId = "policyRuleId";
KpiValue kpiValue = new IntegerKpiValue(100);
PolicyRuleCondition policyRuleCondition =
new PolicyRuleCondition(
"kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue);
PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value");
PolicyRuleAction policyRuleAction =
new PolicyRuleAction(
PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION,
Arrays.asList(policyRuleActionConfig));
policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
Arrays.asList(policyRuleCondition),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
Arrays.asList(policyRuleAction));
ServiceId serviceId = new ServiceId("contextId", "serviceId");
Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0);
List<String> deviceIds = Arrays.asList("device1", "device2");
policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
}
@Test
void contextOrServiceIdMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("", "");
List<String> deviceIds = Arrays.asList("device1", "device2");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, "Context Id of Service Id must not be empty.");
policyService
.addPolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void serviceIdMustNotBeEmpty() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("sdf", "");
List<String> deviceIds = Arrays.asList("device1", "device2");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Service Id must not be empty.");
policyService
.addPolicyService(policyRuleService)
.subscribe()
.with(item -> message.complete(item));
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void policyRuleIdMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
String policyId = "";
PolicyRuleBasic policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
new ArrayList<>(),
null,
new ArrayList<>());
ServiceId serviceId = new ServiceId("contextId", "serviceId");
Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0);
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Policy rule ID must not be empty.");
policyService
.addPolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void checkMessageIfServiceIsNotValid()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("contextId", "serviceId");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, serviceId + " is invalid.");
Mockito.when(
policyRuleConditionValidator.isServiceIdValid(
Mockito.any(ServiceId.class), Mockito.anyList()))
.thenReturn(Uni.createFrom().item(Boolean.FALSE));
policyService
.addPolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void policyServiceSuccess()
throws ExecutionException, InterruptedException, TimeoutException, IOException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_VALIDATED,
VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage());
Mockito.when(
policyRuleConditionValidator.isServiceIdValid(
Mockito.any(ServiceId.class), Mockito.anyList()))
.thenReturn(Uni.createFrom().item(Boolean.TRUE));
Mockito.when(contextService.setPolicyRule(Mockito.any(PolicyRule.class)))
.thenReturn(Uni.createFrom().item("policyRuleId"));
policyService
.addPolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.etsi.tfs.policy.common.ApplicationProperties.REMOVED_POLICYRULE_STATE;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.smallrye.mutiny.Uni;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.etsi.tfs.policy.context.ContextService;
import org.etsi.tfs.policy.context.model.Service;
import org.etsi.tfs.policy.context.model.ServiceId;
import org.etsi.tfs.policy.context.model.ServiceTypeEnum;
import org.etsi.tfs.policy.model.BooleanOperator;
import org.etsi.tfs.policy.model.NumericalOperator;
import org.etsi.tfs.policy.model.PolicyRule;
import org.etsi.tfs.policy.model.PolicyRuleAction;
import org.etsi.tfs.policy.model.PolicyRuleActionConfig;
import org.etsi.tfs.policy.model.PolicyRuleActionEnum;
import org.etsi.tfs.policy.model.PolicyRuleBasic;
import org.etsi.tfs.policy.model.PolicyRuleCondition;
import org.etsi.tfs.policy.model.PolicyRuleService;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
import org.etsi.tfs.policy.model.PolicyRuleType;
import org.etsi.tfs.policy.model.PolicyRuleTypeService;
import org.etsi.tfs.policy.monitoring.MonitoringService;
import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue;
import org.etsi.tfs.policy.monitoring.model.KpiValue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@QuarkusTest
class PolicyDeleteServiceTest {
@Inject PolicyServiceImpl policyService;
@InjectMock ContextService contextService;
@InjectMock MonitoringService monitoringService;
static PolicyRuleBasic policyRuleBasic;
static PolicyRuleService policyRuleService;
@BeforeAll
static void init() {
String policyId = "policyRuleId";
KpiValue kpiValue = new IntegerKpiValue(100);
PolicyRuleCondition policyRuleCondition =
new PolicyRuleCondition(
"kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue);
PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value");
PolicyRuleAction policyRuleAction =
new PolicyRuleAction(
PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION,
Arrays.asList(policyRuleActionConfig));
policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
Arrays.asList(policyRuleCondition),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
Arrays.asList(policyRuleAction));
ServiceId serviceId = new ServiceId("contextId", "serviceId");
Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0);
List<String> deviceIds = Arrays.asList("device1", "device2");
policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
}
@Test
void contextOrServiceIdMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
String policyRuleId = "";
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_REMOVED,
REMOVED_POLICYRULE_STATE.getPolicyRuleStateMessage());
PolicyRuleType policyRuleType = new PolicyRuleTypeService(policyRuleService);
PolicyRule policyRule = new PolicyRule(policyRuleType);
Mockito.when(contextService.getPolicyRule(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(policyRule));
policyService
.deletePolicy(policyRuleId)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
}
......@@ -46,14 +46,14 @@ import policy.PolicyCondition.PolicyRuleCondition;
import policy.PolicyService;
@QuarkusTest
class PolicyServiceTest {
private static final Logger LOGGER = Logger.getLogger(PolicyServiceTest.class);
class PolicyGrpcServiceTest {
private static final Logger LOGGER = Logger.getLogger(PolicyGrpcServiceTest.class);
@GrpcClient PolicyService client;
private final Serializer serializer;
@Inject
PolicyServiceTest(Serializer serializer) {
PolicyGrpcServiceTest(Serializer serializer) {
this.serializer = serializer;
}
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE;
import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.smallrye.mutiny.Uni;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.etsi.tfs.policy.model.BooleanOperator;
import org.etsi.tfs.policy.model.NumericalOperator;
import org.etsi.tfs.policy.model.PolicyRuleAction;
import org.etsi.tfs.policy.model.PolicyRuleActionConfig;
import org.etsi.tfs.policy.model.PolicyRuleActionEnum;
import org.etsi.tfs.policy.model.PolicyRuleBasic;
import org.etsi.tfs.policy.model.PolicyRuleCondition;
import org.etsi.tfs.policy.model.PolicyRuleDevice;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
import org.etsi.tfs.policy.monitoring.MonitoringService;
import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue;
import org.etsi.tfs.policy.monitoring.model.KpiValue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@QuarkusTest
class PolicyUpdateDeviceTest {
@Inject PolicyServiceImpl policyService;
@InjectMock PolicyRuleConditionValidator policyRuleConditionValidator;
@InjectMock MonitoringService monitoringService;
static PolicyRuleBasic policyRuleBasic;
static PolicyRuleDevice policyRuleDevice;
@BeforeAll
static void init() {
String policyId = "policyRuleId";
KpiValue kpiValue = new IntegerKpiValue(100);
PolicyRuleCondition policyRuleCondition =
new PolicyRuleCondition(
"kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue);
PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value");
PolicyRuleAction policyRuleAction =
new PolicyRuleAction(
PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION,
Arrays.asList(policyRuleActionConfig));
policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
Arrays.asList(policyRuleCondition),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
Arrays.asList(policyRuleAction));
List<String> deviceIds = Arrays.asList("device1", "device2");
policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, deviceIds);
}
@Test
void deviceListMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Device Ids must not be empty.");
policyService
.updatePolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void isPolicyRuleBasicValid() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleBasic policyRuleBasic =
new PolicyRuleBasic(
"policyId",
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
0,
new ArrayList<>(),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
new ArrayList<>());
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, "Policy Rule conditions cannot be empty.");
policyService
.updatePolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void isUpdatedPolicyRuleIdValid()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED,
String.format(
INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId()));
Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(Boolean.FALSE));
policyService
.updatePolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void successUpdatePolicyService()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
PolicyRuleDevice policyRuleDevice =
new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1"));
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_VALIDATED,
VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage());
Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(Boolean.TRUE));
policyService
.updatePolicyDevice(policyRuleDevice)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.etsi.tfs.policy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE;
import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.smallrye.mutiny.Uni;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.etsi.tfs.policy.context.ContextService;
import org.etsi.tfs.policy.context.model.Service;
import org.etsi.tfs.policy.context.model.ServiceId;
import org.etsi.tfs.policy.context.model.ServiceTypeEnum;
import org.etsi.tfs.policy.model.BooleanOperator;
import org.etsi.tfs.policy.model.NumericalOperator;
import org.etsi.tfs.policy.model.PolicyRuleAction;
import org.etsi.tfs.policy.model.PolicyRuleActionConfig;
import org.etsi.tfs.policy.model.PolicyRuleActionEnum;
import org.etsi.tfs.policy.model.PolicyRuleBasic;
import org.etsi.tfs.policy.model.PolicyRuleCondition;
import org.etsi.tfs.policy.model.PolicyRuleService;
import org.etsi.tfs.policy.model.PolicyRuleState;
import org.etsi.tfs.policy.model.PolicyRuleStateEnum;
import org.etsi.tfs.policy.monitoring.MonitoringService;
import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue;
import org.etsi.tfs.policy.monitoring.model.KpiValue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@QuarkusTest
class PolicyUpdateServiceTest {
@Inject PolicyServiceImpl policyService;
@InjectMock PolicyRuleConditionValidator policyRuleConditionValidator;
@InjectMock ContextService contextService;
@InjectMock MonitoringService monitoringService;
static PolicyRuleBasic policyRuleBasic;
static PolicyRuleService policyRuleService;
@BeforeAll
static void init() {
String policyId = "policyRuleId";
KpiValue kpiValue = new IntegerKpiValue(100);
PolicyRuleCondition policyRuleCondition =
new PolicyRuleCondition(
"kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue);
PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value");
PolicyRuleAction policyRuleAction =
new PolicyRuleAction(
PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION,
Arrays.asList(policyRuleActionConfig));
policyRuleBasic =
new PolicyRuleBasic(
policyId,
new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"),
1,
Arrays.asList(policyRuleCondition),
BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR,
Arrays.asList(policyRuleAction));
ServiceId serviceId = new ServiceId("contextId", "serviceId");
Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0);
List<String> deviceIds = Arrays.asList("device1", "device2");
policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
}
@Test
void contextOrServiceIdMustNotBeEmpty()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("", "");
List<String> deviceIds = Arrays.asList("device1", "device2");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, "Context Id of Service Id must not be empty.");
policyService
.updatePolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void serviceIdMustNotBeEmpty() throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("sdf", "");
List<String> deviceIds = Arrays.asList("device1", "device2");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, deviceIds);
PolicyRuleState expectedResult =
new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Service Id must not be empty.");
policyService
.updatePolicyService(policyRuleService)
.subscribe()
.with(item -> message.complete(item));
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void checkMessageIfServiceIsNotValid()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("contextId", "serviceId");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, String.format(INVALID_MESSAGE, serviceId));
Mockito.when(
policyRuleConditionValidator.isPolicyRuleServiceValid(
Mockito.anyString(), Mockito.any(ServiceId.class)))
.thenReturn(Uni.createFrom().item(Boolean.FALSE));
policyService
.updatePolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
@Test
void successUpdatePolicyService()
throws ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<PolicyRuleState> message = new CompletableFuture<>();
ServiceId serviceId = new ServiceId("contextId", "serviceId");
PolicyRuleService policyRuleService =
new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>());
PolicyRuleState expectedResult =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_VALIDATED,
VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage());
Mockito.when(
policyRuleConditionValidator.isPolicyRuleServiceValid(
Mockito.anyString(), Mockito.any(ServiceId.class)))
.thenReturn(Uni.createFrom().item(Boolean.TRUE));
policyService
.updatePolicyService(policyRuleService)
.subscribe()
.with(
item -> {
message.complete(item);
});
assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage())
.isEqualTo(expectedResult.getPolicyRuleStateMessage().toString());
}
}
......@@ -3,8 +3,8 @@ apiVersion: v1
kind: Service
metadata:
annotations:
app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467
app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000
app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db
app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
......@@ -29,8 +29,8 @@ apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467
app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000
app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db
app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
......@@ -47,8 +47,8 @@ spec:
template:
metadata:
annotations:
app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467
app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000
app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db
app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
......@@ -63,12 +63,12 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CONTEXT_SERVICE_HOST
value: contextservice
- name: SERVICE_SERVICE_HOST
value: serviceservice
- name: MONITORING_SERVICE_HOST
value: monitoringservice
- name: CONTEXT_SERVICE_HOST
value: contextservice
image: labs.etsi.org:5050/tfs/controller/policy:0.1.0
imagePullPolicy: Always
livenessProbe:
......
......@@ -7,22 +7,17 @@ This REST server implements very basic support for the following YANG data model
- Ref: https://datatracker.ietf.org/doc/draft-ietf-teas-yang-te/
The aim of this server is to enable testing the IetfActnDeviceDriver and the IetfActnServiceHandler.
Follow the steps below to perform the test:
## 1. Deploy TeraFlowSDN controller and the scenario
Deploy the test scenario "ietf_actn_deploy.sh":
```bash
source src/tests/tools/mock_ietf_actn_sdn_ctrl/scenario/ietf_actn_deploy.sh
./deploy/all.sh
```
## 2. Install requirements and run the Mock IETF ACTN SDN controller
__NOTE__: if you run the Mock IETF ACTN SDN controller from the PyEnv used for developping on the TeraFlowSDN framework,
## 1. Install requirements for the Mock IETF ACTN SDN controller
__NOTE__: if you run the Mock IETF ACTN SDN controller from the PyEnv used for developing on the TeraFlowSDN
framework and you followed the official steps in
[Development Guide > Configure Environment > Python](https://labs.etsi.org/rep/tfs/controller/-/wikis/2.-Development-Guide/2.1.-Configure-Environment/2.1.1.-Python),
all the requirements are already in place. Install them only if you execute it in a separate/standalone environment.
Install the required dependencies as follows:
```bash
pip install Flask==2.1.3 Flask-RESTful==0.3.9
pip install -r src/tests/tools/mock_ietf_actn_sdn_ctrl/requirements.in
```
Run the Mock IETF ACTN SDN Controller as follows:
......@@ -30,24 +25,9 @@ Run the Mock IETF ACTN SDN Controller as follows:
python src/tests/tools/mock_ietf_actn_sdn_ctrl/MockIetfActnSdnCtrl.py
```
## 3. Deploy the test descriptors
Edit the descriptors to meet your environment specifications.
Edit "network_descriptors.json" and change IP address and port of the IETF ACTN SDN controller of the "ACTN" device.
- Set value of config rule "_connect/address" to the address of the host where the Mock IETF ACTN SDN controller is
running (default="192.168.1.1").
- Set value of config rule "_connect/port" to the port where your Mock IETF ACTN SDN controller is listening on
(default="8443").
Upload the "network_descriptors.json" through the TeraFlowSDN WebUI.
- If not already selected, select Context(admin)/Topology(admin).
- Check that a network topology with 4 routers + 1 IETF ACTN radio system are loaded. They should form 2 rings.
Upload the "service_descriptor.json" through the TeraFlowSDN WebUI.
- Check that 2 services have been created.
- The "actn-svc" should have a connection and be supported by a sub-service.
- The sub-service should also have a connection.
- The R1, R3, and MW devices should have configuration rules established.
# 4. Delete the IETF ACTN service
Find the "mw-svc" on the WebUI, navigate to its details, and delete the service pressing the "Delete Service" button.
The service, sub-service, and device configuration rules should be removed.
## 2. Run the Mock IETF ACTN SDN controller
Run the Mock IETF ACTN SDN Controller as follows:
```bash
python src/tests/tools/mock_ietf_actn_sdn_ctrl/MockIetfActnSdnCtrl.py
```
......@@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Make folder containing the script the root folder for its execution
cd $(dirname $0)
docker build -t mock-ietf-actn-sdn-ctrl:test -f Dockerfile .
docker tag mock-ietf-actn-sdn-ctrl:test localhost:32000/tfs/mock-ietf-actn-sdn-ctrl:test
docker push localhost:32000/tfs/mock-ietf-actn-sdn-ctrl:test
......@@ -13,4 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Make folder containing the script the root folder for its execution
cd $(dirname $0)
python MockIetfActnSdnCtrl.py