diff options
-rw-r--r-- | roles/lib_openshift/library/oadm_manage_node.py | 14 | ||||
-rw-r--r-- | roles/lib_openshift/src/class/oadm_manage_node.py | 14 | ||||
-rwxr-xr-x | roles/lib_openshift/src/test/unit/oadm_manage_node.py | 8 |
3 files changed, 21 insertions, 15 deletions
diff --git a/roles/lib_openshift/library/oadm_manage_node.py b/roles/lib_openshift/library/oadm_manage_node.py index 39e6384da..1d2b70885 100644 --- a/roles/lib_openshift/library/oadm_manage_node.py +++ b/roles/lib_openshift/library/oadm_manage_node.py @@ -1285,7 +1285,7 @@ class ManageNode(OpenShiftCLI): _node = {} _node['name'] = node['metadata']['name'] _node['schedulable'] = True - if node['spec'].has_key('unschedulable'): + if 'unschedulable' in node['spec']: _node['schedulable'] = False nodes.append(_node) @@ -1363,9 +1363,9 @@ class ManageNode(OpenShiftCLI): # This is a short circuit based on the way we fetch nodes. # If node is a dict/list then we've already fetched them. for node in nodes: - if isinstance(node, dict) and node.has_key('returncode'): + if isinstance(node, dict) and 'returncode' in node: return {'results': nodes, 'returncode': node['returncode']} - if isinstance(node, list) and node[0].has_key('returncode'): + if isinstance(node, list) and 'returncode' in node[0]: return {'results': nodes, 'returncode': node[0]['returncode']} # check all the nodes that were returned and verify they are: # node['schedulable'] == self.config.config_options['schedulable']['value'] @@ -1382,7 +1382,7 @@ class ManageNode(OpenShiftCLI): # removing header line and trailing new line character of node lines for node_results in results['results'].split('\n')[1:-1]: parts = node_results.split() - nodes.append({'name': parts[0], 'schedulable': 'Ready' == parts[1]}) + nodes.append({'name': parts[0], 'schedulable': parts[1] == 'Ready'}) results['nodes'] = nodes return results @@ -1414,8 +1414,12 @@ class ManageNode(OpenShiftCLI): results = None changed = False if params['schedulable'] != None: + if check_mode: + # schedulable returns results after the fact. + # We need to redo how this works to support check_mode completely. + return {'changed': True, 'msg': 'CHECK_MODE: would have called schedulable.'} results = oadm_mn.schedulable() - if not results.has_key('changed'): + if 'changed' not in results: changed = True if params['evacuate']: diff --git a/roles/lib_openshift/src/class/oadm_manage_node.py b/roles/lib_openshift/src/class/oadm_manage_node.py index 948e3f1ef..e0a9fc304 100644 --- a/roles/lib_openshift/src/class/oadm_manage_node.py +++ b/roles/lib_openshift/src/class/oadm_manage_node.py @@ -59,7 +59,7 @@ class ManageNode(OpenShiftCLI): _node = {} _node['name'] = node['metadata']['name'] _node['schedulable'] = True - if node['spec'].has_key('unschedulable'): + if 'unschedulable' in node['spec']: _node['schedulable'] = False nodes.append(_node) @@ -137,9 +137,9 @@ class ManageNode(OpenShiftCLI): # This is a short circuit based on the way we fetch nodes. # If node is a dict/list then we've already fetched them. for node in nodes: - if isinstance(node, dict) and node.has_key('returncode'): + if isinstance(node, dict) and 'returncode' in node: return {'results': nodes, 'returncode': node['returncode']} - if isinstance(node, list) and node[0].has_key('returncode'): + if isinstance(node, list) and 'returncode' in node[0]: return {'results': nodes, 'returncode': node[0]['returncode']} # check all the nodes that were returned and verify they are: # node['schedulable'] == self.config.config_options['schedulable']['value'] @@ -156,7 +156,7 @@ class ManageNode(OpenShiftCLI): # removing header line and trailing new line character of node lines for node_results in results['results'].split('\n')[1:-1]: parts = node_results.split() - nodes.append({'name': parts[0], 'schedulable': 'Ready' == parts[1]}) + nodes.append({'name': parts[0], 'schedulable': parts[1] == 'Ready'}) results['nodes'] = nodes return results @@ -188,8 +188,12 @@ class ManageNode(OpenShiftCLI): results = None changed = False if params['schedulable'] != None: + if check_mode: + # schedulable returns results after the fact. + # We need to redo how this works to support check_mode completely. + return {'changed': True, 'msg': 'CHECK_MODE: would have called schedulable.'} results = oadm_mn.schedulable() - if not results.has_key('changed'): + if 'changed' not in results: changed = True if params['evacuate']: diff --git a/roles/lib_openshift/src/test/unit/oadm_manage_node.py b/roles/lib_openshift/src/test/unit/oadm_manage_node.py index 5a0a4eb17..8fd6f9c55 100755 --- a/roles/lib_openshift/src/test/unit/oadm_manage_node.py +++ b/roles/lib_openshift/src/test/unit/oadm_manage_node.py @@ -127,7 +127,6 @@ class ManageNodeTest(unittest.TestCase): 'dry_run': False, 'force': False} - node = [{ "apiVersion": "v1", "kind": "Node", @@ -155,14 +154,13 @@ class ManageNodeTest(unittest.TestCase): "providerID": "aws:///us-east-1c/i-06bb330e55c699b0f", }}] - #"unschedulable": True mock_openshift_cmd.side_effect = [ {"cmd": "/usr/bin/oc get node -o json ip-172-31-49-140.ec2.internal", "results": node, - "returncode": 0, - }, + "returncode": 0}, {"cmd": "/usr/bin/oadm manage-node ip-172-31-49-140.ec2.internal --schedulable=False", - "results": "NAME STATUS AGE\nip-172-31-49-140.ec2.internal Ready,SchedulingDisabled 5h\n", + "results": "NAME STATUS AGE\n" + + "ip-172-31-49-140.ec2.internal Ready,SchedulingDisabled 5h\n", "returncode": 0}] results = ManageNode.run_ansible(params, False) |