Пример #1
0
    def _check_notifications(self, fake_publisher_cls):
        fake_publisher_cls.side_effect = [self.publisher, self.publisher2]

        self.srv = notification.NotificationService(0, self.CONF, 'harry')
        self.srv2 = notification.NotificationService(0, self.CONF, 'lloyd')
        with mock.patch('ceilometer.coordination.PartitionCoordinator'
                        '._get_members', return_value=['harry', 'lloyd']):
            self.srv.run()
            self.addCleanup(self.srv.terminate)
            self.srv2.run()
            self.addCleanup(self.srv2.terminate)

        notifier = messaging.get_notifier(self.transport,
                                          "compute.vagrant-precise")
        payload1 = TEST_NOTICE_PAYLOAD.copy()
        payload1['instance_id'] = '0'
        notifier.info({}, 'compute.instance.create.end', payload1)
        payload2 = TEST_NOTICE_PAYLOAD.copy()
        payload2['instance_id'] = '1'
        notifier.info({}, 'compute.instance.create.end', payload2)
        self.expected_samples = 4
        with mock.patch('six.moves.builtins.hash', lambda x: int(x)):
            start = time.time()
            while time.time() - start < 60:
                if (len(self.publisher.samples + self.publisher2.samples) >=
                        self.expected_samples):
                    break
                time.sleep(0.1)

        self.assertEqual(2, len(self.publisher.samples))
        self.assertEqual(2, len(self.publisher2.samples))
        self.assertEqual(1, len(set(
            s.resource_id for s in self.publisher.samples)))
        self.assertEqual(1, len(set(
            s.resource_id for s in self.publisher2.samples)))
Пример #2
0
    def _check_notifications(self, fake_publisher_cls):
        fake_publisher_cls.side_effect = [self.publisher, self.publisher2]

        maybe = {"srv": 0, "srv2": -1}

        def _sometimes_srv(item):
            maybe["srv"] += 1
            return (maybe["srv"] % 2) == 0

        self.srv = notification.NotificationService(0, self.CONF)
        self.srv.partition_coordinator = pc = mock.MagicMock()
        hashring_srv1 = mock.MagicMock()
        hashring_srv1.belongs_to_self = _sometimes_srv
        hashring_srv1.ring.nodes = {'id1': mock.Mock()}
        pc.join_partitioned_group.return_value = hashring_srv1
        self.srv.run()
        self.addCleanup(self.srv.terminate)

        def _sometimes_srv2(item):
            maybe["srv2"] += 1
            return (maybe["srv2"] % 2) == 0

        self.srv2 = notification.NotificationService(0, self.CONF)
        self.srv2.partition_coordinator = pc = mock.MagicMock()
        hashring = mock.MagicMock()
        hashring.belongs_to_self = _sometimes_srv2
        hashring.ring.nodes = {'id1': mock.Mock(), 'id2': mock.Mock()}
        self.srv.hashring.ring.nodes = hashring.ring.nodes.copy()
        pc.join_partitioned_group.return_value = hashring
        self.srv2.run()
        self.addCleanup(self.srv2.terminate)

        notifier = messaging.get_notifier(self.transport,
                                          "compute.vagrant-precise")
        payload1 = TEST_NOTICE_PAYLOAD.copy()
        payload1['instance_id'] = '0'
        notifier.info({}, 'compute.instance.create.end', payload1)
        payload2 = TEST_NOTICE_PAYLOAD.copy()
        payload2['instance_id'] = '1'
        notifier.info({}, 'compute.instance.create.end', payload2)
        self.expected_samples = 4
        with mock.patch('six.moves.builtins.hash', lambda x: int(x)):
            start = time.time()
            while time.time() - start < 10:
                if (len(self.publisher.samples + self.publisher2.samples) >=
                        self.expected_samples
                        and len(self.srv.group_state) == 2):
                    break
                time.sleep(0.1)

        self.assertEqual(2, len(self.publisher.samples))
        self.assertEqual(2, len(self.publisher2.samples))
        self.assertEqual(
            1, len(set(s.resource_id for s in self.publisher.samples)))
        self.assertEqual(
            1, len(set(s.resource_id for s in self.publisher2.samples)))
        self.assertEqual(2, len(self.srv.group_state))
