Exemplo n.º 1
0
 def test_sleep_flow_failed(self, sleep_mock):
     sleep_mock.side_effect = errors.RESTError()
     result = self.agent_extension.start_flow(flow=FLOW_INFO)
     result.join()
     self.assertEqual(base.AgentCommandStatus.FAILED, result.command_status)
     self.assertIsInstance(result.command_error,
                           errors.CommandExecutionError)
Exemplo n.º 2
0
    def test_RESTError(self):
        e = errors.RESTError()
        d = e.serialize()

        self.assertEqual("RESTError", e.type)
        self.assertEqual(errors.RESTError.status_code, e.code)
        self.assertEqual(errors.RESTError.message, e.message)
        self.assertEqual(errors.RESTError.details, e.details)

        self.assertEqual("RESTError", d['type'])
        self.assertEqual(errors.RESTError.status_code, d['code'])
        self.assertEqual(errors.RESTError.message, d['message'])
        self.assertEqual(errors.RESTError.details, d['details'])
Exemplo n.º 3
0
    def __init__(self, image_info, time_obj=None):
        """Initialize an instance of the ImageDownload class.

        Trys each URL in image_info successively until a URL returns a
        successful request code. Once the object is initialized, the user may
        retrieve chunks of the image through the standard python iterator
        interface until either the image is fully downloaded, or an error is
        encountered.

        :param image_info: Image information dictionary.
        :param time_obj: Optional time object to indicate when the image
                         download began. Defaults to None. If None, then
                         time.time() will be used to find the start time of
                         the download.

        :raises: ImageDownloadError if starting the image download fails for
                 any reason.
        """
        self._time = time_obj or time.time()
        self._image_info = image_info
        self._request = None

        # Determine the hash algorithm and value will be used for calculation
        # and verification, fallback to md5 if algorithm is not set or not
        # supported.
        algo = image_info.get('os_hash_algo')
        if algo and algo in hashlib.algorithms_available:
            self._hash_algo = hashlib.new(algo)
            self._expected_hash_value = image_info.get('os_hash_value')
        elif image_info.get('checksum'):
            self._hash_algo = hashlib.md5()
            self._expected_hash_value = image_info['checksum']
        else:
            message = ('Unable to verify image {} with available checksums. '
                       'Please make sure the specified \'os_hash_algo\' '
                       '(currently {}) is supported by this ramdisk, or '
                       'provide a md5 checksum via the \'checksum\' '
                       'field'.format(image_info['id'],
                                      image_info.get('os_hash_algo')))
            LOG.error(message)
            raise errors.RESTError(details=message)

        self._expected_hash_value = _fetch_checksum(self._expected_hash_value,
                                                    image_info)

        details = []
        for url in image_info['urls']:
            try:
                LOG.info("Attempting to download image from {}".format(url))
                self._request = _download_with_proxy(image_info, url,
                                                     image_info['id'])
            except errors.ImageDownloadError as e:
                failtime = time.time() - self._time
                log_msg = ('URL: {}; time: {} '
                           'seconds. Error: {}').format(
                               url, failtime, e.secondary_message)
                LOG.warning(log_msg)
                details.append(log_msg)
                continue
            else:
                break
        else:
            details = '\n '.join(details)
            raise errors.ImageDownloadError(image_info['id'], details)
Exemplo n.º 4
0
 def test_RESTError_details(self):
     e = errors.RESTError(DETAILS)
     self.assertEqual("RESTError", e.type)
     self.assertEqual(500, e.code)
     self.assertEqual(errors.RESTError.message, e.message)
     self.assertEqual(DETAILS, e.details)