Example #1
0
    def contact_lifeguard(self):
        device_request_data = {}
        request_config = data.request_config(self.machine.request_id)

        # Determine if we are imaging or just rebooting.
        # We need to pass boot_config as a JSON string, but verify that it's
        # a non-null object.
        if json.loads(request_config['boot_config']):
            event = 'please_pxe_boot'
            device_request_data['boot_config'] = request_config['boot_config']
            # FIXME: differentiate between b2g builds and other (future) image
            # types.
            device_request_data['pxe_config'] = config.get('mozpool',
                                                           'b2g_pxe_config')
        else:
            event = 'please_power_cycle'

        device_url = 'http://%s/api/device/%s/event/%s/' % (
            data.get_server_for_device(request_config['assigned_device']),
            request_config['assigned_device'], event)

        # FIXME: make this asynchronous so slow/missing servers don't halt
        # the state machine.
        try:
            urllib.urlopen(device_url, json.dumps(device_request_data))
        except IOError:
            logs.request_logs.add(self.machine.request_id,
                                  "could not contact lifeguard server at %s" %
                                  device_url)
            return False
        return True
Example #2
0
    def contact_lifeguard(self):
        device_request_data = {}
        request_config = data.request_config(self.machine.request_id)

        # Determine if we are imaging or just rebooting.
        # We need to pass boot_config as a JSON string, but verify that it's
        # a non-null object.
        if json.loads(request_config['boot_config']):
            event = 'please_pxe_boot'
            device_request_data['boot_config'] = request_config['boot_config']
            # FIXME: differentiate between b2g builds and other (future) image
            # types.
            device_request_data['pxe_config'] = config.get(
                'mozpool', 'b2g_pxe_config')
        else:
            event = 'please_power_cycle'

        device_url = 'http://%s/api/device/%s/event/%s/' % (
            data.get_server_for_device(request_config['assigned_device']),
            request_config['assigned_device'], event)

        # FIXME: make this asynchronous so slow/missing servers don't halt
        # the state machine.
        try:
            urllib.urlopen(device_url, json.dumps(device_request_data))
        except IOError:
            logs.request_logs.add(
                self.machine.request_id,
                "could not contact lifeguard server at %s" % device_url)
            return False
        return True
Example #3
0
 def wrapped(self, id, *args):
     try:
         server = data.get_server_for_device(id)
     except data.NotFound:
         raise web.notfound()
     if server != config.get('server', 'fqdn'):
         raise web.found("http://%s%s" % (server, web.ctx.path))
     # otherwise, send an access-control header, so that pages in other domains can
     # call this API endpoint without trouble
     fqdns = data.all_imaging_servers()
     origins = [ 'http://%s' % fqdn for fqdn in fqdns ]
     web.header('Access-Control-Allow-Origin', ' '.join(origins))
     return function(self, id, *args)
Example #4
0
 def free_device(self):
     assigned_device = data.get_assigned_device(self.machine.request_id)
     if assigned_device:
         device_url = 'http://%s/api/device/%s/event/free/' % (
             data.get_server_for_device(assigned_device), assigned_device)
         # FIXME: make this asynchronous so slow/missing servers don't halt
         # the state machine.
         try:
             requests.post(device_url)
         except (requests.ConnectionError, requests.Timeout,
                 requests.HTTPError):
             self.logger.warn('Could not contact lifeguard server at %s to '
                              'free device.' % device_url)
             return False
     return True
Example #5
0
 def wrapped(self, id, *args):
     try:
         server = data.get_server_for_device(id)
     except data.NotFound:
         raise web.notfound()
     if server != config.get('server', 'fqdn'):
         raise web.found("http://%s%s" % (server, web.ctx.path))
     # send an appropriate access-control header, if necessary
     origin = web.ctx.environ.get('HTTP_ORIGIN')
     if origin and origin.startswith('http://'):
         origin_hostname = origin[7:]
         fqdns = data.all_imaging_servers()
         if origin_hostname not in fqdns:
             raise web.Forbidden
         web.header('Access-Control-Allow-Origin', origin)
     return function(self, id, *args)
Example #6
0
 def free_device(self):
     assigned_device = data.get_assigned_device(self.machine.request_id)
     if assigned_device:
         device_url = 'http://%s/api/device/%s/event/free/' % (
             data.get_server_for_device(assigned_device), assigned_device)
         # FIXME: make this asynchronous so slow/missing servers don't halt
         # the state machine.
         try:
             requests.post(device_url)
         except (requests.ConnectionError, requests.Timeout,
                 requests.HTTPError):
             logs.request_logs.add(
                 self.machine.request_id,
                 "could not contact lifeguard server at %s to free device" %
                 device_url)
             return False
     return True
Example #7
0
    def contact_lifeguard(self, request_config):
        # If the requested image is reusable and we got a device with that
        # image and the requested bootconfig, just power cycle it.
        # Otherwise, image it.  Note that there will be a failure if the
        # image is not installed and the device is not imageable.
        event = ''
        device_request_data = {}
        assigned_device_name = request_config['assigned_device']

        if data.image_is_reusable(request_config['image']):
            device_config = data.device_config(request_config['assigned_device'])
            if (device_config['image'] == request_config['image'] and
                data.from_json(device_config['boot_config']) ==
                data.from_json(request_config['boot_config'])):
                event = 'please_power_cycle'

        if not event:
            # Use the device's hardware type and requested image to find the
            # pxe config, if any.
            event = 'please_image'
            device_request_data['boot_config'] = request_config['boot_config']
            device_request_data['image'] = request_config['image']

        device_url = 'http://%s/api/device/%s/event/%s/' % (
            data.get_server_for_device(assigned_device_name),
            assigned_device_name, event)

        # FIXME: make this asynchronous so slow/missing servers don't halt
        # the state machine.
        try:
            urllib.urlopen(device_url, json.dumps(device_request_data))
        except IOError:
            self.logger.warn('Could not contact lifeguard server at %s' %
                             device_url)
            return False
        return True