Skip to content

Commit

Permalink
Make 'os-hosts/node1' case sensitivity defer to DB
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jogo committed Mar 7, 2013
1 parent e237698 commit 0ef6085
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 8 additions & 6 deletions nova/compute/api.py
Expand Up @@ -2480,31 +2480,33 @@ def __init__(self, rpcapi=None):

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)

Expand Down
18 changes: 16 additions & 2 deletions nova/tests/compute/test_host_api.py
Expand Up @@ -38,8 +38,10 @@ def _mock_assert_host_exists(self):
"""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()
Expand All @@ -53,6 +55,18 @@ def test_set_host_enabled(self):
'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(
Expand Down

0 comments on commit 0ef6085

Please sign in to comment.