~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/scheduler/test_least_cost_scheduler.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-10-21 14:37:26 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20111021143726-dk1m1a0vwov3kyls
Tags: upstream-2012.1~e1~20111020.11229
ImportĀ upstreamĀ versionĀ 2012.1~e1~20111020.11229

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        super(LeastCostSchedulerTestCase, self).tearDown()
83
83
 
84
84
    def assertWeights(self, expected, num, request_spec, hosts):
85
 
        weighted = self.sched.weigh_hosts("compute", request_spec, hosts)
 
85
        weighted = self.sched.weigh_hosts(request_spec, hosts)
86
86
        self.assertDictListMatch(weighted, expected, approx_equal=True)
87
87
 
88
88
    def test_no_hosts(self):
97
97
        self.flags(least_cost_scheduler_cost_functions=[
98
98
                'nova.scheduler.least_cost.noop_cost_fn'],
99
99
                noop_cost_fn_weight=1)
100
 
 
101
100
        num = 1
102
101
        request_spec = {}
103
102
        hosts = self.sched.filter_hosts(num, request_spec)
104
 
 
105
 
        expected = [dict(weight=1, hostname=hostname)
106
 
                    for hostname, caps in hosts]
 
103
        expected = [{"hostname": hostname, "weight": 1, "capabilities": caps}
 
104
                for hostname, caps in hosts]
107
105
        self.assertWeights(expected, num, request_spec, hosts)
108
106
 
109
107
    def test_cost_fn_weights(self):
110
108
        self.flags(least_cost_scheduler_cost_functions=[
111
109
                'nova.scheduler.least_cost.noop_cost_fn'],
112
110
                noop_cost_fn_weight=2)
113
 
 
114
111
        num = 1
115
112
        request_spec = {}
116
113
        hosts = self.sched.filter_hosts(num, request_spec)
117
 
 
118
 
        expected = [dict(weight=2, hostname=hostname)
119
 
                    for hostname, caps in hosts]
120
 
        self.assertWeights(expected, num, request_spec, hosts)
121
 
 
122
 
    def test_compute_fill_first_cost_fn(self):
123
 
        self.flags(least_cost_scheduler_cost_functions=[
124
 
                'nova.scheduler.least_cost.compute_fill_first_cost_fn'],
125
 
                compute_fill_first_cost_fn_weight=1)
126
 
        num = 1
127
 
        instance_type = {'memory_mb': 1024}
128
 
        request_spec = {'instance_type': instance_type}
129
 
        svc_states = self.sched.zone_manager.service_states.iteritems()
130
 
        all_hosts = [(host, services["compute"])
131
 
                for host, services in svc_states
132
 
                if "compute" in services]
133
 
        hosts = self.sched.filter_hosts('compute', request_spec, all_hosts)
134
 
 
135
 
        expected = []
136
 
        for idx, (hostname, services) in enumerate(hosts):
137
 
            caps = copy.deepcopy(services["compute"])
138
 
            # Costs are normalized so over 10 hosts, each host with increasing
139
 
            # free ram will cost 1/N more. Since the lowest cost host has some
140
 
            # free ram, we add in the 1/N for the base_cost
141
 
            weight = 0.1 + (0.1 * idx)
142
 
            wtd_dict = dict(hostname=hostname, weight=weight,
143
 
                    capabilities=caps)
144
 
            expected.append(wtd_dict)
145
 
 
 
114
        expected = [{"hostname": hostname, "weight": 2, "capabilities": caps}
 
115
                for hostname, caps in hosts]
146
116
        self.assertWeights(expected, num, request_spec, hosts)