`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>
"""
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)