def test_parse_no_add_on(self):
        flist = cli_mock.create_file('host1\nhost2\nleft2')
        ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
        sys.argv = ['atest', '-U', ulist.name,
                    '--kill-on-failure', '-M', flist.name]
        self.atest.parser.add_option('-M', '--mlist', type='string')
        self.atest.parser.add_option('-U', '--ulist', type='string')
        self.atest.parser.add_option('-u', '--user', type='string')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 filename_option='mlist',
                                                 use_leftover=True)
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user',
                                                 filename_option='ulist')
        (options, leftover) = self.atest.parse([host_info, user_info])
        self.assertEqualNoOrder(self.atest.hosts,
                                ['left2', 'host1', 'host2'])
        self.assertEqualNoOrder(self.atest.users,
                                ['user1', 'user2', 'user3'])

        self.assertEqual({'mlist': flist.name,
                          'ulist': ulist.name,
                          'user': None,
                          'web_server': None,
                          'parse': False,
                          'parse_delim': '|',
                          'kill_on_failure': True,
                          'verbose': False,
                          'debug': False}, options)
        self.assertEqual(leftover, [])
        flist.clean()
        ulist.clean()
    def test_parse_no_flist_add_on(self):
        sys.argv = [
            'atest', '-g', '--parse', '-u', 'myuser,youruser',
            '--kill-on-failure', 'left1', 'left2'
        ]
        self.atest.parser.add_option('-M', '--mlist', type='string')
        self.atest.parser.add_option('-U', '--ulist', type='string')
        self.atest.parser.add_option('-u', '--user', type='string')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 use_leftover=True)
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([host_info, user_info])
        self.assertEqualNoOrder(self.atest.hosts, ['left1', 'left2'])
        self.assertEqualNoOrder(self.atest.users, ['myuser', 'youruser'])

        self.assertEqual(
            {
                'mlist': None,
                'ulist': None,
                'user': '******',
                'web_server': None,
                'parse': True,
                'parse_delim': '|',
                'kill_on_failure': True,
                'verbose': False,
                'debug': True
            }, options)
        self.assertEqual(leftover, [])
    def test_parse_no_add_on_2(self):
        flist = cli_mock.create_file('host1\nhost2\nleft2')
        ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
        sys.argv = [
            'atest', '-U', ulist.name, '--kill-on-failure', '-M', flist.name
        ]
        self.atest.parser.add_option('-M', '--mlist', type='string')
        self.atest.parser.add_option('-U', '--ulist', type='string')
        self.atest.parser.add_option('-u', '--user', type='string')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 filename_option='mlist',
                                                 use_leftover=True)
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user',
                                                 filename_option='ulist')
        (options, leftover) = self.atest.parse([host_info, user_info])
        self.assertEqualNoOrder(self.atest.hosts, ['left2', 'host1', 'host2'])
        self.assertEqualNoOrder(self.atest.users, ['user1', 'user2', 'user3'])

        self.assertEqual(
            {
                'mlist': flist.name,
                'ulist': ulist.name,
                'user': None,
                'web_server': None,
                'parse': False,
                'parse_delim': '|',
                'kill_on_failure': True,
                'verbose': False,
                'debug': False
            }, options)
        self.assertEqual(leftover, [])
        flist.clean()
        ulist.clean()
    def test_parse_no_flist_no_add_on(self):
        sys.argv = [
            'atest', '-u', 'myuser,youruser', '--kill-on-failure', '-a',
            'acl1,acl2'
        ]
        self.atest.parser.add_option('-u', '--user', type='string')
        self.atest.parser.add_option('-a', '--acl', type='string')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acl')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([user_info, acl_info])
        self.assertEqualNoOrder(self.atest.acls, ['acl1', 'acl2'])
        self.assertEqualNoOrder(self.atest.users, ['myuser', 'youruser'])

        self.assertEqual(
            {
                'user': '******',
                'acl': 'acl1,acl2',
                'web_server': None,
                'parse': False,
                'parse_delim': '|',
                'kill_on_failure': True,
                'verbose': False,
                'debug': False
            }, options)
        self.assertEqual(leftover, [])
Beispiel #5
0
    def parse(self, parse_info=[]):
        host_info = topic_common.item_parse_info(
            attribute_name="hosts", inline_option="machine", filename_option="mlist"
        )
        job_info = topic_common.item_parse_info(attribute_name="jobname", use_leftover=True)
        oth_info = topic_common.item_parse_info(attribute_name="one_time_hosts", inline_option="one_time_hosts")
        label_info = topic_common.item_parse_info(attribute_name="labels", inline_option="labels")

        options, leftover = super(job_create_or_clone, self).parse(
            [host_info, job_info, oth_info, label_info] + parse_info, req_items="jobname"
        )
        self.data = {}
        jobname = getattr(self, "jobname")
        if len(jobname) > 1:
            self.invalid_syntax("Too many arguments specified, only expected " "to receive job name: %s" % jobname)
        self.jobname = jobname[0]

        if options.priority:
            self.data["priority"] = options.priority.capitalize()

        if self.one_time_hosts:
            self.data["one_time_hosts"] = self.one_time_hosts

        if self.labels:
            label_hosts = self.execute_rpc(op="get_hosts", multiple_labels=self.labels)
            for host in label_hosts:
                self.hosts.append(host["hostname"])

        self.data["name"] = self.jobname

        (self.data["hosts"], self.data["meta_hosts"]) = self._parse_hosts(self.hosts)

        self.data["email_list"] = options.email

        return options, leftover
    def test_parse_no_flist_add_on(self):
        sys.argv = ['atest', '-g', '--parse', '-u', 'myuser,youruser',
                    '--kill-on-failure', 'left1', 'left2']
        self.atest.parser.add_option('-M', '--mlist', type='string')
        self.atest.parser.add_option('-U', '--ulist', type='string')
        self.atest.parser.add_option('-u', '--user', type='string')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 use_leftover=True)
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([host_info, user_info])
        self.assertEqualNoOrder(self.atest.hosts,
                                ['left1', 'left2'])
        self.assertEqualNoOrder(self.atest.users,
                                ['myuser', 'youruser'])

        self.assertEqual({'mlist': None,
                          'ulist': None,
                          'user': '******',
                          'web_server': None,
                          'parse': True,
                          'parse_delim': '|',
                          'kill_on_failure': True,
                          'verbose': False,
                          'debug': True}, options)
        self.assertEqual(leftover, [])
