aboutsummaryrefslogtreecommitdiffstats
path: root/ms/artifact-manager
diff options
context:
space:
mode:
Diffstat (limited to 'ms/artifact-manager')
-rw-r--r--ms/artifact-manager/README38
-rw-r--r--ms/artifact-manager/manager/servicer.py60
-rw-r--r--ms/artifact-manager/server.py4
-rw-r--r--ms/artifact-manager/tests/servicer_test.py64
4 files changed, 83 insertions, 83 deletions
diff --git a/ms/artifact-manager/README b/ms/artifact-manager/README
index d77762842..290dadfde 100644
--- a/ms/artifact-manager/README
+++ b/ms/artifact-manager/README
@@ -38,9 +38,9 @@ Upload `CBA.zip` file for storage in artifact manager. File needs to be sent as
#### Example
```
-stub: BlueprintManagementServiceStub = BlueprintManagementServiceStub(channel)
+stub: BluePrintManagementServiceStub = BluePrintManagementServiceStub(channel)
with open(file_path, "rb") as cba_file:
- msg: BlueprintUploadInput = BlueprintUploadInput()
+ msg: BluePrintUploadInput = BluePrintUploadInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
msg.fileChunk.chunk = cba_file.read()
@@ -54,8 +54,8 @@ Download existing `CBA.zip` file.
#### Example
```
-stub: BlueprintManagementServiceStub = BlueprintManagementServiceStub(channel)
-msg: BlueprintDownloadInput = BlueprintDownloadInput()
+stub: BluePrintManagementServiceStub = BluePrintManagementServiceStub(channel)
+msg: BluePrintDownloadInput = BluePrintDownloadInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
return stub.downloadBlueprint(msg)
@@ -67,8 +67,8 @@ Delete existing `CBA.zip` file.
#### Example
```
-stub: BlueprintManagementServiceStub = BlueprintManagementServiceStub(channel)
-msg: BlueprintRemoveInput = BlueprintRemoveInput()
+stub: BluePrintManagementServiceStub = BluePrintManagementServiceStub(channel)
+msg: BluePrintRemoveInput = BluePrintRemoveInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
return stub.removeBlueprint(msg)
@@ -88,13 +88,13 @@ import zipfile
from grpc import Channel, ChannelCredentials, insecure_channel, secure_channel, ssl_channel_credentials
-from proto.BlueprintManagement_pb2 import (
- BlueprintDownloadInput,
- BlueprintRemoveInput,
- BlueprintUploadInput,
- BlueprintManagementOutput,
+from proto.BluePrintManagement_pb2 import (
+ BluePrintDownloadInput,
+ BluePrintRemoveInput,
+ BluePrintUploadInput,
+ BluePrintManagementOutput,
)
-from proto.BlueprintManagement_pb2_grpc import BlueprintManagementServiceStub
+from proto.BluePrintManagement_pb2_grpc import BluePrintManagementServiceStub
logging.basicConfig(level=logging.DEBUG)
@@ -139,31 +139,31 @@ class Client:
:param config: ConfigParser object with "client" section
"""
self.channel: Channel = channel
- self.stub: BlueprintManagementServiceStub = BlueprintManagementServiceStub(self.channel)
+ self.stub: BluePrintManagementServiceStub = BluePrintManagementServiceStub(self.channel)
self.config = config
- def upload(self) -> BlueprintManagementOutput:
+ def upload(self) -> BluePrintManagementOutput:
"""Prepare upload message and send it to server."""
logging.info("Call upload client method")
with open(self.config.get("client", "cba_file"), "rb") as cba_file:
- msg: BlueprintUploadInput = BlueprintUploadInput()
+ msg: BluePrintUploadInput = BluePrintUploadInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
msg.fileChunk.chunk = cba_file.read()
return self.stub.uploadBlueprint(msg)
- def download(self) -> BlueprintManagementOutput:
+ def download(self) -> BluePrintManagementOutput:
"""Prepare download message and send it to server."""
logging.info("Call download client method")
- msg: BlueprintDownloadInput = BlueprintDownloadInput()
+ msg: BluePrintDownloadInput = BluePrintDownloadInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
return self.stub.downloadBlueprint(msg)
- def remove(self) -> BlueprintManagementOutput:
+ def remove(self) -> BluePrintManagementOutput:
"""Prepare remove message and send it to server."""
logging.info("Call remove client method")
- msg: BlueprintRemoveInput = BlueprintRemoveInput()
+ msg: BluePrintRemoveInput = BluePrintRemoveInput()
msg.actionIdentifiers.blueprintName = "Test"
msg.actionIdentifiers.blueprintVersion = "0.0.1"
return self.stub.removeBlueprint(msg)
diff --git a/ms/artifact-manager/manager/servicer.py b/ms/artifact-manager/manager/servicer.py
index fd05fe0cc..be740b0e3 100644
--- a/ms/artifact-manager/manager/servicer.py
+++ b/ms/artifact-manager/manager/servicer.py
@@ -23,13 +23,13 @@ from manager.configuration import get_logger
from manager.errors import ArtifactManagerError, InvalidRequestError
from manager.utils import Repository, RepositoryStrategy
from onaplogging.mdcContext import MDC
-from proto.BlueprintManagement_pb2 import (
- BlueprintDownloadInput,
- BlueprintManagementOutput,
- BlueprintRemoveInput,
- BlueprintUploadInput,
+from proto.BluePrintManagement_pb2 import (
+ BluePrintDownloadInput,
+ BluePrintManagementOutput,
+ BluePrintRemoveInput,
+ BluePrintUploadInput,
)
-from proto.BlueprintManagement_pb2_grpc import BlueprintManagementServiceServicer
+from proto.BluePrintManagement_pb2_grpc import BluePrintManagementServiceServicer
MDC_DATETIME_FORMAT = r"%Y-%m-%dT%H:%M:%S.%f%z"
COMMON_HEADER_DATETIME_FORMAT = r"%Y-%m-%dT%H:%M:%S.%fZ"
@@ -47,13 +47,13 @@ def fill_common_header(func):
@wraps(func)
def _decorator(
servicer: "ArtifactManagerServicer",
- request: Union[BlueprintDownloadInput, BlueprintRemoveInput, BlueprintUploadInput],
+ request: Union[BluePrintDownloadInput, BluePrintRemoveInput, BluePrintUploadInput],
context: ServicerContext,
- ) -> BlueprintManagementOutput:
+ ) -> BluePrintManagementOutput:
if not all([request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion]):
- raise InvalidRequestError("Request has to have set both Blueprint name and version")
- output: BlueprintManagementOutput = func(servicer, request, context)
+ raise InvalidRequestError("Request has to have set both BluePrint name and version")
+ output: BluePrintManagementOutput = func(servicer, request, context)
# Set same values for every handler
output.commonHeader.CopyFrom(request.commonHeader)
output.commonHeader.timestamp = datetime.utcnow().strftime(COMMON_HEADER_DATETIME_FORMAT)
@@ -72,11 +72,11 @@ def translate_exception_to_response(func):
@wraps(func)
def _handler(
servicer: "ArtifactManagerServicer",
- request: Union[BlueprintDownloadInput, BlueprintRemoveInput, BlueprintUploadInput],
+ request: Union[BluePrintDownloadInput, BluePrintRemoveInput, BluePrintUploadInput],
context: ServicerContext,
- ) -> BlueprintManagementOutput:
+ ) -> BluePrintManagementOutput:
try:
- output: BlueprintManagementOutput = func(servicer, request, context)
+ output: BluePrintManagementOutput = func(servicer, request, context)
output.status.code = 200
output.status.message = "success"
except ArtifactManagerError as error:
@@ -84,7 +84,7 @@ def translate_exception_to_response(func):
# Every ArtifactManagerError based exception has status_code paramenter
# which has to be set in output. Use also exception's message to
# set errorMessage of the output.
- output: BlueprintManagementOutput = BlueprintManagementOutput()
+ output: BluePrintManagementOutput = BluePrintManagementOutput()
output.status.code = error.status_code
output.status.message = "failure"
output.status.errorMessage = str(error.message)
@@ -112,9 +112,9 @@ def prepare_logging_context(func):
@wraps(func)
def _decorator(
servicer: "ArtifactManagerServicer",
- request: Union[BlueprintDownloadInput, BlueprintRemoveInput, BlueprintUploadInput],
+ request: Union[BluePrintDownloadInput, BluePrintRemoveInput, BluePrintUploadInput],
context: ServicerContext,
- ) -> BlueprintManagementOutput:
+ ) -> BluePrintManagementOutput:
MDC.put("RequestID", request.commonHeader.requestId)
MDC.put("InvocationID", request.commonHeader.subRequestId)
MDC.put("ServiceName", servicer.__class__.__name__)
@@ -129,14 +129,14 @@ def prepare_logging_context(func):
MDC.put("TargetServiceName", func.__name__)
MDC.put("Server", socket.getfqdn())
- output: BlueprintManagementOutput = func(servicer, request, context)
+ output: BluePrintManagementOutput = func(servicer, request, context)
MDC.clear()
return output
return _decorator
-class ArtifactManagerServicer(BlueprintManagementServiceServicer):
+class ArtifactManagerServicer(BluePrintManagementServiceServicer):
"""ArtifactManagerServer class.
Implements methods defined in proto files to manage artifacts repository.
@@ -169,15 +169,15 @@ class ArtifactManagerServicer(BlueprintManagementServiceServicer):
@prepare_logging_context
@translate_exception_to_response
@fill_common_header
- def downloadBlueprint(self, request: BlueprintDownloadInput, context: ServicerContext) -> BlueprintManagementOutput:
+ def downloadBlueprint(self, request: BluePrintDownloadInput, context: ServicerContext) -> BluePrintManagementOutput:
"""Download blueprint file request method.
Currently it only logs when is called and all base class method.
- :param request: BlueprintDownloadInput
+ :param request: BluePrintDownloadInput
:param context: ServicerContext
- :return: BlueprintManagementOutput
+ :return: BluePrintManagementOutput
"""
- output: BlueprintManagementOutput = BlueprintManagementOutput()
+ output: BluePrintManagementOutput = BluePrintManagementOutput()
output.fileChunk.chunk = self.repository.download_blueprint(
request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion
)
@@ -193,13 +193,13 @@ class ArtifactManagerServicer(BlueprintManagementServiceServicer):
@prepare_logging_context
@translate_exception_to_response
@fill_common_header
- def uploadBlueprint(self, request: BlueprintUploadInput, context: ServicerContext) -> BlueprintManagementOutput:
+ def uploadBlueprint(self, request: BluePrintUploadInput, context: ServicerContext) -> BluePrintManagementOutput:
"""Upload blueprint file request method.
Currently it only logs when is called and all base class method.
- :param request: BlueprintUploadInput
+ :param request: BluePrintUploadInput
:param context: ServicerContext
- :return: BlueprintManagementOutput
+ :return: BluePrintManagementOutput
"""
self.repository.upload_blueprint(
request.fileChunk.chunk, request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion
@@ -211,18 +211,18 @@ class ArtifactManagerServicer(BlueprintManagementServiceServicer):
),
extra={"mdc": MDC.result()},
)
- return BlueprintManagementOutput()
+ return BluePrintManagementOutput()
@prepare_logging_context
@translate_exception_to_response
@fill_common_header
- def removeBlueprint(self, request: BlueprintRemoveInput, context: ServicerContext) -> BlueprintManagementOutput:
+ def removeBlueprint(self, request: BluePrintRemoveInput, context: ServicerContext) -> BluePrintManagementOutput:
"""Remove blueprint file request method.
Currently it only logs when is called and all base class method.
- :param request: BlueprintRemoveInput
+ :param request: BluePrintRemoveInput
:param context: ServicerContext
- :return: BlueprintManagementOutput
+ :return: BluePrintManagementOutput
"""
self.repository.remove_blueprint(
request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion
@@ -234,4 +234,4 @@ class ArtifactManagerServicer(BlueprintManagementServiceServicer):
),
extra={"mdc": MDC.result()},
)
- return BlueprintManagementOutput()
+ return BluePrintManagementOutput()
diff --git a/ms/artifact-manager/server.py b/ms/artifact-manager/server.py
index 10034fe58..fe70c8855 100644
--- a/ms/artifact-manager/server.py
+++ b/ms/artifact-manager/server.py
@@ -19,7 +19,7 @@ import click
from grpc import server as grpc_server
from manager.configuration import config
from manager.servicer import ArtifactManagerServicer
-from proto.BlueprintManagement_pb2_grpc import add_BlueprintManagementServiceServicer_to_server
+from proto.BluePrintManagement_pb2_grpc import add_BluePrintManagementServiceServicer_to_server
@click.command()
@@ -34,7 +34,7 @@ def run_server():
max_workers: int = int(config["artifactManagerServer"]["maxWorkers"])
server: grpc_server = grpc_server(ThreadPoolExecutor(max_workers=max_workers))
- add_BlueprintManagementServiceServicer_to_server(ArtifactManagerServicer(), server)
+ add_BluePrintManagementServiceServicer_to_server(ArtifactManagerServicer(), server)
port_number: int = int(config["artifactManagerServer"]["port"])
server.add_insecure_port(f"[::]:{port_number}")
diff --git a/ms/artifact-manager/tests/servicer_test.py b/ms/artifact-manager/tests/servicer_test.py
index 702e1046a..131e6fb2c 100644
--- a/ms/artifact-manager/tests/servicer_test.py
+++ b/ms/artifact-manager/tests/servicer_test.py
@@ -19,17 +19,17 @@ from unittest.mock import patch
import manager.utils
from manager.servicer import ArtifactManagerServicer
-from proto.BlueprintCommon_pb2 import ActionIdentifiers, CommonHeader
-from proto.BlueprintManagement_pb2 import (
- BlueprintDownloadInput,
- BlueprintManagementOutput,
- BlueprintRemoveInput,
- BlueprintUploadInput,
+from proto.BluePrintCommon_pb2 import ActionIdentifiers, CommonHeader
+from proto.BluePrintManagement_pb2 import (
+ BluePrintDownloadInput,
+ BluePrintManagementOutput,
+ BluePrintRemoveInput,
+ BluePrintUploadInput,
FileChunk,
)
-from proto.BlueprintManagement_pb2_grpc import (
- BlueprintManagementServiceStub,
- add_BlueprintManagementServiceServicer_to_server,
+from proto.BluePrintManagement_pb2_grpc import (
+ BluePrintManagementServiceStub,
+ add_BluePrintManagementServiceServicer_to_server,
)
from pytest import fixture
@@ -50,7 +50,7 @@ class MockZipFile(zipfile.ZipFile):
@fixture(scope="module")
def grpc_add_to_server():
"""pytest-grpcio required function."""
- return add_BlueprintManagementServiceServicer_to_server
+ return add_BluePrintManagementServiceServicer_to_server
@fixture(scope="module")
@@ -62,34 +62,34 @@ def grpc_servicer():
@fixture(scope="module") # noqa
def grpc_stub_cls(grpc_channel):
"""pytest-grpcio required function."""
- return BlueprintManagementServiceStub
+ return BluePrintManagementServiceStub
def test_servicer_upload_handler_header_failure(grpc_stub):
"""Test servicer upload handler."""
- request: BlueprintUploadInput = BlueprintUploadInput()
- output: BlueprintManagementOutput = grpc_stub.uploadBlueprint(request)
+ request: BluePrintUploadInput = BluePrintUploadInput()
+ output: BluePrintManagementOutput = grpc_stub.uploadBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
- assert output.status.errorMessage == "Request has to have set both Blueprint name and version"
+ assert output.status.errorMessage == "Request has to have set both BluePrint name and version"
def test_servicer_download_handler_header_failure(grpc_stub):
"""Test servicer download handler."""
- request: BlueprintDownloadInput = BlueprintDownloadInput()
- output: BlueprintManagementOutput = grpc_stub.downloadBlueprint(request)
+ request: BluePrintDownloadInput = BluePrintDownloadInput()
+ output: BluePrintManagementOutput = grpc_stub.downloadBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
- assert output.status.errorMessage == "Request has to have set both Blueprint name and version"
+ assert output.status.errorMessage == "Request has to have set both BluePrint name and version"
def test_servicer_remove_handler_header_failure(grpc_stub):
"""Test servicer remove handler."""
- request: BlueprintRemoveInput = BlueprintRemoveInput()
- output: BlueprintManagementOutput = grpc_stub.removeBlueprint(request)
+ request: BluePrintRemoveInput = BluePrintRemoveInput()
+ output: BluePrintManagementOutput = grpc_stub.removeBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
- assert output.status.errorMessage == "Request has to have set both Blueprint name and version"
+ assert output.status.errorMessage == "Request has to have set both BluePrint name and version"
def test_servicer_upload_handler_failure(grpc_stub):
@@ -97,8 +97,8 @@ def test_servicer_upload_handler_failure(grpc_stub):
action_identifiers: ActionIdentifiers = ActionIdentifiers()
action_identifiers.blueprintName = "sample-cba"
action_identifiers.blueprintVersion = "1.0.0"
- request: BlueprintUploadInput = BlueprintUploadInput(actionIdentifiers=action_identifiers)
- output: BlueprintManagementOutput = grpc_stub.uploadBlueprint(request)
+ request: BluePrintUploadInput = BluePrintUploadInput(actionIdentifiers=action_identifiers)
+ output: BluePrintManagementOutput = grpc_stub.uploadBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
assert output.status.errorMessage == "Invalid request"
@@ -109,8 +109,8 @@ def test_servicer_download_handler_failure(grpc_stub):
action_identifiers: ActionIdentifiers = ActionIdentifiers()
action_identifiers.blueprintName = "sample-cba"
action_identifiers.blueprintVersion = "2.0.0"
- request: BlueprintDownloadInput = BlueprintDownloadInput(actionIdentifiers=action_identifiers)
- output: BlueprintManagementOutput = grpc_stub.downloadBlueprint(request)
+ request: BluePrintDownloadInput = BluePrintDownloadInput(actionIdentifiers=action_identifiers)
+ output: BluePrintManagementOutput = grpc_stub.downloadBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
assert output.status.errorMessage == "Artifact not found"
@@ -121,8 +121,8 @@ def test_servicer_remove_handler_failure(grpc_stub):
action_identifiers: ActionIdentifiers = ActionIdentifiers()
action_identifiers.blueprintName = "sample-cba"
action_identifiers.blueprintVersion = "1.0.0"
- request: BlueprintRemoveInput = BlueprintRemoveInput(actionIdentifiers=action_identifiers)
- output: BlueprintManagementOutput = grpc_stub.removeBlueprint(request)
+ request: BluePrintRemoveInput = BluePrintRemoveInput(actionIdentifiers=action_identifiers)
+ output: BluePrintManagementOutput = grpc_stub.removeBlueprint(request)
assert output.status.code == 500
assert output.status.message == "failure"
assert output.status.errorMessage == "Artifact not found"
@@ -146,10 +146,10 @@ def test_servicer_upload_handler_success(grpc_stub):
# fmt: off
with patch.object(os, "makedirs", return_value=None), \
patch.object(manager.utils, 'ZipFile', return_value=MockZipFile()):
- request: BlueprintUploadInput = BlueprintUploadInput(
+ request: BluePrintUploadInput = BluePrintUploadInput(
commonHeader=header, fileChunk=file_chunk, actionIdentifiers=action_identifiers
)
- output: BlueprintManagementOutput = grpc_stub.uploadBlueprint(request)
+ output: BluePrintManagementOutput = grpc_stub.uploadBlueprint(request)
# fmt: on
assert output.status.code == 200
assert output.status.message == "success"
@@ -168,10 +168,10 @@ def test_servicer_download_handler_success(grpc_stub):
action_identifiers.actionName = "SampleScript"
with patch.object(os.path, "exists", return_value=True):
- request: BlueprintDownloadInput = BlueprintDownloadInput(
+ request: BluePrintDownloadInput = BluePrintDownloadInput(
commonHeader=header, actionIdentifiers=action_identifiers
)
- output: BlueprintManagementOutput = grpc_stub.downloadBlueprint(request)
+ output: BluePrintManagementOutput = grpc_stub.downloadBlueprint(request)
assert output.status.code == 200
assert output.status.message == "success"
assert output.fileChunk.chunk == ZIP_FILE_BINARY
@@ -190,7 +190,7 @@ def test_servicer_remove_handler_success(grpc_stub):
action_identifiers.actionName = "SampleScript"
with patch.object(shutil, "rmtree", return_value=None) as mock_rmtree:
- request: BlueprintRemoveInput = BlueprintRemoveInput(commonHeader=header, actionIdentifiers=action_identifiers)
- output: BlueprintManagementOutput = grpc_stub.removeBlueprint(request)
+ request: BluePrintRemoveInput = BluePrintRemoveInput(commonHeader=header, actionIdentifiers=action_identifiers)
+ output: BluePrintManagementOutput = grpc_stub.removeBlueprint(request)
assert output.status.code == 200
assert output.status.message == "success"