def test_select_hosts_happy_day(self):
        """select_hosts is basically a wrapper around the _select() method.
           Similar to the _select tests, this just does a happy path test to
           ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

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

        self.stubs.Set(sched.host_manager,
                       'get_hosts_stripping_ignored_and_forced',
            fake_get_hosts_stripping_ignored_and_forced)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux'}}
        self.mox.ReplayAll()
        hosts = sched.select_hosts(fake_context, request_spec, {})
        self.assertEquals(len(hosts), 10)
        for host in hosts:
            self.assertTrue(host is not None)
    def test_select_destinations(self):
        """select_destinations is basically a wrapper around _schedule().

        Similar to the _schedule tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        selected_hosts = []
        selected_nodes = []

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

        self.stubs.Set(sched.host_manager,
                       'get_hosts_stripping_ignored_and_forced',
            fake_get_hosts_stripping_ignored_and_forced)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux'},
                        'num_instances': 1}
        self.mox.ReplayAll()
        dests = sched.select_destinations(fake_context, request_spec, {})
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertTrue(host is not None)
        self.assertTrue(node is not None)
    def test_schedule_chooses_best_host(self):
        """The host with the highest free_ram_mb will be chosen!
        """

        self.flags(scheduler_host_subset_size=1)
        self.flags(ram_weight_multiplier=-1)

        sched = fakes.FakeSolverScheduler()

        fake_context = context.RequestContext('user', 'project',
                is_admin=True)
        self.stubs.Set(sched.host_manager,
                       'get_hosts_stripping_ignored_and_forced',
                fake_get_hosts_stripping_ignored_and_forced)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {'project_id': 1,
                                'root_gb': 512,
                                'memory_mb': 512,
                                'ephemeral_gb': 0,
                                'vcpus': 1,
                                'os_type': 'Linux'}

        request_spec = dict(instance_properties=instance_properties)

        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec,
                filter_properties=filter_properties)

        # one host should be chosen
        self.assertEquals(1, len(hosts))
    def test_schedule_large_host_pool(self):
        """Hosts should still be chosen if pool size
        is larger than number of filtered hosts.
        """

        sched = fakes.FakeFilterScheduler()

        fake_context = context.RequestContext("user", "project", is_admin=True)
        self.flags(scheduler_host_subset_size=20)
        self.stubs.Set(sched.host_manager, "get_filtered_hosts", fake_get_filtered_hosts)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {
            "project_id": 1,
            "root_gb": 512,
            "memory_mb": 512,
            "ephemeral_gb": 0,
            "vcpus": 1,
            "os_type": "Linux",
        }
        request_spec = dict(instance_properties=instance_properties, instance_type={})
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec, filter_properties=filter_properties)

        # one host should be chose
        self.assertEqual(len(hosts), 1)
    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_weighted_sum(functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return least_cost.WeightedHost(self.next_weight, host_state=host_state)

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

        self.stubs.Set(sched.host_manager, "filter_hosts", fake_filter_hosts)
        self.stubs.Set(least_cost, "weighted_sum", _fake_weighted_sum)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {
            "num_instances": 10,
            "instance_type": {"memory_mb": 512, "root_gb": 512, "ephemeral_gb": 0, "vcpus": 1},
            "instance_properties": {"project_id": 1, "root_gb": 512, "memory_mb": 512, "ephemeral_gb": 0, "vcpus": 1},
        }
        self.mox.ReplayAll()
        weighted_hosts = sched._schedule(fake_context, "compute", request_spec, {})
        self.assertEquals(len(weighted_hosts), 10)
        for weighted_host in weighted_hosts:
            self.assertTrue(weighted_host.host_state is not None)
    def test_schedule_happy_day(self):
        """Make sure there's nothing glaringly wrong with _schedule()
        by doing a happy day pass through.
        """

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

        self.stubs.Set(sched.host_manager,
                       'get_hosts_stripping_ignored_and_forced',
                fake_get_hosts_stripping_ignored_and_forced)

        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux'}}
        self.mox.ReplayAll()
        selected_hosts = sched._schedule(fake_context, request_spec, {})
        self.assertEquals(len(selected_hosts), 10)
        for host in selected_hosts:
            self.assertTrue(host is not None)
Exemple #7
0
    def test_schedule_host_pool(self):
        """Make sure the scheduler_host_subset_size property works properly."""

        self.flags(scheduler_host_subset_size=2)
        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {
            'project_id': 1,
            'root_gb': 512,
            'memory_mb': 512,
            'ephemeral_gb': 0,
            'vcpus': 1,
            'os_type': 'Linux'
        }

        request_spec = dict(instance_properties=instance_properties,
                            instance_type={})
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context,
                                request_spec,
                                filter_properties=filter_properties)

        # one host should be chosen
        self.assertEqual(len(hosts), 1)
    def test_schedule_host_pool(self, mock_get_extra):
        """Make sure the scheduler_host_subset_size property works properly."""

        self.flags(scheduler_host_subset_size=2)
        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {
            "project_id": 1,
            "root_gb": 512,
            "memory_mb": 512,
            "ephemeral_gb": 0,
            "vcpus": 1,
            "os_type": "Linux",
            "uuid": "fake-uuid",
        }

        request_spec = dict(instance_properties=instance_properties, instance_type={})
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec, filter_properties=filter_properties)

        # one host should be chosen
        self.assertEqual(len(hosts), 1)
    def test_schedule_large_host_pool(self):
        """Hosts should still be chosen if pool size
        is larger than number of filtered hosts.
        """

        sched = fakes.FakeFilterScheduler()

        fake_context = context.RequestContext('user', 'project',
                is_admin=True)
        self.flags(scheduler_host_subset_size=20)
        self.stubs.Set(sched.host_manager, 'get_filtered_hosts',
                fake_get_filtered_hosts)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {'project_id': 1,
                                    'root_gb': 512,
                                    'memory_mb': 512,
                                    'ephemeral_gb': 0,
                                    'vcpus': 1,
                                    'os_type': 'Linux'}
        request_spec = dict(instance_properties=instance_properties)
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec,
                filter_properties=filter_properties)

        # one host should be chose
        self.assertEqual(len(hosts), 1)
