def test_nodes_stats(self, mock_get_slaves): """This method tests retrieving all the nodes statistics for the three hour duration requested""" mock_get_slaves.return_value = [ SlaveInfo(self.node1.hostname, self.node1.port, HardwareResources(1, 2, 3)), SlaveInfo(self.node3.hostname, self.node3.port, HardwareResources(4, 5, 6)), ] response = self.client.generic('GET', '/v4/nodes/status/?started=PT3H00M0S') self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertTrue(isinstance(result, dict), 'result must be a dictionary') assert_message = '({0} != 3) Expected to get the 3 nodes'.format( len(result['results'])) self.assertEqual(len(result['results']), 3, assert_message) for entry in result['results']: hostname = entry['node']['hostname'] self.assertIn(hostname, [ self.node1.hostname, self.node2.hostname, self.node3.hostname ]) if hostname == self.node1.hostname: self.assertTrue(entry['is_online']) self.assertEqual(len(entry['job_exe_counts']), 2) for status_count in entry['job_exe_counts']: if status_count['status'] == 'COMPLETED': self.assertEqual(status_count['count'], 1) elif status_count['status'] == 'FAILED': self.assertEqual(status_count['count'], 1) else: self.fail('Unexpected job execution status found: %s' % status_count['status']) elif hostname == self.node2.hostname: self.assertFalse(entry['is_online']) for status_count in entry['job_exe_counts']: if status_count['status'] == 'FAILED' and status_count[ 'category'] == 'DATA': self.assertEqual(status_count['count'], 1) elif status_count['status'] == 'FAILED' and status_count[ 'category'] == 'SYSTEM': self.assertEqual(status_count['count'], 1) else: self.fail('Unexpected job execution status found: %s' % status_count['status']) elif hostname == self.node3.hostname: self.assertTrue(entry['is_online']) self.assertEqual(len(entry['job_exes_running']), 1) for status_count in entry['job_exe_counts']: if status_count['status'] == 'RUNNING': self.assertEqual(status_count['count'], 1)
def test_nodes_system_stats(self, mock_get_slaves): '''This method tests for when a node has not processed any jobs for the duration of time requested.''' mock_get_slaves.return_value = [ SlaveInfo(self.node1.hostname, self.node1.port, HardwareResources(1, 2, 3)), SlaveInfo(self.node3.hostname, self.node3.port, HardwareResources(4, 5, 6)), ] url = u'/nodes/status/?started=PT1H30M0S' response = self.client.generic('GET', url) self.assertEqual(response.status_code, status.HTTP_200_OK) result = json.loads(response.content) self.assertTrue(isinstance(result, dict), u'result must be a dictionary') assert_message = u'({0} != 3) Expected to get the 3 nodes'.format(len(result[u'results'])) self.assertEqual(len(result[u'results']), 3, assert_message) for entry in result[u'results']: hostname = entry[u'node'][u'hostname'] self.assertIn(hostname, [self.node1.hostname, self.node2.hostname, self.node3.hostname]) if hostname == self.node1.hostname: self.assertTrue(entry[u'is_online']) self.assertEqual(len(entry[u'job_exe_counts']), 2) for status_count in entry[u'job_exe_counts']: if status_count[u'status'] == u'COMPLETED': self.assertEqual(status_count[u'count'], 1) elif status_count[u'status'] == u'FAILED': self.assertEqual(status_count[u'count'], 1) else: self.fail(u'Unexpected job execution status found: %s' % status_count[u'status']) elif hostname == self.node2.hostname: self.assertFalse(entry[u'is_online']) for status_count in entry[u'job_exe_counts']: if status_count[u'status'] == u'FAILED' and status_count[u'category'] == u'DATA': self.assertEqual(status_count[u'count'], 1) elif status_count[u'status'] == u'FAILED' and status_count[u'category'] == u'SYSTEM': self.assertEqual(status_count[u'count'], 1) else: self.fail(u'Unexpected job execution status found: %s' % status_count[u'status']) elif hostname == self.node3.hostname: self.assertTrue(entry[u'is_online']) self.assertEqual(len(entry[u'job_exes_running']), 1) for status_count in entry[u'job_exe_counts']: if status_count[u'status'] == u'RUNNING': self.assertEqual(status_count[u'count'], 1)
def test_status_success_v4(self, mock_get_scheduler): """Test getting overall scheduler status information successfully""" mock_get_scheduler.return_value = SchedulerInfo( 'scheduler', True, HardwareResources(5, 10, 20), HardwareResources(1, 2, 3), HardwareResources()) response = self.client.generic('GET', '/v4/status/') self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertEqual(result['master']['hostname'], 'master') self.assertEqual(result['master']['port'], 5050) self.assertTrue(result['master']['is_online']) self.assertEqual(result['scheduler']['hostname'], 'scheduler') self.assertTrue(result['scheduler']['is_online']) self.assertFalse(result['scheduler']['is_paused']) self.assertEqual(result['queue_depth'], 0) self.assertEqual(result['resources']['total']['cpus'], 5) self.assertEqual(result['resources']['scheduled']['cpus'], 1) self.assertEqual(result['resources']['used']['cpus'], 0)
def test_get_node_success(self, mock_get_slave): """Test successfully calling the Get Node method.""" mock_get_slave.return_value = SlaveInfo( self.node2.hostname, self.node2.port, HardwareResources(4., 2048., 40000.)) url = rest_util.get_url('/nodes/%d/' % self.node2.id) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertIn('hostname', result) self.assertEqual(result['hostname'], self.node2.hostname)
def test_get_node_success(self, mock_get_slave): '''Test successfully calling the Get Node method.''' mock_get_slave.return_value = SlaveInfo(self.node2.hostname, self.node2.port, HardwareResources(4., 2048., 40000.)) url = '/nodes/%d/' % self.node2.id response = self.client.get(url) data = json.loads(response.content) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('hostname', data) self.assertEqual(data['hostname'], self.node2.hostname) self.assertEqual(data['resources']['total']['cpus'], 4.) self.assertEqual(data['resources']['total']['mem'], 2048.) self.assertEqual(data['resources']['total']['disk'], 40000.) self.assertEqual(data['job_exes_running'], []) self.assertNotIn('disconnected', data)
def test_update_node_unpause(self, mock_get_slave): """Tests unpausing the node and specifying a reason.""" mock_get_slave.return_value = SlaveInfo( self.node2.hostname, self.node2.port, HardwareResources(4., 2048., 40000.)) json_data = {'is_paused': False, 'pause_reason': 'Test reason'} url = rest_util.get_url('/nodes/%d/' % self.node2.id) response = self.client.patch(url, json.dumps(json_data), 'application/json') self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertEqual(result['is_paused'], False) self.assertIsNone(result['pause_reason']) self.assertIn('hostname', result) self.assertEqual(result['hostname'], self.node2.hostname)
def test_update_node_success(self, mock_get_slave): """Test successfully calling the Update Node method.""" mock_get_slave.return_value = SlaveInfo( self.node2.hostname, self.node2.port, HardwareResources(4., 2048., 40000.)) json_data = { 'is_paused': True, 'pause_reason': 'Test reason', } url = rest_util.get_url('/nodes/%d/' % self.node2.id) response = self.client.patch(url, json.dumps(json_data), 'application/json') self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertEqual(result['is_paused'], True) self.assertEqual(result['pause_reason'], json_data['pause_reason']) self.assertIn('hostname', result) self.assertEqual(result['hostname'], self.node2.hostname)