def test_atest_list_execute_filters_wildcard(self):
     filters = {}
     check_results = {}
     filters['name__in'] = ['label*']
     check_results['name__in'] = 'name'
     values = [{u'id': 180,
                u'platform': False,
                u'name': u'label0',
                u'invalid': False,
                u'kernel_config': u''},
               {u'id': 338,
                u'platform': False,
                u'name': u'label1',
                u'invalid': False,
                u'kernel_config': u''}]
     mytest = action_common.atest_list()
     mytest.afe = rpc.afe_comm()
     self.mock_rpcs([('get_labels', {'name__startswith': 'label'},
                      True, values)])
     self.god.mock_io()
     self.assertEqual(values,
                      mytest.execute(op='get_labels',
                                     filters=filters,
                                     check_results=check_results))
     (out, err) = self.god.unmock_io()
     self.god.check_playback()
     self.assertEqual(err, '')
    def construct_without_parse(
            cls,
            web_server,
            hosts,
            platform=None,
            locked=False,
            lock_reason='',
            labels=[],
            acls=[],
            protection=host_protections.Protection.NO_PROTECTION):
        """Construct a host_create object and fill in data from args.

        Do not need to call parse after the construction.

        Return an object of site_host_create ready to execute.

        @param web_server: A string specifies the autotest webserver url.
            It is needed to setup comm to make rpc.
        @param hosts: A list of hostnames as strings.
        @param platform: A string or None.
        @param locked: A boolean.
        @param lock_reason: A string.
        @param labels: A list of labels as strings.
        @param acls: A list of acls as strings.
        @param protection: An enum defined in host_protections.
        """
        obj = cls()
        obj.web_server = web_server
        try:
            # Setup stuff needed for afe comm.
            obj.afe = rpc.afe_comm(web_server)
        except rpc.AuthError, s:
            obj.failure(str(s), fatal=True)
Exemple #3
0
 def test_atest_list_execute_filters_wildcard(self):
     filters = {}
     check_results = {}
     filters['name__in'] = ['label*']
     check_results['name__in'] = 'name'
     values = [{
         u'id': 180,
         u'platform': False,
         u'name': u'label0',
         u'invalid': False,
         u'kernel_config': u''
     }, {
         u'id': 338,
         u'platform': False,
         u'name': u'label1',
         u'invalid': False,
         u'kernel_config': u''
     }]
     mytest = action_common.atest_list()
     mytest.afe = rpc.afe_comm()
     self.mock_rpcs([('get_labels', {
         'name__startswith': 'label'
     }, True, values)])
     self.god.mock_io()
     self.assertEqual(
         values,
         mytest.execute(op='get_labels',
                        filters=filters,
                        check_results=check_results))
     (out, err) = self.god.unmock_io()
     self.god.check_playback()
     self.assertEqual(err, '')
    def parse_global(self):
        """Parse the global arguments.

        It consumes what the common object needs to know, and
        let the children look at all the options.  We could
        remove the options that we have used, but there is no
        harm in leaving them, and the children may need them
        in the future.

        Must be called from its children parse()"""
        (options, leftover) = self.parser.parse_args()
        # Handle our own options setup in __init__()
        self.debug = options.debug
        self.kill_on_failure = options.kill_on_failure

        if options.parse:
            suffix = '_parse'
        else:
            suffix = '_std'
        for func in [
                'print_fields', 'print_table', 'print_by_ids', 'print_list'
        ]:
            setattr(self, func, getattr(self, func + suffix))

        self.parse_delim = options.parse_delim

        self.verbose = options.verbose
        self.no_confirmation = options.no_confirmation
        self.web_server = options.web_server
        try:
            self.afe = rpc.afe_comm(self.web_server)
        except rpc.AuthError, s:
            self.failure(str(s), fatal=True)
 def _atest_list_execute(self, filters={}, check_results={}):
     values = [{u'id': 180,
                u'platform': 0,
                u'name': u'label0',
                u'invalid': 0,
                u'kernel_config': u''},
               {u'id': 338,
                u'platform': 0,
                u'name': u'label1',
                u'invalid': 0,
                u'kernel_config': u''}]
     mytest = action_common.atest_list()
     mytest.afe = rpc.afe_comm()
     self.mock_rpcs([('get_labels',
                      filters,
                      True,
                      values)])
     self.god.mock_io()
     self.assertEqual(values,
                      mytest.execute(op='get_labels',
                                     filters=filters,
                                     check_results=check_results))
     (out, err) = self.god.unmock_io()
     self.god.check_playback()
     return (out, err)