Beispiel #7
0
    def parse(self):
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine')

        (options, leftover) = super(acl_list, self).parse([user_info,
                                                           host_info])

        users = getattr(self, 'users')
        hosts = getattr(self, 'hosts')
        acls = getattr(self, 'acls')
        if ((users and (hosts or acls)) or
            (hosts and acls)):
            self.invalid_syntax('Only specify one of --user,'
                                '--machine or ACL')

        if len(users) > 1:
            self.invalid_syntax('Only specify one <user>')
        if len(hosts) > 1:
            self.invalid_syntax('Only specify one <machine>')

        try:
            self.users = users[0]
        except IndexError:
            pass

        try:
            self.hosts = hosts[0]
        except IndexError:
            pass
        return (options, leftover)
Beispiel #8
0
    def parse(self):
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine')

        (options, leftover) = super(acl_list,
                                    self).parse([user_info, host_info])

        users = getattr(self, 'users')
        hosts = getattr(self, 'hosts')
        acls = getattr(self, 'acls')
        if ((users and (hosts or acls)) or (hosts and acls)):
            self.invalid_syntax('Only specify one of --user,'
                                '--machine or ACL')

        if len(users) > 1:
            self.invalid_syntax('Only specify one <user>')
        if len(hosts) > 1:
            self.invalid_syntax('Only specify one <machine>')

        try:
            self.users = users[0]
        except IndexError:
            pass

        try:
            self.hosts = hosts[0]
        except IndexError:
            pass
        return (options, leftover)
    def __init__(self, hostname_required=True):
        """Add to the parser the options common to all the server actions.

        @param hostname_required: True to require the command has hostname
                                  specified. Default is True.
        """
        super(server, self).__init__()

        self.parser.add_option('-r',
                               '--role',
                               help='Name of a role',
                               type='string',
                               default=None,
                               metavar='ROLE')
        self.parser.add_option('-x',
                               '--action',
                               help=('Set to True to apply actions when role '
                                     'or status is changed, e.g., restart '
                                     'scheduler when a drone is removed.'),
                               action='store_true',
                               default=False,
                               metavar='ACTION')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='hostname', use_leftover=True)

        self.hostname_required = hostname_required
Beispiel #10
0
    def parse(self):
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user',
                                                 filename_option='ulist')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        (options, leftover) = super(acl_add_or_remove,
                                    self).parse([user_info, host_info],
                                                req_items='acls')

        if (not getattr(self, 'users', None) and
            not getattr(self, 'hosts', None)):
            self.invalid_syntax('Specify at least one USER or MACHINE')

        return (options, leftover)
    def test_parse_req_items_missing(self):
        sys.argv = ['atest', '-u', 'myuser,youruser', '--kill-on-failure']
        self.atest.parser.add_option('-u', '--user', type='string')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acl')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        self.god.mock_io()
        sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
        self.assertRaises(cli_mock.ExitException, self.atest.parse,
                          [user_info, acl_info], 'acls')
        self.assertEqualNoOrder(self.atest.users, ['myuser', 'youruser'])

        self.assertEqualNoOrder(self.atest.acls, [])
        self.god.check_playback()
        self.god.unmock_io()
Beispiel #12
0
    def __init__(self):
        """Add to the parser the options common to all the
        shard actions"""
        super(shard, self).__init__()

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='shards', use_leftover=True)
    def parse(self):
        """Parse command arguments.
        """
        role_info = topic_common.item_parse_info(attribute_name='role')
        kwargs = {}
        if self.hostname_required:
            kwargs['req_items'] = 'hostname'
        (options, leftover) = super(server, self).parse([role_info], **kwargs)
        if options.web_server:
            self.invalid_syntax('Server actions will access server database '
                                'defined in your local global config. It does '
                                'not rely on RPC, no autotest server needs to '
                                'be specified.')

        # self.hostname is a list. Action on server only needs one hostname at
        # most.
        if ((not self.hostname and self.hostname_required)
                or len(self.hostname) > 1):
            self.invalid_syntax('`server` topic can only manipulate 1 server. '
                                'Use -h to see available options.')
        if self.hostname:
            # Override self.hostname with the first hostname in the list.
            self.hostname = self.hostname[0]
        self.role = options.role
        return (options, leftover)
    def test_parse_add_on(self):
        flist = cli_mock.create_file('host1\nhost2\nleft2')
        sys.argv = [
            'atest', '--web', 'fooweb', '--parse', '--kill-on-failure',
            'left1', 'left2', '-M', flist.name
        ]
        self.atest.parser.add_option('-M', '--mlist', type='string')
        item_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 filename_option='mlist',
                                                 use_leftover=True)
        (options, leftover) = self.atest.parse([item_info])
        self.assertEqualNoOrder(self.atest.hosts,
                                ['left1', 'left2', 'host1', 'host2'])

        self.assertEqual(
            {
                'mlist': flist.name,
                'web_server': 'fooweb',
                'parse': True,
                'parse_delim': '|',
                'kill_on_failure': True,
                'verbose': False,
                'debug': False
            }, options)
        self.assertEqual(leftover, [])
        flist.clean()
