Fix: CLI default filter wrong

- If no filter items are specified on the command
  line, the CLI created a default node filter that
  evaluated to no nodes instead of all nodes
- Add unit test to test the null node filter condition

Closes #85

Change-Id: I948059028207a86ff52479b244dbbc449c8741bc
This commit is contained in:
Scott Hussey 2018-02-22 20:32:13 -06:00 committed by Bryan Strassner
parent 83f57669fb
commit 2749f98125
2 changed files with 46 additions and 11 deletions

View File

@ -71,19 +71,22 @@ class TaskCreate(CliAction): # pylint: disable=too-few-public-methods
self.block = block
self.poll_interval = poll_interval
filter_items = {'filter_type': 'union'}
if any([node_names, rack_names, node_tags]):
filter_items = {'filter_type': 'union'}
if node_names is not None:
filter_items['node_names'] = node_names
if rack_names is not None:
filter_items['rack_names'] = rack_names
if node_tags is None:
filter_items['node_tags'] = node_tags
if node_names is not None:
filter_items['node_names'] = node_names
if rack_names is not None:
filter_items['rack_names'] = rack_names
if node_tags is None:
filter_items['node_tags'] = node_tags
self.node_filter = {
'filter_set_type': 'intersection',
'filter_set': [filter_items]
}
self.node_filter = {
'filter_set_type': 'intersection',
'filter_set': [filter_items]
}
else:
self.node_filter = None
def invoke(self):
"""Invoke execution of this action."""

View File

@ -0,0 +1,32 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import drydock_provisioner.drydock_client.session as dc_session
import drydock_provisioner.drydock_client.client as dc_client
from drydock_provisioner.cli.task.actions import TaskCreate
def test_taskcli_blank_nodefilter():
"""If no filter values are specified, node filter should be None."""
host = 'foo.bar.baz'
dd_ses = dc_session.DrydockSession(host)
dd_client = dc_client.DrydockClient(dd_ses)
action = TaskCreate(dd_client,
"http://foo.bar",
action_name="deploy_nodes")
assert action.node_filter is None