Exemple #6
0
    def parse_global(self):
        """Parse the global arguments.

        It consumes what the common object needs to know, and
        let the children look at all the options.  We could
        remove the options that we have used, but there is no
        harm in leaving them, and the children may need them
        in the future.

        Must be called from its children parse()"""
        (options, leftover) = self.parser.parse_args()
        # Handle our own options setup in __init__()
        self.debug = options.debug
        self.kill_on_failure = options.kill_on_failure

        if options.parse:
            suffix = '_parse'
        else:
            suffix = '_std'
        for func in ['print_fields', 'print_table',
                     'print_by_ids', 'print_list']:
            setattr(self, func, getattr(self, func + suffix))

        self.parse_delim = options.parse_delim

        self.verbose = options.verbose
        self.web_server = options.web_server
        try:
            self.afe = rpc.afe_comm(self.web_server)
        except rpc.AuthError, s:
            self.failure(str(s), fatal=True)
Exemple #7
0
 def _atest_list_execute(self, filters={}, check_results={}):
     values = [{
         u'id': 180,
         u'platform': 0,
         u'name': u'label0',
         u'invalid': 0,
         u'kernel_config': u''
     }, {
         u'id': 338,
         u'platform': 0,
         u'name': u'label1',
         u'invalid': 0,
         u'kernel_config': u''
     }]
     mytest = action_common.atest_list()
     mytest.afe = rpc.afe_comm()
     self.mock_rpcs([('get_labels', filters, True, values)])
     self.god.mock_io()
     self.assertEqual(
         values,
         mytest.execute(op='get_labels',
                        filters=filters,
                        check_results=check_results))
     (out, err) = self.god.unmock_io()
     self.god.check_playback()
     return (out, err)
 def test_execute_rpc_bad_server(self):
     self.atest.afe = rpc.afe_comm('http://does_not_exist')
     self.god.mock_io()
     rpc.afe_comm.run.expect_call('myop').and_raises(urllib2.URLError("<urlopen error (-2, 'Name or service not known')>"))
     sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
     self.assertRaises(cli_mock.ExitException,
                       self.atest.execute_rpc, 'myop')
     (output, err) = self.god.unmock_io()
     self.god.check_playback()
     self.assert_(err.find('http://does_not_exist') >= 0)
    def _create_cr_del(self, items):
        def _items():
            return items
        crdel = action_common.atest_create_or_delete()
        crdel.afe = rpc.afe_comm()

        crdel.topic =  crdel.usage_topic = 'label'
        crdel.op_action = 'add'
        crdel.get_items = _items
        crdel.data['platform'] = False
        crdel.data_item_key = 'name'
        return crdel
 def test_execute_rpc_bad_server(self):
     self.atest.afe = rpc.afe_comm('http://does_not_exist')
     self.god.mock_io()
     rpc.afe_comm.run.expect_call('myop').and_raises(
         urllib2.URLError(
             "<urlopen error (-2, 'Name or service not known')>"))
     sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
     self.assertRaises(cli_mock.ExitException, self.atest.execute_rpc,
                       'myop')
     (output, err) = self.god.unmock_io()
     self.god.check_playback()
     self.assert_(err.find('http://does_not_exist') >= 0)
Exemple #11
0
    def _create_cr_del(self, items):
        def _items():
            return items

        crdel = action_common.atest_create_or_delete()
        crdel.afe = rpc.afe_comm()

        crdel.topic = crdel.usage_topic = 'label'
        crdel.op_action = 'add'
        crdel.get_items = _items
        crdel.data['platform'] = False
        crdel.data_item_key = 'name'
        return crdel
    def _create_add_remove(self, items, users=None, hosts=None):
        def _items():
            return [items]
        addrm = action_common.atest_add_or_remove()
        addrm.afe = rpc.afe_comm()
        if users:
            addrm.users = users
        if hosts:
            addrm.hosts = hosts

        addrm.topic = 'acl_group'
        addrm.msg_topic = 'ACL'
        addrm.op_action = 'add'
        addrm.msg_done = 'Added to'
        addrm.get_items = _items
        return addrm
