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({'username': None,
                          'user': '******',
                          'acl': 'acl1,acl2',
                          'web_server': None,
                          'parse': False,
                          'parse_delim': '|',
                          'kill_on_failure': True,
                          'verbose': False,
                          'debug': False}, options)
        self.assertEqual(leftover, [])
Beispiel #2
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 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_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 #5
0
    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()
Beispiel #6
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, [])
    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()
Beispiel #9
0
    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_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 #11
0
    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 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_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()
    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 #15
0
    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 #16
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 #17
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 #18
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 #19
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)
    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 __init__(self):
        """Add to the parser the options common to all the
        label actions"""
        super(label, self).__init__()

        self.parser.add_option(
            "-B", "--blist", help="File listing the labels", type="string", default=None, metavar="LABEL_FLIST"
        )

        self.topic_parse_info = topic_common.item_parse_info(
            attribute_name="labels", filename_option="blist", use_leftover=True
        )
Beispiel #25
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 #26
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 #27
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 #28
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 #29
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 #30
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 #31
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 #32
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 #33
0
    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
        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 #35
0
    def parse(self):
        """Consume the specific options"""
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels',
                                                  filename_option='blist')

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

        self._parse_lock_options(options)
        self.platform = getattr(options, 'platform', None)

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

        return (options, leftover)
Beispiel #36
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 #37
0
    def parse(self):
        """Consume the specific options"""
        label_info = topic_common.item_parse_info(attribute_name='labels',
                                                  inline_option='labels',
                                                  filename_option='blist')

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

        self._parse_lock_options(options)
        self.platform = getattr(options, 'platform', None)

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

        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 #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)
Beispiel #40
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)
Beispiel #41
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)
    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 #43
0
    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 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 #48
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 options.hostless:
            if (self.hosts or self.one_time_hosts or options.labels
                    or options.atomic_group or options.synch_count):
                self.invalid_syntax('If hostless is specified cannot specify'
                                    ' machine, atomic group or synch count'
                                    ' (-m, -M, -b, -G, --synch_count')
        else:
            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, '
                                    'atomic group or hostless'
                                    '(-m, -M, -b, -G, --one-time-hosts '
                                    'or hostless).')
        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,
                config_list=options.kernel_config)
        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'

        if options.hostless:
            self.data['hostless'] = True

        return options, leftover
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):
     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')