Exemple #10
0
    def test_schedule_large_host_pool(self, mock_get_extra):
        """Hosts should still be chosen if pool size
        is larger than number of filtered hosts.
        """

        sched = fakes.FakeFilterScheduler()

        fake_context = context.RequestContext('user', 'project', is_admin=True)
        self.flags(scheduler_host_subset_size=20)
        self.stubs.Set(sched.host_manager, 'get_filtered_hosts',
                       fake_get_filtered_hosts)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {
            'project_id': 1,
            'root_gb': 512,
            'memory_mb': 512,
            'ephemeral_gb': 0,
            'vcpus': 1,
            'os_type': 'Linux',
            'uuid': 'fake-uuid'
        }
        request_spec = dict(instance_properties=instance_properties,
                            instance_type={})
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context,
                                request_spec,
                                filter_properties=filter_properties)

        # one host should be chose
        self.assertEqual(len(hosts), 1)
Exemple #11
0
    def test_schedule_host_pool(self, mock_get_extra):
        """Make sure the scheduler_host_subset_size property works properly."""

        self.flags(scheduler_host_subset_size=2)
        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        instance_properties = {'project_id': 1,
                               'root_gb': 512,
                               'memory_mb': 512,
                               'ephemeral_gb': 0,
                               'vcpus': 1,
                               'os_type': 'Linux',
                               'uuid': 'fake-uuid'}

        request_spec = dict(instance_properties=instance_properties,
                            instance_type={})
        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec,
                filter_properties=filter_properties)

        # one host should be chosen
        self.assertEqual(len(hosts), 1)
 def _get_all_hosts(self):
     ctxt = context.get_admin_context()
     fakes.mox_host_manager_db_calls(self.mox, ctxt)
     self.mox.ReplayAll()
     host_states = self.host_manager.get_all_host_states(ctxt)
     self.mox.VerifyAll()
     self.mox.ResetAll()
     return host_states
Exemple #13
0
 def _get_all_hosts(self):
     ctxt = context.get_admin_context()
     fakes.mox_host_manager_db_calls(self.mox, ctxt)
     self.mox.ReplayAll()
     host_states = self.host_manager.get_all_host_states(ctxt, "compute")
     self.mox.VerifyAll()
     self.mox.ResetAll()
     return host_states