Beispiel #15
0
    def parse(self):
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user',
                                                 filename_option='ulist')
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        (options, leftover) = super(acl_add_or_remove,
                                    self).parse([user_info, host_info],
                                                req_items='acls')

        if (not getattr(self, 'users', None)
                and not getattr(self, 'hosts', None)):
            self.invalid_syntax('Specify at least one USER or MACHINE')

        return (options, leftover)
Beispiel #16
0
    def parse(self):
        """Parse command arguments.
        """
        board_info = topic_common.item_parse_info(attribute_name='board')
        (options, leftover) = super(stable_version, self).parse([board_info])

        self.board = options.board
        return (options, leftover)
    def parse(self):
        board_info = topic_common.item_parse_info(attribute_name='board',
                                                  inline_option='board')
        build_info = topic_common.item_parse_info(attribute_name='build',
                                                  inline_option='build')
        pool_info = topic_common.item_parse_info(attribute_name='pool',
                                                 inline_option='pool')
        num_info = topic_common.item_parse_info(attribute_name='num',
                                                inline_option='num')
        check_info = topic_common.item_parse_info(attribute_name='check_hosts',
                                                  inline_option='check_hosts')
        bugs_info = topic_common.item_parse_info(attribute_name='file_bugs',
                                                 inline_option='file_bugs')
        suite_info = topic_common.item_parse_info(attribute_name='name',
                                                  use_leftover=True)
        wait_for_results_info = topic_common.item_parse_info(
            attribute_name='wait_for_results',
            inline_option='wait_for_results')
        delay_minutes_info = topic_common.item_parse_info(
            attribute_name='delay_minutes', inline_option='delay_minutes')

        options, leftover = suite.parse(self, [
            suite_info, board_info, build_info, pool_info, num_info,
            check_info, bugs_info, wait_for_results_info, delay_minutes_info
        ],
                                        req_items='name')
        self.data = {}
        name = getattr(self, 'name')
        if len(name) > 1:
            self.invalid_syntax('Too many arguments specified, only expected '
                                'to receive suite name: %s' % name)
        self.data['suite_name'] = name[0]
        self.data['pool'] = options.pool  # None is OK.
        if options.num is not None:
            warnings.warn('num is deprecated')
        del options.num
        self.data['check_hosts'] = options.check_hosts
        self.data['file_bugs'] = options.file_bugs
        self.data['wait_for_results'] = options.wait_for_results
        self.data['delay_minutes'] = options.delay_minutes
        if options.board:
            self.data['board'] = options.board
        else:
            self.invalid_syntax('--board is required.')
        if options.build:
            self.data['build'] = options.build
        else:
            self.invalid_syntax('--build is required.')

        return options, leftover
Beispiel #18
0
    def parse(self):
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                 inline_option='labels',
                                                 filename_option='blist')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acls',
                                                filename_option='alist')

        (options, leftover) = super(host_create, self).parse([label_info,
                                                              acl_info],
                                                             req_items='hosts')

        self._parse_lock_options(options)
        self.locked = options.lock
        self.platform = getattr(options, 'platform', None)
        if options.protection:
            self.data['protection'] = options.protection
        return (options, leftover)
Beispiel #19
0
    def parse(self):
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels',
                                                  filename_option='blist')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acls',
                                                filename_option='alist')

        (options, leftover) = super(host_create,
                                    self).parse([label_info, acl_info],
                                                req_items='hosts')

        self._parse_lock_options(options)
        self.locked = options.lock
        self.platform = getattr(options, 'platform', None)
        if options.protection:
            self.data['protection'] = options.protection
        return (options, leftover)
    def test_parse_req_items_missing(self):
        sys.argv = ['atest', '-u', 'myuser,youruser', '--kill-on-failure']
        self.atest.parser.add_option('-u', '--user', type='string')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acl')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        self.god.mock_io()
        sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
        self.assertRaises(cli_mock.ExitException,
                          self.atest.parse,
                          [user_info, acl_info],
                          'acls')
        self.assertEqualNoOrder(self.atest.users,
                                ['myuser', 'youruser'])

        self.assertEqualNoOrder(self.atest.acls, [])
        self.god.check_playback()
        self.god.unmock_io()
Beispiel #21
0
    def __init__(self):
        super(atomicgroup, self).__init__()
        self.parser.add_option('-G', '--glist',
                               help='File listing the ATOMIC GROUPs',
                               type='string', default=None,
                               metavar='ATOMIC_GROUP_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='atomicgroups',
            filename_option='glist',
            use_leftover=True)
