Esempio n. 1
0
 def test_submit_priority(self):
     cp, uuids = cli.submit('ls',
                            self.cook_url,
                            submit_flags='--priority 0')
     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(0, jobs[0]['priority'])
     cp, uuids = cli.submit('ls',
                            self.cook_url,
                            submit_flags='--priority 100')
     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(100, jobs[0]['priority'])
     cp, uuids = cli.submit('ls',
                            self.cook_url,
                            submit_flags='--priority -1')
     self.assertEqual(2, cp.returncode, cp.stderr)
     self.assertIn('--priority/-p: invalid choice', cli.decode(cp.stderr))
     cp, uuids = cli.submit('ls',
                            self.cook_url,
                            submit_flags='--priority 101')
     self.assertEqual(2, cp.returncode, cp.stderr)
     self.assertIn('--priority/-p: invalid choice', cli.decode(cp.stderr))
Esempio n. 2
0
    def test_complex_commands(self):
        desired_command = '(foo -x \'def bar = "baz"\')'
        # Incorrectly submitted command
        command = '"(foo -x \'def bar = "baz"\')"'
        cp, uuids = cli.submit(command, 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(desired_command.replace('"', ''), jobs[0]['command'])
        # Correctly submitted command
        command = '"(foo -x \'def bar = \\"baz\\"\')"'
        cp, uuids = cli.submit(command, 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(desired_command, jobs[0]['command'])

        desired_command = "export HOME=$MESOS_DIRECTORY; export LOGNAME=$(whoami); JAVA_OPTS='-Xmx15000m' foo"
        # Incorrectly submitted command
        command = "'export HOME=$MESOS_DIRECTORY; export LOGNAME=$(whoami); JAVA_OPTS='-Xmx15000m' foo'"
        cp, uuids = cli.submit(command, 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(desired_command.replace("'", ''), jobs[0]['command'])
        # Correctly submitted command
        command = "'export HOME=$MESOS_DIRECTORY; export LOGNAME=$(whoami); JAVA_OPTS='\"'\"'-Xmx15000m'\"'\"' foo'"
        cp, uuids = cli.submit(command, 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(desired_command, jobs[0]['command'])
Esempio n. 3
0
    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'])
Esempio n. 4
0
 def test_submit_with_application(self):
     # Specifying application name and version
     cp, uuids = cli.submit(
         'ls',
         self.cook_url,
         submit_flags='--application-name %s --application-version %s' %
         ('foo', '1.2.3'))
     self.assertEqual(0, cp.returncode, cp.stderr)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual('foo', jobs[0]['application']['name'])
     self.assertEqual('1.2.3', jobs[0]['application']['version'])
     # Default application name
     cp, uuids = cli.submit('ls', self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual('cook-scheduler-cli', jobs[0]['application']['name'])
Esempio n. 5
0
 def test_submit_raw_multiple(self):
     command = 'ls'
     name = 'foo'
     priority = 32
     max_retries = 12
     max_runtime = 3456
     cpus = 0.1
     mem = 56
     raw_job = {
         'command': command,
         'name': name,
         'priority': priority,
         'max-retries': max_retries,
         'max-runtime': max_runtime,
         'cpus': cpus,
         'mem': mem
     }
     cp, uuids = cli.submit(stdin=cli.encode(
         json.dumps([raw_job, raw_job, raw_job])),
                            cook_url=self.cook_url,
                            submit_flags='--raw')
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(3, len(uuids), uuids)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(3, len(jobs), jobs)
     for job in jobs:
         self.assertEqual(0, cp.returncode, cp.stderr)
         self.assertEqual(command, job['command'])
         self.assertEqual(name, job['name'])
         self.assertEqual(priority, job['priority'])
         self.assertEqual(max_retries, job['max_retries'])
         self.assertEqual(max_runtime, job['max_runtime'])
         self.assertEqual(cpus, job['cpus'])
         self.assertEqual(mem, job['mem'])
Esempio n. 6
0
    def test_config_defaults_are_respected(self):
        # Submit job with defaults in config file
        config = {
            'defaults': {
                'submit': {
                    'mem': 256,
                    'cpus': 2,
                    'priority': 16,
                    'max-retries': 2,
                    'max-runtime': 300
                }
            }
        }
        with cli.temp_config_file(config) as path:
            cp, uuids = cli.submit('ls', self.cook_url, '--config %s' % path)
            self.assertEqual(0, cp.returncode, cp.stderr)

        # Assert that the job was submitted with the defaults from the file
        cp, jobs = cli.show_json(uuids, self.cook_url)
        self.assertEqual(0, cp.returncode, cp.stderr)
        self.assertEqual(1, len(jobs))
        job = jobs[0]
        defaults = config['defaults']['submit']
        self.assertEqual(defaults['mem'], job['mem'])
        self.assertEqual(defaults['cpus'], job['cpus'])
        self.assertEqual(defaults['priority'], job['priority'])
        self.assertEqual(defaults['max-retries'], job['max_retries'])
        self.assertEqual(defaults['max-runtime'], job['max_runtime'])
Esempio n. 7
0
 def test_submit_raw(self):
     command = 'ls'
     juuid = uuid.uuid4()
     name = 'foo'
     priority = 32
     max_retries = 12
     max_runtime = 3456
     cpus = 0.1
     mem = 56
     raw_job = {
         'command': command,
         'uuid': str(juuid),
         'name': name,
         'priority': priority,
         'max-retries': max_retries,
         'max-runtime': max_runtime,
         'cpus': cpus,
         'mem': mem
     }
     cp, uuids = cli.submit(stdin=cli.encode(json.dumps(raw_job)),
                            cook_url=self.cook_url,
                            submit_flags='--raw')
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(str(juuid), uuids[0], uuids)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(command, jobs[0]['command'])
     self.assertEqual(name, jobs[0]['name'])
     self.assertEqual(priority, jobs[0]['priority'])
     self.assertEqual(max_retries, jobs[0]['max_retries'])
     self.assertEqual(max_runtime, jobs[0]['max_runtime'])
     self.assertEqual(cpus, jobs[0]['cpus'])
     self.assertEqual(mem, jobs[0]['mem'])
Esempio n. 8
0
 def test_double_dash_for_end_of_options(self):
     # Double-dash for 'end of options'
     cp, uuids = cli.submit('-- ls -al', 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('ls -al', jobs[0]['command'])
     # Double-dash along with other flags
     cp, uuids = cli.submit('-- ls -al',
                            self.cook_url,
                            submit_flags='--name foo --priority 12')
     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('ls -al', jobs[0]['command'])
     self.assertEqual('foo', jobs[0]['name'])
     self.assertEqual(12, jobs[0]['priority'])
Esempio n. 9
0
 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'])
Esempio n. 10
0
 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'])
Esempio n. 11
0
 def test_submit_accepts_command_from_stdin(self):
     cp, uuids = cli.submit(cook_url=self.cook_url, stdin=cli.encode('ls'))
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(1, len(uuids), uuids)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(1, len(jobs))
     cp, uuids = cli.submit(cook_url=self.cook_url, stdin=cli.encode(''))
     self.assertEqual(1, cp.returncode, cp.stderr)
     self.assertIn('must specify at least one command',
                   cli.decode(cp.stderr))
Esempio n. 12
0
 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'])
Esempio n. 13
0
 def test_multiple_commands_submits_multiple_jobs(self):
     cp, uuids = cli.submit_stdin(['ls', 'ls', 'ls'], self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(3, len(uuids))
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(3, len(jobs))
     cp, uuids = cli.submit_stdin(['ls', 'ls', 'ls'],
                                  self.cook_url,
                                  submit_flags='--uuid %s' % uuid.uuid4())
     self.assertEqual(1, cp.returncode, cp.stderr)
     self.assertIn('cannot specify multiple subcommands with a single UUID',
                   cli.decode(cp.stderr))
Esempio n. 14
0
 def test_submit_specify_fields(self):
     juuid = uuid.uuid4()
     name = 'foo'
     priority = 32
     max_retries = 12
     max_runtime = 34
     cpus = 0.1
     mem = 56
     submit_flags = '--uuid %s --name %s --priority %s --max-retries %s --max-runtime %s --cpus %s --mem %s' % \
                    (juuid, name, priority, max_retries, max_runtime, cpus, mem)
     cp, uuids = cli.submit('ls', self.cook_url, submit_flags=submit_flags)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(str(juuid), uuids[0], uuids)
     cp, jobs = cli.show_json(uuids, self.cook_url)
     self.assertEqual(0, cp.returncode, cp.stderr)
     self.assertEqual(name, jobs[0]['name'])
     self.assertEqual(priority, jobs[0]['priority'])
     self.assertEqual(max_retries, jobs[0]['max_retries'])
     self.assertEqual(max_runtime, jobs[0]['max_runtime'])
     self.assertEqual(cpus, jobs[0]['cpus'])
     self.assertEqual(mem, jobs[0]['mem'])
Esempio n. 15
0
 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)
Esempio n. 16
0
 def test_name_default(self):
     cp, uuids = cli.submit('ls', 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('%s_job' % os.environ['USER'], jobs[0]['name'])