From 1022ad395594fe0b248200ecdb3b5170f0aefc90 Mon Sep 17 00:00:00 2001 From: eRRyOos <38071730+eddyoosthuizen@users.noreply.github.com> Date: Tue, 4 Feb 2025 20:36:16 +0200 Subject: [PATCH] fix(ibm-classic): add missing whitespace in logging message Corrected a small typo in the IBM Classic logging call where a missing whitespace was present between the port number and "to" in the log message. Fixes: GH-455 (#455) --- VERSION | 2 +- pycloudlib/ibm_classic/cloud.py | 2 +- tests/unit_tests/ibm_classic/test_cloud.py | 26 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 961f2f93..fa3ed472 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1!10.7.3 +1!10.7.4 diff --git a/pycloudlib/ibm_classic/cloud.py b/pycloudlib/ibm_classic/cloud.py index c36b3e32..b9d89b5d 100644 --- a/pycloudlib/ibm_classic/cloud.py +++ b/pycloudlib/ibm_classic/cloud.py @@ -445,7 +445,7 @@ def _add_rules_to_security_group( port_max=port, ) self._log.debug( - "Added rule allowing %s %s traffic on port %sto security group %s", + "Added rule allowing %s %s traffic on port %s to security group %s", ethertype, direction, port, diff --git a/tests/unit_tests/ibm_classic/test_cloud.py b/tests/unit_tests/ibm_classic/test_cloud.py index 13831bd2..172406d8 100644 --- a/tests/unit_tests/ibm_classic/test_cloud.py +++ b/tests/unit_tests/ibm_classic/test_cloud.py @@ -1,6 +1,7 @@ from typing import List import mock import pytest +import logging from pycloudlib.errors import InvalidTagNameError from pycloudlib.ibm_classic.cloud import IBMClassic @@ -41,8 +42,16 @@ def mock_ibmclassic(): ], ) def test_add_rules_valid_input( - mock_ibmclassic, directions, ipv6, port, protocol, expected_call_count + mock_ibmclassic, + directions, + ipv6, + port, + protocol, + expected_call_count, + caplog, ): + mock_ibmclassic._log = logging.getLogger("ibm_classic_logger") + caplog.set_level(logging.DEBUG) mock_ibmclassic._add_rules_to_security_group( group_id="sg-1234", directions=directions, @@ -51,6 +60,21 @@ def test_add_rules_valid_input( protocol=protocol, ) + expected_log_messages = [] + ethertypes = ["IPv4", "IPv6"] if ipv6 else ["IPv4"] + + for direction in directions: + for ethertype in ethertypes: + expected_log_messages.append( + f"Added rule allowing {ethertype} {direction} traffic on port {port} to security group sg-1234", + ) + + for expected_log in expected_log_messages: + assert any( + expected_log in message for message in caplog.messages + ), f"Expected log not found: {expected_log}" + + caplog.clear() assert mock_ibmclassic._network_manager.add_securitygroup_rule.call_count == expected_call_count