]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: do not try to iterate through None 31705/head
authorKefu Chai <kchai@redhat.com>
Mon, 18 Nov 2019 08:34:48 +0000 (16:34 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 21 Nov 2019 09:02:50 +0000 (17:02 +0800)
`PlacementSpec` instances could be constructed with `nodes=None`, see
`OrchestratorCli._mds_add()` in orchestrator_cli/module.py, so we need
to handle the case of `None`.

also, it's dangerous to pass a list as the default parameter to a
method in python, as the value of reference point to that list will
be stored. and multiple calls of that method will share the same
instance of list. which is not expected under most circumstances.

in this change, list comprehension is unsed instead of more functional
`list(map(...))`, because, the behavior of `map()` in python3 is quite
different from that in python2. in python3, `map()` returns an iterator.
and `list()` actually materializes the iterator by walking through it,
and `list()` changes the iterator by advancing it. so, to improve the
readability and to reduce the menta load of developers, list
comprehension is better in most cases.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/orchestrator.py

index ba2156e31915935c9aec2c1c21097bbed75f78db..ad6923bb11915cedfcb20df4d59a4da16d18318c 100644 (file)
@@ -667,10 +667,13 @@ class PlacementSpec(object):
     """
     For APIs that need to specify a node subset
     """
-    def __init__(self, label=None, nodes=[]):
+    def __init__(self, label=None, nodes=None):
         self.label = label
+        if nodes:
+            self.nodes = [parse_host_specs(x, require_network=False) for x in nodes]
+        else:
+            self.nodes = []
 
-        self.nodes = [parse_host_specs(x, require_network=False) for x in nodes]
 
 def handle_type_error(method):
     @wraps(method)