From e0cb3aee59077d9bf30efab63ad059a3e1fae23b Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Wed, 1 Jul 2020 08:27:02 -0600 Subject: [PATCH] python-common: RGW service_id might not contain a zone also adds missing RGWSpec.validate() Fixes: https://tracker.ceph.com/issues/46268 Signed-off-by: Michael Fritch (cherry picked from commit b54a800b748dc94cb847cc44e23b481c8c3a85b4) --- src/pybind/mgr/cephadm/tests/test_scheduling.py | 9 ++++++++- src/python-common/ceph/deployment/service_spec.py | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/cephadm/tests/test_scheduling.py b/src/pybind/mgr/cephadm/tests/test_scheduling.py index 4c4d10dddf457..806625934bf60 100644 --- a/src/pybind/mgr/cephadm/tests/test_scheduling.py +++ b/src/pybind/mgr/cephadm/tests/test_scheduling.py @@ -430,9 +430,16 @@ def test_node_assignment(service_type, placement, hosts, daemons, expected): return [HostSpec(h) for h in hosts] return hosts + service_id = None + if service_type == 'rgw': + service_id = 'realm.zone' + + spec = ServiceSpec(service_type=service_type, + service_id=service_id, + placement=placement) hosts = HostAssignment( - spec=ServiceSpec(service_type, placement=placement), + spec=spec, get_hosts_func=get_hosts_func, get_daemons_func=lambda _: daemons).place() assert sorted([h.hostname for h in hosts]) == sorted(expected) diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 3c3c017d209dd..9111c75ad71e7 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -612,7 +612,8 @@ class RGWSpec(ServiceSpec): if service_id: a = service_id.split('.', 2) rgw_realm = a[0] - rgw_zone = a[1] + if len(a) > 1: + rgw_zone = a[1] if len(a) > 2: subcluster = a[2] else: @@ -650,6 +651,16 @@ class RGWSpec(ServiceSpec): ports.append(f"port={self.get_port()}") return f'beast {" ".join(ports)}' + def validate(self): + super(RGWSpec, self).validate() + + if not self.rgw_realm: + raise ServiceSpecValidationError( + 'Cannot add RGW: No realm specified') + if not self.rgw_zone: + raise ServiceSpecValidationError( + 'Cannot add RGW: No zone specified') + yaml.add_representer(RGWSpec, ServiceSpec.yaml_representer) -- 2.39.5