Beispiel #22
0
    def parse(self, parse_info=[]):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        job_info = topic_common.item_parse_info(attribute_name='jobname',
                                                use_leftover=True)
        oth_info = topic_common.item_parse_info(attribute_name='one_time_hosts',
                                                inline_option='one_time_hosts')
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels')

        options, leftover = super(job_create_or_clone, self).parse(
                [host_info, job_info, oth_info, label_info] + parse_info,
                req_items='jobname')
        self.data = {}
        jobname = getattr(self, 'jobname')
        if len(jobname) > 1:
            self.invalid_syntax('Too many arguments specified, only expected '
                                'to receive job name: %s' % jobname)
        self.jobname = jobname[0]

        if options.priority:
            self.data['priority'] = options.priority.capitalize()

        if self.one_time_hosts:
            self.data['one_time_hosts'] = self.one_time_hosts

        if self.labels:
            label_hosts = self.execute_rpc(op='get_hosts',
                                           multiple_labels=self.labels)
            for host in label_hosts:
                self.hosts.append(host['hostname'])

        self.data['name'] = self.jobname

        (self.data['hosts'],
         self.data['meta_hosts']) = self._parse_hosts(self.hosts)

        self.data['email_list'] = options.email

        return options, leftover
Beispiel #23
0
    def parse(self, parse_info=[]):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        job_info = topic_common.item_parse_info(attribute_name='jobname',
                                                use_leftover=True)
        oth_info = topic_common.item_parse_info(
            attribute_name='one_time_hosts', inline_option='one_time_hosts')
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels')

        options, leftover = super(job_create_or_clone, self).parse(
            [host_info, job_info, oth_info, label_info] + parse_info,
            req_items='jobname')
        self.data = {}
        jobname = getattr(self, 'jobname')
        if len(jobname) > 1:
            self.invalid_syntax('Too many arguments specified, only expected '
                                'to receive job name: %s' % jobname)
        self.jobname = jobname[0]

        if options.priority:
            self.data['priority'] = options.priority.capitalize()

        if self.one_time_hosts:
            self.data['one_time_hosts'] = self.one_time_hosts

        if self.labels:
            label_hosts = self.execute_rpc(op='get_hosts',
                                           multiple_labels=self.labels)
            for host in label_hosts:
                self.hosts.append(host['hostname'])

        self.data['name'] = self.jobname

        (self.data['hosts'],
         self.data['meta_hosts']) = self._parse_hosts(self.hosts)

        self.data['email_list'] = options.email

        return options, leftover
Beispiel #24
0
    def parse(self):
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='label',
                                                  filename_option='label_list')

        options, leftover = super(atomicgroup_add_or_remove,
                                  self).parse([label_info],
                                              req_items='atomicgroups')
        if not getattr(self, 'labels', None):
            self.invalid_syntax('%s %s requires at least one label' %
                                (self.msg_topic, self.usage_action))
        return options, leftover
Beispiel #25
0
    def __init__(self):
        """Add to the parser the options common to all the ACL actions"""
        super(acl, self).__init__()
        self.parser.add_option('-A',
                               '--alist',
                               help='File listing the ACLs',
                               type='string',
                               default=None,
                               metavar='ACL_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='acls', filename_option='alist', use_leftover=True)
    def parse(self):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        (options, leftover) = super(label_add_or_remove,
                                    self).parse([host_info],
                                                req_items='labels')

        if not getattr(self, 'hosts', None):
            self.invalid_syntax('%s %s requires at least one host' %
                                (self.msg_topic, self.usage_action))
        return (options, leftover)
Beispiel #27
0
    def parse(self):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine',
                                                 filename_option='mlist')
        (options, leftover) = super(label_add_or_remove,
                                    self).parse([host_info],
                                                req_items='labels')

        if not getattr(self, 'hosts', None):
            self.invalid_syntax('%s %s requires at least one host' %
                                (self.msg_topic,
                                 self.usage_action))
        return (options, leftover)
Beispiel #28
0
    def __init__(self):
        super(atomicgroup, self).__init__()
        self.parser.add_option('-G',
                               '--glist',
                               help='File listing the ATOMIC GROUPs',
                               type='string',
                               default=None,
                               metavar='ATOMIC_GROUP_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='atomicgroups',
            filename_option='glist',
            use_leftover=True)
Beispiel #29
0
    def parse(self):
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='label',
                                                  filename_option='label_list')

        options, leftover = super(atomicgroup_add_or_remove,
                                  self).parse([label_info],
                                              req_items='atomicgroups')
        if not getattr(self, 'labels', None):
            self.invalid_syntax('%s %s requires at least one label' %
                                (self.msg_topic,
                                 self.usage_action))
        return options, leftover
Beispiel #30
0
    def __init__(self):
        """Add to the parser the options common to all the ACL actions"""
        super(acl, self).__init__()
        self.parser.add_option('-A', '--alist',
                               help='File listing the ACLs',
                               type='string',
                               default=None,
                               metavar='ACL_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='acls',
            filename_option='alist',
            use_leftover=True)
Beispiel #31
0
    def __init__(self):
        """Add to the parser the options common to all the
        stable_version actions.
        """
        super(stable_version_modify, self).__init__()

        self.parser.add_option('-i',
                               '--version',
                               help='Stable version.',
                               type='string',
                               metavar='VERSION')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='board', use_leftover=True)
