16
16
Fakes For Scheduler tests.
22
from cinder.openstack.common import timeutils
23
from cinder.scheduler import filter_scheduler
20
24
from cinder.scheduler import host_manager
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()),
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()
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"""
29
49
def __init__(self):
30
50
super(FakeHostManager, self).__init__()
32
52
self.service_states = {
34
'compute': {'host_memory_free': 1073741824},
37
'compute': {'host_memory_free': 2147483648},
40
'compute': {'host_memory_free': 3221225472},
43
'compute': {'host_memory_free': 999999999},
53
'host1': {'total_capacity_gb': 1024,
54
'free_capacity_gb': 1024,
55
'reserved_percentage': 10,
57
'host2': {'total_capacity_gb': 2048,
58
'free_capacity_gb': 300,
59
'reserved_percentage': 10,
61
'host3': {'total_capacity_gb': 512,
62
'free_capacity_gb': 512,
63
'reserved_percentage': 0,
65
'host4': {'total_capacity_gb': 2048,
66
'free_capacity_gb': 200,
67
'reserved_percentage': 5,
47
def get_host_list_from_db(self, context):
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)),
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)
79
def mox_host_manager_db_calls(mock, context):
80
mock.StubOutWithMock(db, 'service_get_all_by_topic')
82
db.service_get_all_by_topic(mox.IgnoreArg(),
83
mox.IgnoreArg()).AndReturn(VOLUME_SERVICES)