]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/orch: from_strings -> from_string; do not accept a list
authorSage Weil <sage@redhat.com>
Thu, 5 Mar 2020 15:18:50 +0000 (09:18 -0600)
committerSage Weil <sage@redhat.com>
Sat, 7 Mar 2020 12:42:07 +0000 (06:42 -0600)
Normalize all callers to pass a single string.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/tests/test_scheduling.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py
src/pybind/mgr/tests/test_orchestrator.py
src/pybind/mgr/volumes/fs/fs_util.py

index b00bf365fcc6368de093c629984fee539d0cca03..940bd43edd191807cb19abce384fed75814c13c6 100644 (file)
@@ -209,7 +209,7 @@ def test_node_assignment3(service_type, placement, hosts,
     ])
 def test_bad_placements(placement):
     try:
-        s = PlacementSpec.from_strings(placement.split(' '))
+        s = PlacementSpec.from_string(placement.split(' '))
         assert False
     except OrchestratorValidationError as e:
         pass
index 8d83c9acbdf6249d5dc12d27e731aacee7c63453..3f0e5dab5792dea04de262964f8ad9041f37af91 100644 (file)
@@ -1312,25 +1312,25 @@ class PlacementSpec(object):
             raise OrchestratorValidationError("num/count must be > 1")
 
     @classmethod
-    def from_strings(cls, arg):
+    def from_string(cls, arg):
         # type: (Optional[str]) -> PlacementSpec
         """
         A single integer is parsed as a count:
-        >>> PlacementSpec.from_strings('3'.split())
+        >>> PlacementSpec.from_string('3')
         PlacementSpec(count=3)
         A list of names is parsed as host specifications:
-        >>> PlacementSpec.from_strings('host1 host2'.split())
+        >>> PlacementSpec.from_string('host1 host2')
         PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')])
         You can also prefix the hosts with a count as follows:
-        >>> PlacementSpec.from_strings('2 host1 host2'.split())
+        >>> PlacementSpec.from_string('2 host1 host2')
         PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')], count=2)
         You can spefify labels using `label:<label>`
-        >>> PlacementSpec.from_strings('label:mon'.split())
+        >>> PlacementSpec.from_string('label:mon')
         PlacementSpec(label='label:mon')
         Labels als support a count:
-        >>> PlacementSpec.from_strings('3 label:mon'.split())
+        >>> PlacementSpec.from_string('3 label:mon')
         PlacementSpec(label='label:mon', count=3)
-        >>> PlacementSpec.from_strings(None)
+        >>> PlacementSpec.from_string(None)
         PlacementSpec()
         """
         if arg is None:
@@ -1348,8 +1348,6 @@ class PlacementSpec(object):
                 strings = arg.split(',')
             else:
                 strings = [arg]
-        elif isinstance(arg, list):
-            strings = arg
         else:
             raise OrchestratorValidationError('invalid placement %s' % arg)
 
index dd28ad75a341e5f8ae16ea55c2259fab890ae732..2e935058deda77d496ad1256d29cf90d16596f65 100644 (file)
@@ -509,7 +509,7 @@ Usage:
         'name=placement,type=CephString,req=false',
         'Start monitor daemon(s)')
     def _daemon_add_mon(self, placement=None):
-        placement = PlacementSpec.from_strings(placement)
+        placement = PlacementSpec.from_string(placement)
         placement.validate()
 
         spec = ServiceSpec('mon', placement=placement)
