From 86463bd822dc004c812acf79ad95aeed7e43f71e Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Thu, 9 Jul 2020 15:19:03 +0200 Subject: [PATCH] [Functional] Add logging to the check test file function In the functional tests module which is testing WSGI Server, there is used function to assert that file created by the WSGI service is created and has got correct size. This function wasn't logging anything so in case of test failure there was no way to check why it really failed. This patch adds some log messages to the check so it will be clear if file wasn't created at all or if size was not as expected. Change-Id: Ib610b8513b4ea888a540873b26c3f205ac575b17 Related-Bug: #1886956 (cherry picked from commit 0c55ab9c78df028e9e321a3f8dea59ede217fef8) --- neutron/tests/functional/test_server.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index 41bbedda09b..fc8b5c7b610 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -23,6 +23,7 @@ import httplib2 import mock from neutron_lib import worker as neutron_worker from oslo_config import cfg +from oslo_log import log import psutil import six @@ -33,6 +34,8 @@ from neutron.tests.functional import base from neutron import wsgi +LOG = log.getLogger(__name__) + CONF = cfg.CONF # Those messages will be written to temporary file each time @@ -156,12 +159,19 @@ class TestNeutronServer(base.BaseLoggingTestCase): # Wait for temp file to be created and its size reaching the expected # value expected_size = len(expected_msg) - condition = lambda: (os.path.isfile(self.temp_file) and - os.stat(self.temp_file).st_size == - expected_size) + + def is_temp_file_ok(): + LOG.debug("Checking file %s", self.temp_file) + if not os.path.isfile(self.temp_file): + LOG.debug("File %s not exists.", self.temp_file) + return False + temp_file_size = os.stat(self.temp_file).st_size + LOG.debug("Size of file %s is %s. Expected size: %s", + self.temp_file, temp_file_size, expected_size) + return temp_file_size == expected_size try: - utils.wait_until_true(condition, timeout=5, sleep=1) + utils.wait_until_true(is_temp_file_ok, timeout=5, sleep=1) except utils.TimerTimeout: if not os.path.isfile(self.temp_file): raise RuntimeError(