~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/scheduler/fakes.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
Fakes For Scheduler tests.
17
17
"""
18
18
 
 
19
import mox
19
20
 
 
21
from cinder import db
 
22
from cinder.openstack.common import timeutils
 
23
from cinder.scheduler import filter_scheduler
20
24
from cinder.scheduler import host_manager
21
25
 
22
26
 
 
27
VOLUME_SERVICES = [
 
28
    dict(id=1, host='host1', topic='volume', disabled=False,
 
29
         availability_zone='zone1', updated_at=timeutils.utcnow()),
 
30
    dict(id=2, host='host2', topic='volume', disabled=False,
 
31
         availability_zone='zone1', updated_at=timeutils.utcnow()),
 
32
    dict(id=3, host='host3', topic='volume', disabled=False,
 
33
         availability_zone='zone2', updated_at=timeutils.utcnow()),
 
34
    dict(id=4, host='host4', topic='volume', disabled=False,
 
35
         availability_zone='zone3', updated_at=timeutils.utcnow()),
 
36
    # service on host5 is disabled
 
37
    dict(id=5, host='host5', topic='volume', disabled=True,
 
38
         availability_zone='zone4', updated_at=timeutils.utcnow()),
 
39
]
 
40
 
 
41
 
 
42
class FakeFilterScheduler(filter_scheduler.FilterScheduler):
 
43
    def __init__(self, *args, **kwargs):
 
44
        super(FakeFilterScheduler, self).__init__(*args, **kwargs)
 
45
        self.host_manager = host_manager.HostManager()
 
46
 
 
47
 
23
48
class FakeHostManager(host_manager.HostManager):
24
 
    """host1: free_ram_mb=1024-512-512=0, free_disk_gb=1024-512-512=0
25
 
       host2: free_ram_mb=2048-512=1536  free_disk_gb=2048-512=1536
26
 
       host3: free_ram_mb=4096-1024=3072  free_disk_gb=4096-1024=3072
27
 
       host4: free_ram_mb=8192  free_disk_gb=8192"""
28
 
 
29
49
    def __init__(self):
30
50
        super(FakeHostManager, self).__init__()
31
51
 
32
52
        self.service_states = {
33
 
            'host1': {
34
 
                'compute': {'host_memory_free': 1073741824},
35
 
            },
36
 
            'host2': {
37
 
                'compute': {'host_memory_free': 2147483648},
38
 
            },
39
 
            'host3': {
40
 
                'compute': {'host_memory_free': 3221225472},
41
 
            },
42
 
            'host4': {
43
 
                'compute': {'host_memory_free': 999999999},
44
 
            },
 
53
            'host1': {'total_capacity_gb': 1024,
 
54
                      'free_capacity_gb': 1024,
 
55
                      'reserved_percentage': 10,
 
56
                      'timestamp': None},
 
57
            'host2': {'total_capacity_gb': 2048,
 
58
                      'free_capacity_gb': 300,
 
59
                      'reserved_percentage': 10,
 
60
                      'timestamp': None},
 
61
            'host3': {'total_capacity_gb': 512,
 
62
                      'free_capacity_gb': 512,
 
63
                      'reserved_percentage': 0,
 
64
                      'timestamp': None},
 
65
            'host4': {'total_capacity_gb': 2048,
 
66
                      'free_capacity_gb': 200,
 
67
                      'reserved_percentage': 5,
 
68
                      'timestamp': None},
45
69
        }
46
70
 
47
 
    def get_host_list_from_db(self, context):
48
 
        return [
49
 
            ('host1', dict(free_disk_gb=1024, free_ram_mb=1024)),
50
 
            ('host2', dict(free_disk_gb=2048, free_ram_mb=2048)),
51
 
            ('host3', dict(free_disk_gb=4096, free_ram_mb=4096)),
52
 
            ('host4', dict(free_disk_gb=8192, free_ram_mb=8192)),
53
 
        ]
54
 
 
55
71
 
56
72
class FakeHostState(host_manager.HostState):
57
 
    def __init__(self, host, topic, attribute_dict):
58
 
        super(FakeHostState, self).__init__(host, topic)
 
73
    def __init__(self, host, attribute_dict):
 
74
        super(FakeHostState, self).__init__(host)
59
75
        for (key, val) in attribute_dict.iteritems():
60
76
            setattr(self, key, val)
 
77
 
 
78
 
 
79
def mox_host_manager_db_calls(mock, context):
 
80
    mock.StubOutWithMock(db, 'service_get_all_by_topic')
 
81
 
 
82
    db.service_get_all_by_topic(mox.IgnoreArg(),
 
83
                                mox.IgnoreArg()).AndReturn(VOLUME_SERVICES)