@@ -526,7 +526,7 @@ Usage:
     def _daemon_add_mgr(self, placement=None):
         spec = ServiceSpec(
             'mgr',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_mgr(spec)
         self._orchestrator_wait([completion])
@@ -549,7 +549,7 @@ Usage:
     def _rbd_mirror_add(self, placement=None):
         spec = ServiceSpec(
             'rbd-mirror',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_rbd_mirror(spec)
         self._orchestrator_wait([completion])
@@ -564,7 +564,7 @@ Usage:
     def _mds_add(self, fs_name, placement=None):
         spec = ServiceSpec(
             'mds', fs_name,
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_mds(spec)
         self._orchestrator_wait([completion])
@@ -592,7 +592,7 @@ Usage:
         rgw_spec = RGWSpec(
             rgw_realm=realm_name,
             rgw_zone=zone_name,
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
 
         completion = self.add_rgw(rgw_spec)
@@ -612,7 +612,7 @@ Usage:
             svc_arg,
             pool=pool,
             namespace=namespace,
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         spec.validate_add()
         completion = self.add_nfs(spec)
@@ -627,7 +627,7 @@ Usage:
     def _daemon_add_prometheus(self, placement=None):
         spec = ServiceSpec(
             'prometheus',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_prometheus(spec)
         self._orchestrator_wait([completion])
@@ -640,7 +640,7 @@ Usage:
     def _daemon_add_node_exporter(self, placement=None):
         spec = ServiceSpec(
             'node-exporter',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_node_exporter(spec)
         self._orchestrator_wait([completion])
@@ -653,7 +653,7 @@ Usage:
     def _daemon_add_crash(self, placement=None):
         spec = ServiceSpec(
             'crash',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_crash(spec)
         self._orchestrator_wait([completion])
@@ -667,7 +667,7 @@ Usage:
         # type: (Optional[str]) -> HandleCommandResult
         spec = ServiceSpec(
             'grafana',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_grafana(spec)
         self._orchestrator_wait([completion])
@@ -681,7 +681,7 @@ Usage:
         # type: (Optional[str]) -> HandleCommandResult
         spec = ServiceSpec(
             'alertmanager',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.add_alertmanager(spec)
         self._orchestrator_wait([completion])
@@ -754,7 +754,7 @@ Usage:
         'name=placement,type=CephString,req=false',
         'Update the size or placement of managers')
     def _apply_mgr(self, placement=None):
-        placement = PlacementSpec.from_strings(placement)
+        placement = PlacementSpec.from_string(placement)
         placement.validate()
 
         spec = ServiceSpec('mgr', placement=placement)
@@ -769,7 +769,7 @@ Usage:
         'name=placement,type=CephString,req=false',
         'Update the number of monitor instances')
     def _apply_mon(self, placement=None):
-        placement = PlacementSpec.from_strings(placement)
+        placement = PlacementSpec.from_string(placement)
         placement.validate()
 
         spec = ServiceSpec('mon', placement=placement)
@@ -785,7 +785,7 @@ Usage:
         'name=placement,type=CephString,req=false',
         'Update the number of MDS instances for the given fs_name')
     def _apply_mds(self, fs_name, placement=None):
-        placement = PlacementSpec.from_strings(placement)
+        placement = PlacementSpec.from_string(placement)
         placement.validate()
         spec = ServiceSpec(
             'mds', fs_name,
@@ -802,7 +802,7 @@ Usage:
     def _apply_rbd_mirror(self, placement=None):
         spec = ServiceSpec(
             'rbd-mirror',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_rbd_mirror(spec)
         self._orchestrator_wait([completion])
@@ -819,7 +819,7 @@ Usage:
         spec = RGWSpec(
             rgw_realm=realm_name,
             rgw_zone=zone_name,
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_rgw(spec)
         self._orchestrator_wait([completion])
@@ -834,7 +834,7 @@ Usage:
     def _apply_nfs(self, svc_id, placement=None):
         spec = NFSServiceSpec(
             svc_id,
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_nfs(spec)
         self._orchestrator_wait([completion])
@@ -847,7 +847,7 @@ Usage:
     def _apply_prometheus(self, placement=None):
         spec = ServiceSpec(
             'prometheus',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_prometheus(spec)
         self._orchestrator_wait([completion])
@@ -860,7 +860,7 @@ Usage:
     def _apply_grafana(self, placement=None):
         spec = ServiceSpec(
             'grafana',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_grafana(spec)
         self._orchestrator_wait([completion])
@@ -873,7 +873,7 @@ Usage:
     def _apply_alertmanager(self, placement=None):
         spec = ServiceSpec(
             'alertmanager',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_alertmanager(spec)
         self._orchestrator_wait([completion])
@@ -886,7 +886,7 @@ Usage:
     def _apply_node_exporter(self, placement=None):
         spec = ServiceSpec(
             'node-exporter',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_node_exporter(spec)
         self._orchestrator_wait([completion])
@@ -899,7 +899,7 @@ Usage:
     def _apply_crash(self, placement=None):
         spec = ServiceSpec(
             'crash',
-            placement=PlacementSpec.from_strings(placement),
+            placement=PlacementSpec.from_string(placement),
         )
         completion = self.apply_crash(spec)
         self._orchestrator_wait([completion])
index 7bf176980f5d0831e2ec50e176700fc54a70a9df..6e2fbaa45938163b559b8864c0b4b1d4c9f98234 100644 (file)
@@ -42,11 +42,10 @@ def test_parse_host_placement_specs(test_input, expected, require_network):
         ('2 host1 host2', "PlacementSpec(count:2 host1,host2)"),
         ('label:foo', "PlacementSpec(label:foo)"),
         ('3 label:foo', "PlacementSpec(count:3 label:foo)"),
-        (['*'], 'PlacementSpec(all:true)'),
         ('*', 'PlacementSpec(all:true)'),
     ])
 def test_parse_placement_specs(test_input, expected):
-    ret = PlacementSpec.from_strings(test_input)
+    ret = PlacementSpec.from_string(test_input)
     assert str(ret) == expected
 
 @pytest.mark.parametrize("test_input",
index c889776d09dac7c8abc689d2ae57b7aabd79c75f..7d2d3c88694934b30217b5bd55f151dfa32bdff1 100644 (file)
@@ -36,7 +36,7 @@ def remove_filesystem(mgr, fs_name):
 def create_mds(mgr, fs_name, placement):
     spec = orchestrator.ServiceSpec(service_type='mds',
                                     service_id=fs_name,
-                                    placement=orchestrator.PlacementSpec.from_strings(placement))
+                                    placement=orchestrator.PlacementSpec.from_string(placement))
     try:
         completion = mgr.apply_mds(spec)
         mgr._orchestrator_wait([completion])