コード例 #1
0
ファイル: test_file.py プロジェクト: TheUtils/ceilometer
    def test_file_dispatcher_with_path_only(self):
        # Create a temporaryFile to get a file name
        tf = tempfile.NamedTemporaryFile('r')
        filename = tf.name
        tf.close()

        self.CONF.dispatcher_file.file_path = filename
        self.CONF.dispatcher_file.max_bytes = None
        self.CONF.dispatcher_file.backup_count = None
        dispatcher = file.FileDispatcher(self.CONF)

        # The number of the handlers should be 1
        self.assertEqual(1, len(dispatcher.log.handlers))
        # The handler should be RotatingFileHandler
        handler = dispatcher.log.handlers[0]
        self.assertTrue(isinstance(handler,
                                   logging.FileHandler))

        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        # The record_metering_data method should exist and not produce errors.
        dispatcher.record_metering_data(None, msg)
        # After the method call above, the file should have been created.
        self.assertTrue(os.path.exists(handler.baseFilename))
コード例 #2
0
ファイル: test_file.py プロジェクト: mydaisy2/ceilometer
    def test_file_dispatcher_with_path_only(self):
        # Create a temporaryFile to get a file name
        tf = tempfile.NamedTemporaryFile('r')
        filename = tf.name
        tf.close()

        cfg.CONF.dispatcher_file.file_path = filename
        cfg.CONF.dispatcher_file.max_bytes = None
        cfg.CONF.dispatcher_file.backup_count = None
        dispatcher = file.FileDispatcher(cfg.CONF)

        # The number of the handlers should be 1
        self.assertEqual(1, len(dispatcher.log.handlers))
        # The handler should be RotatingFileHandler
        handler = dispatcher.log.handlers[0]
        self.assertTrue(isinstance(handler, logging.FileHandler))

        msg = {
            'counter_name': 'test',
            'resource_id': self.id(),
            'counter_volume': 1,
        }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            cfg.CONF.publisher_rpc.metering_secret,
        )

        # The record_metering_data method should exist and not produce errors.
        dispatcher.record_metering_data(None, msg)
        # After the method call above, the file should have been created.
        self.assertTrue(os.path.exists(handler.baseFilename))
コード例 #3
0
 def test_verify_signature_nested(self):
     data = {'a': 'A',
             'b': 'B',
             'nested': {'a': 'A',
                        'b': 'B',
                        },
             }
     data['message_signature'] = rpc.compute_signature(
         data,
         'not-so-secret')
     self.assertTrue(rpc.verify_signature(data, 'not-so-secret'))
コード例 #4
0
def test_verify_signature_nested():
    data = {
        'a': 'A',
        'b': 'B',
        'nested': {
            'a': 'A',
            'b': 'B',
        },
    }
    data['message_signature'] = rpc.compute_signature(data, 'not-so-secret')
    assert rpc.verify_signature(data, 'not-so-secret')
コード例 #5
0
 def test_verify_signature_nested_list_of_dict(self):
     small = 1
     big = 1 << 64
     nested = {small: 99, big: 42}
     data = {'a': 'A',
             'b': 'B',
             'nested': {'list': [nested]}}
     data['message_signature'] = rpc.compute_signature(
         data,
         'not-so-secret')
     # the keys 1 and 1<<64 cause a hash collision on 64bit platforms
     data['nested']['list'] = [{big: 42, small: 99}]
     self.assertTrue(rpc.verify_signature(data, 'not-so-secret'))
コード例 #6
0
def test_verify_signature_nested_json():
    data = {
        'a': 'A',
        'b': 'B',
        'nested': {
            'a': 'A',
            'b': 'B',
            'c': ('c', ),
            'd': ['d']
        },
    }
    data['message_signature'] = rpc.compute_signature(data, 'not-so-secret')
    jsondata = jsonutils.loads(jsonutils.dumps(data))
    assert rpc.verify_signature(jsondata, 'not-so-secret')
コード例 #7
0
 def test_verify_signature_nested_json(self):
     data = {'a': 'A',
             'b': 'B',
             'nested': {'a': 'A',
                        'b': 'B',
                        'c': ('c',),
                        'd': ['d']
                        },
             }
     data['message_signature'] = rpc.compute_signature(
         data,
         'not-so-secret')
     jsondata = jsonutils.loads(jsonutils.dumps(data))
     self.assertTrue(rpc.verify_signature(jsondata, 'not-so-secret'))