Exemple #14
0
    def test_schedule_correct_instance_type(self):
        """ Make sure "_schedule" correct the instance_type of request_spec
        and filter_properties"""
        self.next_weight = 1.0
        expect_inst_type = {'project_id': 1,
                            'root_gb': 512,
                            'memory_mb': 512,
                            'ephemeral_gb': 0,
                            'vcpus': 1,
                            'extra_specs': {'vcpus': 20, 'ecus_per_vcpu:': 2}}

        old_inst_type = {'project_id': 1,
                         'root_gb': 512,
                         'memory_mb': 512,
                         'ephemeral_gb': 0,
                         'vcpus': 1,
                         'extra_specs': {'ecus_per_vcpu:': 2}}

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

        def _fake_instance_type_g_b_fid(*args, **kwargs):
            return expect_inst_type

        def _fake_weighted_sum(functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return least_cost.WeightedHost(self.next_weight,
                                           host_state=host_state)
            return least_cost.WeightedHost(1, host_state=hosts[0])

        self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum)

        self.stubs.Set(db,
            'instance_type_get_by_flavor_id', _fake_instance_type_g_b_fid)
        self.stubs.Set(sched.host_manager, 'filter_hosts', fake_filter_hosts)

        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'num_instances': 10,
                        'instance_type': old_inst_type,
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1}}
        filter_pros = {}
        self.mox.ReplayAll()
        sched._schedule(fake_context, 'compute', request_spec, filter_pros)
        self.assertEqual(filter_pros['instance_type'], expect_inst_type)
        self.assertEqual(request_spec['instance_type'], expect_inst_type)
Exemple #15
0
    def test_select_destinations(self, mock_get_extra):
        """select_destinations is basically a wrapper around _schedule().

        Similar to the _schedule tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

        selected_hosts = []
        selected_nodes = []

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            selected_hosts.append(host_state.host)
            selected_nodes.append(host_state.nodename)
            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 = {
            'instance_type': {
                'memory_mb': 512,
                'root_gb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1
            },
            'instance_properties': {
                'project_id': 1,
                'root_gb': 512,
                'memory_mb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1,
                'os_type': 'Linux',
                'uuid': 'fake-uuid'
            },
            'num_instances': 1
        }
        self.mox.ReplayAll()
        dests = sched.select_destinations(fake_context, request_spec, {})
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual(host, selected_hosts[0])
        self.assertEqual(node, selected_nodes[0])
Exemple #16
0
    def test_schedule_chooses_best_host(self, mock_get_extra):
        """If scheduler_host_subset_size is 1, the largest host with greatest
        weight should be returned.
        """

        self.flags(scheduler_host_subset_size=1)

        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        self.next_weight = 50

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

        instance_properties = {
            'project_id': 1,
            'root_gb': 512,
            'memory_mb': 512,
            'ephemeral_gb': 0,
            'vcpus': 1,
            'os_type': 'Linux',
            'uuid': 'fake-uuid'
        }

        request_spec = dict(instance_properties=instance_properties,
                            instance_type={})

        self.stubs.Set(weights.HostWeightHandler, 'get_weighed_objects',
                       _fake_weigh_objects)

        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context,
                                request_spec,
                                filter_properties=filter_properties)

        # one host should be chosen
        self.assertEqual(1, len(hosts))

        self.assertEqual(50, hosts[0].weight)
Exemple #17
0
    def test_select_hosts_happy_day(self):
        """select_hosts is basically a wrapper around the _select() method.

        Similar to the _select tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

        selected_hosts = []

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            selected_hosts.append(host_state.host)
            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 = {
            'num_instances': 10,
            'instance_type': {
                'memory_mb': 512,
                'root_gb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1
            },
            'instance_properties': {
                'project_id': 1,
                'root_gb': 512,
                'memory_mb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1,
                'os_type': 'Linux'
            }
        }
        self.mox.ReplayAll()
        hosts = sched.select_hosts(fake_context, request_spec, {})
        self.assertEquals(len(hosts), 10)
        self.assertEquals(hosts, selected_hosts)
