Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ BuildRequires: python%{python3_pkgversion}-pyOpenSSL
BuildRequires: socat
BuildRequires: python%{python3_pkgversion}-asyncssh
BuildRequires: python%{python3_pkgversion}-natsort
BuildRequires: python%{python3_pkgversion}-grpcio
BuildRequires: python%{python3_pkgversion}-grpcio-tools
%endif
%if 0%{?suse_version}
BuildRequires: libthrift-devel >= 0.13.0
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ Build-Depends: automake,
python3-grpcio <pkg.ceph.check>,
python3-jmespath (>=0.10) <pkg.ceph.check>,
python3-xmltodict <pkg.ceph.check>,
python3-grpc-tools <pkg.ceph.check>,
python3-openssl <pkg.ceph.check>,
python3-prettytable <pkg.ceph.check>,
python3-routes <pkg.ceph.check>,
python3-requests <pkg.ceph.check>,
python3-scipy <pkg.ceph.check>,
python3-setuptools,
Expand Down
2 changes: 2 additions & 0 deletions src/pybind/mgr/dashboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ else()
DESTINATION ${CEPH_INSTALL_DATADIR}/mgr/dashboard/frontend)
endif()
endif()

add_subdirectory(services/proto)
2 changes: 1 addition & 1 deletion src/pybind/mgr/dashboard/controllers/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .. import mgr
from ..exceptions import DashboardException
from ..services.orchestrator import OrchClient
from ..services.orchestrator import OrchClient # pylint: disable=import-error
from . import APIDoc, Endpoint, EndpointDoc, ReadPermission, RESTController, UIRouter

