コード例 #1
0
ファイル: topic_common.py プロジェクト: spcui/autotest
    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
        self.username = options.username
        try:
            self.afe = rpc.afe_comm(self.web_server, username=self.username)
        except rpc.AuthError, s:
            self.failure(str(s), fatal=True)
コード例 #2
0
ファイル: topic_common.py プロジェクト: autotest/autotest
    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
        self.username = options.username
        try:
            self.afe = rpc.afe_comm(self.web_server, username=self.username)
        except rpc.AuthError, s:
            self.failure(str(s), fatal=True)
コード例 #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, '')
コード例 #4
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)
コード例 #5
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, '')
コード例 #6
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))
     errors = mytest.failed
     (out, err) = self.god.unmock_io()
     self.god.check_playback()
     return (out, err, errors)
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
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
コード例 #10
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
コード例 #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
コード例 #12
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)
コード例 #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
コード例 #14
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
コード例 #15
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, "")
コード例 #16
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.
コード例 #17
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.
コード例 #18
0
 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']
コード例 #19
0
 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']