Пример #3
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.CONF = service.prepare_service([], [])
     self.CONF.set_override("connection", "log://", group='database')
     self.CONF.set_override("backend_url", "zake://", group="coordination")
     self.setup_messaging(self.CONF)
     self.srv = notification.NotificationService(0, self.CONF)
Пример #4
0
def agent_notification():
    service.prepare_service()
    launcher = os_service.ProcessLauncher()
    launcher.launch_service(notification.NotificationService(
        cfg.CONF.host, 'ceilometer.agent.notification'),
                            workers=service.get_workers('notification'))
    launcher.wait()
Пример #5
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.CONF = self.useFixture(fixture_config.Config()).conf
     self.CONF.set_override("connection", "log://", group='database')
     self.CONF.set_override("store_events", False, group="notification")
     self.setup_messaging(self.CONF)
     self.srv = notification.NotificationService()
Пример #6
0
def agent_notification():
    service.prepare_service()
    launcher = os_service.ProcessLauncher()
    launcher.launch_service(
        notification.NotificationService(),
        workers=service.get_workers('notification'))
    launcher.wait()
Пример #7
0
 def setUp(self):
     super(TestRealNotificationHA, self).setUp()
     self.CONF.set_override('workload_partitioning',
                            True,
                            group='notification')
     self.CONF.set_override("backend_url", "zake://", group="coordination")
     self.srv = notification.NotificationService(0, self.CONF)
Пример #8
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
     messaging.setup('fake://')
     self.addCleanup(messaging.cleanup)
     self.CONF.set_override("connection", "log://", group='database')
     self.CONF.set_override("store_events", False, group="notification")
     self.srv = notification.NotificationService()
 def setUp(self):
     super(TestNotification, self).setUp()
     conf = service.prepare_service([], [])
     self.CONF = self.useFixture(fixture_config.Config(conf)).conf
     self.CONF.set_override("connection", "log://", group='database')
     self.CONF.set_override("backend_url", None, group="coordination")
     self.CONF.set_override("workload_partitioning", True,
                            group='notification')
     self.setup_messaging(self.CONF)
     self.srv = notification.NotificationService(0, self.CONF)
Пример #10
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.CONF = self.useFixture(fixture_config.Config()).conf
     self.CONF.set_override("connection", "log://", group='database')
     self.CONF.set_override("backend_url", None, group="coordination")
     self.CONF.set_override("store_events", False, group="notification")
     self.CONF.set_override("disable_non_metric_meters",
                            False,
                            group="notification")
     self.setup_messaging(self.CONF)
     self.srv = notification.NotificationService()
    def _check_notifications(self, fake_publisher_cls):
        fake_publisher_cls.side_effect = [self.publisher, self.publisher2]

        self.srv = notification.NotificationService()
        self.srv2 = notification.NotificationService()
        with mock.patch(
                'ceilometer.coordination.PartitionCoordinator'
                '._get_members',
                return_value=['harry', 'lloyd']):
            with mock.patch('uuid.uuid4', return_value='harry'):
                self.srv.start()
            with mock.patch('uuid.uuid4', return_value='lloyd'):
                self.srv2.start()

        notifier = messaging.get_notifier(self.transport,
                                          "compute.vagrant-precise")
        payload1 = TEST_NOTICE_PAYLOAD.copy()
        payload1['instance_id'] = '0'
        notifier.info(context.RequestContext(), 'compute.instance.create.end',
                      payload1)
        payload2 = TEST_NOTICE_PAYLOAD.copy()
        payload2['instance_id'] = '1'
        notifier.info(context.RequestContext(), 'compute.instance.create.end',
                      payload2)
        self.expected_samples = 4
        start = timeutils.utcnow()
        with mock.patch('six.moves.builtins.hash', lambda x: int(x)):
            while timeutils.delta_seconds(start, timeutils.utcnow()) < 60:
                if (len(self.publisher.samples + self.publisher2.samples) >=
                        self.expected_samples):
                    break
                eventlet.sleep(0)
            self.srv.stop()
            self.srv2.stop()

        self.assertEqual(2, len(self.publisher.samples))
        self.assertEqual(2, len(self.publisher2.samples))
        self.assertEqual(
            1, len(set(s.resource_id for s in self.publisher.samples)))
        self.assertEqual(
            1, len(set(s.resource_id for s in self.publisher2.samples)))