Exemple #18
0
    def test_schedule_chooses_best_host(self, mock_get_extra):
        """If scheduler_host_subset_size is 1, the largest host with greatest
        weight should be returned.
        """

        self.flags(scheduler_host_subset_size=1)

        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        self.next_weight = 50

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

        instance_properties = {'project_id': 1,
                                'root_gb': 512,
                                'memory_mb': 512,
                                'ephemeral_gb': 0,
                                'vcpus': 1,
                                'os_type': 'Linux',
                                'uuid': 'fake-uuid'}

        request_spec = dict(instance_properties=instance_properties,
                            instance_type={})

        self.stubs.Set(weights.HostWeightHandler,
                        'get_weighed_objects', _fake_weigh_objects)

        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec,
                filter_properties=filter_properties)

        # one host should be chosen
        self.assertEqual(1, len(hosts))

        self.assertEqual(50, hosts[0].weight)
Exemple #19
0
    def test_select_destinations(self, mock_get_extra):
        """select_destinations is basically a wrapper around _schedule().

        Similar to the _schedule tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

        selected_hosts = []
        selected_nodes = []

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            selected_hosts.append(host_state.host)
            selected_nodes.append(host_state.nodename)
            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 = {'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux',
                                                'uuid': 'fake-uuid'},
                        'num_instances': 1}
        self.mox.ReplayAll()
        dests = sched.select_destinations(fake_context, request_spec, {})
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual(host, selected_hosts[0])
        self.assertEqual(node, selected_nodes[0])
Exemple #20
0
    def test_schedule_happy_day(self, mock_get_extra):
        """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 = {
            'num_instances': 10,
            'instance_type': {
                'memory_mb': 512,
                'root_gb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1
            },
            'instance_properties': {
                'project_id': 1,
                'root_gb': 512,
                'memory_mb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1,
                'os_type': 'Linux',
                'uuid': 'fake-uuid'
            }
        }
        self.mox.ReplayAll()
        weighed_hosts = sched._schedule(fake_context, request_spec, {})
        self.assertEqual(len(weighed_hosts), 10)
        for weighed_host in weighed_hosts:
            self.assertIsNotNone(weighed_host.obj)
    def test_select_destinations(self, mock_get_extra):
        """select_destinations is basically a wrapper around _schedule().

        Similar to the _schedule tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

        selected_hosts = []
        selected_nodes = []

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            selected_hosts.append(host_state.host)
            selected_nodes.append(host_state.nodename)
            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 = {
            "instance_type": {"memory_mb": 512, "root_gb": 512, "ephemeral_gb": 0, "vcpus": 1},
            "instance_properties": {
                "project_id": 1,
                "root_gb": 512,
                "memory_mb": 512,
                "ephemeral_gb": 0,
                "vcpus": 1,
                "os_type": "Linux",
                "uuid": "fake-uuid",
            },
            "num_instances": 1,
        }
        self.mox.ReplayAll()
        dests = sched.select_destinations(fake_context, request_spec, {})
        (host, node) = (dests[0]["host"], dests[0]["nodename"])
        self.assertEqual(host, selected_hosts[0])
        self.assertEqual(node, selected_nodes[0])
    def test_schedule_chooses_best_host(self):
        """If scheduler_host_subset_size is 1, the largest host with greatest
        weight should be returned.
        """

        self.flags(scheduler_host_subset_size=1)

        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)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        self.next_weight = 50

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

        instance_properties = {
            "project_id": 1,
            "root_gb": 512,
            "memory_mb": 512,
            "ephemeral_gb": 0,
            "vcpus": 1,
            "os_type": "Linux",
        }

        request_spec = dict(instance_properties=instance_properties, instance_type={})

        self.stubs.Set(weights.HostWeightHandler, "get_weighed_objects", _fake_weigh_objects)

        filter_properties = {}
        self.mox.ReplayAll()
        hosts = sched._schedule(self.context, request_spec, filter_properties=filter_properties)

        # one host should be chosen
        self.assertEquals(1, len(hosts))

        self.assertEquals(50, hosts[0].weight)
Exemple #23
0
    def test_schedule_local_zone(self):
        """Test to make sure _schedule makes no call out to zones if
        local_zone_only in the filter_properties is True.
        """

        self.next_weight = 1.0

        def _fake_weighted_sum(functions, hosts, options):
            self.next_weight += 2.0
            host = hosts[0]
            return least_cost.WeightedHost(self.next_weight, host_state=host)

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

        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        self.stubs.Set(sched.host_manager, 'filter_hosts',
                fake_filter_hosts)
        self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum)
        self.stubs.Set(db, 'zone_get_all', fake_zone_get_all)
        self.stubs.Set(sched, '_call_zone_method', fake_call_zone_method)

        request_spec = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 256},
                        'instance_properties': {'project_id': 1,
                                                'memory_mb': 512,
                                                'root_gb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1}}
        filter_properties = {'local_zone_only': True}
        self.mox.ReplayAll()
        weighted_hosts = sched._schedule(fake_context, 'compute',
                request_spec, filter_properties=filter_properties)
        self.mox.VerifyAll()
        self.assertEquals(len(weighted_hosts), 10)
        for weighted_host in weighted_hosts:
            # There should be no remote hosts
            self.assertTrue(weighted_host.host_state is not None)
            self.assertTrue(weighted_host.zone is None)
    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_weighted_sum(functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return least_cost.WeightedHost(self.next_weight,
                                           host_state=host_state)

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

        self.stubs.Set(sched.host_manager, 'filter_hosts', fake_filter_hosts)
        self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum)
        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {
            'num_instances': 10,
            'instance_type': {
                'memory_mb': 512,
                'root_gb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1
            },
            'instance_properties': {
                'project_id': 1,
                'root_gb': 512,
                'memory_mb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1,
                'os_type': 'Linux'
            }
        }
        self.mox.ReplayAll()
        weighted_hosts = sched._schedule(fake_context, 'compute', request_spec,
                                         {})
        self.assertEquals(len(weighted_hosts), 10)
        for weighted_host in weighted_hosts:
            self.assertTrue(weighted_host.host_state is not None)
    def test_select_hosts_happy_day(self):
        """select_hosts is basically a wrapper around the _select() method.

        Similar to the _select tests, this just does a happy path test to
        ensure there is nothing glaringly wrong.
        """

        self.next_weight = 1.0

        selected_hosts = []

        def _fake_weigh_objects(_self, functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            selected_hosts.append(host_state.host)
            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 = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux'}}
        self.mox.ReplayAll()
        hosts = sched.select_hosts(fake_context, request_spec, {})
        self.assertEquals(len(hosts), 10)
        self.assertEquals(hosts, selected_hosts)
Exemple #26
0
    def test_schedule_happy_day(self, mock_get_extra):
        """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 = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1,
                                                'os_type': 'Linux',
                                                'uuid': 'fake-uuid'}}
        self.mox.ReplayAll()
        weighed_hosts = sched._schedule(fake_context, request_spec, {})
        self.assertEqual(len(weighed_hosts), 10)
        for weighed_host in weighed_hosts:
            self.assertIsNotNone(weighed_host.obj)
