def test_federated_query(self): # Submit to cluster #1 cp, uuids = cli.submit('ls', self.cook_url_1) self.assertEqual(0, cp.returncode, cp.stderr) uuid_1 = uuids[0] # Submit to cluster #2 cp, uuids = cli.submit('ls', self.cook_url_2) self.assertEqual(0, cp.returncode, cp.stderr) uuid_2 = uuids[0] # Single query for both jobs, federated across clusters config = {'clusters': [{'name': 'cook1', 'url': self.cook_url_1}, {'name': 'cook2', 'url': self.cook_url_2}]} with cli.temp_config_file(config) as path: cp = cli.wait([uuid_1, uuid_2], flags='--config %s' % path) self.assertEqual(0, cp.returncode, cp.stderr) cp, jobs = cli.show_json([uuid_1, uuid_2], flags='--config %s' % path) uuids = [job['uuid'] for job in jobs] self.assertEqual(0, cp.returncode, cp.stderr) self.assertEqual(2, len(jobs), jobs) self.assertIn(str(uuid_1), uuids) self.assertIn(str(uuid_2), uuids) self.assertEqual('completed', jobs[0]['status']) self.assertEqual('completed', jobs[1]['status'])
def test_query_invalid_uuid(self): cp = cli.show([uuid.uuid4()], self.cook_url) self.assertEqual(1, cp.returncode, cp.stderr) self.assertIn('No matching data found', cli.stdout(cp)) cp = cli.wait([uuid.uuid4()], self.cook_url) self.assertEqual(1, cp.returncode, cp.stderr) self.assertIn('No matching data found', cli.stdout(cp))
def test_basic_submit_and_wait(self): cp, uuids = cli.submit('ls', self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp = cli.wait(uuids, self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp, jobs = cli.show_json(uuids, self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) self.assertEqual('completed', jobs[0]['status'])
def test_quoting(self): cp, uuids = cli.submit('echo "Hello; exit 1"', self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp = cli.wait(uuids, self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp, jobs = cli.show_json(uuids, self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) self.assertEqual('completed', jobs[0]['status']) self.assertEqual('success', jobs[0]['state'])
def test_wait_specify_timeout_and_interval(self): cp, uuids = cli.submit('"sleep 60"', self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) start_time = time.time() cp = cli.wait(uuids, self.cook_url, wait_flags='--timeout 1') elapsed_time = time.time() - start_time self.assertEqual(1, cp.returncode, cp.stderr) self.assertIn('Timeout waiting', cli.decode(cp.stderr)) self.assertLess(elapsed_time, 15) self.assertGreater(elapsed_time, 3) start_time = time.time() cp = cli.wait(uuids, self.cook_url, wait_flags='--timeout 1 --interval 1') elapsed_time_2 = time.time() - start_time self.assertEqual(1, cp.returncode, cp.stderr) self.assertIn('Timeout waiting', cli.decode(cp.stderr)) self.assertLess(elapsed_time_2, 3)
def test_wait_for_multiple_jobs(self): cp, uuids = cli.submit_stdin(['ls', 'ls', 'ls'], self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp = cli.wait(uuids, self.cook_url) self.assertEqual(0, cp.returncode, cp.stderr) cp, jobs = cli.show_json(uuids, self.cook_url) self.assertEqual(uuids[0], jobs[0]['uuid']) self.assertEqual(uuids[1], jobs[1]['uuid']) self.assertEqual(uuids[2], jobs[2]['uuid']) self.assertEqual('completed', jobs[0]['status']) self.assertEqual('completed', jobs[1]['status']) self.assertEqual('completed', jobs[2]['status'])
def test_specifying_cluster_name_explicitly(self): config = { 'clusters': [{ 'name': 'foo', 'url': self.cook_url }], 'defaults': { 'submit': { 'mem': 256, 'cpus': 2, 'max-retries': 2 } } } with cli.temp_config_file(config) as path: flags = '--config %s --cluster foo' % path cp, uuids = cli.submit('ls', flags=flags) self.assertEqual(0, cp.returncode, cp.stderr) cp, jobs = cli.show_json(uuids, flags=flags) self.assertEqual(0, cp.returncode, cp.stderr) cp = cli.wait(uuids, flags=flags) self.assertEqual(0, cp.returncode, cp.stderr)
def test_wait_requires_at_least_one_uuid(self): cp = cli.wait([], self.cook_url) self.assertEqual(2, cp.returncode, cp.stderr) self.assertIn('the following arguments are required: uuid', cli.decode(cp.stderr))