コード例 #8
0
ファイル: test_db.py プロジェクト: c08007/ceilometer
    def test_valid_message(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        with mock.patch.object(self.dispatcher.storage_conn,
                               'record_metering_data') as record_metering_data:
            self.dispatcher.record_metering_data(msg)

        record_metering_data.assert_called_once_with(msg)
コード例 #9
0
ファイル: test_db.py プロジェクト: lookmee/ceilometer
    def test_valid_message(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(msg)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
コード例 #10
0
    def test_valid_message(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(msg)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
        self.mox.VerifyAll()
コード例 #11
0
ファイル: test_db.py プロジェクト: c08007/ceilometer
    def test_timestamp_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-07-02T13:53:40Z',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = msg.copy()
        expected['timestamp'] = datetime.datetime(2012, 7, 2, 13, 53, 40)

        with mock.patch.object(self.dispatcher.storage_conn,
                               'record_metering_data') as record_metering_data:
            self.dispatcher.record_metering_data(msg)

        record_metering_data.assert_called_once_with(expected)
コード例 #12
0
ファイル: test_db.py プロジェクト: c08007/ceilometer
    def test_timestamp_tzinfo_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-09-30T15:31:50.262-08:00',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = msg.copy()
        expected['timestamp'] = datetime.datetime(2012, 9, 30, 23,
                                                  31, 50, 262000)

        with mock.patch.object(self.dispatcher.storage_conn,
                               'record_metering_data') as record_metering_data:
            self.dispatcher.record_metering_data(msg)

        record_metering_data.assert_called_once_with(expected)
コード例 #13
0
    def test_timestamp_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-07-02T13:53:40Z',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 7, 2, 13, 53, 40)

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
コード例 #14
0
ファイル: test_db.py プロジェクト: lookmee/ceilometer
    def test_timestamp_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-07-02T13:53:40Z',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 7, 2, 13, 53, 40)

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
コード例 #15
0
    def test_timestamp_tzinfo_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-09-30T15:31:50.262-08:00',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 9, 30, 23, 31, 50, 262000)

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
コード例 #16
0
ファイル: test_db.py プロジェクト: lookmee/ceilometer
    def test_timestamp_tzinfo_conversion(self):
        msg = {'counter_name': 'test',
               'resource_id': self.id(),
               'counter_volume': 1,
               'timestamp': '2012-09-30T15:31:50.262-08:00',
               }
        msg['message_signature'] = rpc.compute_signature(
            msg,
            self.CONF.publisher_rpc.metering_secret,
        )

        expected = {}
        expected.update(msg)
        expected['timestamp'] = datetime(2012, 9, 30, 23, 31, 50, 262000)

        self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
        self.dispatcher.storage_conn.record_metering_data(expected)
        self.mox.ReplayAll()

        self.dispatcher.record_metering_data(self.ctx, msg)
コード例 #17
0
ファイル: test_file.py プロジェクト: JioCloud/ceilometer
    def test_file_dispatcher_with_all_config(self):
        # Create a temporaryFile to get a file name
        tf = tempfile.NamedTemporaryFile("r")
        filename = tf.name
        tf.close()

        cfg.CONF.dispatcher_file.file_path = filename
        cfg.CONF.dispatcher_file.max_bytes = 50
        cfg.CONF.dispatcher_file.backup_count = 5
        dispatcher = file.FileDispatcher(cfg.CONF)

        # The number of the handlers should be 1
        self.assertEqual(1, len(dispatcher.log.handlers))
        # The handler should be RotatingFileHandler
        handler = dispatcher.log.handlers[0]
        self.assertTrue(isinstance(handler, logging.handlers.RotatingFileHandler))

        msg = {"counter_name": "test", "resource_id": self.id(), "counter_volume": 1}
        msg["message_signature"] = rpc.compute_signature(msg, cfg.CONF.publisher_rpc.metering_secret)

        # The record_metering_data method should exist and not produce errors.
        dispatcher.record_metering_data(None, msg)
        # After the method call above, the file should have been created.
        self.assertTrue(os.path.exists(handler.baseFilename))
コード例 #18
0
 def test_compute_signature_use_configured_secret(self):
     data = {'a': 'A', 'b': 'B'}
     sig1 = rpc.compute_signature(data, 'not-so-secret')
     sig2 = rpc.compute_signature(data, 'different-value')
     self.assertNotEqual(sig1, sig2)
コード例 #19
0
def test_compute_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = rpc.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    sig2 = rpc.compute_signature(data, 'not-so-secret')
    assert sig1 == sig2
コード例 #20
0
 def test_verify_signature_signed(self):
     data = {'a': 'A', 'b': 'B'}
     sig1 = rpc.compute_signature(data, 'not-so-secret')
     data['message_signature'] = sig1
     self.assertTrue(rpc.verify_signature(data, 'not-so-secret'))
コード例 #21
0
 def test_compute_signature_signed(self):
     data = {'a': 'A', 'b': 'B'}
     sig1 = rpc.compute_signature(data, 'not-so-secret')
     data['message_signature'] = sig1
     sig2 = rpc.compute_signature(data, 'not-so-secret')
     self.assertEqual(sig1, sig2)
コード例 #22
0
 def test_compute_signature_signed(self):
     data = {'a': 'A', 'b': 'B'}
     sig1 = rpc.compute_signature(data, 'not-so-secret')
     data['message_signature'] = sig1
     sig2 = rpc.compute_signature(data, 'not-so-secret')
     self.assertEqual(sig1, sig2)
コード例 #23
0
def test_compute_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = rpc.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    sig2 = rpc.compute_signature(data, 'not-so-secret')
    assert sig1 == sig2
コード例 #24
0
def test_compute_signature_change_value():
    sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'},
                                 'not-so-secret')
    sig2 = rpc.compute_signature({'a': 'a', 'b': 'B'},
                                 'not-so-secret')
    assert sig1 != sig2
コード例 #25
0
def test_compute_signature_use_configured_secret():
    data = {'a': 'A', 'b': 'B'}
    sig1 = rpc.compute_signature(data, 'not-so-secret')
    sig2 = rpc.compute_signature(data, 'different-value')
    assert sig1 != sig2
コード例 #26
0
def test_compute_signature_change_value():
    sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = rpc.compute_signature({'a': 'a', 'b': 'B'}, 'not-so-secret')
    assert sig1 != sig2
コード例 #27
0
def test_verify_signature_signed():
    data = {'a': 'A', 'b': 'B'}
    sig1 = rpc.compute_signature(data, 'not-so-secret')
    data['message_signature'] = sig1
    assert rpc.verify_signature(data, 'not-so-secret')
コード例 #28
0
def test_compute_signature_same():
    sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'},
                                 'not-so-secret')
    sig2 = rpc.compute_signature({'a': 'A', 'b': 'B'},
                                 'not-so-secret')
    assert sig1 == sig2
コード例 #29
0
 def test_compute_signature_signed(self):
     data = {"a": "A", "b": "B"}
     sig1 = rpc.compute_signature(data, "not-so-secret")
     data["message_signature"] = sig1
     sig2 = rpc.compute_signature(data, "not-so-secret")
     self.assertEqual(sig1, sig2)
コード例 #30
0
def test_compute_signature_use_configured_secret():
    data = {'a': 'A', 'b': 'B'}
    sig1 = rpc.compute_signature(data, 'not-so-secret')
    sig2 = rpc.compute_signature(data, 'different-value')
    assert sig1 != sig2
コード例 #31
0
 def test_compute_signature_use_configured_secret(self):
     data = {"a": "A", "b": "B"}
     sig1 = rpc.compute_signature(data, "not-so-secret")
     sig2 = rpc.compute_signature(data, "different-value")
     self.assertNotEqual(sig1, sig2)
コード例 #32
0
 def test_compute_signature_same(self):
     sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'},
                                  'not-so-secret')
     sig2 = rpc.compute_signature({'a': 'A', 'b': 'B'},
                                  'not-so-secret')
     self.assertEqual(sig1, sig2)
