From 1fa821fda9c29bc1312d5f06283bbeb1e4849f32 Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Fri, 22 Sep 2023 10:55:10 -0400 Subject: [PATCH] Set default value for HSTS options to None The default value of these options was False, it means that octaviaclient sends {'attr': False} to the Octavia API even if it is not required. Setting the default value to None, the attribute will not be send when it is not needed. It also fixes a potential issue when using recent python-octaviaclient release with an old octavia release that doesn't support HSTS. Closes-Bug: #2037253 Change-Id: Ica89bbd257216ef423afc44e0c81498037aece20 (cherry picked from commit db6b62ebdd5bf2a168aad448f3ef6bc723589e9d) --- octaviaclient/osc/v2/listener.py | 2 ++ octaviaclient/tests/unit/osc/v2/test_listener.py | 3 +++ ...ed-attributes-in-listener-create-2e7cb2de281ac7fe.yaml | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 releasenotes/notes/remove-unneeded-attributes-in-listener-create-2e7cb2de281ac7fe.yaml diff --git a/octaviaclient/osc/v2/listener.py b/octaviaclient/osc/v2/listener.py index 6ea388c..987b518 100644 --- a/octaviaclient/osc/v2/listener.py +++ b/octaviaclient/osc/v2/listener.py @@ -215,6 +215,7 @@ class CreateListener(command.ShowOne): '--hsts-include-subdomains', action='store_true', dest='hsts_include_subdomains', + default=None, help="Define whether the includeSubDomains directive should be " "added to the Strict-Transport-Security HTTP response " "header." @@ -223,6 +224,7 @@ class CreateListener(command.ShowOne): '--hsts-preload', action='store_true', dest='hsts_preload', + default=None, help="Define whether the preload directive should be " "added to the Strict-Transport-Security HTTP response " "header." diff --git a/octaviaclient/tests/unit/osc/v2/test_listener.py b/octaviaclient/tests/unit/osc/v2/test_listener.py index 3e00d4d..d17a21e 100644 --- a/octaviaclient/tests/unit/osc/v2/test_listener.py +++ b/octaviaclient/tests/unit/osc/v2/test_listener.py @@ -195,6 +195,9 @@ class TestListenerCreate(TestListener): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.assertIsNone(parsed_args.hsts_include_subdomains) + self.assertIsNone(parsed_args.hsts_preload) + self.assertIsNone(parsed_args.hsts_max_age) self.cmd.take_action(parsed_args) self.api_mock.listener_create.assert_called_with( json={'listener': self.listener_info}) diff --git a/releasenotes/notes/remove-unneeded-attributes-in-listener-create-2e7cb2de281ac7fe.yaml b/releasenotes/notes/remove-unneeded-attributes-in-listener-create-2e7cb2de281ac7fe.yaml new file mode 100644 index 0000000..b405f3a --- /dev/null +++ b/releasenotes/notes/remove-unneeded-attributes-in-listener-create-2e7cb2de281ac7fe.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Removed unneeded attributes that could have been passed to the API when + calling "listener create", hsts_include_subdomains and hsts_preload were + passed even when not used. + It fixes an issue when using a recent python-octaviaclient release with + older Octavia releases (without this HSTS feature).