diff --git a/src/sdx_datamodel/parsing/connectionhandler.py b/src/sdx_datamodel/parsing/connectionhandler.py index 1c33dae..70346ad 100644 --- a/src/sdx_datamodel/parsing/connectionhandler.py +++ b/src/sdx_datamodel/parsing/connectionhandler.py @@ -41,7 +41,7 @@ def import_connection_data(self, data: dict) -> Connection: bandwidth_required_obj = qos_metrics.get("min_bw") if bandwidth_required_obj is not None: bandwidth_required = bandwidth_required_obj.get("value") - latency_required_obj = qos_metrics.get("max_latency") + latency_required_obj = qos_metrics.get("max_delay") if latency_required_obj is not None: latency_required = latency_required_obj.get("value") diff --git a/src/sdx_datamodel/validation/connectionvalidator.py b/src/sdx_datamodel/validation/connectionvalidator.py index ef51031..dddff5e 100644 --- a/src/sdx_datamodel/validation/connectionvalidator.py +++ b/src/sdx_datamodel/validation/connectionvalidator.py @@ -37,8 +37,8 @@ def is_valid(self) -> bool: def validate(self, raise_error=True) -> [str]: errors = self._validate_connection(self._connection) - if errors and raise_error: - raise ValueError("\n".join(errors)) + # if errors and raise_error: + # raise ValueError("\n".join(errors)) return errors def _validate_connection(self, conn: Connection): @@ -56,19 +56,32 @@ def _validate_connection(self, conn: Connection): :return: A list of any issues in the data. """ + errors = [] errors += self._validate_object_defaults(conn) errors += self._validate_port(conn.ingress_port, conn) errors += self._validate_port(conn.egress_port, conn) - if hasattr(conn, "scheduling"): + + if hasattr(conn, "start_time") or hasattr(conn, "end_time"): errors += self._validate_time(conn.start_time, conn.end_time, conn) - if hasattr(conn, "qos_metrics"): - errors += self._validate_qos_metrics_value(conn.qos_metrics) + if hasattr(conn, "latency_required"): + errors += self._validate_qos_metrics_value( + "max_delay", conn.latency_required, 1000 + ) + if hasattr(conn, "bandwidth_required"): + errors += self._validate_qos_metrics_value( + "min_bw", conn.bandwidth_required, 100 + ) + + if hasattr(conn, "max_number_oxps"): + errors += self._validate_qos_metrics_value( + "max_number_oxps", conn.bandwidth_required, 100 + ) return errors - def _validate_qos_metrics_value(self, qos_metrics: dict): + def _validate_qos_metrics_value(self, metric, value, max_value): """ Validate that the QoS Metrics provided meets the XSD standards. @@ -86,22 +99,10 @@ def _validate_qos_metrics_value(self, qos_metrics: dict): """ errors = [] - if not isinstance(qos_metrics.max_delay, int): - errors.append( - f"{qos_metrics.max_delay} max_delay must be a number" - ) - if not (0 <= qos_metrics.max_delay <= 1000): - errors.append( - f"{qos_metrics.max_delay} max_delay must be between 0 and 1000" - ) - if not isinstance(qos_metrics.max_number_oxps, int): - errors.append( - f"{qos_metrics.max_number_oxps} max_number_oxps must be a number" - ) - if not (0 <= qos_metrics.max_number_oxps <= 100): - errors.append( - f"{qos_metrics.max_number_oxps} max_number_oxps must be between 0 and 100" - ) + if not isinstance(value, int): + errors.append(f"{value} {metric} must be a number") + if not (0 <= value <= max_value): + errors.append(f"{value} {metric} must be between 0 and 1000") return errors @@ -154,6 +155,8 @@ def _validate_time(self, start_time: str, end_time: str, conn: Connection): errors = [] # if not match(ISO_TIME_FORMAT, time): # errors.append(f"{time} time needs to be in full ISO format") + if not start_time: + start_time = datetime.now().isoformat() try: start_time_obj = datetime.fromisoformat(start_time) if start_time_obj < datetime.now(): diff --git a/tests/test_connection_v2.py b/tests/test_connection_v2.py index 21974e1..bd116f6 100644 --- a/tests/test_connection_v2.py +++ b/tests/test_connection_v2.py @@ -75,13 +75,14 @@ def test_connection_invalid_qos_metrics(self): ], "scheduling": {"end_time": "2023-12-30"}, "qos_metrics": { + "min_bw": {"value": 101}, "max_delay": {"value": 1001}, "max_number_oxps": {"value": 101}, }, } validator = self._get_validator(connection_request) - self.assertTrue(validator.is_valid()) + self.assertFalse(validator.is_valid()) if __name__ == "__main__":