Beispiel #32
0
    def __init__(self):
        """Add to the parser the options common to all the
        host actions"""
        super(host, self).__init__()

        self.parser.add_option('-M',
                               '--mlist',
                               help='File listing the machines',
                               type='string',
                               default=None,
                               metavar='MACHINE_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='hosts', filename_option='mlist', use_leftover=True)
    def test_parse_no_flist_no_add_on(self):
        sys.argv = ['atest', '-u', 'myuser,youruser', '--kill-on-failure',
                    '-a', 'acl1,acl2']
        self.atest.parser.add_option('-u', '--user', type='string')
        self.atest.parser.add_option('-a', '--acl', type='string')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acl')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([user_info, acl_info])
        self.assertEqualNoOrder(self.atest.acls,
                                ['acl1', 'acl2'])
        self.assertEqualNoOrder(self.atest.users,
                                ['myuser', 'youruser'])

        self.assertEqual({'user': '******',
                          'acl': 'acl1,acl2',
                          'web_server': None,
                          'parse': False,
                          'parse_delim': '|',
                          'kill_on_failure': True,
                          'verbose': False,
                          'debug': False}, options)
        self.assertEqual(leftover, [])
Beispiel #34
0
    def __init__(self):
        """Add to the parser the options common to all the
        stable_version actions.
        """
        super(stable_version, self).__init__()

        self.parser.add_option('-b',
                               '--board',
                               help='Name of the board',
                               type='string',
                               default=None,
                               metavar='BOARD')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='board', use_leftover=True)
Beispiel #35
0
    def parse(self):
        """Consume the options common to host create and host mod.
        """
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels',
                                                  filename_option='blist')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acls',
                                                filename_option='alist')

        (options, leftover) = super(BaseHostModCreate,
                                    self).parse([label_info, acl_info],
                                                req_items='hosts')

        self._parse_lock_options(options)

        if options.protection:
            self.data['protection'] = options.protection
            self.messages.append('Protection set to "%s"' % options.protection)

        self.attributes = {}
        if options.attribute:
            for pair in options.attribute:
                m = re.match(self.attribute_regex, pair)
                if not m:
                    raise topic_common.CliError(
                        'Attribute must be in key=value '
                        'syntax.')
                elif m.group('attribute') in self.attributes:
                    raise topic_common.CliError(
                        'Multiple values provided for attribute '
                        '%s.' % m.group('attribute'))
                self.attributes[m.group('attribute')] = m.group('value')

        self.platform = options.platform
        return (options, leftover)
Beispiel #36
0
    def parse(self):
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels',
                                                  filename_option='blist')
        acl_info = topic_common.item_parse_info(attribute_name='acls',
                                                inline_option='acls',
                                                filename_option='alist')

        (options, leftover) = super(host_create,
                                    self).parse([label_info, acl_info],
                                                req_items='hosts')

        self._parse_lock_options(options)
        self.locked = options.lock
        self.platform = getattr(options, 'platform', None)
        self.serials = getattr(options, 'serials', None)
        if self.serials:
            if len(self.hosts) > 1:
                raise topic_common.CliError('Can not specify serials with '
                                            'multiple hosts')
            self.serials = self.serials.split(',')
        if options.protection:
            self.data['protection'] = options.protection
        return (options, leftover)
Beispiel #37
0
    def __init__(self):
        """Add to the parser the options common to all the
        host actions"""
        super(host, self).__init__()

        self.parser.add_option('-M', '--mlist',
                               help='File listing the machines',
                               type='string',
                               default=None,
                               metavar='MACHINE_FLIST')

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='hosts',
            filename_option='mlist',
            use_leftover=True)
Beispiel #38
0
    def parse(self):
        status_list = topic_common.item_parse_info(attribute_name="status_list", inline_option="list_hosts_status")
        options, leftover = super(job_stat, self).parse([status_list], req_items="jobs")

        if not self.jobs:
            self.invalid_syntax("Must specify at least one job.")

        self.show_control_file = options.control_file
        self.list_hosts = options.list_hosts

        if self.list_hosts and self.status_list:
            self.invalid_syntax("--list-hosts is implicit when using " "--list-hosts-status.")
        if len(self.jobs) > 1 and (self.list_hosts or self.status_list):
            self.invalid_syntax("--list-hosts and --list-hosts-status should " "only be used on a single job.")

        return options, leftover
Beispiel #39
0
    def parse(self):
        """Consume the specific options"""
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='label')

        (options, leftover) = super(host_list, self).parse([label_info])

        self.status = options.status
        self.acl = options.acl
        self.user = options.user
        self.hostnames_only = options.hostnames_only

        if options.locked and options.unlocked:
            self.invalid_syntax('--locked and --unlocked are '
                                'mutually exclusive')
        self.locked = options.locked
        self.unlocked = options.unlocked
        return (options, leftover)
    def parse(self):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine')
        (options, leftover) = super(label_list, self).parse([host_info])

        exclusives = [options.all, options.platform_only]
        if exclusives.count(True) > 1:
            self.invalid_syntax('Only specify one of --all,' '--platform')

        if len(self.hosts) > 1:
            self.invalid_syntax(
                ('Only one machine name allowed. '
                 '''Use '%s host list %s' '''
                 'instead.') % (sys.argv[0], ','.join(self.hosts)))
        self.all = options.all
        self.platform_only = options.platform_only
        self.valid_only = options.valid_only
        return (options, leftover)
    def test_parse_req_items_ok(self):
        sys.argv = ['atest', '-u', 'myuser,youruser']
        self.atest.parser.add_option('-u', '--user', type='string')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([user_info],
                                               req_items='users')
        self.assertEqualNoOrder(self.atest.users,
                                ['myuser', 'youruser'])

        self.assertEqual({'user': '******',
                          'web_server': None,
                          'parse': False,
                          'parse_delim': '|',
                          'kill_on_failure': False,
                          'verbose': False,
                          'debug': False}, options)
        self.assertEqual(leftover, [])
