665
666
self.fake_instance.image_id = glance_stubs.FakeGlance.IMAGE_VHD
666
667
self.fake_instance.kernel_id = None
667
668
self.assert_disk_type(vm_utils.ImageType.DISK_VHD)
671
class FakeXenApi(object):
672
"""Fake XenApi for testing HostState."""
674
class FakeSR(object):
675
def get_record(self, ref):
676
return {'virtual_allocation': 10000,
677
'physical_utilisation': 20000}
682
class FakeSession(object):
683
"""Fake Session class for HostState testing."""
685
def async_call_plugin(self, *args):
688
def wait_for_task(self, *args):
693
return json.dumps({'host_memory': vm})
695
def get_xenapi(self):
699
class HostStateTestCase(test.TestCase):
700
"""Tests HostState, which holds metrics from XenServer that get
701
reported back to the Schedulers."""
703
def _fake_safe_find_sr(self, session):
704
"""None SR ref since we're ignoring it in FakeSR."""
707
def test_host_state(self):
708
self.stubs = stubout.StubOutForTesting()
709
self.stubs.Set(vm_utils, 'safe_find_sr', self._fake_safe_find_sr)
710
host_state = xenapi_conn.HostState(FakeSession())
711
stats = host_state._stats
712
self.assertEquals(stats['disk_total'], 10000)
713
self.assertEquals(stats['disk_used'], 20000)
714
self.assertEquals(stats['host_memory_total'], 10)
715
self.assertEquals(stats['host_memory_overhead'], 20)
716
self.assertEquals(stats['host_memory_free'], 30)
717
self.assertEquals(stats['host_memory_free_computed'], 40)