|
@@ -6,7 +6,7 @@
|
|
|
# python -m unittest version
|
|
|
#
|
|
|
# .
|
|
|
-# Ran 1 test in 0.597s
|
|
|
+# Ran 2 tests in 0.001s
|
|
|
#
|
|
|
# OK
|
|
|
|
|
@@ -36,10 +36,10 @@ class ManageNodeTest(unittest.TestCase):
|
|
|
pass
|
|
|
|
|
|
@mock.patch('oadm_manage_node.ManageNode.openshift_cmd')
|
|
|
- def test_state_list(self, mock_openshift_cmd):
|
|
|
+ def test_list_pods(self, mock_openshift_cmd):
|
|
|
''' Testing a get '''
|
|
|
- params = {'node': 'test-node-1',
|
|
|
- 'namespace': 'default',
|
|
|
+ params = {'node': ['ip-172-31-49-140.ec2.internal'],
|
|
|
+ 'schedulable': None,
|
|
|
'selector': None,
|
|
|
'pod_selector': None,
|
|
|
'list_pods': True,
|
|
@@ -49,78 +49,126 @@ class ManageNodeTest(unittest.TestCase):
|
|
|
'dry_run': False,
|
|
|
'force': False}
|
|
|
|
|
|
- dc = '''{"kind": "DeploymentConfig",
|
|
|
- "apiVersion": "v1",
|
|
|
- "metadata": {
|
|
|
- "name": "router",
|
|
|
- "namespace": "default",
|
|
|
- "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router",
|
|
|
- "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42",
|
|
|
- "resourceVersion": "6558",
|
|
|
- "generation": 8,
|
|
|
- "creationTimestamp": "2017-01-23T20:58:07Z",
|
|
|
- "labels": {
|
|
|
- "router": "router"
|
|
|
- }
|
|
|
- },
|
|
|
- "spec": {
|
|
|
- "replicas": 2,
|
|
|
- }
|
|
|
- }'''
|
|
|
+ pod_list = '''{
|
|
|
+ "metadata": {},
|
|
|
+ "items": [
|
|
|
+ {
|
|
|
+ "metadata": {
|
|
|
+ "name": "docker-registry-1-xuhik",
|
|
|
+ "generateName": "docker-registry-1-",
|
|
|
+ "namespace": "default",
|
|
|
+ "selfLink": "/api/v1/namespaces/default/pods/docker-registry-1-xuhik",
|
|
|
+ "uid": "ae2a25a2-e316-11e6-80eb-0ecdc51fcfc4",
|
|
|
+ "resourceVersion": "1501",
|
|
|
+ "creationTimestamp": "2017-01-25T15:55:23Z",
|
|
|
+ "labels": {
|
|
|
+ "deployment": "docker-registry-1",
|
|
|
+ "deploymentconfig": "docker-registry",
|
|
|
+ "docker-registry": "default"
|
|
|
+ },
|
|
|
+ "annotations": {
|
|
|
+ "openshift.io/deployment-config.latest-version": "1",
|
|
|
+ "openshift.io/deployment-config.name": "docker-registry",
|
|
|
+ "openshift.io/deployment.name": "docker-registry-1",
|
|
|
+ "openshift.io/scc": "restricted"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "spec": {}
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "metadata": {
|
|
|
+ "name": "router-1-kp3m3",
|
|
|
+ "generateName": "router-1-",
|
|
|
+ "namespace": "default",
|
|
|
+ "selfLink": "/api/v1/namespaces/default/pods/router-1-kp3m3",
|
|
|
+ "uid": "9e71f4a5-e316-11e6-80eb-0ecdc51fcfc4",
|
|
|
+ "resourceVersion": "1456",
|
|
|
+ "creationTimestamp": "2017-01-25T15:54:56Z",
|
|
|
+ "labels": {
|
|
|
+ "deployment": "router-1",
|
|
|
+ "deploymentconfig": "router",
|
|
|
+ "router": "router"
|
|
|
+ },
|
|
|
+ "annotations": {
|
|
|
+ "openshift.io/deployment-config.latest-version": "1",
|
|
|
+ "openshift.io/deployment-config.name": "router",
|
|
|
+ "openshift.io/deployment.name": "router-1",
|
|
|
+ "openshift.io/scc": "hostnetwork"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "spec": {}
|
|
|
+ }]
|
|
|
+}'''
|
|
|
|
|
|
mock_openshift_cmd.side_effect = [
|
|
|
- {"cmd": '/usr/bin/oc get dc router -n default',
|
|
|
- 'results': dc,
|
|
|
- 'returncode': 0}]
|
|
|
+ {"cmd": "/usr/bin/oadm manage-node ip-172-31-49-140.ec2.internal --list-pods",
|
|
|
+ "results": pod_list,
|
|
|
+ "returncode": 0}
|
|
|
+ ]
|
|
|
|
|
|
- results = OCScale.run_ansible(params, False)
|
|
|
+ results = ManageNode.run_ansible(params, False)
|
|
|
|
|
|
- self.assertFalse(results['changed'])
|
|
|
- self.assertEqual(results['result'][0], 2)
|
|
|
+ # returned a single node
|
|
|
+ self.assertTrue(len(results['results']['nodes']) == 1)
|
|
|
+ # returned 2 pods
|
|
|
+ self.assertTrue(len(results['results']['nodes']['ip-172-31-49-140.ec2.internal']) == 2)
|
|
|
|
|
|
- @mock.patch('oc_scale.OCScale.openshift_cmd')
|
|
|
- def test_scale(self, mock_openshift_cmd):
|
|
|
+ @mock.patch('oadm_manage_node.ManageNode.openshift_cmd')
|
|
|
+ def test_schedulable_false(self, mock_openshift_cmd):
|
|
|
''' Testing a get '''
|
|
|
- params = {'name': 'router',
|
|
|
- 'namespace': 'default',
|
|
|
- 'replicas': 3,
|
|
|
- 'state': 'list',
|
|
|
- 'kind': 'dc',
|
|
|
+ params = {'node': ['ip-172-31-49-140.ec2.internal'],
|
|
|
+ 'schedulable': False,
|
|
|
+ 'selector': None,
|
|
|
+ 'pod_selector': None,
|
|
|
+ 'list_pods': False,
|
|
|
'kubeconfig': '/etc/origin/master/admin.kubeconfig',
|
|
|
- 'debug': False}
|
|
|
-
|
|
|
- dc = '''{"kind": "DeploymentConfig",
|
|
|
- "apiVersion": "v1",
|
|
|
- "metadata": {
|
|
|
- "name": "router",
|
|
|
- "namespace": "default",
|
|
|
- "selfLink": "/oapi/v1/namespaces/default/deploymentconfigs/router",
|
|
|
- "uid": "a441eedc-e1ae-11e6-a2d5-0e6967f34d42",
|
|
|
- "resourceVersion": "6558",
|
|
|
- "generation": 8,
|
|
|
- "creationTimestamp": "2017-01-23T20:58:07Z",
|
|
|
- "labels": {
|
|
|
- "router": "router"
|
|
|
- }
|
|
|
- },
|
|
|
- "spec": {
|
|
|
- "replicas": 3,
|
|
|
- }
|
|
|
- }'''
|
|
|
-
|
|
|
- mock_openshift_cmd.side_effect = [
|
|
|
- {"cmd": '/usr/bin/oc get dc router -n default',
|
|
|
- 'results': dc,
|
|
|
- 'returncode': 0},
|
|
|
- {"cmd": '/usr/bin/oc create -f /tmp/router -n default',
|
|
|
- 'results': '',
|
|
|
- 'returncode': 0}
|
|
|
- ]
|
|
|
+ 'evacuate': False,
|
|
|
+ 'grace_period': False,
|
|
|
+ 'dry_run': False,
|
|
|
+ 'force': False}
|
|
|
|
|
|
- results = OCScale.run_ansible(params, False)
|
|
|
|
|
|
- self.assertFalse(results['changed'])
|
|
|
- self.assertEqual(results['result'][0], 3)
|
|
|
+ node = [{
|
|
|
+ "apiVersion": "v1",
|
|
|
+ "kind": "Node",
|
|
|
+ "metadata": {
|
|
|
+ "creationTimestamp": "2017-01-26T14:34:43Z",
|
|
|
+ "labels": {
|
|
|
+ "beta.kubernetes.io/arch": "amd64",
|
|
|
+ "beta.kubernetes.io/instance-type": "m4.large",
|
|
|
+ "beta.kubernetes.io/os": "linux",
|
|
|
+ "failure-domain.beta.kubernetes.io/region": "us-east-1",
|
|
|
+ "failure-domain.beta.kubernetes.io/zone": "us-east-1c",
|
|
|
+ "hostname": "opstest-node-compute-0daaf",
|
|
|
+ "kubernetes.io/hostname": "ip-172-31-51-111.ec2.internal",
|
|
|
+ "ops_node": "old",
|
|
|
+ "region": "us-east-1",
|
|
|
+ "type": "compute"
|
|
|
+ },
|
|
|
+ "name": "ip-172-31-51-111.ec2.internal",
|
|
|
+ "resourceVersion": "6936",
|
|
|
+ "selfLink": "/api/v1/nodes/ip-172-31-51-111.ec2.internal",
|
|
|
+ "uid": "93d7fdfb-e3d4-11e6-a982-0e84250fc302"
|
|
|
+ },
|
|
|
+ "spec": {
|
|
|
+ "externalID": "i-06bb330e55c699b0f",
|
|
|
+ "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,
|
|
|
+ },
|
|
|
+ {"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",
|
|
|
+ "returncode": 0}]
|
|
|
+ results = ManageNode.run_ansible(params, False)
|
|
|
+
|
|
|
+ self.assertTrue(results['changed'])
|
|
|
+ self.assertEqual(results['results']['nodes'][0]['name'], 'ip-172-31-49-140.ec2.internal')
|
|
|
+ self.assertEqual(results['results']['nodes'][0]['schedulable'], False)
|
|
|
|
|
|
def tearDown(self):
|
|
|
'''TearDown method'''
|