Beispiel #42
0
    def parse(self):
        """Consume the specific options"""
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='label')

        (options, leftover) = super(host_list, self).parse([label_info])

        self.status = options.status
        self.acl = options.acl
        self.user = options.user
        self.hostnames_only = options.hostnames_only

        if options.locked and options.unlocked:
            self.invalid_syntax('--locked and --unlocked are '
                                'mutually exclusive')
        self.locked = options.locked
        self.unlocked = options.unlocked
        return (options, leftover)
    def test_parse_req_items_ok(self):
        sys.argv = ['atest', '-u', 'myuser,youruser']
        self.atest.parser.add_option('-u', '--user', type='string')
        user_info = topic_common.item_parse_info(attribute_name='users',
                                                 inline_option='user')
        (options, leftover) = self.atest.parse([user_info], req_items='users')
        self.assertEqualNoOrder(self.atest.users, ['myuser', 'youruser'])

        self.assertEqual(
            {
                'user': '******',
                'web_server': None,
                'parse': False,
                'parse_delim': '|',
                'kill_on_failure': False,
                'verbose': False,
                'debug': False
            }, options)
        self.assertEqual(leftover, [])
Beispiel #44
0
    def parse(self):
        host_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 inline_option='machine')
        (options, leftover) = super(label_list, self).parse([host_info])

        exclusives = [options.all, options.platform_only, options.atomicgroup]
        if exclusives.count(True) > 1:
            self.invalid_syntax('Only specify one of --all,'
                                '--platform, --atomicgroup')

        if len(self.hosts) > 1:
            self.invalid_syntax(('Only one machine name allowed. '
                                '''Use '%s host list %s' '''
                                 'instead.') %
                                (sys.argv[0], ','.join(self.hosts)))
        self.all = options.all
        self.atomicgroup = options.atomicgroup
        self.platform_only = options.platform_only
        self.valid_only = options.valid_only
        return (options, leftover)
Beispiel #45
0
    def parse(self):
        status_list = topic_common.item_parse_info(
            attribute_name='status_list', inline_option='list_hosts_status')
        options, leftover = super(job_stat, self).parse([status_list],
                                                        req_items='jobs')

        if not self.jobs:
            self.invalid_syntax('Must specify at least one job.')

        self.show_control_file = options.control_file
        self.list_hosts = options.list_hosts

        if self.list_hosts and self.status_list:
            self.invalid_syntax('--list-hosts is implicit when using '
                                '--list-hosts-status.')
        if len(self.jobs) > 1 and (self.list_hosts or self.status_list):
            self.invalid_syntax('--list-hosts and --list-hosts-status should '
                                'only be used on a single job.')

        return options, leftover
    def test_parse_no_add_on(self):
        flist = cli_mock.create_file('host1\nhost2\nleft2')
        sys.argv = ['atest', '--web', 'fooweb', '--parse', '-g',
                    '--kill-on-failure', 'left1', 'left2', '-M', flist.name]
        self.atest.parser.add_option('-M', '--mlist', type='string')
        item_info = topic_common.item_parse_info(attribute_name='hosts',
                                                 filename_option='mlist')
        (options, leftover) = self.atest.parse([item_info])
        self.assertEqualNoOrder(self.atest.hosts,
                                ['left2', 'host1', 'host2'])

        self.assertEqual({'mlist': flist.name,
                          'web_server': 'fooweb',
                          'parse': True,
                          'parse_delim': '|',
                          'kill_on_failure': True,
                          'verbose': False,
                          'debug': True}, options)
        self.assertEqual(leftover, ['left1', 'left2'])
        flist.clean()
Beispiel #47
0
    def __init__(self):
        super(job_list_stat, self).__init__()

        self.topic_parse_info = topic_common.item_parse_info(attribute_name="jobs", use_leftover=True)
Beispiel #48
0
 def parse(self):
     job_info = topic_common.item_parse_info(attribute_name='jobids',
                                             use_leftover=True)
     options, leftover = super(job_abort, self).parse([job_info],
                                                      req_items='jobids')
