summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2013-03-07 00:01:29 +0000
committerJoe Gordon <jogo@cloudscaling.com>2013-03-07 22:30:00 +0000
commit0ef60856fb2f1f1fd83647c3422e1b510a871ebd (patch)
treee2d5725f1ff40d38f4f7194891492dd1773e15c7
parente23769827dbd5c9eb9d392e6452ca33253f88329 (diff)
Make 'os-hosts/node1' case sensitivity defer to DB
RPC is case sensitive, but URL is not, and DB can be. So pull host_name from DB in HostAPI RPC layer instead of from passed in from URL. This means RPC will always get the proper capitalization, and case sensitivity is defined in DB layer. Fix bug 996879 Change-Id: I448dd4ec3aec4af1adf4487f26ea996db572fa3d
-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 252f326d4..2b4353e9f 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2480,31 +2480,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(