fix: automation invoked correctly

Closes issue #361 (closed)

Merge request reports

Loading
+0 −7
Changes for proto/automation.proto: 0 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -37,10 +37,6 @@ enum ZSMServiceStateEnum {
  ZSM_REMOVED = 5;       // ZSM loop is removed
}

enum ZSMTypeEnum {
  ZSMTYPE_UNKNOWN = 0;
}

message ZSMCreateRequest {
  context.ServiceId           target_service_id = 1;
  context.ServiceId           telemetry_service_id = 2;
@@ -62,9 +58,6 @@ message ZSMServiceState {
// Basic ZSM service attributes
message ZSMService {
  ZSMServiceID zsmServiceId = 1;

  context.ServiceId serviceId = 2;
  policy.PolicyRuleList policyList = 3;

  // TODO: When new Analytics and updated Monitoring are in place, add the necessary binding to them
}
+54 −0
Changes for src/automation/client/AutomationClient.py: 54 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (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.

import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.automation_pb2_grpc import AutomationServiceStub
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService, ZSMServiceID, ZSMServiceState
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string

LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')

class AutomationClient:
    def __init__(self, host=None, port=None):
        if not host: host = get_service_host(ServiceNameEnum.AUTOMATION)
        if not port: port = get_service_port_grpc(ServiceNameEnum.AUTOMATION)
        self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
        LOGGER.info('Creating channel to {:s}...'.format(str(self.endpoint)))
        self.channel = None
        self.stub = None
        self.openconfig_stub = None
        self.connect()
        LOGGER.info('Channel created')

    def connect(self):
        self.channel = grpc.insecure_channel(self.endpoint)
        self.stub = AutomationServiceStub(self.channel)

    def close(self):
        if self.channel is not None: self.channel.close()
        self.channel = None
        self.stub = None

    @RETRY_DECORATOR
    def ZSMCreate(self, request : ZSMCreateRequest) -> ZSMService: # type: ignore
        LOGGER.info('ZSMCreate request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.ZSMCreate(request)
        LOGGER.info('ZSMCreate result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
+4 −4
Changes for src/automation/client/PolicyClient.py: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc, logging
import grpc, logging, uuid
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.policy_pb2 import PolicyRuleService, PolicyRuleState
@@ -47,8 +47,8 @@ class PolicyClient:
        self.stub = None

    @RETRY_DECORATOR
    def PolicyAddService(self, request : PolicyRuleService) -> PolicyRuleState:
        LOGGER.debug('AddPolicy request: {:s}'.format(grpc_message_to_json_string(request)))
    def PolicyAddService(self, request : PolicyRuleService) -> PolicyRuleState: # type: ignore
        LOGGER.info('AddPolicy request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.PolicyAddService(request)
        LOGGER.debug('AddPolicy result: {:s}'.format(grpc_message_to_json_string(response)))
        LOGGER.info('AddPolicy result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
+1 −1
Changes for src/automation/service/database/AutomationDB.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -22,5 +22,5 @@ METRICS_POOL = MetricsPool('Automation', 'Database')

class AutomationDB(Database):
    def __init__(self, model) -> None:
        LOGGER.info('Init AutomationService')
        LOGGER.info('Init Automation database')
        super().__init__(model)
+1 −2
Changes for src/automation/service/database/AutomationModel.py: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ from sqlalchemy.orm import registry
from .models._Base import _Base
from common.proto.automation_pb2 import ZSMService

logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)

class AutomationModel(_Base):
@@ -47,7 +46,7 @@ class AutomationModel(_Base):
    @classmethod
    def convert_row_to_Automation(cls, row):
        """
        Create and return a dictionary representation of a Automation instance.
        Create and return a dictionary representation of an Automation instance.
        Args:   row: The Automation instance (row) containing the data.
        Returns: Automation object
        """
Loading
Loading