Exemple #27
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_weighted_sum(functions, hosts, options):
            self.next_weight += 2.0
            host_state = hosts[0]
            return least_cost.WeightedHost(self.next_weight,
                    host_state=host_state)

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

        self.stubs.Set(sched.host_manager, 'filter_hosts',
                fake_filter_hosts)
        self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum)

        fakes.mox_host_manager_db_calls(self.mox, fake_context)

        request_spec = {'num_instances': 10,
                        'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                          'ephemeral_gb': 0,
                                          'vcpus': 1,
                                          'extra_specs':
                                                {'ecus_per_vcpu:': 2}},
                        'instance_properties': {'project_id': 1,
                                                'root_gb': 512,
                                                'memory_mb': 512,
                                                'ephemeral_gb': 0,
                                                'vcpus': 1}}
        self.mox.ReplayAll()
        weighted_hosts = sched._schedule(fake_context, 'compute',
                request_spec, {})
        self.assertEquals(len(weighted_hosts), 10)
        for weighted_host in weighted_hosts:
            self.assertTrue(weighted_host.host_state is not None)
    def test_schedule_happy_day(self, mock_get_extra):
        """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 = {
            "num_instances": 10,
            "instance_type": {"memory_mb": 512, "root_gb": 512, "ephemeral_gb": 0, "vcpus": 1},
            "instance_properties": {
                "project_id": 1,
                "root_gb": 512,
                "memory_mb": 512,
                "ephemeral_gb": 0,
                "vcpus": 1,
                "os_type": "Linux",
                "uuid": "fake-uuid",
            },
        }
        self.mox.ReplayAll()
        weighed_hosts = sched._schedule(fake_context, request_spec, {})
        self.assertEqual(len(weighed_hosts), 10)
        for weighed_host in weighed_hosts:
            self.assertIsNotNone(weighed_host.obj)
    def test_basic_schedule_run_instances_anti_affinity(self):
        filter_properties = {'scheduler_hints':
                             {'group': 'cats'}}
        # Request spec 1
        instance_opts1 = {'project_id': 1, 'os_type': 'Linux',
                          'memory_mb': 512, 'root_gb': 512,
                          'ephemeral_gb': 0, 'vcpus': 1,
                          'system_metadata': {'system': 'metadata'}}
        request_spec1 = {'instance_uuids': ['fake-uuid1-1', 'fake-uuid1-2'],
                         'instance_properties': instance_opts1,
                         'instance_type': {'memory_mb': 512, 'root_gb': 512,
                                           'ephemeral_gb': 0, 'vcpus': 1}}
        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_group_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.StubOutWithMock(driver, 'instance_update_db')
        self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, 'run_instance')
        self.mox.StubOutWithMock(sched, 'group_hosts')

        instance1_1 = {'uuid': 'fake-uuid1-1'}
        instance1_2 = {'uuid': 'fake-uuid1-2'}

        sched.group_hosts(mox.IgnoreArg(), 'cats').AndReturn([])

        def inc_launch_index1(*args, **kwargs):
            request_spec1['instance_properties']['launch_index'] = (
                request_spec1['instance_properties']['launch_index'] + 1)

        expected_metadata = {'system_metadata':
                             {'system': 'metadata', 'group': 'cats'}}
        driver.instance_update_db(fake_context, instance1_1['uuid'],
                extra_values=expected_metadata).WithSideEffects(
                inc_launch_index1).AndReturn(instance1_1)
        compute_rpcapi.ComputeAPI.run_instance(fake_context, host='host3',
                instance=instance1_1, requested_networks=None,
                injected_files=None, admin_password=None, is_first_time=None,
                request_spec=request_spec1, filter_properties=mox.IgnoreArg(),
                node='node3')

        driver.instance_update_db(fake_context, instance1_2['uuid'],
                extra_values=expected_metadata).WithSideEffects(
                inc_launch_index1).AndReturn(instance1_2)
        compute_rpcapi.ComputeAPI.run_instance(fake_context, host='host4',
                instance=instance1_2, requested_networks=None,
                injected_files=None, admin_password=None, is_first_time=None,
                request_spec=request_spec1, filter_properties=mox.IgnoreArg(),
                node='node4')
        self.mox.ReplayAll()
        sched.schedule_run_instance(fake_context, request_spec1,
                None, None, None, None, filter_properties)
    def test_basic_schedule_run_instances_anti_affinity(self):
        filter_properties = {"scheduler_hints": {"group": "cats"}}
        # Request spec 1
        instance_opts1 = {
            "project_id": 1,
            "os_type": "Linux",
            "memory_mb": 512,
            "root_gb": 512,
            "ephemeral_gb": 0,
            "vcpus": 1,
            "system_metadata": {"system": "metadata"},
        }
        request_spec1 = {
            "instance_uuids": ["fake-uuid1-1", "fake-uuid1-2"],
            "instance_properties": instance_opts1,
            "instance_type": {"memory_mb": 512, "root_gb": 512, "ephemeral_gb": 0, "vcpus": 1},
        }
        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_group_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.StubOutWithMock(driver, "instance_update_db")
        self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, "run_instance")
        self.mox.StubOutWithMock(sched, "group_hosts")

        instance1_1 = {"uuid": "fake-uuid1-1"}
        instance1_2 = {"uuid": "fake-uuid1-2"}

        sched.group_hosts(mox.IgnoreArg(), "cats").AndReturn([])

        def inc_launch_index1(*args, **kwargs):
            request_spec1["instance_properties"]["launch_index"] = (
                request_spec1["instance_properties"]["launch_index"] + 1
            )

        expected_metadata = {"system_metadata": {"system": "metadata", "group": "cats"}}
        driver.instance_update_db(fake_context, instance1_1["uuid"], extra_values=expected_metadata).WithSideEffects(
            inc_launch_index1
        ).AndReturn(instance1_1)
        compute_rpcapi.ComputeAPI.run_instance(
            fake_context,
            host="host3",
            instance=instance1_1,
            requested_networks=None,
            injected_files=None,
            admin_password=None,
            is_first_time=None,
            request_spec=request_spec1,
            filter_properties=mox.IgnoreArg(),
            node="node3",
            legacy_bdm_in_spec=False,
        )

        driver.instance_update_db(fake_context, instance1_2["uuid"], extra_values=expected_metadata).WithSideEffects(
            inc_launch_index1
        ).AndReturn(instance1_2)
        compute_rpcapi.ComputeAPI.run_instance(
            fake_context,
            host="host4",
            instance=instance1_2,
            requested_networks=None,
            injected_files=None,
            admin_password=None,
            is_first_time=None,
            request_spec=request_spec1,
            filter_properties=mox.IgnoreArg(),
            node="node4",
            legacy_bdm_in_spec=False,
        )
        self.mox.ReplayAll()
        sched.schedule_run_instance(fake_context, request_spec1, None, None, None, None, filter_properties, False)
Exemple #31
0
    def test_basic_schedule_run_instances_anti_affinity(self):
        filter_properties = {'scheduler_hints': {'group': 'cats'}}
        # Request spec 1
        instance_opts1 = {
            'project_id': 1,
            'os_type': 'Linux',
            'memory_mb': 512,
            'root_gb': 512,
            'ephemeral_gb': 0,
            'vcpus': 1,
            'system_metadata': {
                'system': 'metadata'
            }
        }
        request_spec1 = {
            'instance_uuids': ['fake-uuid1-1', 'fake-uuid1-2'],
            'instance_properties': instance_opts1,
            'instance_type': {
                'memory_mb': 512,
                'root_gb': 512,
                'ephemeral_gb': 0,
                'vcpus': 1
            }
        }
        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_group_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.StubOutWithMock(driver, 'instance_update_db')
        self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI, 'run_instance')
        self.mox.StubOutWithMock(sched, 'group_hosts')

        instance1_1 = {'uuid': 'fake-uuid1-1'}
        instance1_2 = {'uuid': 'fake-uuid1-2'}

        sched.group_hosts(mox.IgnoreArg(), 'cats').AndReturn([])

        def inc_launch_index1(*args, **kwargs):
            request_spec1['instance_properties']['launch_index'] = (
                request_spec1['instance_properties']['launch_index'] + 1)

        expected_metadata = {
            'system_metadata': {
                'system': 'metadata',
                'group': 'cats'
            }
        }
        driver.instance_update_db(
            fake_context, instance1_1['uuid'],
            extra_values=expected_metadata).WithSideEffects(
                inc_launch_index1).AndReturn(instance1_1)
        compute_rpcapi.ComputeAPI.run_instance(
            fake_context,
            host='host3',
            instance=instance1_1,
            requested_networks=None,
            injected_files=None,
            admin_password=None,
            is_first_time=None,
            request_spec=request_spec1,
            filter_properties=mox.IgnoreArg(),
            node='node3',
            legacy_bdm_in_spec=False)

        driver.instance_update_db(
            fake_context, instance1_2['uuid'],
            extra_values=expected_metadata).WithSideEffects(
                inc_launch_index1).AndReturn(instance1_2)
        compute_rpcapi.ComputeAPI.run_instance(
            fake_context,
            host='host4',
            instance=instance1_2,
            requested_networks=None,
            injected_files=None,
            admin_password=None,
            is_first_time=None,
            request_spec=request_spec1,
            filter_properties=mox.IgnoreArg(),
            node='node4',
            legacy_bdm_in_spec=False)
        self.mox.ReplayAll()
        sched.schedule_run_instance(fake_context, request_spec1, None, None,
                                    None, None, filter_properties, False)