Пример #1
0
    def setUp(self):
        super(TestNovaListeners, self).setUp()
        self.servers_plugin = self.initialized_plugins['OS::Nova::Server']
        self.sg_plugin = self.initialized_plugins['OS::Nova::ServerGroup']
        self.flavor_plugin = self.initialized_plugins['OS::Nova::Flavor']

        notification_plugins = {
            plugin.document_type: utils.StevedoreMock(plugin)
            for plugin in (self.servers_plugin, self.sg_plugin,
                           self.flavor_plugin)
        }
        self.notification_endpoint = NotificationEndpoint(
            notification_plugins, PipelineManager(notification_plugins))
        self.listener_alias = self.servers_plugin.alias_name_listener
Пример #2
0
    def setUp(self):
        version_notifications = \
            'searchlight.elasticsearch.plugins.nova.notification_handler'\
            '.InstanceHandler._use_versioned_notifications'
        mock_versioned = mock.patch(version_notifications, return_value=False)
        mock_versioned.start()
        self.addCleanup(mock_versioned.stop)

        super(TestNovaUnversionedListener, self).setUp()
        self.servers_plugin = self.initialized_plugins['OS::Nova::Server']
        self.server_events = self._load_fixture_data('events/servers.json')

        sp = self.servers_plugin
        notification_plugins = {sp.document_type: utils.StevedoreMock(sp)}

        self.notification_endpoint = NotificationEndpoint(
            notification_plugins, PipelineManager(notification_plugins))
        self.listener_alias = self.servers_plugin.alias_name_listener
Пример #3
0
    def test_manage_type_glob(self, mock_get_plugins, mock_utcnow):
        mock_utcnow.return_value = datetime.datetime(year=2016, month=3, day=3)
        expected_index_name = 'searchlight-2016_03_03_00_00_00'

        simple_plugin = fake_plugins.FakeSimplePlugin(self.elastic_connection)
        child_plugin = fake_plugins.FakeChildPlugin(self.elastic_connection)
        non_role_plugin = fake_plugins.NonRoleSeparatedPlugin(
            self.elastic_connection)
        child_plugin.register_parent(simple_plugin)

        mock_get_plugins.return_value = {
            plugin.get_document_type(): test_utils.StevedoreMock(plugin)
            for plugin in (simple_plugin, child_plugin, non_role_plugin)
        }
        index_command = manage.IndexCommands()

        # Expect this to match simple plugin and child plugin, but not
        # non_role_plugin. Patch the index->index function call since it won't
        # find any data, and we want to check it's called correctly
        with mock.patch.object(index_command,
                               '_es_reindex_worker') as patch_es_reindex:
            try:
                # Use two wildcard matches
                index_command.sync(_type='fake-sim*,fake-chi*', force=True)

                es_results = self._get_all_elasticsearch_docs()
                es_hits = self._get_hit_source(es_results)
            finally:
                es_utils.delete_index(expected_index_name)

            patch_es_reindex.assert_called_with(
                {non_role_plugin.get_document_type(): non_role_plugin},
                [('searchlight', 'searchlight-search',
                 'searchlight-listener')],
                {'searchlight': expected_index_name}
            )

        expected = ['simple1', 'child1']
        self.assertEqual(len(expected), len(es_hits))
        self.assertEqual(
            set(expected),
            set(hit['_id'] for hit in es_results['hits']['hits']))
    def setUp(self):
        super(TestNeutronListeners, self).setUp()

        self.networks_plugin = self.initialized_plugins['OS::Neutron::Net']
        self.ports_plugin = self.initialized_plugins['OS::Neutron::Port']
        self.subnets_plugin = self.initialized_plugins['OS::Neutron::Subnet']
        self.routers_plugin = self.initialized_plugins['OS::Neutron::Router']
        self.fip_plugin = self.initialized_plugins['OS::Neutron::FloatingIP']
        self.secgroup_plugin = (
            self.initialized_plugins['OS::Neutron::SecurityGroup'])

        notification_plugins = {
            plugin.document_type: utils.StevedoreMock(plugin)
            for plugin in (self.networks_plugin, self.ports_plugin,
                           self.subnets_plugin, self.routers_plugin,
                           self.fip_plugin, self.secgroup_plugin)
        }
        self.notification_endpoint = NotificationEndpoint(notification_plugins)

        self.listener_alias = self.networks_plugin.alias_name_listener