STATUS_SCHEMA = {
Expand Down
4 changes: 3 additions & 1 deletion src/pybind/mgr/dashboard/controllers/osd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from typing import Any, Dict, List, Optional, Union

import cherrypy
from ceph.deployment.drive_group import DriveGroupSpec, DriveGroupValidationError # type: ignore
from ceph.deployment.drive_group import DriveGroupSpec # type: ignore; pylint: disable=import-error
from ceph.deployment.drive_group import \
DriveGroupValidationError # type: ignore; pylint: disable=import-error
from mgr_util import get_most_recent_rate

from .. import mgr
Expand Down
2 changes: 1 addition & 1 deletion src/pybind/mgr/dashboard/controllers/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, List, Optional

import cherrypy
from ceph.deployment.service_spec import ServiceSpec
from ceph.deployment.service_spec import ServiceSpec # pylint: disable=import-error

from ..security import Scope
from ..services.exception import handle_custom_error, handle_orchestrator_error
Expand Down
3 changes: 2 additions & 1 deletion src/pybind/mgr/dashboard/plugins/motd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from enum import Enum
from typing import Dict, NamedTuple, Optional

from ceph.utils import datetime_now, datetime_to_str, parse_timedelta, str_to_datetime
from ceph.utils import datetime_now, datetime_to_str # pylint: disable=import-error
from ceph.utils import parse_timedelta, str_to_datetime # pylint: disable=import-error
from mgr_module import CLICommand

from . import PLUGIN_MANAGER as PM
Expand Down
2 changes: 0 additions & 2 deletions src/pybind/mgr/dashboard/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pyyaml
natsort
setuptools
jsonpatch
grpcio==1.46.5
grpcio-tools==1.46.5
jmespath
lxml==4.8.0 # to fix https://github.com/xmlsec/python-xmlsec/issues/320
xmltodict
2 changes: 1 addition & 1 deletion src/pybind/mgr/dashboard/services/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from functools import wraps
from typing import Any, Dict, List, Optional, Tuple

from ceph.deployment.service_spec import ServiceSpec
from ceph.deployment.service_spec import ServiceSpec # pylint: disable=import-error
from orchestrator import DaemonDescription, DeviceLightLoc, HostSpec, \
InventoryFilter, OrchestratorClientMixin, OrchestratorError, OrchResult, \
ServiceDescription, raise_if_exception
Expand Down
108 changes: 108 additions & 0 deletions src/pybind/mgr/dashboard/services/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# This CMake file is primarily responsible for generating/building the dashboard NVME grpc protos at build time.
# This is done so these files can be dynamically generated and make it to the build instead of being hardcoded in the repository
# to a given version of the protoc generator.

# All three versions of the grpc_tools module (ubuntu22.04, centos9, latest) have "quirks" when asked to handle the existing NVME proto file.

# The if(NOT LIBPROTOC_VERSION) block below has been simplified to handle the Ubuntu case which relates to a version equal or lower than 3.12 in a "special" way
# and to handle all the other cases in the same way.

# This will generate the correct protoc versions based on the given OS system python3 grpc module.

# Failing to find any module version it will just not generate anything but still continue the cmake build.

# For any of the most recent gprc_tools it should just work provided there are no major semantic differences in behaviour.

# This implementation will also be able to cope with repo updates to the `src/nvmeof/gateway` module.



#####################################
# Notes about python package loading:
#####################################

# For`gateway_pb2_grpc.py` to be successfully imported by python
# These files must be created from the dashboard parent directory
# so that `gateway_pb2_grpc.py` is written with an import statement that matches the module location. e.g. import dashboard.services.proto.gateway_pb2

# WORKING_DIRECTORY: /ceph/src/pybind/mgr/dashboard/services/proto/../../..
# /usr/bin/python3 -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. dashboard/services/proto/gateway.proto

# view from python:

# <module 'dashboard.services.orchestrator' from '/ceph/src/pybind/mgr/dashboard/services/orchestrator.py'>,
# <module 'dashboard.services.nvmeof_conf' from '/ceph/src/pybind/mgr/dashboard/services/nvmeof_conf.py'>,
# <module 'dashboard.services.nvmeof_cli' from '/ceph/src/pybind/mgr/dashboard/services/nvmeof_cli.py'>,
# <module 'dashboard.services.nvmeof_client' from '/ceph/src/pybind/mgr/dashboard/services/nvmeof_client.py'>,
# <module 'dashboard.services.proto' (namespace) from ['/ceph/src/pybind/mgr/dashboard/services/proto']>,
# <module 'dashboard.services.proto.gateway_pb2' from '/ceph/src/pybind/mgr/dashboard/services/proto/gateway_pb2.py'>,
# <module 'dashboard.services.proto.gateway_pb2_grpc' from '/ceph/src/pybind/mgr/dashboard/services/proto/gateway_pb2_grpc.py'>]

# The grpc_tool generates an import statement for the gateway_pb2_grpc.py to the gateway_pb2.py based on the location of the file.
# This import statement is static and not relative and you have no control over it other than by modifying their path at generation time from the tool.

# By explicitly setting sys.path in the consuming code with an extra directory pointing at these files,
# it would be possible to generate the files from/to anywhere as modules that did not depend on the dashboard module namespace.


# Setting paths for required files and locations
set(CEPH_DASHBOARD_GATEWAY_PROTO_FILE dashboard/services/proto/gateway.proto)
set(CEPH_DASHBOARD_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
set(CEPH_NVME_GATEWAY_PROTO_FILE ${CEPH_DASHBOARD_PARENT_DIR}/../../../src/nvmeof/gateway/control/proto/gateway.proto)

# Find the installed version of the grpc_tools module
execute_process(
COMMAND ${Python3_EXECUTABLE} -m grpc_tools.protoc --version
COMMAND awk "{ print $2 }"
OUTPUT_VARIABLE LIBPROTOC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Set defaults for variables
set(GRPC_TOOLS_EXPERIMENTAL_FLAG "")
set(GRPC_TOOLS_NVME_PREPARE_SOURCE_CMD cp ${CEPH_NVME_GATEWAY_PROTO_FILE} ${CEPH_DASHBOARD_GATEWAY_PROTO_FILE})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we set a symlink in the git tree instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baum had actually suggested that in the previous MR.
This time around I left it like this because I was either copying or seding the optional keyword out.
Check the comment below for the sed reasons.

set(GRPC_TOOLS_NVME_PREPARE_SOURCE_MSG "copy verbatim source gateway.proto file")

# Evaluate existing version and set toggles
if(NOT LIBPROTOC_VERSION)
message(DEBUG "Unknown grpc_tools version. libprotoc '${LIBPROTOC_VERSION}' NOT FOUND")

elseif(LIBPROTOC_VERSION VERSION_LESS_EQUAL "3.12")
message(DEBUG "grpc_tools version less or equal than 3.12. libprotoc ${LIBPROTOC_VERSION}")
set(GRPC_TOOLS_NVME_PREPARE_SOURCE_CMD sed 's|optional ||g' ${CEPH_NVME_GATEWAY_PROTO_FILE} > ${CEPH_DASHBOARD_GATEWAY_PROTO_FILE})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbregman @baum FYI: is this ok (removing optional from the protobuf file)? Could it be problematic or cause issues?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epuertat it might cause comparability issues when mixing different versions of gateway and CLI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, grpc APIs, as long as they are in the same protobuf version (v2 or v3), are compatible no matter the grpc/protobuf library version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about compatibility between the gateway and the CLI, not the protocol layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a straightforward way to test that ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about compatibility between the gateway and the CLI, not the protocol layer.

But if they're not colocated, they could (and probably will) run different versions of the gRPC libs (GW runs inside a ubi9 container, while Ceph Dashboard and CLI might run on Ubuntu 22/24,for those users running Deb packages).

set(GRPC_TOOLS_NVME_PREPARE_SOURCE_MSG "copy amended source gateway.proto file")

elseif(LIBPROTOC_VERSION VERSION_GREATER "3.12")
message(DEBUG "grpc_tools version bigger than 3.12. libprotoc ${LIBPROTOC_VERSION}")
set(GRPC_TOOLS_EXPERIMENTAL_FLAG "--experimental_allow_proto3_optional")
endif()

# Protobuffer files generation
if (LIBPROTOC_VERSION)

add_custom_command(
OUTPUT "${CEPH_DASHBOARD_PARENT_DIR}/${CEPH_DASHBOARD_GATEWAY_PROTO_FILE}"
COMMAND ${GRPC_TOOLS_NVME_PREPARE_SOURCE_CMD}
WORKING_DIRECTORY ${CEPH_DASHBOARD_PARENT_DIR}
DEPENDS ${CEPH_NVME_GATEWAY_PROTO_FILE}
COMMENT ${GRPC_TOOLS_NVME_PREPARE_SOURCE_MSG})

add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/gateway_pb2.py" "${CMAKE_CURRENT_SOURCE_DIR}/gateway_pb2_grpc.py"
COMMAND ${Python3_EXECUTABLE} -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. ${CEPH_DASHBOARD_GATEWAY_PROTO_FILE} ${GRPC_TOOLS_EXPERIMENTAL_FLAG}
WORKING_DIRECTORY ${CEPH_DASHBOARD_PARENT_DIR}
DEPENDS ${CEPH_DASHBOARD_PARENT_DIR}/${CEPH_DASHBOARD_GATEWAY_PROTO_FILE}
COMMENT "proto generation for grpc deps")

add_custom_target(mgr-dashboard-services-proto
ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gateway_pb2.py ${CMAKE_CURRENT_SOURCE_DIR}/gateway_pb2_grpc.py
WORKING_DIRECTORY ${CEPH_DASHBOARD_PARENT_DIR})

add_dependencies(tests mgr-dashboard-services-proto)

endif()

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION ${CEPH_INSTALL_DATADIR}/mgr/dashboard/services
PATTERN "CMakeLists.txt" EXCLUDE)
Loading
Loading