Пример #1
0
    def test_toomanyinvalidation_errors_cause_retry(self, MockClient):
        error = CloudFrontServerError(400, 'Bad Request')
        error.error_code = 'TooManyInvalidationsInProgress'

        cloudfront = Mock()
        cloudfront.create_invalidation_request.side_effect = error

        config = Client().config()
        client = Mock()
        client.config.return_value = config
        client.get_cloudfront.return_value = cloudfront
        MockClient.return_value = client

        session = Client().session()
        transaction_id = TaskTransaction.new_id()
        image = Image(filename='abad1dea')
        image.created_at = '2001-01-01 00:00:00'
        session.add(image)
        session.flush()

        invalidate = NeverCalledDirectlyInvalidate()
        invalidate.retry = Mock()
        invalidate(transaction_id, image.image_id)

        invalidate.retry.assert_called_with(exc=error)
Пример #2
0
 def delete_distribution(self, distribution_id, etag):
     response = self.make_request(
         'DELETE', '/%s/distribution/%s' % (self.Version, distribution_id),
         {'If-Match': etag})
     body = response.read()
     if response.status != 204:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #3
0
 def _delete_object(self, id, etag, resource):
     uri = '/%s/%s/%s' % (self.Version, resource, id)
     response = self.make_request('DELETE', uri, {'If-Match': etag})
     body = response.read()
     boto.log.debug(body)
     if response.status != 204:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #4
0
 def get_all_distributions(self):
     response = self.make_request('GET', '/%s/distribution' % self.Version)
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     rs = ResultSet([('DistributionSummary', DistributionSummary)])
     h = handler.XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
Пример #5
0
 def _get_all_objects(self, resource, tags):
     if not tags:
         tags=[('DistributionSummary', DistributionSummary)]
     response = self.make_request('GET', '/%s/%s' % (self.Version, resource))
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     rs = ResultSet(tags)
     h = handler.XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
Пример #6
0
 def _get_config(self, id, resource, config_class):
     uri = '/%s/%s/%s/config' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = config_class(connection=self)
     d.etag = self.get_etag(response)
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Пример #7
0
 def set_distribution_config(self, distribution_id, etag, config):
     response = self.make_request(
         'PUT',
         '/%s/distribution/%s/config' % (self.Version, distribution_id), {
             'If-Match': etag,
             'Content-Type': 'text/xml'
         }, config.to_xml())
     body = response.read()
     return self.get_etag(response)
     if response.status != 200:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #8
0
 def _create_object(self, config, resource, dist_class):
     response = self.make_request('POST', '/%s/%s' % (self.Version, resource),
                                  {'Content-Type' : 'text/xml'}, data=config.to_xml())
     body = response.read()
     if response.status == 201:
         d = dist_class(connection=self)
         h = handler.XmlHandler(d, self)
         xml.sax.parseString(body, h)
         return d
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #9
0
 def get_distribution_config(self, distribution_id):
     response = self.make_request(
         'GET',
         '/%s/distribution/%s/config' % (self.Version, distribution_id))
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = DistributionConfig(connection=self)
     d.etag = self.get_etag(response)
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Пример #10
0
 def _set_config(self, distribution_id, etag, config):
     if isinstance(config, StreamingDistributionConfig):
         resource = 'streaming-distribution'
     else:
         resource = 'distribution'
     uri = '/%s/%s/%s/config' % (self.Version, resource, distribution_id)
     headers = {'If-Match' : etag, 'Content-Type' : 'text/xml'}
     response = self.make_request('PUT', uri, headers, config.to_xml())
     body = response.read()
     return self.get_etag(response)
     if response.status != 200:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #11
0
    def test_unknown_cloudfront_errors_reraise(self, MockClient):
        error = CloudFrontServerError(400, 'Bad Request')
        error.error_code = 'CloudFrontHatesYouToday'

        cloudfront = Mock()
        cloudfront.create_invalidation_request.side_effect = error

        config = Client().config()
        client = Mock()
        client.config.return_value = config
        client.get_cloudfront.return_value = cloudfront
        MockClient.return_value = client

        transaction_id = TaskTransaction.new_id()
        session = Client().session()
        image = Image(filename='abad1dea')
        image.created_at = '2001-01-01 00:00:00'
        session.add(image)
        session.flush()

        Invalidate()(transaction_id, image.image_id)
Пример #12
0
 def invalidation_request_status(self, distribution_id,
                                  request_id, caller_reference=None):
     uri = '/%s/distribution/%s/invalidation/%s' % (self.Version,
                                                    distribution_id,
                                                    request_id)
     response = self.make_request('GET', uri, {'Content-Type': 'text/xml'})
     body = response.read()
     if response.status == 200:
         paths = InvalidationBatch([])
         h = handler.XmlHandler(paths, self)
         xml.sax.parseString(body, h)
         return paths
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
Пример #13
0
 def get_distribution_info(self, distribution_id):
     response = self.make_request(
         'GET', '/%s/distribution/%s' % (self.Version, distribution_id))
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = Distribution(connection=self)
     response_headers = response.msg
     for key in response_headers.keys():
         if key.lower() == 'etag':
             d.etag = response_headers[key]
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Пример #14
0
 def _get_info(self, id, resource, dist_class):
     uri = '/%s/%s/%s' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = dist_class(connection=self)
     response_headers = response.msg
     for key in response_headers.keys():
         if key.lower() == 'etag':
             d.etag = response_headers[key]
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
Пример #15
0
 def _get_all_objects(self, resource, tags, result_set_class=None,
                      result_set_kwargs=None):
     if not tags:
         tags = [('DistributionSummary', DistributionSummary)]
     response = self.make_request('GET', '/%s/%s' % (self.Version,
                                                     resource))
     body = response.read()
     boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     rs_class = result_set_class or ResultSet
     rs_kwargs = result_set_kwargs or dict()
     rs = rs_class(tags, **rs_kwargs)
     h = handler.XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
	def create_invalidation_request(self, distribution_id, paths,
	                                caller_reference=None):
	    """Creates a new invalidation request
	        :see: http://goo.gl/8vECq
	    """
	    # We allow you to pass in either an array or
	    # an InvalidationBatch object
	    if not isinstance(paths, InvalidationBatch):
	        paths = InvalidationBatch(paths)
	    paths.connection = self
	    uri = '/%s/distribution/%s/invalidation' % (self.Version,
	                                                distribution_id)
	    response = self.make_request('POST', uri,
	                                 {'Content-Type': 'text/xml'},
	                                 data=paths.to_xml())
	    body = response.read()
	    if response.status == 201:
	        h = handler.XmlHandler(paths, self)
	        xml.sax.parseString(body, h)
	        return paths
	    else:
	        raise CloudFrontServerError(response.status, response.reason, body)
Пример #17
0
 def create_distribution(self,
                         origin,
                         enabled,
                         caller_reference='',
                         cnames=None,
                         comment=''):
     config = DistributionConfig(origin=origin,
                                 enabled=enabled,
                                 caller_reference=caller_reference,
                                 cnames=cnames,
                                 comment=comment)
     response = self.make_request('POST',
                                  '/%s/distribution' % self.Version,
                                  {'Content-Type': 'text/xml'},
                                  data=config.to_xml())
     body = response.read()
     if response.status == 201:
         d = Distribution(connection=self)
         h = handler.XmlHandler(d, self)
         xml.sax.parseString(body, h)
         return d
     else:
         raise CloudFrontServerError(response.status, response.reason, body)