Example #1
0
    def test_schedule_share_with_cg_pool_support(
            self, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': {
                'name': 'NFS',
                'extra_specs': {'consistency_group_support': 'pool'}
            },
            'share_properties': {'project_id': 1, 'size': 1},
            'share_instance_properties': {'project_id': 1, 'size': 1},
            'consistency_group': {
                'id': 'fake-cg-id',
                'host': 'host5#_pool0',
            }
        }

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertEqual('host5#_pool0', weighed_host.obj.host)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #2
0
    def test__schedule_share_with_valid_replication_spec(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project', is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_instance_properties': {
                'project_id': 1,
                'size': 1
            },
        }
        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(hasattr(weighed_host.obj, REPLICATION_TYPE_SPEC))
        expected_replication_type_support = (share_type.get(
            'extra_specs', {}).get(REPLICATION_TYPE_SPEC))
        self.assertEqual(expected_replication_type_support,
                         getattr(weighed_host.obj, REPLICATION_TYPE_SPEC))
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #3
0
    def test__schedule_share_valid_storage_protocol(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project', is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_instance_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_proto': 'GLUSTERFS',
        }
        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertEqual('GLUSTERFS',
                         getattr(weighed_host.obj, 'storage_protocol'))
        self.assertEqual('host6', weighed_host.obj.host.split('#')[0])
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #4
0
    def test__schedule_share_with_snapshot_support(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {'project_id': 1, 'size': 1},
            'share_instance_properties': {},
        }

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(hasattr(weighed_host.obj, SNAPSHOT_SUPPORT))
        expected_snapshot_support = strutils.bool_from_string(
            share_type.get('extra_specs', {}).get(
                SNAPSHOT_SUPPORT, 'True').split()[-1])
        self.assertEqual(
            expected_snapshot_support,
            getattr(weighed_host.obj, SNAPSHOT_SUPPORT))
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #5
0
 def _get_all_hosts(self, _mock_service_get_all_by_topic, disabled=False):
     ctxt = context.get_admin_context()
     fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic,
                                      disabled=disabled)
     host_states = self.host_manager.get_all_host_states_share(ctxt)
     _mock_service_get_all_by_topic.assert_called_once_with(
         ctxt, CONF.share_topic)
     return host_states
Example #6
0
    def test__schedule_share_with_default_dedupe_value_fail(
            self, capability, _mock_service_get_all_by_topic):
        sched, fake_context, request_spec = self._setup_dedupe_fakes(
            {'capabilities:dedupe': capability})
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)

        self.assertRaises(exception.NoValidHost, sched._schedule_share,
                          fake_context, request_spec, {})
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #7
0
    def test__schedule_share_with_default_dedupe_value_fail(
            self, capability, _mock_service_get_all_by_topic):
        sched, fake_context, request_spec = self._setup_dedupe_fakes(
            {'capabilities:dedupe': capability})
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)

        self.assertRaises(exception.NoValidHost, sched._schedule_share,
                          fake_context, request_spec, {})
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #8
0
    def _host_passes_filters_setup(self, mock_obj):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)

        fakes.mock_host_manager_db_calls(mock_obj)

        return (sched, fake_context)
Example #9
0
    def test__schedule_share_with_default_dedupe_value_fail(
            self, capability, _mock_service_get_all_by_topic):
        sched, fake_context, request_spec = self._setup_dedupe_fakes(
            {'capabilities:dedupe': capability})
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNone(weighed_host)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #10
0
    def test__schedule_share_with_default_dedupe_value(
            self, _mock_service_get_all_by_topic):
        sched, fake_context, request_spec = self._setup_dedupe_fakes(
            {'capabilities:dedupe': '<is> False'})
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(hasattr(weighed_host.obj, 'dedupe'))
        self.assertFalse(weighed_host.obj.dedupe)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #11
0
    def test_get_weighted_candidates_for_consistency_group_many_hosts(
            self, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project')
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {'share_types': [{'name': 'NFS',
                                         'extra_specs': {
                                             SNAPSHOT_SUPPORT: True
                                         }}]}

        hosts = sched._get_weighted_candidates_cg(fake_context,
                                                  request_spec)

        self.assertEqual(2, len(hosts))
Example #12
0
 def test_schedule_happy_day_share(self, _mock_service_get_all_by_topic):
     # Make sure there's nothing glaringly wrong with _schedule()
     # by doing a happy day pass through.
     sched = fakes.FakeFilterScheduler()
     sched.host_manager = fakes.FakeHostManager()
     fake_context = context.RequestContext('user', 'project',
                                           is_admin=True)
     fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
     request_spec = {
         'share_type': {'name': 'LVM_NFS'},
         'share_properties': {'project_id': 1, 'size': 1},
     }
     weighed_host = sched._schedule_share(fake_context, request_spec, {})
     self.assertIsNotNone(weighed_host.obj)
     self.assertTrue(_mock_service_get_all_by_topic.called)
Example #13
0
 def test__schedule_share_with_invalid_replication_type_spec(
         self, share_type, _mock_service_get_all_by_topic):
     sched = fakes.FakeFilterScheduler()
     sched.host_manager = fakes.FakeHostManager()
     fake_context = context.RequestContext('user', 'project',
                                           is_admin=True)
     fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
     request_spec = {
         'share_type': share_type,
         'share_properties': {'project_id': 1, 'size': 1},
         'share_instance_properties': {'project_id': 1, 'size': 1},
     }
     self.assertRaises(exception.NoValidHost, sched._schedule_share,
                       fake_context, request_spec, {})
     self.assertTrue(_mock_service_get_all_by_topic.called)
Example #14
0
    def test__schedule_share_without_snapshot_support(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {'project_id': 1, 'size': 1},
            'share_instance_properties': {'project_id': 1, 'size': 1},
        }

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNone(weighed_host)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #15
0
    def test_schedule_share_with_instance_properties(
            self, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        share_type = {'name': 'foo'}
        request_spec = {
            'share_type': share_type,
            'share_properties': {'project_id': 1, 'size': 1},
            'share_instance_properties': {'availability_zone_id': "fake_az"},
        }

        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNone(weighed_host)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #16
0
    def test__schedule_share_with_valid_replication_spec(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project',
                                              is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {'project_id': 1, 'size': 1},
            'share_instance_properties': {'project_id': 1, 'size': 1},
        }
        weighed_host = sched._schedule_share(fake_context, request_spec, {})

        self.assertIsNotNone(weighed_host)
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(hasattr(weighed_host.obj, REPLICATION_TYPE_SPEC))
        expected_replication_type_support = (
            share_type.get('extra_specs', {}).get(REPLICATION_TYPE_SPEC))
        self.assertEqual(
            expected_replication_type_support,
            getattr(weighed_host.obj, REPLICATION_TYPE_SPEC))
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #17
0
    def test__schedule_share_storage_protocol_not_supported(
            self, share_type, _mock_service_get_all_by_topic):
        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        requested_share_proto = (share_type.get('storage_protocol',
                                                '').strip('<in> ') or 'MAPRFS')
        fake_context = context.RequestContext('user', 'project', is_admin=True)
        fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
        request_spec = {
            'share_type': share_type,
            'share_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_instance_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_proto': requested_share_proto,
        }

        self.assertRaises(exception.NoValidHost, sched._schedule_share,
                          fake_context, request_spec, {})
        self.assertTrue(_mock_service_get_all_by_topic.called)