Exemple #13
0
    def _create_add_remove(self, items, users=None, hosts=None):
        def _items():
            return [items]

        addrm = action_common.atest_add_or_remove()
        addrm.afe = rpc.afe_comm()
        if users:
            addrm.users = users
        if hosts:
            addrm.hosts = hosts

        addrm.topic = 'acl_group'
        addrm.msg_topic = 'ACL'
        addrm.op_action = 'add'
        addrm.msg_done = 'Added to'
        addrm.get_items = _items
        return addrm
import sys, optparse, traceback, pwd, os
import common
from autotest_lib.cli import rpc, host

usage = 'usage: %prog [options] new_protection_level machine1 machine2 ...'
parser = optparse.OptionParser(usage=usage)
parser.add_option('-w', '--web',
                  help='Autotest server to use (i.e. "autotest")')

options, leftover_args = parser.parse_args()
assert len(leftover_args) > 1, 'Must pass protection level and hosts'
protection_level = leftover_args[0]

user = pwd.getpwuid(os.getuid())[0]
autotest_host = rpc.get_autotest_server(options.web)
afe_proxy = rpc.afe_comm(autotest_host, '/afe/server/noauth/rpc/')

hosts = afe_proxy.run('get_hosts', hostname__in=leftover_args[1:])
for host in hosts:
    try:
        afe_proxy.run('modify_host', host['id'], protection=protection_level)
    except Exception, exc:
        print 'For host %s:', host['hostname']
        traceback.print_exc()
    else:
        print 'Host %s succeeded' % host['hostname']

print 'Invalid hosts:'
print ','.join(set(leftover_args[1:]) - set(host['hostname'] for host in hosts))
parser = optparse.OptionParser(
    usage='Usage: %prog [options] <job id> [<hostname>]\n\n'
          'Describes why the given job on the given host has not started.')
parser.add_option('-w', '--web',
                  help='Autotest server to use (i.e. "autotest")')
options, args = parser.parse_args()

if len(args) < 1:
    parser.print_help()
    sys.exit(1)

job_id = int(args[0])

autotest_host = rpc.get_autotest_server(options.web)
proxy = rpc.afe_comm(autotest_host)

# job exists?
jobs = proxy.run('get_jobs', id=job_id)
if not jobs:
    print 'No such job', job_id
    sys.exit(1)
job = jobs[0]
owner = job['owner']

RUNNING_HQE_STATUSES = host_queue_entry_states.ACTIVE_STATUSES

# any entry eligible for this host?
queue_entries = proxy.run('get_host_queue_entries', job__id=job_id)

### Divine why an atomic group job is or is not running.
 def setUp(self):
     super(atest_unittest, self).setUp()
     self.atest = topic_common.atest()
     self.atest.afe = rpc.afe_comm()
     if 'AUTOTEST_WEB' in os.environ:
         del os.environ['AUTOTEST_WEB']
 def setUp(self):
     super(atest_unittest, self).setUp()
     self.atest = topic_common.atest()
     self.atest.afe = rpc.afe_comm()
     if 'AUTOTEST_WEB' in os.environ:
         del os.environ['AUTOTEST_WEB']
Exemple #18
0
parser = optparse.OptionParser(
    usage='Usage: %prog [options] <job id> [<hostname>]\n\n'
    'Describes why the given job on the given host has not started.')
parser.add_option('-w',
                  '--web',
                  help='Autotest server to use (i.e. "autotest")')
options, args = parser.parse_args()

if len(args) < 1:
    parser.print_help()
    sys.exit(1)

job_id = int(args[0])

autotest_host = rpc.get_autotest_server(options.web)
proxy = rpc.afe_comm(autotest_host)

# job exists?
jobs = proxy.run('get_jobs', id=job_id)
if not jobs:
    print 'No such job', job_id
    sys.exit(1)
job = jobs[0]
owner = job['owner']

RUNNING_HQE_STATUSES = host_queue_entry_states.ACTIVE_STATUSES

# any entry eligible for this host?
queue_entries = proxy.run('get_host_queue_entries', job__id=job_id)

### Divine why an atomic group job is or is not running.