コード例 #1
0
    def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(s3_host=None,
                                              s3_port=None,
                                              s3_key=None,
                                              s3_ssl=False,
                                              s3_secret=None,
                                              oops_config=oops_config,
                                              reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))
コード例 #2
0
    def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(
            s3_host=None,
            s3_port=None,
            s3_key=None,
            s3_ssl=False,
            s3_secret=None,
            oops_config=oops_config,
            reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))
コード例 #3
0
class NotificationErrorsTestCase(testcase.TestWithDatabase):
    """Test Notification error handling.

    These tests will throw notifications at the server that will raise
    exceptions and check the oops recorded. Some events don't trigger
    exceptions in themselves, but an exception is created at broadcast.
    """

    induced_error = ValueError

    @defer.inlineCallbacks
    def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(
            s3_host=None,
            s3_port=None,
            s3_key=None,
            s3_ssl=False,
            s3_secret=None,
            oops_config=oops_config,
            reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))

    @defer.inlineCallbacks
    def tearDown(self):
        self.ssfactory.metrics.connection.disconnect()
        self.ssfactory.user_metrics.connection.disconnect()
        yield super(NotificationErrorsTestCase, self).tearDown()

    @defer.inlineCallbacks
    def check_event(self, event, **kwargs):
        """Test an error in node update."""
        original_event = event
        self.notifier.send_event(original_event)
        oops_data = yield self.oops_deferred
        tl = oops_data["timeline"]
        _, _, category, detail, _ = tl[-1]
        self.assertEqual("EVENT-%s" % original_event.event_type, category)

        expected = "NOTIFY WITH %r (%s)" % (original_event, kwargs)
        self.assertEqual(expected, detail)
        self.assertEqual("Test error", oops_data["value"])
        self.assertEqual("ValueError", oops_data["type"])

    def test_share_created(self):
        """Test the share events."""
        event_args = (
            uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, Share.VIEW, False)
        self.check_event(ShareCreated(*event_args))

    def test_share_deleted(self):
        """Test the share events."""
        event_args = (
            uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, Share.VIEW, False)
        self.check_event(ShareDeleted(*event_args))

    def test_share_declined(self):
        """Test the share events."""
        event_args = (
            uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, Share.VIEW, False)
        self.check_event(ShareDeclined(*event_args))

    def test_share_accepted(self):
        """Test the share events."""
        event_args = (
            uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, Share.VIEW, True)
        self.check_event(ShareAccepted(*event_args), recipient_id=u'test')

    def test_udf_delete(self):
        """Test UDF Delete."""
        self.check_event(UDFDelete(1, uuid.uuid4(), uuid.uuid4()))

    def test_udf_create(self):
        """Test UDF Create."""
        self.check_event(UDFCreate(1, uuid.uuid4(), uuid.uuid4(),
                                   u"suggested path", uuid.uuid4()))

    def test_new_volume_gen(self):
        """Test the new gen for volume events."""
        event = VolumeNewGeneration(1, uuid.uuid4(), 77, uuid.uuid4())
        self.check_event(event)
コード例 #4
0
class NotificationErrorsTestCase(testcase.TestWithDatabase):
    """Test Notification error handling.

    These tests will throw notifications at the server that will raise
    exceptions and check the oops recorded. Some events don't trigger
    exceptions in themselves, but an exception is created at broadcast.
    """

    induced_error = ValueError

    @defer.inlineCallbacks
    def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(s3_host=None,
                                              s3_port=None,
                                              s3_key=None,
                                              s3_ssl=False,
                                              s3_secret=None,
                                              oops_config=oops_config,
                                              reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))

    @defer.inlineCallbacks
    def tearDown(self):
        self.ssfactory.metrics.connection.disconnect()
        self.ssfactory.user_metrics.connection.disconnect()
        yield super(NotificationErrorsTestCase, self).tearDown()

    @defer.inlineCallbacks
    def check_event(self, event, **kwargs):
        """Test an error in node update."""
        original_event = event
        self.notifier.send_event(original_event)
        oops_data = yield self.oops_deferred
        tl = oops_data["timeline"]
        _, _, category, detail, _ = tl[-1]
        self.assertEqual("EVENT-%s" % original_event.event_type, category)

        expected = "NOTIFY WITH %r (%s)" % (original_event, kwargs)
        self.assertEqual(expected, detail)
        self.assertEqual("Test error", oops_data["value"])
        self.assertEqual("ValueError", oops_data["type"])

    def test_share_created(self):
        """Test the share events."""
        event_args = (uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, "View", False)
        self.check_event(ShareCreated(*event_args))

    def test_share_deleted(self):
        """Test the share events."""
        event_args = (uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, "View", False)
        self.check_event(ShareDeleted(*event_args))

    def test_share_declined(self):
        """Test the share events."""
        event_args = (uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, "View", False)
        self.check_event(ShareDeclined(*event_args))

    def test_share_accepted(self):
        """Test the share events."""
        event_args = (uuid.uuid4(), u"name", uuid.uuid4(), 1, 2, "View", True)
        self.check_event(ShareAccepted(*event_args), recipient_id='test')

    def test_udf_delete(self):
        """Test UDF Delete."""
        self.check_event(UDFDelete(1, uuid.uuid4(), uuid.uuid4()))

    def test_udf_create(self):
        """Test UDF Create."""
        self.check_event(
            UDFCreate(1, uuid.uuid4(), uuid.uuid4(), u"suggested path",
                      uuid.uuid4()))

    def test_new_volume_gen(self):
        """Test the new gen for volume events."""
        event = VolumeNewGeneration(1, uuid.uuid4(), 77, uuid.uuid4())
        self.check_event(event)