Пример #5
0
    def setUp(self):
        super(TestGlanceListener, self).setUp()
        openstack_client_mod = "searchlight.elasticsearch.plugins." \
                               "openstack_clients.get_glanceclient"
        osclient_patcher = mock.patch(
            openstack_client_mod, mock_glance_pyclient.get_fake_glance_client)
        osclient_patcher.start()
        self.addCleanup(osclient_patcher.stop)

        self.images_plugin = self.initialized_plugins['OS::Glance::Image']
        self.metadefs_plugin = self.initialized_plugins['OS::Glance::Metadef']

        notification_plugins = {
            plugin.document_type: utils.StevedoreMock(plugin)
            for plugin in (self.images_plugin, self.metadefs_plugin)
        }
        self.notification_endpoint = NotificationEndpoint(notification_plugins)

        self.images_index = self.images_plugin.alias_name_listener
        self.metadefs_index = self.metadefs_plugin.alias_name_listener
Пример #6
0
    def setUp(self):
        super(TestDesignateListener, self).setUp()

        self.zones_plugin = self.initialized_plugins['OS::Designate::Zone']
        self.recordsets_plugin = self.initialized_plugins[
            'OS::Designate::RecordSet']
        '''openstack_client_mod = "searchlight.elasticsearch.plugins." \
                               "openstack_clients.get_designateclient"
        osclient_patcher = mock.patch(
            openstack_client_mod,
            mock_designate_pyclient.get_fake_designate_client
        )
        osclient_patcher.start()
        self.addCleanup(osclient_patcher.stop)'''

        notification_plugins = {
            plugin.document_type: utils.StevedoreMock(plugin)
            for plugin in (self.zones_plugin, self.recordsets_plugin)
        }
        self.notification_endpoint = NotificationEndpoint(notification_plugins)

        self.listener_alias = self.zones_plugin.alias_name_listener
Пример #7
0
    def setUp(self):
        super(TestCinderNotifications, self).setUp()
        self.volume_plugin = self.initialized_plugins['OS::Cinder::Volume']
        self.snapshot_plugin = self.initialized_plugins['OS::Cinder::Snapshot']

        self.volume_events = self._load_fixture_data('events/volumes.json')
        self.snapshot_events = self._load_fixture_data('events/snapshots.json')

        notification_plugins = {
            plugin.document_type: utils.StevedoreMock(plugin)
            for plugin in (self.volume_plugin, self.snapshot_plugin)
        }
        self.notification_endpoint = NotificationEndpoint(notification_plugins)

        self.index_alias = self.volume_plugin.alias_name_listener

        volume = {
            'id': VOLUME_ID1,
            'user_id': USER_ID,
            'created_at': '2016-03-07T16:51:09.000000',
            'updated_at': '2016-03-07T16:51:09.000000'
        }
        self.volume_fixture = utils.DictObj(**volume)
Пример #8
0
    def test_manage(self, mock_get_plugins, mock_utcnow):
        """Test that manage index sync works from end to end. Uses fake plugins
        because it avoids having to fake service data and is less dependent
        on functional tests for each service plugin.
        """
        mock_utcnow.return_value = datetime.datetime(year=2016, month=1, day=1)
        expected_index_name = 'searchlight-2016_01_01_00_00_00'

        simple_plugin = fake_plugins.FakeSimplePlugin(self.elastic_connection)
        child_plugin = fake_plugins.FakeChildPlugin(self.elastic_connection)
        non_role_plugin = fake_plugins.NonRoleSeparatedPlugin(
            self.elastic_connection)
        child_plugin.register_parent(simple_plugin)

        mock_get_plugins.return_value = {
            plugin.get_document_type(): test_utils.StevedoreMock(plugin)
            for plugin in (simple_plugin, child_plugin, non_role_plugin)
        }
        index_command = manage.IndexCommands()
        # The fake plugins all have hardcoded data for get_objects that will
        # be indexed. Use force=True to avoid the 'are you sure?' prompt
        try:
            index_command.sync(force=True)

            es_results = self._get_all_elasticsearch_docs()
            es_hits = self._get_hit_source(es_results)
        finally:
            es_utils.delete_index(expected_index_name)

        self.assertEqual(expected_index_name,
                         es_results['hits']['hits'][0]['_index'])

        expected = ['simple1', 'child1', 'non-role-fake1', 'non-role-fake2']
        self.assertEqual(len(expected), len(es_hits))
        self.assertEqual(
            set(expected),
            set(hit['_id'] for hit in es_results['hits']['hits']))