def getMemoryStatus(): client = TroiaClient(ADDRESS) csvFile = open('memoryConsumption_Status.csv','wb') csvWriter = csv.writer(csvFile, delimiter=',', quotechar='"') counter = 1 while (counter > 0): response = client.status() result = response['result'] csvData = [counter, response['status'], result['memory']['total'], result['memory']['free'], result['memory']['max'], result['memory']['used']] print csvData csvWriter.writerow(csvData) csvFile.flush() time.sleep(1) counter += 1
class TestConfiguration(unittest.TestCase): def setUp(self): self.client = TroiaClient(ADDRESS) self.initialConfigParams = self._get_config_params() def tearDown(self): #revert any of the config changes response = self.client.post_config(self.initialConfigParams) self.assertEqual(200, response.status_code) self.client.delete() def _get_config_params(self): response = self.client.get_config() htmlPage = BeautifulSoup(response.content) configParams = {} configParams['JOBS_STORAGE'] = htmlPage.find_all("option", {'selected':'selected'})[0]['value'] for inputTag in htmlPage.find_all("input"): try: configParams[inputTag['name']] = inputTag['value'] except: pass return configParams def test_Status(self): response = self.client.status() self.assertEqual('OK', response['status']) self.assertEqual('OK', response['result']['status']) #self.assertEqual('OK', response['result']['job_storage_status']) @unittest.skip('Skipping until the test is fixed') def test_GetDefaultConfig(self): response = self.client.get_config() self.assertEqual(200, response.status_code) @unittest.skip('Skipping until the test is fixed') def test_SetWrongDbUrl(self): inputParams = {'JOBS_STORAGE':'DB_FULL', 'DB_DRIVER_CLASS':'com.mysql.jdbc.Driver', 'DB_URL':'dbUrl', 'DB_NAME':'Troia' } response = self.client.post_config(inputParams) self.assertEqual(500, response.status_code) self.assertEqual(u'No suitable driver found for dbUrl?useUnicode=true&characterEncoding=utf-8', response.text) @unittest.skip('Skipping until the test is fixed') def test_SetWrongDbAccessSettings(self): inputParams = {'JOBS_STORAGE':'DB_FULL', 'DB_DRIVER_CLASS':'com.mysql.jdbc.Driver', 'DB_URL':'jdbc:mysql://localhost/', 'DB_NAME':'Troia', 'DB_PASSWORD':'******', 'DB_USER':'******', 'DOWNLOADS_PATH':'dbDownloadPath'} response = self.client.post_config(inputParams) self.assertEqual(500, response.status_code) self.assertEqual(u'Access denied for user \'dbUser\'@\'localhost\' (using password: YES)', response.text) @unittest.skip('Skipping until the test is fixed') def test_SetConfigParams(self): inputParams = {'CACHE_DUMP_TIME':'600', 'CACHE_SIZE':'100', 'DB_DRIVER_CLASS':'com.mysql.jdbc.Driver', 'DB_NAME':'Troia', 'DB_PASSWORD':'******', 'DB_URL':'jdbc:mysql://localhost/', 'DB_USER':'******', 'DOWNLOADS_PATH':'dbDownloadPath', 'EXECUTOR_THREADS_NUM':'10', 'FREEZE_CONFIGURATION_AT_START':'false', 'MEMCACHE_EXPIRATION_TIME':'100', 'MEMCACHE_PORT':'30', 'MEMCACHE_URL':'memCacheUrl', 'RESPONSES_CACHE_SIZE':'10', 'RESPONSES_DUMP_TIME':'100', 'JOBS_STORAGE':'DB_FULL'} response = self.client.post_config(inputParams) self.assertEqual(200, response.status_code) currentConfigParams = self._get_config_params() for key in inputParams.keys(): self.assertEqual(inputParams[key], currentConfigParams[key]) @unittest.skip('Skipping until the test is fixed') def test_ResetDB(self): response = self.client.resetDB() self.assertEqual(200, response.status_code)
from client.gal import TroiaClient from nominalJobsTests.testSettings import * def check_status(res): if res['status'] != "OK" or res['result']['job_storage_status'] != "OK": print "FAILURE" if __name__ == "__main__": client = TroiaClient(ADDRESS) check_status(client.status()) client.create(CATEGORIES) client.await_completion(client.post_assigned_labels(ASSIGNED_LABELS)) client.await_completion(client.post_gold_data(GOLD_SAMPLES)) client.await_completion(client.post_compute()) # client.await_completion(client.get_predictions_objects()) # client.await_completion(client.get_prediction_workers_quality()) client.await_completion(client.get_prediction_zip()) client.delete() check_status(client.status())