From aa227f8d16f22159548bc992f28c1963709e8bce Mon Sep 17 00:00:00 2001
From: Johannes Kulik <johannes.kulik@sap.com>
Date: Thu, 16 Mar 2023 11:46:00 +0100
Subject: [PATCH] Fix --security-group for port list

"openstack port list --security-group <id>" was using a filter that
didn't exist in `openstacksdk`: "security_groups". Up until version
1.0.1, `openstacksdk` did not support filtering `Port` objects by
security groups. Later versions will support the filtering (via [1]),
but the filter is called the same way the attribute on the `Port` object
is called: `security_group_ids`.

We're not bumping the `openstacksdk` version here, because the feature
we're using [1] is merged too recently and a bump of min requirements
thus unlikely. `openstackclient` continue to work with older versions of
`openstacksdk` - the "--security-group" filter will just do nothing like
before.

[1] https://review.opendev.org/c/openstack/openstacksdk/+/866008

Change-Id: I07088484592e99ce0a12b67d68a3e47ae7c7af81
---
 openstackclient/network/v2/port.py                 | 2 +-
 openstackclient/tests/unit/network/v2/test_port.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 8bf14d6a73..46b70bb80c 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -694,7 +694,7 @@ class ListPort(command.Lister):
             filters['fixed_ips'] = _prepare_filter_fixed_ips(
                 self.app.client_manager, parsed_args)
         if parsed_args.security_groups:
-            filters['security_groups'] = parsed_args.security_groups
+            filters['security_group_ids'] = parsed_args.security_groups
 
         _tag.get_tag_filtering_args(parsed_args, filters)
 
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 04412c5a84..f7be71750f 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -1318,7 +1318,7 @@ class TestListPort(TestPort):
 
         columns, data = self.cmd.take_action(parsed_args)
         filters = {
-            'security_groups': ['sg-id1', 'sg-id2'],
+            'security_group_ids': ['sg-id1', 'sg-id2'],
             'fields': LIST_FIELDS_TO_RETRIEVE,
         }