Пример #12
0
    def setUp(self):
        super(TestRealNotification, self).setUp()
        self.CONF = self.useFixture(fixture_config.Config()).conf
        self.setup_messaging(self.CONF, 'nova')

        pipeline = yaml.dump([{
            'name': 'test_pipeline',
            'interval': 5,
            'counters': ['instance', 'memory'],
            'transformers': [],
            'publishers': ['test://'],
        }])

        self.expected_samples = 2

        pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
                                                        prefix="pipeline",
                                                        suffix="yaml")
        self.CONF.set_override("pipeline_cfg_file", pipeline_cfg_file)
        self.srv = notification.NotificationService()
        self.publisher = test_publisher.TestPublisher("")
    def setUp(self):
        super(TestRealNotification, self).setUp()
        self.CONF = self.useFixture(config.Config()).conf
        self.useFixture(oslo.messaging.conffixture.ConfFixture(self.CONF))

        pipeline = yaml.dump([{
            'name': 'test_pipeline',
            'interval': 5,
            'counters': ['*'],
            'transformers': [],
            'publishers': ['test://'],
        }])
        pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
                                                        prefix="pipeline",
                                                        suffix="yaml")
        self.CONF.set_override("pipeline_cfg_file", pipeline_cfg_file)
        self.CONF.set_override("notification_driver", "messaging")
        self.CONF.set_override("control_exchange", "nova")
        messaging.setup('fake://')
        self.addCleanup(messaging.cleanup)

        self.srv = notification.NotificationService()
Пример #14
0
    def test_multiple_agents(self, fake_publisher_cls):
        fake_publisher_cls.return_value = self.publisher

        self.srv2 = notification.NotificationService()
        with mock.patch(
                'ceilometer.coordination.PartitionCoordinator'
                '._get_members',
                return_value=['harry', 'lloyd']):
            with mock.patch('uuid.uuid4', return_value='harry'):
                self.srv.start()
            with mock.patch('uuid.uuid4', return_value='lloyd'):
                self.srv2.start()

        notifier = messaging.get_notifier(self.transport,
                                          "compute.vagrant-precise")
        payload1 = TEST_NOTICE_PAYLOAD.copy()
        payload1['instance_id'] = '0'
        notifier.info(context.RequestContext(), 'compute.instance.create.end',
                      payload1)
        payload2 = TEST_NOTICE_PAYLOAD.copy()
        payload2['instance_id'] = '1'
        notifier.info(context.RequestContext(), 'compute.instance.create.end',
                      payload2)
        self.expected_samples = 4
        self.expected_events = 2
        start = timeutils.utcnow()
        while timeutils.delta_seconds(start, timeutils.utcnow()) < 60:
            if (len(self.publisher.samples) >= self.expected_samples
                    and len(self.publisher.events) >= self.expected_events):
                break
            eventlet.sleep(0)
        self.srv.stop()
        self.srv2.stop()

        resources = set(s.resource_id for s in self.publisher.samples)
        self.assertEqual(self.expected_samples, len(self.publisher.samples))
        self.assertEqual(self.expected_events, len(self.publisher.events))
        self.assertEqual(set(['1', '0']), resources)
Пример #15
0
def main():
    service.prepare_service()
    os_service.launch(CONF,
                      notification.NotificationService(),
                      workers=service.get_workers('notification')).wait()
Пример #16
0
def main():
    service.prepare_service()
    os_service.launch(CONF, notification.NotificationService(),
                      workers=CONF.notification.workers).wait()
Пример #17
0
 def setUp(self):
     super(TestRealNotificationHA, self).setUp()
     self.CONF.set_override('workload_partitioning', True,
                            group='notification')
     self.srv = notification.NotificationService()
Пример #18
0
 def setUp(self):
     super(TestRealNotification, self).setUp()
     self.srv = notification.NotificationService()
Пример #19
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.srv = notification.NotificationService('the-host', 'the-topic')
     self.CONF = self.useFixture(config.Config()).conf
     self.CONF.set_override("connection", "log://", group='database')
Пример #20
0
 def setUp(self):
     super(TestRealNotificationReloadablePipeline, self).setUp()
     self.CONF.set_override('refresh_pipeline_cfg', True)
     self.CONF.set_override('pipeline_polling_interval', 1)
     self.srv = notification.NotificationService()
Пример #21
0
 def setUp(self):
     super(TestNotification, self).setUp()
     self.CONF = service.prepare_service([], [])
     self.setup_messaging(self.CONF)
     self.srv = notification.NotificationService(0, self.CONF)