Beispiel #49
0
    def __init__(self):
        super(job_list_stat, self).__init__()

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name='jobs', use_leftover=True)
Beispiel #50
0
    def parse(self):
        deps_info = topic_common.item_parse_info(attribute_name='dependencies',
                                                 inline_option='dependencies')
        options, leftover = super(job_create,
                                  self).parse(parse_info=[deps_info])

        if (len(self.hosts) == 0 and not self.one_time_hosts
                and not options.labels):
            self.invalid_syntax('Must specify at least one machine.'
                                '(-m, -M, -b or --one-time-hosts).')
        if not options.control_file and not options.test:
            self.invalid_syntax('Must specify either --test or --control-file'
                                ' to create a job.')
        if options.control_file and options.test:
            self.invalid_syntax('Can only specify one of --control-file or '
                                '--test, not both.')
        if options.control_file:
            try:
                control_file_f = open(options.control_file)
                try:
                    control_file_data = control_file_f.read()
                finally:
                    control_file_f.close()
            except IOError:
                self.generic_error('Unable to read from specified '
                                   'control-file: %s' % options.control_file)
            self.data['control_file'] = control_file_data
        if options.test:
            if options.server:
                self.invalid_syntax('If you specify tests, then the '
                                    'client/server setting is implicit and '
                                    'cannot be overriden.')
            tests = [t.strip() for t in options.test.split(',') if t.strip()]
            self.ctrl_file_data['tests'] = tests

        if options.image:
            self.data['image'] = options.image

        if options.reboot_before:
            self.data['reboot_before'] = options.reboot_before.capitalize()
        if options.reboot_after:
            self.data['reboot_after'] = options.reboot_after.capitalize()
        if options.parse_failed_repair:
            self.data['parse_failed_repair'] = (
                options.parse_failed_repair == 'true')
        if options.noverify:
            self.data['run_verify'] = False
        if options.timeout_mins:
            self.data['timeout_mins'] = options.timeout_mins
        if options.max_runtime:
            self.data['max_runtime_mins'] = options.max_runtime

        self.data['dependencies'] = self.dependencies

        if options.synch_count:
            self.data['synch_count'] = options.synch_count
        if options.server:
            self.data['control_type'] = control_data.CONTROL_TYPE_NAMES.SERVER
        else:
            self.data['control_type'] = control_data.CONTROL_TYPE_NAMES.CLIENT

        self.data['require_ssp'] = options.require_ssp

        return options, leftover
Beispiel #51
0
    def parse(self):
        deps_info = topic_common.item_parse_info(attribute_name="dependencies", inline_option="dependencies")
        options, leftover = super(job_create, self).parse(parse_info=[deps_info])

        if len(self.hosts) == 0 and not self.one_time_hosts and not options.labels and not options.atomic_group:
            self.invalid_syntax(
                "Must specify at least one machine " "or an atomic group " "(-m, -M, -b, -G or --one-time-hosts)."
            )
        if not options.control_file and not options.test:
            self.invalid_syntax("Must specify either --test or --control-file" " to create a job.")
        if options.control_file and options.test:
            self.invalid_syntax("Can only specify one of --control-file or " "--test, not both.")
        if options.kernel:
            self.ctrl_file_data["kernel"] = self._get_kernel_data(options.kernel, options.kernel_cmdline)
        if options.control_file:
            try:
                control_file_f = open(options.control_file)
                try:
                    control_file_data = control_file_f.read()
                finally:
                    control_file_f.close()
            except IOError:
                self.generic_error("Unable to read from specified " "control-file: %s" % options.control_file)
            if options.kernel:
                # execute() will pass this to the AFE server to wrap this
                # control file up to include the kernel installation steps.
                self.ctrl_file_data["client_control_file"] = control_file_data
            else:
                self.data["control_file"] = control_file_data
        if options.test:
            if options.server:
                self.invalid_syntax(
                    "If you specify tests, then the " "client/server setting is implicit and " "cannot be overriden."
                )
            tests = [t.strip() for t in options.test.split(",") if t.strip()]
            self.ctrl_file_data["tests"] = tests

        if options.reboot_before:
            self.data["reboot_before"] = options.reboot_before.capitalize()
        if options.reboot_after:
            self.data["reboot_after"] = options.reboot_after.capitalize()
        if options.parse_failed_repair:
            self.data["parse_failed_repair"] = options.parse_failed_repair == "true"
        if options.noverify:
            self.data["run_verify"] = False
        if options.timeout:
            self.data["timeout"] = options.timeout
        if options.max_runtime:
            self.data["max_runtime_hrs"] = options.max_runtime

        if options.atomic_group:
            self.data["atomic_group_name"] = options.atomic_group

        self.data["dependencies"] = self.dependencies

        if options.synch_count:
            self.data["synch_count"] = options.synch_count
        if options.server:
            self.data["control_type"] = "Server"
        else:
            self.data["control_type"] = "Client"

        return options, leftover
Beispiel #52
0
 def parse(self):
     job_info = topic_common.item_parse_info(attribute_name="jobids", use_leftover=True)
     options, leftover = super(job_abort, self).parse([job_info], req_items="jobids")
