summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-09 01:42:28 +0000
committerGerrit Code Review <review@openstack.org>2013-03-09 01:42:28 +0000
commit55b248b6d509d8dc61ec0e4e6e6f05417b1b590e (patch)
treebda42c9e91e7f2ff11e4f317995904142b8e1b7a
parent7e96d76d762a67e534d769bc3e4e48adb56a130e (diff)
parent0ef60856fb2f1f1fd83647c3422e1b510a871ebd (diff)
downloadnova-55b248b6d509d8dc61ec0e4e6e6f05417b1b590e.tar.gz
nova-55b248b6d509d8dc61ec0e4e6e6f05417b1b590e.tar.xz
nova-55b248b6d509d8dc61ec0e4e6e6f05417b1b590e.zip
Merge "Make 'os-hosts/node1' case sensitivity defer to DB"
-rw-r--r--nova/compute/api.py14
-rw-r--r--nova/tests/compute/test_host_api.py18
2 files changed, 24 insertions, 8 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index fba538c5e..83ea98c8f 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2481,31 +2481,33 @@ class HostAPI(base.Base):
def _assert_host_exists(self, context, host_name):
"""Raise HostNotFound if compute host doesn't exist."""
- if not self.db.service_get_by_host_and_topic(context, host_name,
- CONF.compute_topic):
+ service = self.db.service_get_by_host_and_topic(context, host_name,
+ CONF.compute_topic)
+ if not service:
raise exception.HostNotFound(host=host_name)
+ return service['host']
def set_host_enabled(self, context, host_name, enabled):
"""Sets the specified host's ability to accept new instances."""
- self._assert_host_exists(context, host_name)
+ host_name = self._assert_host_exists(context, host_name)
return self.rpcapi.set_host_enabled(context, enabled=enabled,
host=host_name)
def get_host_uptime(self, context, host_name):
"""Returns the result of calling "uptime" on the target host."""
- self._assert_host_exists(context, host_name)
+ host_name = self._assert_host_exists(context, host_name)
return self.rpcapi.get_host_uptime(context, host=host_name)
def host_power_action(self, context, host_name, action):
"""Reboots, shuts down or powers up the host."""
- self._assert_host_exists(context, host_name)
+ host_name = self._assert_host_exists(context, host_name)
return self.rpcapi.host_power_action(context, action=action,
host=host_name)
def set_host_maintenance(self, context, host_name, mode):
"""Start/Stop host maintenance window. On start, it triggers
guest VMs evacuation."""
- self._assert_host_exists(context, host_name)
+ host_name = self._assert_host_exists(context, host_name)
return self.rpcapi.host_maintenance_mode(context,
host_param=host_name, mode=mode, host=host_name)
diff --git a/nova/tests/compute/test_host_api.py b/nova/tests/compute/test_host_api.py
index 3b5a9b871..38a7d2c37 100644
--- a/nova/tests/compute/test_host_api.py
+++ b/nova/tests/compute/test_host_api.py
@@ -38,8 +38,10 @@ class ComputeHostAPITestCase(test.TestCase):
"""Sets it so that the host API always thinks that 'fake_host'
exists.
"""
- self.mox.StubOutWithMock(self.host_api, '_assert_host_exists')
- self.host_api._assert_host_exists(self.ctxt, 'fake_host')
+ def fake_assert_host_exists(context, host_name):
+ return 'fake_host'
+ self.stubs.Set(self.host_api, '_assert_host_exists',
+ fake_assert_host_exists)
def test_set_host_enabled(self):
self._mock_assert_host_exists()
@@ -53,6 +55,18 @@ class ComputeHostAPITestCase(test.TestCase):
'fake_enabled')
self.assertEqual('fake-result', result)
+ def test_host_name_from_assert_hosts_exists(self):
+ self._mock_assert_host_exists()
+ self._mock_rpc_call(
+ {'method': 'set_host_enabled',
+ 'args': {'enabled': 'fake_enabled'},
+ 'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION})
+
+ self.mox.ReplayAll()
+ result = self.host_api.set_host_enabled(self.ctxt, 'fake_hosT',
+ 'fake_enabled')
+ self.assertEqual('fake-result', result)
+
def test_get_host_uptime(self):
self._mock_assert_host_exists()
self._mock_rpc_call(