Example #1
0
    def test_create_volume_non_admin(self):
        """Test creating an instance locally using run_instance, passing
        a non-admin context.  DB actions should work.
        """
        self.was_admin = False

        def fake_get(context, *args, **kwargs):
            # make sure this is called with admin context, even though
            # we're using user context below
            self.was_admin = context.is_admin
            return {}

        sched = fakes.FakeFilterScheduler()
        self.stubs.Set(sched.host_manager, 'get_all_host_states', fake_get)

        fake_context = context.RequestContext('user', 'project')

        request_spec = {
            'volume_properties': {
                'project_id': 1,
                'size': 1
            },
            'volume_type': {
                'name': 'LVM_iSCSI'
            },
            'volume_id': ['fake-id1']
        }
        self.assertRaises(exception.NoValidHost, sched.schedule_create_volume,
                          fake_context, request_spec, {})
        self.assertTrue(self.was_admin)
Example #2
0
    def test_schedule_consistencygroup(self, _mock_service_get_all_by_topic):
        # Make sure _schedule_group() can find host successfully.
        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)

        specs = {'capabilities:consistencygroup_support': '<is> True'}
        request_spec = {
            'volume_properties': {
                'project_id': 1,
                'size': 0
            },
            'volume_type': {
                'name': 'Type1',
                'extra_specs': specs
            }
        }
        request_spec2 = {
            'volume_properties': {
                'project_id': 1,
                'size': 0
            },
            'volume_type': {
                'name': 'Type2',
                'extra_specs': specs
            }
        }
        request_spec_list = [request_spec, request_spec2]
        weighed_host = sched._schedule_group(fake_context, request_spec_list,
                                             {})
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #3
0
    def test_create_volume_non_admin(self, _mock_get_all_host_states):
        # Test creating a volume locally using create_volume, passing
        # a non-admin context.  DB actions should work.
        self.was_admin = False

        def fake_get(ctxt):
            # Make sure this is called with admin context, even though
            # we're using user context below.
            self.was_admin = ctxt.is_admin
            return {}

        sched = fakes.FakeFilterScheduler()
        _mock_get_all_host_states.side_effect = fake_get

        fake_context = context.RequestContext('user', 'project')

        request_spec = {
            'volume_properties': {
                'project_id': 1,
                'size': 1
            },
            'volume_type': {
                'name': 'LVM_iSCSI'
            },
            'volume_id': ['fake-id1']
        }
        self.assertRaises(exception.NoValidHost, sched.schedule_create_volume,
                          fake_context, request_spec, {})
        self.assertTrue(self.was_admin)
Example #4
0
    def test_create_consistencygroup_no_hosts(self):
        # Ensure empty hosts result in NoValidHosts exception.
        sched = fakes.FakeFilterScheduler()

        fake_context = context.RequestContext('user', 'project')
        request_spec = {
            'volume_properties': {
                'project_id': 1,
                'size': 0
            },
            'volume_type': {
                'name': 'Type1',
                'extra_specs': {}
            }
        }
        request_spec2 = {
            'volume_properties': {
                'project_id': 1,
                'size': 0
            },
            'volume_type': {
                'name': 'Type2',
                'extra_specs': {}
            }
        }
        request_spec_list = [request_spec, request_spec2]
        self.assertRaises(exception.NoValidHost,
                          sched.schedule_create_consistencygroup, fake_context,
                          'faki-id1', request_spec_list, {})
Example #5
0
    def test_schedule_happy_day(self):
        """Make sure there's nothing glaringly wrong with _schedule()
        by doing a happy day pass through."""

        self.next_weight = 1.0

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return [weights.WeighedHost(host_state, self.next_weight)]

        sched = fakes.FakeFilterScheduler()
        fake_context = context.RequestContext('user', 'project', is_admin=True)

        self.stubs.Set(sched.host_manager, 'get_filtered_hosts',
                       fake_get_filtered_hosts)
        self.stubs.Set(weights.HostWeightHandler, 'get_weighed_objects',
                       _fake_weigh_objects)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {
            'volume_type': {
                'name': 'LVM_iSCSI'
            },
            'volume_properties': {
                'project_id': 1,
                'size': 1
            }
        }
        self.mox.ReplayAll()
        weighed_host = sched._schedule(fake_context, request_spec, {})
        self.assertTrue(weighed_host.obj is not None)
Example #6
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 #7
0
    def test_add_retry_host(self):
        retry = dict(num_attempts=1, hosts=[])
        filter_properties = dict(retry=retry)
        host = "fakehost"

        sched = fakes.FakeFilterScheduler()
        sched._add_retry_host(filter_properties, host)

        hosts = filter_properties['retry']['hosts']
        self.assertEqual(1, len(hosts))
        self.assertEqual(host, hosts[0])