Beispiel #53
0
    def parse(self):
        host_info = topic_common.item_parse_info(
            attribute_name="hosts", inline_option="machine", filename_option="mlist"
        )
        job_info = topic_common.item_parse_info(attribute_name="jobname", use_leftover=True)
        oth_info = topic_common.item_parse_info(attribute_name="one_time_hosts", inline_option="one_time_hosts")

        options, leftover = super(job_create, self).parse([host_info, job_info, oth_info], req_items="jobname")
        self.data = {}
        if len(self.jobname) > 1:
            self.invalid_syntax("Too many arguments specified, only expected " "to receive job name: %s" % self.jobname)
        self.jobname = self.jobname[0]

        if options.reuse_hosts and not options.clone:
            self.invalid_syntax("--reuse-hosts only to be used with --clone.")
        # If cloning skip parse, parsing is done in execute
        self.clone_id = options.clone
        if options.clone:
            self.op_action = "clone"
            self.msg_items = "jobid"
            self.reuse_hosts = options.reuse_hosts
            return options, leftover

        if len(self.hosts) == 0 and not self.one_time_hosts and not options.labels and not options.atomic_group:
            self.invalid_syntax(
                "Must specify at least one machine " "or an atomic group " "(-m, -M, -b, -G or --one-time-hosts)."
            )
        if not options.control_file and not options.test:
            self.invalid_syntax("Must specify either --test or --control-file" " to create a job.")
        if options.control_file and options.test:
            self.invalid_syntax("Can only specify one of --control-file or " "--test, not both.")
        if options.kernel:
            self.ctrl_file_data["kernel"] = options.kernel
            self.ctrl_file_data["do_push_packages"] = True
        if options.control_file:
            try:
                control_file_f = open(options.control_file)
                try:
                    control_file_data = control_file_f.read()
                finally:
                    control_file_f.close()
            except IOError:
                self.generic_error("Unable to read from specified " "control-file: %s" % options.control_file)
            if options.kernel:
                if options.server:
                    self.invalid_syntax(
                        "A control file and a kernel may only be specified" " together on client side jobs."
                    )
                # execute() will pass this to the AFE server to wrap this
                # control file up to include the kernel installation steps.
                self.ctrl_file_data["client_control_file"] = control_file_data
            else:
                self.data["control_file"] = control_file_data
        if options.test:
            if options.server:
                self.invalid_syntax(
                    "If you specify tests, then the " "client/server setting is implicit and " "cannot be overriden."
                )
            tests = [t.strip() for t in options.test.split(",") if t.strip()]
            self.ctrl_file_data["tests"] = tests

        if options.priority:
            self.data["priority"] = options.priority.capitalize()
        if options.reboot_before:
            self.data["reboot_before"] = options.reboot_before.capitalize()
        if options.reboot_after:
            self.data["reboot_after"] = options.reboot_after.capitalize()
        if options.parse_failed_repair:
            self.data["parse_failed_repair"] = options.parse_failed_repair == "true"
        if options.noverify:
            self.data["run_verify"] = False
        if options.timeout:
            self.data["timeout"] = options.timeout
        if options.max_runtime:
            self.data["max_runtime_hrs"] = options.max_runtime

        if self.one_time_hosts:
            self.data["one_time_hosts"] = self.one_time_hosts
        if options.labels:
            labels = options.labels.split(",")
            labels = [label.strip() for label in labels if label.strip()]
            label_hosts = self.execute_rpc(op="get_hosts", multiple_labels=labels)
            for host in label_hosts:
                self.hosts.append(host["hostname"])

        self.data["name"] = self.jobname

        (self.data["hosts"], self.data["meta_hosts"]) = self.parse_hosts(self.hosts)

        if options.atomic_group:
            self.data["atomic_group_name"] = options.atomic_group

        deps = options.dependencies.split(",")
        deps = [dep.strip() for dep in deps if dep.strip()]
        self.data["dependencies"] = deps

        self.data["email_list"] = options.email
        if options.synch_count:
            self.data["synch_count"] = options.synch_count
        if options.server:
            self.data["control_type"] = "Server"
        else:
            self.data["control_type"] = "Client"

        return options, leftover
Beispiel #54
0
    def parse(self):
        deps_info = topic_common.item_parse_info(attribute_name='dependencies',
                                                 inline_option='dependencies')
        options, leftover = super(job_create, self).parse(
                parse_info=[deps_info])

        if (len(self.hosts) == 0 and not self.one_time_hosts
            and not options.labels and not options.atomic_group):
            self.invalid_syntax('Must specify at least one machine '
                                'or an atomic group '
                                '(-m, -M, -b, -G or --one-time-hosts).')
        if not options.control_file and not options.test:
            self.invalid_syntax('Must specify either --test or --control-file'
                                ' to create a job.')
        if options.control_file and options.test:
            self.invalid_syntax('Can only specify one of --control-file or '
                                '--test, not both.')
        if options.kernel:
            self.ctrl_file_data['kernel'] = self._get_kernel_data(
                    options.kernel, options.kernel_cmdline)
        if options.control_file:
            try:
                control_file_f = open(options.control_file)
                try:
                    control_file_data = control_file_f.read()
                finally:
                    control_file_f.close()
            except IOError:
                self.generic_error('Unable to read from specified '
                                   'control-file: %s' % options.control_file)
            if options.kernel:
                # execute() will pass this to the AFE server to wrap this
                # control file up to include the kernel installation steps.
                self.ctrl_file_data['client_control_file'] = control_file_data
            else:
                self.data['control_file'] = control_file_data
        if options.test:
            if options.server:
                self.invalid_syntax('If you specify tests, then the '
                                    'client/server setting is implicit and '
                                    'cannot be overriden.')
            tests = [t.strip() for t in options.test.split(',') if t.strip()]
            self.ctrl_file_data['tests'] = tests


        if options.reboot_before:
            self.data['reboot_before'] = options.reboot_before.capitalize()
        if options.reboot_after:
            self.data['reboot_after'] = options.reboot_after.capitalize()
        if options.parse_failed_repair:
            self.data['parse_failed_repair'] = (
                options.parse_failed_repair == 'true')
        if options.noverify:
            self.data['run_verify'] = False
        if options.timeout:
            self.data['timeout'] = options.timeout
        if options.max_runtime:
            self.data['max_runtime_hrs'] = options.max_runtime

        if options.atomic_group:
            self.data['atomic_group_name'] = options.atomic_group

        self.data['dependencies'] = self.dependencies

        if options.synch_count:
            self.data['synch_count'] = options.synch_count
        if options.server:
            self.data['control_type'] = 'Server'
        else:
            self.data['control_type'] = 'Client'

        return options, leftover