Exemple #1
0
 def test_metadata_headers(self):
     app = swift_middleware.CeilometerMiddleware(
         FakeApp(), {'metadata_headers': 'X_VAR1, x-var2, x-var3'})
     req = FakeRequest('/1.0/account/container',
                       environ={'REQUEST_METHOD': 'GET'},
                       headers={
                           'X_VAR1': 'value1',
                           'X_VAR2': 'value2'
                       })
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(2, len(samples))
     data = samples[0]
     http_headers = [
         k for k in data.resource_metadata.keys()
         if k.startswith('http_header_')
     ]
     self.assertEqual(2, len(http_headers))
     self.assertEqual('1.0', data.resource_metadata['version'])
     self.assertEqual('container', data.resource_metadata['container'])
     self.assertIsNone(data.resource_metadata['object'])
     self.assertEqual('value1',
                      data.resource_metadata['http_header_x_var1'])
     self.assertEqual('value2',
                      data.resource_metadata['http_header_x_var2'])
     self.assertFalse('http_header_x_var3' in data.resource_metadata)
Exemple #2
0
 def test_metadata_headers(self):
     app = swift_middleware.CeilometerMiddleware(
         FakeApp(), {'metadata_headers': 'X_VAR1, x-var2, x-var3'})
     req = Request.blank('/1.0/account/container',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={
                             'X_VAR1': 'value1',
                             'X_VAR2': 'value2'
                         })
     resp = list(app(req.environ, self.start_response))
     counters = self.pipeline_manager.pipelines[0].counters
     self.assertEqual(len(counters), 2)
     data = counters[0]
     http_headers = [
         k for k in data.resource_metadata.keys()
         if k.startswith('http_header_')
     ]
     self.assertEqual(len(http_headers), 2)
     self.assertEqual(data.resource_metadata['version'], '1.0')
     self.assertEqual(data.resource_metadata['container'], 'container')
     self.assertEqual(data.resource_metadata['object'], None)
     self.assertEqual(data.resource_metadata['http_header_x_var1'],
                      'value1')
     self.assertEqual(data.resource_metadata['http_header_x_var2'],
                      'value2')
     self.assertFalse('http_header_x_var3' in data.resource_metadata)
 def test_bogus_path(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     req = REQUEST.Request.blank('/5.0//',
                                 environ={'REQUEST_METHOD': 'GET'})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(0, len(samples))
Exemple #4
0
    def test_reseller_prefix(self):
        # No reseller prefix set: ensure middleware uses AUTH_
        app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
        req = FakeRequest('/1.0/AUTH_account/container/obj',
                          environ={'REQUEST_METHOD': 'GET'})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples[0]
        self.assertEqual("account", samples.resource_id)

        # Custom reseller prefix set
        app = swift_middleware.CeilometerMiddleware(
            FakeApp(), {'reseller_prefix': 'CUSTOM_'})
        req = FakeRequest('/1.0/CUSTOM_account/container/obj',
                          environ={'REQUEST_METHOD': 'GET'})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples[0]
        self.assertEqual("account", samples.resource_id)
Exemple #5
0
 def test_invalid_reseller_prefix(self):
     # Custom reseller prefix set, but without trailing underscore
     app = swift_middleware.CeilometerMiddleware(
         FakeApp(), {'reseller_prefix': 'CUSTOM'})
     req = FakeRequest('/1.0/CUSTOM_account/container/obj',
                       environ={'REQUEST_METHOD': 'GET'})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples[0]
     self.assertEqual("account", samples.resource_id)
Exemple #6
0
 def test_publish_sample_fail(self, mocked_publish_sample):
     mocked_publish_sample.side_effect = Exception("a exception")
     app = swift_middleware.CeilometerMiddleware(FakeApp(body=["test"]), {})
     req = FakeRequest('/1.0/account/container',
                       environ={'REQUEST_METHOD': 'GET'})
     resp = list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(0, len(samples))
     self.assertEqual(["test"], resp)
     mocked_publish_sample.assert_called_once_with(mock.ANY, 0, 4)
Exemple #7
0
 def test_get_container(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     req = Request.blank('/1.0/account/container',
                         environ={'REQUEST_METHOD': 'GET'})
     resp = list(app(req.environ, self.start_response))
     counters = self.pipeline_manager.pipelines[0].counters
     self.assertEqual(len(counters), 2)
     data = counters[0]
     self.assertEqual(data.volume, 28)
     self.assertEqual(data.resource_metadata['version'], '1.0')
     self.assertEqual(data.resource_metadata['container'], 'container')
     self.assertEqual(data.resource_metadata['object'], None)
Exemple #8
0
 def test_get_container(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     req = FakeRequest('/1.0/account/container',
                       environ={'REQUEST_METHOD': 'GET'})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(2, len(samples))
     data = samples[0]
     self.assertEqual(28, data.volume)
     self.assertEqual('1.0', data.resource_metadata['version'])
     self.assertEqual('container', data.resource_metadata['container'])
     self.assertIsNone(data.resource_metadata['object'])
Exemple #9
0
 def test_no_metadata_headers(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     req = webob.Request.blank('/1.0/account/container',
                               environ={'REQUEST_METHOD': 'GET'})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(len(samples), 2)
     data = samples[0]
     http_headers = [k for k in data.resource_metadata.keys()
                     if k.startswith('http_header_')]
     self.assertEqual(len(http_headers), 0)
     self.assertEqual(data.resource_metadata['version'], '1.0')
     self.assertEqual(data.resource_metadata['container'], 'container')
     self.assertIsNone(data.resource_metadata['object'])
Exemple #10
0
    def test_head(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = Request.blank('/1.0/account/container/obj',
                            environ={'REQUEST_METHOD': 'HEAD'})
        resp = list(app(req.environ, self.start_response))
        counters = self.pipeline_manager.pipelines[0].counters
        self.assertEqual(len(counters), 1)
        data = counters[0]
        self.assertEqual(data.resource_metadata['version'], '1.0')
        self.assertEqual(data.resource_metadata['container'], 'container')
        self.assertEqual(data.resource_metadata['object'], 'obj')
        self.assertEqual(data.resource_metadata['method'], 'head')

        self.assertEqual(data.name, 'storage.api.request')
        self.assertEqual(data.volume, 1)
Exemple #11
0
    def test_head(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = FakeRequest('/1.0/account/container/obj',
                          environ={'REQUEST_METHOD': 'HEAD'})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples
        self.assertEqual(1, len(samples))
        data = samples[0]
        self.assertEqual('1.0', data.resource_metadata['version'])
        self.assertEqual('container', data.resource_metadata['container'])
        self.assertEqual('obj', data.resource_metadata['object'])
        self.assertEqual('head', data.resource_metadata['method'])

        self.assertEqual('storage.api.request', data.name)
        self.assertEqual(1, data.volume)
Exemple #12
0
 def test_metadata_headers_on_not_existing_header(self):
     app = swift_middleware.CeilometerMiddleware(
         FakeApp(), {'metadata_headers': 'x-var3'})
     req = Request.blank('/1.0/account/container',
                         environ={'REQUEST_METHOD': 'GET'})
     resp = list(app(req.environ, self.start_response))
     counters = self.pipeline_manager.pipelines[0].counters
     self.assertEqual(len(counters), 2)
     data = counters[0]
     http_headers = [
         k for k in data.resource_metadata.keys()
         if k.startswith('http_header_')
     ]
     self.assertEqual(len(http_headers), 0)
     self.assertEqual(data.resource_metadata['version'], '1.0')
     self.assertEqual(data.resource_metadata['container'], 'container')
     self.assertEqual(data.resource_metadata['object'], None)
Exemple #13
0
    def test_bogus_request(self):
        """Test even for arbitrary request method, this will still work."""
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = FakeRequest('/1.0/account/container/obj',
                          environ={'REQUEST_METHOD': 'BOGUS'})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples

        self.assertEqual(1, len(samples))
        data = samples[0]
        self.assertEqual('1.0', data.resource_metadata['version'])
        self.assertEqual('container', data.resource_metadata['container'])
        self.assertEqual('obj', data.resource_metadata['object'])
        self.assertEqual('bogus', data.resource_metadata['method'])

        self.assertEqual('storage.api.request', data.name)
        self.assertEqual(1, data.volume)
Exemple #14
0
    def test_bogus_request(self):
        """Test even for arbitrary request method, this will still work."""
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = Request.blank('/1.0/account/container/obj',
                            environ={'REQUEST_METHOD': 'BOGUS'})
        list(app(req.environ, self.start_response))
        counters = self.pipeline_manager.pipelines[0].counters

        self.assertEqual(len(counters), 1)
        data = counters[0]
        self.assertEqual(data.resource_metadata['version'], '1.0')
        self.assertEqual(data.resource_metadata['container'], 'container')
        self.assertEqual(data.resource_metadata['object'], 'obj')
        self.assertEqual(data.resource_metadata['method'], 'bogus')

        self.assertEqual(data.name, 'storage.api.request')
        self.assertEqual(data.volume, 1)
Exemple #15
0
    def test_get(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
        req = Request.blank('/1.0/account/container/obj',
                            environ={'REQUEST_METHOD': 'GET'})
        resp = app(req.environ, self.start_response)
        self.assertEqual(list(resp), ["This string is 28 bytes long"])
        counters = self.pipeline_manager.pipelines[0].counters
        self.assertEqual(len(counters), 2)
        data = counters[0]
        self.assertEqual(data.volume, 28)
        self.assertEqual(data.resource_metadata['version'], '1.0')
        self.assertEqual(data.resource_metadata['container'], 'container')
        self.assertEqual(data.resource_metadata['object'], 'obj')

        # test the # of request and the request method
        data = counters[1]
        self.assertEqual(data.name, 'storage.api.request')
        self.assertEqual(data.volume, 1)
        self.assertEqual(data.resource_metadata['method'], 'get')
Exemple #16
0
    def test_get(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
        req = FakeRequest('/1.0/account/container/obj',
                          environ={'REQUEST_METHOD': 'GET'})
        resp = app(req.environ, self.start_response)
        self.assertEqual(["This string is 28 bytes long"], list(resp))
        samples = self.pipeline_manager.pipelines[0].samples
        self.assertEqual(2, len(samples))
        data = samples[0]
        self.assertEqual(28, data.volume)
        self.assertEqual('1.0', data.resource_metadata['version'])
        self.assertEqual('container', data.resource_metadata['container'])
        self.assertEqual('obj', data.resource_metadata['object'])

        # test the # of request and the request method
        data = samples[1]
        self.assertEqual('storage.api.request', data.name)
        self.assertEqual(1, data.volume)
        self.assertEqual('get', data.resource_metadata['method'])
Exemple #17
0
    def test_post(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = webob.Request.blank(
            '/1.0/account/container/obj',
            environ={'REQUEST_METHOD': 'POST',
                     'wsgi.input': StringIO.StringIO('some other stuff')})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples
        self.assertEqual(len(samples), 2)
        data = samples[0]
        self.assertEqual(data.volume, 16)
        self.assertEqual(data.resource_metadata['version'], '1.0')
        self.assertEqual(data.resource_metadata['container'], 'container')
        self.assertEqual(data.resource_metadata['object'], 'obj')

        # test the # of request and the request method
        data = samples[1]
        self.assertEqual(data.name, 'storage.api.request')
        self.assertEqual(data.volume, 1)
        self.assertEqual(data.resource_metadata['method'], 'post')
Exemple #18
0
    def test_post(self):
        app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
        req = FakeRequest(
            '/1.0/account/container/obj',
            environ={'REQUEST_METHOD': 'POST',
                     'wsgi.input': six.moves.cStringIO('some other stuff')})
        list(app(req.environ, self.start_response))
        samples = self.pipeline_manager.pipelines[0].samples
        self.assertEqual(2, len(samples))
        data = samples[0]
        self.assertEqual(16, data.volume)
        self.assertEqual('1.0', data.resource_metadata['version'])
        self.assertEqual('container', data.resource_metadata['container'])
        self.assertEqual('obj', data.resource_metadata['object'])

        # test the # of request and the request method
        data = samples[1]
        self.assertEqual('storage.api.request', data.name)
        self.assertEqual(1, data.volume)
        self.assertEqual('post', data.resource_metadata['method'])
 def test_metadata_headers_unicode(self):
     app = swift_middleware.CeilometerMiddleware(
         FakeApp(), {'metadata_headers': 'unicode'})
     uni = u'\xef\xbd\xa1\xef\xbd\xa5'
     req = FakeRequest('/1.0/account/container',
                       environ={'REQUEST_METHOD': 'GET'},
                       headers={'UNICODE': uni})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(2, len(samples))
     data = samples[0]
     http_headers = [
         k for k in data.resource_metadata.keys()
         if k.startswith('http_header_')
     ]
     self.assertEqual(1, len(http_headers))
     self.assertEqual('1.0', data.resource_metadata['version'])
     self.assertEqual('container', data.resource_metadata['container'])
     self.assertIsNone(data.resource_metadata['object'])
     self.assertEqual(uni.encode('utf-8'),
                      data.resource_metadata['http_header_unicode'])
Exemple #20
0
 def test_missing_resource_id(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     req = FakeRequest('/v1/', environ={'REQUEST_METHOD': 'GET'})
     list(app(req.environ, self.start_response))
     samples = self.pipeline_manager.pipelines[0].samples
     self.assertEqual(0, len(samples))
Exemple #21
0
 def test_rpc_setup(self):
     app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
     self.assertEqual(cfg.CONF.control_exchange, 'ceilometer')