Example #8
0
    def test_post_select_populate(self):
        # Test addition of certain filter props after a node is selected.
        retry = {'hosts': [], 'num_attempts': 1}
        filter_properties = {'retry': retry}
        sched = fakes.FakeFilterScheduler()

        host_state = host_manager.HostState('host')
        host_state.total_capacity_gb = 1024
        sched._post_select_populate_filter_properties(filter_properties,
                                                      host_state)

        self.assertEqual('host', filter_properties['retry']['hosts'][0])

        self.assertEqual(1024, host_state.total_capacity_gb)
    def test_create_volume_no_hosts(self):
        """Ensure empty hosts/child_zones result in NoValidHosts exception."""
        def _fake_empty_call_zone_method(*args, **kwargs):
            return []

        sched = fakes.FakeFilterScheduler()

        fake_context = context.RequestContext('user', 'project')
        request_spec = {'volume_properties': {'project_id': 1,
                                              'size': 1},
                        'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_id': ['fake-id1']}
        self.assertRaises(exception.NoValidHost, sched.schedule_create_volume,
                          fake_context, request_spec, {})
    def test_retry_exceeded_max_attempts(self):
        # Test for necessary explosion when max retries is exceeded.
        self.flags(scheduler_max_attempts=2)
        sched = fakes.FakeFilterScheduler()

        request_spec = {'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_properties': {'project_id': 1,
                                              'size': 1}}

        retry = dict(num_attempts=2)
        filter_properties = dict(retry=retry)

        self.assertRaises(exception.NoValidHost, sched._schedule, self.context,
                          request_spec, filter_properties=filter_properties)
    def test_retry_attempt_one(self):
        # Test retry logic on initial scheduling attempt.
        self.flags(scheduler_max_attempts=2)
        sched = fakes.FakeFilterScheduler()

        request_spec = {'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_properties': {'project_id': 1,
                                              'size': 1}}
        filter_properties = {}

        sched._schedule(self.context, request_spec,
                        filter_properties=filter_properties)

        num_attempts = filter_properties['retry']['num_attempts']
        self.assertEqual(1, num_attempts)
    def test_retry_disabled(self):
        # Retry info should not get populated when re-scheduling is off.
        self.flags(scheduler_max_attempts=1)
        sched = fakes.FakeFilterScheduler()

        request_spec = {'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_properties': {'project_id': 1,
                                              'size': 1}}
        filter_properties = {}

        sched._schedule(self.context, request_spec,
                        filter_properties=filter_properties)

        # should not have retry info in the populated filter properties:
        self.assertNotIn("retry", filter_properties)
    def test_retry_attempt_two(self):
        # Test retry logic when re-scheduling.
        self.flags(scheduler_max_attempts=2)
        sched = fakes.FakeFilterScheduler()

        request_spec = {'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_properties': {'project_id': 1,
                                              'size': 1}}

        retry = dict(num_attempts=1)
        filter_properties = dict(retry=retry)

        sched._schedule(self.context, request_spec,
                        filter_properties=filter_properties)

        num_attempts = filter_properties['retry']['num_attempts']
        self.assertEqual(2, num_attempts)
    def test_schedule_happy_day(self):
        """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.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'volume_type': {'name': 'LVM_iSCSI'},
                        'volume_properties': {'project_id': 1,
                                              'size': 1}}
        self.mox.ReplayAll()
        weighed_host = sched._schedule(fake_context, request_spec, {})
        self.assertIsNotNone(weighed_host.obj)
    def _host_passes_filters_setup(self):
        self.next_weight = 1.0

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return [weights.WeighedHost(host_state, self.next_weight)]

        sched = fakes.FakeFilterScheduler()
        sched.host_manager = fakes.FakeHostManager()
        fake_context = context.RequestContext('user', 'project', is_admin=True)

        self.stubs.Set(sched.host_manager, 'get_filtered_hosts',
                       fake_get_filtered_hosts)
        self.stubs.Set(weights.HostWeightHandler, 'get_weighed_objects',
                       _fake_weigh_objects)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        self.mox.ReplayAll()
        return (sched, fake_context)
Example #16
0
    def test_schedule_happy_day(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 = {
            'volume_type': {
                'name': 'LVM_iSCSI'
            },
            'volume_properties': {
                'project_id': 1,
                'size': 1
            }
        }
        weighed_host = sched._schedule(fake_context, request_spec, {})
        self.assertIsNotNone(weighed_host.obj)
        self.assertTrue(_mock_service_get_all_by_topic.called)
Example #17
0
    def test_max_attempts(self):
        self.flags(scheduler_max_attempts=4)

        sched = fakes.FakeFilterScheduler()
        self.assertEqual(4, sched._max_attempts())