From cdf20386479ccf34d70f919929bdb0235216ea0a Mon Sep 17 00:00:00 2001 From: imran malik Date: Thu, 16 Jun 2016 00:43:57 -0700 Subject: [PATCH] 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 --- tempest/api/compute/servers/test_create_server.py | 5 ++++- tempest/common/utils/linux/remote_client.py | 4 ++-- tempest/tests/common/utils/linux/test_remote_client.py | 9 ++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tempest/api/compute/servers/test_create_server.py b/tempest/api/compute/servers/test_create_server.py index 07423ff70d..da9d548949 100644 --- a/tempest/api/compute/servers/test_create_server.py +++ b/tempest/api/compute/servers/test_create_server.py @@ -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): diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py index 0a3e8d3841..7cb9ebee81 100644 --- a/tempest/common/utils/linux/remote_client.py +++ b/tempest/common/utils/linux/remote_client.py @@ -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') diff --git a/tempest/tests/common/utils/linux/test_remote_client.py b/tempest/tests/common/utils/linux/test_remote_client.py index 7d625cf704..e59e08f522 100644 --- a/tempest/tests/common/utils/linux/test_remote_client.py +++ b/tempest/tests/common/utils/linux/test_remote_client.py @@ -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" \