summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorArmando Migliaccio <armando.migliaccio@eu.citrix.com>2012-02-17 16:17:44 +0000
committerArmando Migliaccio <armando.migliaccio@eu.citrix.com>2012-02-23 13:28:21 +0000
commit939f082cc2fb0b71bb601f80e3ea95d0be355e4c (patch)
treeec1d9ff36d598ea5f2338441a0ded1e92e19b63f /nova/tests
parent0c6765a71ad5538a7569dbc03dd8fe95713dc818 (diff)
downloadnova-939f082cc2fb0b71bb601f80e3ea95d0be355e4c.tar.gz
nova-939f082cc2fb0b71bb601f80e3ea95d0be355e4c.tar.xz
nova-939f082cc2fb0b71bb601f80e3ea95d0be355e4c.zip
blueprint host-aggregates: host maintenance - xenapi implementation
this changeset introduces the following: - refactoring around host-related operations for xenapi - increased test coverage - first cut at implementing host evacuation for a XS/XCP host Change-Id: I8509cdde95f6777ecfa928663b0c4bedbccf5d38
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_xenapi.py83
-rw-r--r--nova/tests/xenapi/stubs.py3
2 files changed, 42 insertions, 44 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index fc8e535e7..4a971ff21 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -20,7 +20,6 @@ import ast
import contextlib
import datetime
import functools
-import json
import os
import re
import stubout
@@ -1114,52 +1113,22 @@ class CompareVersionTestCase(test.TestCase):
self.assertTrue(vmops.cmp_version('1.2.3', '1.2.3.4') < 0)
-class FakeXenApi(object):
- """Fake XenApi for testing HostState."""
-
- class FakeSR(object):
- def get_record(self, ref):
- return {'virtual_allocation': 10000,
- 'physical_utilisation': 20000}
-
- SR = FakeSR()
-
-
-class FakeSession(object):
- """Fake Session class for HostState testing."""
-
- def async_call_plugin(self, *args):
- return None
-
- def wait_for_task(self, *args):
- vm = {'total': 10,
- 'overhead': 20,
- 'free': 30,
- 'free-computed': 40}
- return json.dumps({'host_memory': vm})
-
- def call_xenapi(self, method, *args):
- f = FakeXenApi()
- for m in method.split('.'):
- f = getattr(f, m)
- return f(*args)
-
-
-class HostStateTestCase(test.TestCase):
+class XenAPIHostTestCase(test.TestCase):
"""Tests HostState, which holds metrics from XenServer that get
reported back to the Schedulers."""
- @classmethod
- def _fake_safe_find_sr(cls, session):
- """None SR ref since we're ignoring it in FakeSR."""
- return None
+ def setUp(self):
+ super(XenAPIHostTestCase, self).setUp()
+ self.stubs = stubout.StubOutForTesting()
+ self.flags(xenapi_connection_url='test_url',
+ xenapi_connection_password='test_pass')
+ stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
+ xenapi_fake.reset()
+ xenapi_fake.create_local_srs()
+ self.conn = xenapi_conn.get_connection(False)
def test_host_state(self):
- self.stubs = stubout.StubOutForTesting()
- self.stubs.Set(vm_utils.VMHelper, 'safe_find_sr',
- self._fake_safe_find_sr)
- host_state = xenapi_conn.HostState(FakeSession())
- stats = host_state._stats
+ stats = self.conn.get_host_stats()
self.assertEquals(stats['disk_total'], 10000)
self.assertEquals(stats['disk_used'], 20000)
self.assertEquals(stats['host_memory_total'], 10)
@@ -1167,6 +1136,36 @@ class HostStateTestCase(test.TestCase):
self.assertEquals(stats['host_memory_free'], 30)
self.assertEquals(stats['host_memory_free_computed'], 40)
+ def _test_host_action(self, method, action, expected=None):
+ result = method('host', action)
+ if not expected:
+ expected = action
+ self.assertEqual(result, expected)
+
+ def test_host_reboot(self):
+ self._test_host_action(self.conn.host_power_action, 'reboot')
+
+ def test_host_shutdown(self):
+ self._test_host_action(self.conn.host_power_action, 'shutdown')
+
+ def test_host_startup(self):
+ self.assertRaises(NotImplementedError,
+ self.conn.host_power_action, 'host', 'startup')
+
+ def test_host_maintenance_on(self):
+ self._test_host_action(self.conn.host_maintenance_mode,
+ True, 'on_maintenance')
+
+ def test_host_maintenance_off(self):
+ self._test_host_action(self.conn.host_maintenance_mode,
+ False, 'off_maintenance')
+
+ def test_set_enable_host_enable(self):
+ self._test_host_action(self.conn.set_host_enabled, True, 'enabled')
+
+ def test_set_enable_host_disable(self):
+ self._test_host_action(self.conn.set_host_enabled, False, 'disabled')
+
class XenAPIAutoDiskConfigTestCase(test.TestCase):
def setUp(self):
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 01077be8d..683bc91de 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -206,8 +206,7 @@ class FakeSessionForVMTests(fake.SessionBase):
def VM_start_on(self, _1, vm_ref, host_ref, _2, _3):
vm_rec = self.VM_start(_1, vm_ref, _2, _3)
- host_rec = fake.get_record('host', host_ref)
- vm_rec['resident_on'] = host_rec['uuid']
+ vm_rec['resident_on'] = host_ref
def VM_snapshot(self, session_ref, vm_ref, label):
status = "Running"