Beispiel #1
0
 def test_retries(self):
     # Default retries = 2
     cp, uuids = cli.submit('-- ls -al', 'localhost:99999', '--verbose')
     stderr = cli.decode(cp.stderr)
     self.assertEqual(1, cp.returncode, stderr)
     self.assertIn('Starting new HTTP connection (1)', stderr)
     self.assertIn('Starting new HTTP connection (2)', stderr)
     self.assertIn('Starting new HTTP connection (3)', stderr)
     self.assertNotIn('Starting new HTTP connection (4)', stderr)
     # Set retries = 0
     config = {'http': {'retries': 0}}
     with cli.temp_config_file(config) as path:
         cp, uuids = cli.submit('-- ls -al', 'localhost:99999',
                                '--verbose --config %s' % path)
         stderr = cli.decode(cp.stderr)
         self.assertEqual(1, cp.returncode, stderr)
         self.assertIn('Starting new HTTP connection (1)', stderr)
         self.assertNotIn('Starting new HTTP connection (2)', stderr)
     # Set retries = 4
     config = {'http': {'retries': 4}}
     with cli.temp_config_file(config) as path:
         cp, uuids = cli.submit('-- ls -al', 'localhost:99999',
                                '--verbose --config %s' % path)
         stderr = cli.decode(cp.stderr)
         self.assertEqual(1, cp.returncode, stderr)
         self.assertIn('Starting new HTTP connection (1)', stderr)
         self.assertIn('Starting new HTTP connection (2)', stderr)
         self.assertIn('Starting new HTTP connection (3)', stderr)
         self.assertIn('Starting new HTTP connection (4)', stderr)
         self.assertIn('Starting new HTTP connection (5)', stderr)
         self.assertNotIn('Starting new HTTP connection (6)', stderr)
Beispiel #2
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))
Beispiel #3
0
 def test_no_cluster(self):
     config = {'clusters': []}
     with cli.temp_config_file(config) as path:
         flags = '--config %s' % path
         cp, uuids = cli.submit('ls', flags=flags)
         self.assertEqual(1, cp.returncode, cp.stderr)
         self.assertIn('must specify at least one cluster',
                       cli.decode(cp.stderr))
Beispiel #4
0
 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)
Beispiel #5
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))
Beispiel #6
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))
Beispiel #7
0
    def test_multicluster_usage(self):
        pools_1, _ = util.all_pools(self.cook_url_1)
        pools_2, _ = util.all_pools(self.cook_url_2)
        pools = pools_1 + pools_2
        user = '******'

        half_of_the_pools = [pool['name'] for pool in pools[:len(pools) // 2]]
        expected_pools_1 = set(half_of_the_pools) & set(
            [pool['name'] for pool in pools_1])
        expected_pools_2 = set(half_of_the_pools) & set(
            [pool['name'] for pool in pools_2])

        config = self.__two_cluster_config()
        with cli.temp_config_file(config) as path:
            # filter half
            cp, usage = cli.usage(user,
                                  None,
                                  ' '.join(f'--pool {pool}'
                                           for pool in half_of_the_pools),
                                  flags='--config %s' % path)
            self.assertEqual(0, cp.returncode, cp.stderr)
            if expected_pools_1:
                self.assertEqual(
                    set(usage['clusters']['cook1']['pools'].keys()),
                    expected_pools_1)
            if expected_pools_2:
                self.assertEqual(
                    set(usage['clusters']['cook2']['pools'].keys()),
                    expected_pools_2)
            self.assertEqual('', cli.decode(cp.stderr))

            # filter half with one bad pool
            cp, usage = cli.usage(user,
                                  None,
                                  '-p zzzz ' +
                                  ' '.join(f'--pool {pool}'
                                           for pool in half_of_the_pools),
                                  flags='--config %s' % path)
            self.assertEqual(0, cp.returncode, cp.stderr)
            if expected_pools_1:
                self.assertEqual(
                    set(usage['clusters']['cook1']['pools'].keys()),
                    expected_pools_1)
            if expected_pools_2:
                self.assertEqual(
                    set(usage['clusters']['cook2']['pools'].keys()),
                    expected_pools_2)
            self.assertIn("zzzz is not a valid pool in ",
                          cli.decode(cp.stderr))

            # filter half with two bad pools
            cp, usage = cli.usage(user,
                                  None,
                                  '-p zzzz -p zzzzx ' +
                                  ' '.join(f'--pool {pool}'
                                           for pool in half_of_the_pools),
                                  flags='--config %s' % path)
            self.assertEqual(0, cp.returncode, cp.stderr)
            if expected_pools_1:
                self.assertEqual(
                    set(usage['clusters']['cook1']['pools'].keys()),
                    expected_pools_1)
            if expected_pools_2:
                self.assertEqual(
                    set(usage['clusters']['cook2']['pools'].keys()),
                    expected_pools_2)
            self.assertIn(" are not valid pools in ", cli.decode(cp.stderr))
Beispiel #8
0
 def test_list_invalid_state(self):
     cp = cli.list_jobs(self.cook_url, '--state foo')
     self.assertEqual(2, cp.returncode, cp.stderr)
     self.assertIn("invalid choice: 'foo'", cli.decode(cp.stderr))
Beispiel #9
0
 def test_submit_raw_should_error_if_command_is_given(self):
     cp, _ = cli.submit('ls', self.cook_url, submit_flags='--raw')
     self.assertEqual(1, cp.returncode, cp.stderr)
     self.assertIn(
         'cannot specify a command at the command line when using --raw/-r',
         cli.decode(cp.stderr))
Beispiel #10
0
 def test_show_requires_at_least_one_uuid(self):
     cp = cli.show([], self.cook_url)
     self.assertEqual(2, cp.returncode, cp.stderr)
     self.assertIn('the following arguments are required: uuid',
                   cli.decode(cp.stderr))
Beispiel #11
0
 def test_submit_raw_invalid(self):
     cp, _ = cli.submit(stdin=cli.encode('1'),
                        cook_url=self.cook_url,
                        submit_flags='--raw')
     self.assertEqual(1, cp.returncode, cp.stderr)
     self.assertIn('malformed JSON for raw', cli.decode(cp.stderr))
Beispiel #12
0
 def test_error_if_both_cluster_and_url_specified(self):
     cp, _ = cli.submit('ls', flags='--cluster foo --url bar')
     self.assertEqual(1, cp.returncode, cp.stderr)
     self.assertIn('cannot specify both a cluster name and a cluster url',
                   cli.decode(cp.stderr))