示例#1
0
    def _do_run_queue(self, first_elem):
        ''' Actually run first element in queue '''

        # Make a copy of current settings
        conf = CONFIG.copy()

        # Make sure we abide to M-Lab policy
        if privacy.count_valid(conf, 'privacy.') != 3:
            privacy.complain()
            raise RuntimeError('runner_core: bad privacy settings')

        elif first_elem[0] == 'rendezvous':
            runner_rendezvous.run(conf['agent.master'], '9773')

        elif first_elem[0] == 'speedtest':
            uri = RUNNER_TESTS.test_to_negotiate_uri('speedtest')
            conf['speedtest.client.uri'] =  uri
            client = ClientSpeedtest(POLLER)
            client.configure(conf)
            client.connect_uri()

        elif first_elem[0] == 'bittorrent':
            uri = RUNNER_TESTS.test_to_negotiate_uri('bittorrent')
            conf['bittorrent._uri'] =  uri
            bittorrent.run(POLLER, conf)

        elif first_elem[0] == 'dload':
            RunnerDload(first_elem[2])

        elif first_elem[0] == 'raw':
            address = RUNNER_HOSTS.get_random_host()
            handler = RawNegotiate()
            handler.connect((address, 8080), CONFIG['prefer_ipv6'], 0, {})

        elif first_elem[0] == 'mlab-ns':
            handler = RunnerMlabns()
            if not first_elem[2]:
                extra = {'policy': ''}  # get closest server by default
            else:
                extra = first_elem[2]
            handler.connect(('mlab-ns.appspot.com', 80),
              CONFIG['prefer_ipv6'], 0, extra)

        elif first_elem[0] in self.dynamic_tests:
            address = RUNNER_HOSTS.get_random_host()
            port = 80  # XXX
            self.dynamic_tests[first_elem[0]]["test_func"]({
                "address": address,
                "conf": CONFIG.copy(),
                "poller": POLLER,
                "port": port,
            })

        else:
            raise RuntimeError('runner_core: asked to run an unknown test')
示例#2
0
 def handle_end_of_body(self, stream):
     HttpClient.handle_end_of_body(self, stream)
     context = stream.opaque
     extra = context.extra
     if extra['requests'] <= 0:
         raise RuntimeError('runner_mlabns: unexpected response')
     extra['requests'] -= 1
     tmp = context.headers.get(CONTENT_TYPE)
     if context.code != CODE200 or tmp != APPLICATION_JSON:
         logging.error('runner_mlabns: bad response')
         stream.close()
         return
     content = six.bytes_to_string(context.body.getvalue(), 'utf-8')
     response = json.loads(content)
     http_utils.prettyprint_json(response, '<')
     if extra['policy'] == 'random':
         RUNNER_HOSTS.set_random_host(response)
     else:
         RUNNER_HOSTS.set_closest_host(response)
     stream.close()
示例#3
0
 def test_to_negotiate_uri(self, test):
     ''' Map test to its negotiate URI '''
     if test in self.avail:
         # Do not cache results (see runner_hosts comment on that)
         result = self.avail[test][0]
         self.avail.clear()
         return result
     else:
         fqdn = RUNNER_HOSTS.get_random_static_host()
         endpoint = (fqdn, 8080)
         uri = 'http://%s/' % utils_net.format_epnt(endpoint)
         return uri