示例#1
0
 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)]
示例#2
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)]
示例#3
0
 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)]
示例#4
0
 def test_dict_conversion(self):
     host_state = fakes.FakeHostState('somehost', None, {})
     host = weights.WeighedHost(host_state, 'someweight')
     expected = {'weight': 'someweight', 'host': 'somehost'}
     self.assertThat(host.to_dict(), matchers.DictMatches(expected))
示例#5
0
 def _return_hosts(*args, **kwargs):
     host_state = host_manager.HostState('host2', 'node2')
     return [weights.WeighedHost(host_state, 1.0)]
示例#6
0
    def test_prep_resize_post_populates_retry(self):
        # Prep resize should add a ('host', 'node') entry to the retry dict.
        sched = fakes.FakeFilterScheduler()

        image = 'image'
        instance = {
            'disable_terminate': False,
            'uuid': 'fakeuuid',
            'deleted': 0,
            'info_cache': {},
            'created_at': None,
            'system_metadata': [],
            'shutdown_terminate': False,
            'id': 1,
            'security_groups': [],
            'metadata': []
        }

        instance_properties = {'project_id': 'fake', 'os_type': 'Linux'}
        instance_type = {
            'memory_mb': 1024,
            'root_gb': 40,
            'deleted_at': None,
            'name': u'm1.medium',
            'deleted': 0,
            'created_at': None,
            'ephemeral_gb': 0,
            'updated_at': None,
            'disabled': False,
            'vcpus': 2,
            'extra_specs': {},
            'swap': 0,
            'rxtx_factor': 1.0,
            'is_public': True,
            'flavorid': u'3',
            'vcpu_weight': None,
            'id': 1
        }

        request_spec = {
            'instance_properties': instance_properties,
            'instance_type': instance_type
        }
        retry = {'hosts': [], 'num_attempts': 1}
        filter_properties = {'retry': retry}
        reservations = None

        host = fakes.FakeHostState('host', 'node', {})
        weighed_host = weights.WeighedHost(host, 1)
        weighed_hosts = [weighed_host]

        self.mox.StubOutWithMock(sched, '_schedule')
        self.mox.StubOutWithMock(sched.compute_rpcapi, 'prep_resize')

        sched._schedule(self.context, request_spec, filter_properties,
                        [instance['uuid']]).AndReturn(weighed_hosts)
        sched.compute_rpcapi.prep_resize(self.context,
                                         image,
                                         instance,
                                         instance_type,
                                         'host',
                                         reservations,
                                         request_spec=request_spec,
                                         filter_properties=filter_properties,
                                         node='node')

        self.mox.ReplayAll()
        sched.schedule_prep_resize(self.context, image, request_spec,
                                   filter_properties, instance, instance_type,
                                   reservations)

        self.assertEqual([['host', 'node']],
                         filter_properties['retry']['hosts'])
    def test_select_destinations_kill_preemptible(self, mock_schedule,
                                                  mock_terminate):
        host = fakes.FakeHostState(
            "host", "node", {
                "free_ram_mb": -1000,
                "total_usable_ram_mb": 1000,
                "ram_allocation_ratio": 1.5
            })
        instances = {
            'uuid-preemptible':
            fake_instance.fake_instance_obj("fake context",
                                            root_gb=1,
                                            ephemeral_gb=1,
                                            memory_mb=3,
                                            vcpus=4,
                                            project_id='12345',
                                            vm_state=vm_states.ACTIVE,
                                            task_state=task_states.RESIZE_PREP,
                                            os_type='Linux',
                                            uuid='uuid-preemptible'),
            'uuid-normal':
            fake_instance.fake_instance_obj("fake context",
                                            root_gb=1,
                                            ephemeral_gb=1,
                                            memory_mb=3,
                                            vcpus=4,
                                            project_id='12345',
                                            vm_state=vm_states.ACTIVE,
                                            task_state=task_states.RESIZE_PREP,
                                            os_type='Linux',
                                            uuid='uuid-preemptible')
        }
        instances['uuid-normal'].system_metadata = {"preemptible": False}
        instances['uuid-preemptible'].system_metadata = {"preemptible": True}
        host.instances = instances

        mock_schedule.return_value = [weights.WeighedHost(host, 1)]
        mock_terminate.return_value = None

        request_spec = {
            'num_instances': 1,
            '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',
                'system_metadata': {
                    'preemptible': False
                }
            }
        }

        dests = self.driver.select_destinations(self.context, request_spec, {})
        self.assertEqual(host.host, dests[0]["host"])
        self.assertEqual(host.nodename, dests[0]["nodename"])