]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common,mgr/cephadm: move assert_valid_host to service_spec
authorSebastian Wagner <sebastian.wagner@suse.com>
Tue, 17 Mar 2020 14:08:50 +0000 (15:08 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 17 Mar 2020 14:08:50 +0000 (15:08 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_scheduling.py
src/python-common/ceph/deployment/service_spec.py

index b6ac1ca456179ffb18dcd8e8952c75d2377a9e7c..487f520ecf3383b2c016b586898e7ee012bdb62d 100644 (file)
@@ -31,7 +31,8 @@ import uuid
 from ceph.deployment import inventory, translate
 from ceph.deployment.drive_group import DriveGroupSpec
 from ceph.deployment.drive_selection import selector
-from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec, PlacementSpec
+from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec, PlacementSpec, \
+    assert_valid_host
 
 from mgr_module import MgrModule
 import orchestrator
@@ -107,18 +108,6 @@ def name_to_config_section(name):
     else:
         return 'mon'
 
-def assert_valid_host(name):
-    p = re.compile('^[a-zA-Z0-9-]+$')
-    try:
-        assert len(name) <= 250, 'name is too long (max 250 chars)'
-        parts = name.split('.')
-        for part in name.split('.'):
-            assert len(part) > 0, '.-delimited name component must not be empty'
-            assert len(part) <= 63, '.-delimited name component must not be more than 63 chars'
-            assert p.match(part), 'name component must include only a-z, 0-9, and -'
-    except AssertionError as e:
-        raise OrchestratorError(e)
-
 
 class SpecStore():
     def __init__(self, mgr):
index 5c01d6d75aebff7f4c0f612a7c65721b17d5b1cd..54402bad469c0f07d4c2dac1c5750403a5e9257e 100644 (file)
@@ -246,6 +246,7 @@ def test_node_assignment3(service_type, placement, hosts,
         ('1 *'),
         ('* label:foo'),
         ('* host1 host2'),
+        ('hostname12hostname12hostname12hostname12hostname12hostname12hostname12'),  # > 63 chars
     ])
 def test_bad_placements(placement):
     try:
index 07dd2a14f8fe5a7e66a954d5a47f590e15bb3207..08edc09170d6dceb24d6db1030f0225d98deaee4 100644 (file)
@@ -16,6 +16,18 @@ class ServiceSpecValidationError(Exception):
         super(ServiceSpecValidationError, self).__init__(msg)
 
 
+def assert_valid_host(name):
+    p = re.compile('^[a-zA-Z0-9-]+$')
+    try:
+        assert len(name) <= 250, 'name is too long (max 250 chars)'
+        for part in name.split('.'):
+            assert len(part) > 0, '.-delimited name component must not be empty'
+            assert len(part) <= 63, '.-delimited name component must not be more than 63 chars'
+            assert p.match(part), 'name component must include only a-z, 0-9, and -'
+    except AssertionError as e:
+        raise ServiceSpecValidationError(e)
+
+
 class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])):
     def __str__(self):
         res = ''
@@ -99,9 +111,12 @@ class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network',
             except ValueError as e:
                 # logging?
                 raise e
-
+        host_spec.validate()
         return host_spec
 
+    def validate(self):
+        assert_valid_host(self.hostname)
+
 
 class PlacementSpec(object):
     """
@@ -198,6 +213,8 @@ class PlacementSpec(object):
             raise ServiceSpecValidationError("num/count must be > 1")
         if self.host_pattern and self.hosts:
             raise ServiceSpecValidationError('cannot combine host patterns and hosts')
+        for h in self.hosts:
+            h.validate()
 
     @classmethod
     def from_string(cls, arg):