Commit 324cd085 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

NBI component:

- Added mock service dependency log file generation
- Added mock service dependency log file as CI/CD pipeline artifact
parent 8dd17fe3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ unit_test nbi:
      when: always
      reports:
        junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report_*.xml
      paths:
        - src/$IMAGE_NAME/tests/mock_service_dependencies.log

## Deployment of the service in Kubernetes Cluster
#deploy nbi:
+11 −2
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 logging, signal, sys, threading
import logging, os, signal, sys, threading
from common.proto.context_pb2_grpc import add_ContextServiceServicer_to_server
from common.proto.service_pb2_grpc import add_ServiceServiceServicer_to_server
from common.proto.slice_pb2_grpc import add_SliceServiceServicer_to_server
@@ -23,7 +23,16 @@ from common.tools.service.GenericGrpcService import GenericGrpcService
from .Constants import LOCAL_HOST, MOCKSERVICE_PORT


logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s")
if 'GITLAB_CI' in os.environ:
    log_path = '/opt/results/mock_service_dependencies.log'
else:
    log_path = 'mock_service_dependencies.log'

logging.basicConfig(
    level=logging.DEBUG,
    format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s',
    filename=log_path,
)
LOGGER = logging.getLogger(__name__)

class MockService_Dependencies(GenericGrpcService):
+24 −10
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 enum, logging, os, pytest, requests, subprocess, time
import enum, logging, os, pytest, requests, subprocess, threading, time
from typing import Any, Dict, List, Optional, Set, Union
from socketio import Namespace
from common.Constants import ServiceNameEnum
@@ -56,11 +56,29 @@ def mock_service():
        cmd,
        env=custom_env,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        stdin=subprocess.DEVNULL,
        text=True
        text=True,
        bufsize=1
    )

    mock_service_logger = logging.getLogger('MockService_Dependencies')
    mock_service_logger.info('Started')

    def stream_stdout():
        for line in iter(mock_service_process.stdout.readline, ''):
            mock_service_logger.info(line.strip())

    def stream_stderr():
        for line in iter(mock_service_process.stderr.readline, ''):
            mock_service_logger.error(line.strip())

    stream_stdout_thread = threading.Thread(target=stream_stdout, daemon=True)
    stream_stdout_thread.start()

    stream_stderr_thread = threading.Thread(target=stream_stderr, daemon=True)
    stream_stderr_thread.start()

    yield True

    # Check if process is still running
@@ -70,13 +88,9 @@ def mock_service():
        if mock_service_process.poll() is None:
            mock_service_process.kill()  # Force kill if still running

    # Capture final output after process terminates
    stdout, stderr = mock_service_process.communicate()
    LOGGER = logging.getLogger('MockService_Dependencies')
    if stdout: LOGGER.info('STDOUT:\n{:s}'.format(str(stdout.strip())))
    if stderr: LOGGER.error('STDERR:\n{:s}'.format(str(stderr.strip())))
    LOGGER.info('Terminated')

    mock_service_logger.info('Terminated')
    stream_stdout_thread.join()
    stream_stderr_thread.join()

@pytest.fixture(scope='session')
def nbi_application(