~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandleman, Chuck Short
  • Date: 2012-03-02 11:04:04 UTC
  • mfrom: (1.1.47)
  • Revision ID: package-import@ubuntu.com-20120302110404-fr230yakr8hov3dj
Tags: 2012.1~e4-0ubuntu1
[ Adam Gandleman ]
* debian/patches/libvirt-use-console-pipe.patch: Refreshed. 
* debain/nova-volume.upstart.in: Ensure lock directory is created
  (LP: #940780)
* debain/control: Fix nova-compute-$flavor Depends
* debian/control: Add python-iso8601 to python-nova Depends

[ Chuck Short ]
* debian/rules: Fix FTBFS.
* Merge Ubuntu/Debian packaging:
  - Thanks to Julien Danjou, Ghe Rivero, and Thomas Goirand
  - debian/copyright: Update copyright file.
  - debian/nova-api.init, debian/nova-compute.init,
    debian/nova-network.init, debian/nova-objectstore,
    debian/nova-scheduler, debian/nova-volume.init:
    Synchronize init scripts.
  - nova-common.install, debian/rules: Install policy.json
  - debian/rules, debian/nova-xcp-network.install,
    debian/nova-xcp-plugins.install, nova-xcp-plugins.postrm,
    debian/nova-xcp-plugins.doc, debian/nova-xcp-plugins.postinst,
    debian/README.xcp_and_openstack, debian/control,
    debian/ubuntu_xen-openvswitch-nova.rules,
    debian/patches/path-to-the-xenhost.conf-fixup.patch:
    Add Xen XCP support.
  - debian/control,
    debian/nova-compute-{kvm,lxc,qemu,xen,uml}.postinst: Make
    nova-compute a virtual package.
  - Dropped ubuntu_ubuntu_control_vars: We dont use it
* New upstream release.
* Dropped python-babel, it will be handled by langpacks.
* debian/patches/ec2-fixes.patch: Backport turnk fix for ec2
  permissions.
* debian/patches/path-to-the-xenhost.conf-fixup.patch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
Tests For Distributed Scheduler.
17
17
"""
18
18
 
 
19
import mox
 
20
 
19
21
from nova import context
20
22
from nova import exception
21
23
from nova.scheduler import least_cost
22
24
from nova.scheduler import host_manager
 
25
from nova.scheduler import distributed_scheduler
23
26
from nova import test
24
 
from nova.tests.scheduler import fakes
 
27
from nova.tests.scheduler import fakes, test_scheduler
25
28
 
26
29
 
27
30
def fake_filter_hosts(hosts, filter_properties):
28
31
    return list(hosts)
29
32
 
30
33
 
31
 
class DistributedSchedulerTestCase(test.TestCase):
 
34
class DistributedSchedulerTestCase(test_scheduler.SchedulerTestCase):
32
35
    """Test case for Distributed Scheduler."""
33
36
 
 
37
    driver_cls = distributed_scheduler.DistributedScheduler
 
38
 
34
39
    def test_run_instance_no_hosts(self):
35
40
        """
36
41
        Ensure empty hosts & child_zones result in NoValidHosts exception.
76
81
        self.assertRaises(NotImplementedError, sched._schedule, fake_context,
77
82
                          "foo", {})
78
83
 
 
84
    def test_scheduler_includes_launch_index(self):
 
85
        ctxt = "fake-context"
 
86
        fake_kwargs = {'fake_kwarg1': 'fake_value1',
 
87
                       'fake_kwarg2': 'fake_value2'}
 
88
        instance_opts = {'fake_opt1': 'meow'}
 
89
        request_spec = {'num_instances': 2,
 
90
                        'instance_properties': instance_opts}
 
91
        instance1 = {'uuid': 'fake-uuid1'}
 
92
        instance2 = {'uuid': 'fake-uuid2'}
 
93
 
 
94
        def _has_launch_index(expected_index):
 
95
            """Return a function that verifies the expected index."""
 
96
            def _check_launch_index(value):
 
97
                if 'instance_properties' in value:
 
98
                    if 'launch_index' in value['instance_properties']:
 
99
                        index = value['instance_properties']['launch_index']
 
100
                        if index == expected_index:
 
101
                            return True
 
102
                return False
 
103
            return _check_launch_index
 
104
 
 
105
        class ContextFake(object):
 
106
            def elevated(self):
 
107
                return ctxt
 
108
        context_fake = ContextFake()
 
109
 
 
110
        self.mox.StubOutWithMock(self.driver, '_schedule')
 
111
        self.mox.StubOutWithMock(self.driver, '_provision_resource')
 
112
 
 
113
        self.driver._schedule(context_fake, 'compute',
 
114
                              request_spec, **fake_kwargs
 
115
                              ).AndReturn(['host1', 'host2'])
 
116
        # instance 1
 
117
        self.driver._provision_resource(
 
118
            ctxt, 'host1',
 
119
            mox.Func(_has_launch_index(0)), fake_kwargs).AndReturn(instance1)
 
120
        # instance 2
 
121
        self.driver._provision_resource(
 
122
            ctxt, 'host2',
 
123
            mox.Func(_has_launch_index(1)), fake_kwargs).AndReturn(instance2)
 
124
        self.mox.ReplayAll()
 
125
 
 
126
        self.driver.schedule_run_instance(context_fake, request_spec,
 
127
                                          **fake_kwargs)
 
128
 
79
129
    def test_schedule_happy_day(self):
80
130
        """Make sure there's nothing glaringly wrong with _schedule()
81
131
        by doing a happy day pass through."""