From 88fd22de796b8b936287ee0e39fed6a0bcf3b604 Mon Sep 17 00:00:00 2001
From: Dmitry Tantsur <dtantsur@protonmail.com>
Date: Fri, 15 Sep 2023 14:52:23 +0200
Subject: [PATCH] Remove most prints for unit tests

Generally, print should not be used for unit tests, it may pollute
the output stream. Right now, our internal build system is facing

    BlockingIOError: [Errno 11] write could not complete without blocking

on prints. Especially ACL tests seem to be a big offender because they
are vary numerous and each may print several times. Many prints in other
tests are cryptic and probably just leftover from debugging.

I only leave the API unit tests where the output is arguably useful.
But I reduce it to one print per call since the input is already known.

Change-Id: Ic5aaf9624f86b39609e2db6157c98cf8e35712fc
---
 ironic/tests/unit/api/base.py                     |  9 +++------
 ironic/tests/unit/api/controllers/v1/test_port.py |  1 -
 ironic/tests/unit/api/test_acl.py                 | 10 ----------
 ironic/tests/unit/common/test_neutron.py          |  1 -
 ironic/tests/unit/common/test_pxe_utils.py        |  2 --
 5 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/ironic/tests/unit/api/base.py b/ironic/tests/unit/api/base.py
index 5f53e30735..7a0638fcb3 100644
--- a/ironic/tests/unit/api/base.py
+++ b/ironic/tests/unit/api/base.py
@@ -104,7 +104,6 @@ class BaseApiTest(db_base.DbTestCase):
         :param path_prefix: prefix of the url path
         """
         full_path = path_prefix + path
-        print('%s: %s %s' % (method.upper(), full_path, params))
         response = getattr(self.app, "%s_json" % method)(
             str(full_path),
             params=params,
@@ -113,7 +112,7 @@ class BaseApiTest(db_base.DbTestCase):
             extra_environ=extra_environ,
             expect_errors=expect_errors
         )
-        print('GOT:%s' % response)
+        print(method.upper(), full_path, "WITH", params, "GOT", str(response))
         return response
 
     def put_json(self, path, params, expect_errors=False, headers=None,
@@ -187,13 +186,12 @@ class BaseApiTest(db_base.DbTestCase):
         :param path_prefix: prefix of the url path
         """
         full_path = path_prefix + path
-        print('DELETE: %s' % (full_path))
         response = self.app.delete(str(full_path),
                                    headers=headers,
                                    status=status,
                                    extra_environ=extra_environ,
                                    expect_errors=expect_errors)
-        print('GOT:%s' % response)
+        print("DELETE", full_path, "GOT", str(response))
         return response
 
     def get_json(self, path, expect_errors=False, headers=None,
@@ -225,15 +223,14 @@ class BaseApiTest(db_base.DbTestCase):
         all_params.update(params)
         if q:
             all_params.update(query_params)
-        print('GET: %s %r' % (full_path, all_params))
         response = self.app.get(full_path,
                                 params=all_params,
                                 headers=headers,
                                 extra_environ=extra_environ,
                                 expect_errors=expect_errors)
+        print("GET", full_path, "WITH", params, "GOT", str(response))
         if not expect_errors:
             response = response.json
-        print('GOT:%s' % response)
         return response
 
     def validate_link(self, link, bookmark=False, headers=None):
diff --git a/ironic/tests/unit/api/controllers/v1/test_port.py b/ironic/tests/unit/api/controllers/v1/test_port.py
index 31885f45fa..088fe3cbea 100644
--- a/ironic/tests/unit/api/controllers/v1/test_port.py
+++ b/ironic/tests/unit/api/controllers/v1/test_port.py
@@ -1114,7 +1114,6 @@ class TestListPortsByShard(test_api_base.BaseApiTest):
 
         res = self.get_json('/ports?shard=shard1,shard2', headers=self.headers)
         self.assertEqual(2, len(res['ports']))
-        print(res['ports'][0])
         self.assertNotEqual(res['ports'][0]['address'], bad_shard_address)
         self.assertNotEqual(res['ports'][1]['address'], bad_shard_address)
 
diff --git a/ironic/tests/unit/api/test_acl.py b/ironic/tests/unit/api/test_acl.py
index 0481843bd7..ded1d0b2b5 100644
--- a/ironic/tests/unit/api/test_acl.py
+++ b/ironic/tests/unit/api/test_acl.py
@@ -102,7 +102,6 @@ class TestACLBase(base.BaseApiTest):
         # in troubleshooting ACL testing. This is a pattern
         # followed in API unit testing in ironic, and
         # really does help.
-        print('API ACL Testing Path %s %s' % (method, path))
         if headers:
             for k, v in headers.items():
                 rheaders[k] = v.format(**self.format_data)
@@ -185,8 +184,6 @@ class TestACLBase(base.BaseApiTest):
         if assert_dict_contains:
             for k, v in assert_dict_contains.items():
                 self.assertIn(k, response)
-                print(k)
-                print(v)
                 if str(v) == "None":
                     # Compare since the variable loaded from the
                     # json ends up being null in json or None.
@@ -219,13 +216,6 @@ class TestACLBase(base.BaseApiTest):
                     # a filtered view in these cases.
                     self.assertEqual(0, len(items))
 
-        # NOTE(TheJulia): API tests in Ironic tend to have a pattern
-        # to print request and response data to aid in development
-        # and troubleshooting. As such the prints should remain,
-        # at least until we are through primary development of the
-        # this test suite.
-        print('ACL Test GOT %s' % response)
-
 
 @ddt.ddt
 class TestRBACBasic(TestACLBase):
diff --git a/ironic/tests/unit/common/test_neutron.py b/ironic/tests/unit/common/test_neutron.py
index c3595a130b..fe238df48c 100644
--- a/ironic/tests/unit/common/test_neutron.py
+++ b/ironic/tests/unit/common/test_neutron.py
@@ -678,7 +678,6 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
 
         network_data = neutron.get_neutron_port_data('port1', 'vif1')
 
-        print(network_data)
         expected_port = {
             'id': 'port1',
             'type': 'vif',
diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py
index 1e2d93bda5..a57441f588 100644
--- a/ironic/tests/unit/common/test_pxe_utils.py
+++ b/ironic/tests/unit/common/test_pxe_utils.py
@@ -2162,8 +2162,6 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase):
         if iso_boot:
             self.node.instance_info = {'boot_iso': 'http://test.url/file.iso'}
             self.node.save()
-            print(expected_options)
-            print(image_info)
             iso_url = os.path.join(http_url, self.node.uuid, 'boot_iso')
             expected_options.update(
                 {