]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: remove `all_hosts` from `PlacementSpec`
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 12 Mar 2020 16:12:10 +0000 (17:12 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 12 Mar 2020 16:12:10 +0000 (17:12 +0100)
replace it with `PlacementSpec(host_pattern='*')`

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/python-common/ceph/deployment/service_spec.py
src/python-common/ceph/tests/test_service_spec.py

index bc6fb6222fb59be45173aa3c6d1022eae7459b6e..5be71659096f8de3a40ea9a1beb96b1a25a5e5f8 100644 (file)
@@ -1679,8 +1679,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
     def _get_spec_size(self, spec):
         if spec.placement.count:
             return spec.placement.count
-        elif spec.placement.all_hosts:
-            return len(self.inventory)
+        elif spec.placement.host_pattern:
+            return len(spec.placement.pattern_matches_hosts(self.inventory.keys()))
         elif spec.placement.label:
             return len(self._get_hosts(spec.placement.label))
         elif spec.placement.hosts:
@@ -2442,8 +2442,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                 'grafana': PlacementSpec(count=1),
                 'alertmanager': PlacementSpec(count=1),
                 'prometheus': PlacementSpec(count=1),
-                'node-exporter': PlacementSpec(all_hosts=True),
-                'crash': PlacementSpec(all_hosts=True),
+                'node-exporter': PlacementSpec(host_pattern='*'),
+                'crash': PlacementSpec(host_pattern='*'),
             }
             spec.placement = defaults[spec.service_type]
         elif spec.service_type in ['mon', 'mgr'] and \
@@ -3089,15 +3089,6 @@ class HostAssignment(object):
             logger.debug('Provided hosts: %s' % self.spec.placement.hosts)
             return self.spec.placement.hosts
 
-        # respect all_hosts=true
-        if self.spec.placement.all_hosts:
-            candidates = [
-                HostPlacementSpec(x, '', '')
-                for x in self.get_hosts_func(None)
-            ]
-            logger.debug('All hosts: {}'.format(candidates))
-            return candidates
-
         # respect host_pattern
         if self.spec.placement.host_pattern:
             candidates = [
@@ -3139,7 +3130,6 @@ class HostAssignment(object):
                 assert self.spec.placement.count is None
                 assert not self.spec.placement.hosts
                 assert not self.spec.placement.label
-                assert not self.spec.placement.all_hosts
                 count = 1
             logger.debug('place %d over all hosts: %s' % (count, hosts))
 
index 5bf357ed3a3727340c8afc7d9f1e8f63a70cd596..d20a4b8b0287e19dee4f8ea4820be0036d43fe36 100644 (file)
@@ -108,10 +108,8 @@ class PlacementSpec(object):
     For APIs that need to specify a host subset
     """
 
-    def __init__(self, label=None, hosts=None, count=None, all_hosts=False, host_pattern=None):
-        # type: (Optional[str], Optional[List], Optional[int], bool, Optional[str]) -> None
-        if all_hosts and (count or hosts or label):
-            raise ServiceSpecValidationError('cannot combine all:true and count|hosts|label')
+    def __init__(self, label=None, hosts=None, count=None, host_pattern=None):
+        # type: (Optional[str], Optional[List], Optional[int], Optional[str]) -> None
         self.label = label
         self.hosts = []  # type: List[HostPlacementSpec]
         if hosts:
@@ -121,14 +119,14 @@ class PlacementSpec(object):
                 self.hosts = [HostPlacementSpec.parse(x, require_network=False) for x in hosts if x]
 
         self.count = count  # type: Optional[int]
-        self.all_hosts = all_hosts  # type: bool
 
         #: An fnmatch pattern to select hosts. Can also be a single host.
         self.host_pattern = host_pattern
 
+        self.validate()
+
     def is_empty(self):
-        return not self.all_hosts and \
-            self.label is None and \
+        return self.label is None and \
             not self.hosts and \
             not self.host_pattern and \
             self.count is None
@@ -152,8 +150,6 @@ class PlacementSpec(object):
             kv.append('label:%s' % self.label)
         if self.hosts:
             kv.append('%s' % ','.join([str(h) for h in self.hosts]))
-        if self.all_hosts:
-            kv.append('all:true')
         if self.host_pattern:
             kv.append('host_pattern:{}'.format(self.host_pattern))
         return ' '.join(kv)
@@ -166,8 +162,6 @@ class PlacementSpec(object):
             kv.append('label=%s' % repr(self.label))
         if self.hosts:
             kv.append('hosts={!r}'.format(self.hosts))
-        if self.all_hosts:
-            kv.append('all_hosts=True')
         if self.host_pattern:
             kv.append('host_pattern={!r}'.format(self.host_pattern))
         return "PlacementSpec(%s)" % ', '.join(kv)
@@ -186,7 +180,6 @@ class PlacementSpec(object):
             'label': self.label,
             'hosts': [host.to_json() for host in self.hosts] if self.hosts else [],
             'count': self.count,
-            'all_hosts': self.all_hosts,
             'host_pattern': self.host_pattern,
         }
 
@@ -196,9 +189,8 @@ class PlacementSpec(object):
             raise ServiceSpecValidationError('Host and label are mutually exclusive')
         if self.count is not None and self.count <= 0:
             raise ServiceSpecValidationError("num/count must be > 1")
-        if self.host_pattern and (self.hosts or self.label or self.all_hosts):
-            raise ServiceSpecValidationError('Host pattern is mutually exclusive to everything else'
-                                             '.')
+        if self.host_pattern and self.hosts:
+            raise ServiceSpecValidationError('cannot combine host_pattern and hosts')
 
     @classmethod
     def from_string(cls, arg):
@@ -267,13 +259,9 @@ tPlacementSpec(hostname='host2', network='', name='')])
                 except ValueError:
                     pass
 
-        all_hosts = False
         if '*' in strings:
-            all_hosts = True
             strings.remove('*')
-        if 'all:true' in strings:
-            all_hosts = True
-            strings.remove('all:true')
+            strings.append('host_pattern:*')
 
         hosts = [x for x in strings
                  if x != '*' and 'label:' not in x and not x.startswith('host_pattern:')]
@@ -288,9 +276,7 @@ tPlacementSpec(hostname='host2', network='', name='')])
         ps = PlacementSpec(count=count,
                            hosts=hosts,
                            label=labels[0] if labels else None,
-                           all_hosts=all_hosts,
                            host_pattern=host_patterns[0] if host_patterns else None)
-        ps.validate()
         return ps
 
 
index 7c3057587a0e26d0c3f4692ee5cb0d4f53be3f80..83c1864f5656fb4e057d8916b7e4ddc0cb4131b7 100644 (file)
@@ -36,7 +36,7 @@ def test_parse_host_placement_specs(test_input, expected, require_network):
         ('2 host1 host2', "PlacementSpec(count=2, hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
         ('label:foo', "PlacementSpec(label='foo')"),
         ('3 label:foo', "PlacementSpec(count=3, label='foo')"),
-        ('*', 'PlacementSpec(all_hosts=True)'),
+        ('*', "PlacementSpec(host_pattern='*')"),
     ])
 def test_parse_placement_specs(test_input, expected):
     ret = PlacementSpec.from_string(test_input)