Change hostname_equals_servername to get_hostname

This patch fixes the issue with current logic of checking hostname
equals servername. The function hostname_equals_servername is a
util function, which means assert calls cannot be made there.
It only returns True or False based on comparison of hostname and
vm name.
However, if they are not equal, one can never know what was the
expected value vs the actual value of hostname because the assertTrue
call inside the test doesn't reveal that info.
Util functions should better just return hostname value and comparison
is to be made in actual test using assertEqual, this will help debugging
and logging the values of actual vm name and hostname returned from
util function.

Change-Id: I8c89680471547c4aeb556a34eb3b298f9ffbed62
This commit is contained in:
imran malik 2016-06-16 00:43:57 -07:00
parent 32f80f2ed5
commit cdf2038647
3 changed files with 8 additions and 10 deletions

View File

@ -136,7 +136,10 @@ class ServersTestJSON(base.BaseV2ComputeTest):
self.validation_resources['keypair']['private_key'],
server=self.server,
servers_client=self.client)
self.assertTrue(linux_client.hostname_equals_servername(self.name))
hostname = linux_client.get_hostname()
msg = ('Failed while verifying servername equals hostname. Expected '
'hostname "%s" but got "%s".' % (self.name, hostname))
self.assertEqual(self.name, hostname, msg)
@test.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
def test_create_server_with_scheduler_hint_group(self):

View File

@ -99,10 +99,10 @@ class RemoteClient(object):
"""
self.ssh_client.test_connection_auth()
def hostname_equals_servername(self, expected_hostname):
def get_hostname(self):
# Get host name using command "hostname"
actual_hostname = self.exec_command("hostname").rstrip()
return expected_hostname == actual_hostname
return actual_hostname
def get_ram_size_in_mb(self):
output = self.exec_command('free -m | grep Mem')

View File

@ -67,14 +67,9 @@ class TestRemoteClient(base.TestCase):
self.ssh_mock = self.useFixture(mockpatch.PatchObject(self.conn,
'ssh_client'))
def test_hostname_equals_servername_for_expected_names(self):
def test_get_hostname(self):
self.ssh_mock.mock.exec_command.return_value = 'fake_hostname'
self.assertTrue(self.conn.hostname_equals_servername('fake_hostname'))
def test_hostname_equals_servername_for_unexpected_names(self):
self.ssh_mock.mock.exec_command.return_value = 'fake_hostname'
self.assertFalse(
self.conn.hostname_equals_servername('unexpected_hostname'))
self.assertEqual(self.conn.get_hostname(), 'fake_hostname')
def test_get_ram_size(self):
free_output = "Mem: 48294 45738 2555 0" \