コード例 #33
0
 def test_verify_signature_signed(self):
     data = {"a": "A", "b": "B"}
     sig1 = rpc.compute_signature(data, "not-so-secret")
     data["message_signature"] = sig1
     self.assertTrue(rpc.verify_signature(data, "not-so-secret"))
コード例 #34
0
 def test_compute_signature_use_configured_secret(self):
     data = {'a': 'A', 'b': 'B'}
     sig1 = rpc.compute_signature(data, 'not-so-secret')
     sig2 = rpc.compute_signature(data, 'different-value')
     self.assertNotEqual(sig1, sig2)
コード例 #35
0
 def test_verify_signature_nested(self):
     data = {"a": "A", "b": "B", "nested": {"a": "A", "b": "B"}}
     data["message_signature"] = rpc.compute_signature(data, "not-so-secret")
     self.assertTrue(rpc.verify_signature(data, "not-so-secret"))
コード例 #36
0
 def test_compute_signature_same(self):
     sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
     sig2 = rpc.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
     self.assertEqual(sig1, sig2)
コード例 #37
0
 def test_verify_signature_nested_json(self):
     data = {"a": "A", "b": "B", "nested": {"a": "A", "b": "B", "c": ("c",), "d": ["d"]}}
     data["message_signature"] = rpc.compute_signature(data, "not-so-secret")
     jsondata = jsonutils.loads(jsonutils.dumps(data))
     self.assertTrue(rpc.verify_signature(jsondata, "not-so-secret"))
コード例 #38
0
 def test_compute_signature_same(self):
     sig1 = rpc.compute_signature({"a": "A", "b": "B"}, "not-so-secret")
     sig2 = rpc.compute_signature({"a": "A", "b": "B"}, "not-so-secret")
     self.assertEqual(sig1, sig2)
コード例 #39
0
def test_compute_signature_same():
    sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    sig2 = rpc.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
    assert sig1 == sig2