~johannes.erdfelt/nova/lp707224

« back to all changes in this revision

Viewing changes to nova/tests/test_xenapi.py

  • Committer: Cerberus
  • Date: 2011-05-11 19:41:39 UTC
  • mfrom: (1063 nova)
  • mto: This revision was merged to the branch mainline in revision 1082.
  • Revision ID: matt.dietz@rackspace.com-20110511194139-1vko8ss0l4auxslr
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test suite for XenAPI."""
18
18
 
19
19
import functools
 
20
import json
20
21
import os
21
22
import re
22
23
import stubout
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)
 
669
 
 
670
 
 
671
class FakeXenApi(object):
 
672
    """Fake XenApi for testing HostState."""
 
673
 
 
674
    class FakeSR(object):
 
675
        def get_record(self, ref):
 
676
            return {'virtual_allocation': 10000,
 
677
                    'physical_utilisation': 20000}
 
678
 
 
679
    SR = FakeSR()
 
680
 
 
681
 
 
682
class FakeSession(object):
 
683
    """Fake Session class for HostState testing."""
 
684
 
 
685
    def async_call_plugin(self, *args):
 
686
        return None
 
687
 
 
688
    def wait_for_task(self, *args):
 
689
        vm = {'total': 10,
 
690
              'overhead': 20,
 
691
              'free': 30,
 
692
              'free-computed': 40}
 
693
        return json.dumps({'host_memory': vm})
 
694
 
 
695
    def get_xenapi(self):
 
696
        return FakeXenApi()
 
697
 
 
698
 
 
699
class HostStateTestCase(test.TestCase):
 
700
    """Tests HostState, which holds metrics from XenServer that get
 
701
    reported back to the Schedulers."""
 
702
 
 
703
    def _fake_safe_find_sr(self, session):
 
704
        """None SR ref since we're ignoring it in FakeSR."""
 
705
        return None
 
706
 
 
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)