Repository: rucio/rucio

Issue:
Unnecessary option `--csv` under `rucio rse show`
### Description

The output of `rse-info` is complex and can’t be reduced to CSV format. Was this supposed to do something?

### Steps to reproduce

```console
rucio rse show --csv CERN-PROD_DATADISK
…
```

### Rucio Version

37.0.0rc1

### Additional Information

_No response_

Hints from issue comments:

Solution patch:
diff --git a/lib/rucio/cli/rse.py b/lib/rucio/cli/rse.py
index 600b4c2fc..4fbb7b2ee 100644
--- a/lib/rucio/cli/rse.py
+++ b/lib/rucio/cli/rse.py
@@ -55,11 +55,10 @@ def list_(ctx, rses, csv):
 
 @rse.command("show")
 @click.argument("rse-name")
-@click.option("--csv", is_flag=True, default=False, help="Output list of RSE property key and values as a csv")
 @click.pass_context
-def show(ctx, rse_name, csv):
+def show(ctx, rse_name):
     """Usage, protocols, settings, and attributes for a given RSE"""
-    info_rse(Arguments({"no_pager": ctx.obj.no_pager, "rse": rse_name, "csv": csv}), ctx.obj.client, ctx.obj.logger, ctx.obj.console, ctx.obj.spinner)
+    info_rse(Arguments({"no_pager": ctx.obj.no_pager, "rse": rse_name}), ctx.obj.client, ctx.obj.logger, ctx.obj.console, ctx.obj.spinner)
 
 
 @rse.command("add")
diff --git a/lib/rucio/common/plugins.py b/lib/rucio/common/plugins.py
index b385c5c3a..1de8ee42e 100644
--- a/lib/rucio/common/plugins.py
+++ b/lib/rucio/common/plugins.py
@@ -27,41 +27,34 @@ from rucio.version import current_version
 
 if TYPE_CHECKING:
     from collections.abc import Callable
+    from types import ModuleType
 
     from rucio.common.types import LoggerFunction
 
 PolicyPackageAlgorithmsT = TypeVar('PolicyPackageAlgorithmsT', bound='PolicyPackageAlgorithms')
 
 
-def check_policy_package_version(package: str, logger: 'LoggerFunction' = logging.log) -> None:
+def check_policy_module_version(module: 'ModuleType', logger: 'LoggerFunction' = logging.log) -> None:
 
     '''
-    Checks that the Rucio version supported by the policy package is compatible
+    Checks that the Rucio version supported by the policy module is compatible
     with this version. Raises an exception if not.
-    :param package: the fully qualified name of the policy package
+    :param module: the top level module of the policy package
     '''
     try:
-        supported_versionset = _get_supported_versions_from_policy_package(package)
-    except ImportError:
-        logger(logging.DEBUG, 'Policy package %s not found' % package)
-        return
+        supported_versionset = _get_supported_versions_from_policy_package(module)
     except PolicyPackageIsNotVersioned:
-        logger(logging.DEBUG, 'Policy package %s does not include information about which Rucio versions it supports' % package)
+        logger(logging.DEBUG, 'Policy package %s does not include information about which Rucio versions it supports' % module.__name__)
         return
 
     rucio_version = current_version()
     if rucio_version not in supported_versionset:
-        raise PolicyPackageVersionError(rucio_version=rucio_version, supported_versionset=str(supported_versionset), package=package)
-
+        raise PolicyPackageVersionError(rucio_version=rucio_version, supported_versionset=str(supported_versionset), package=module.__name__)
 
-def _get_supported_versions_from_policy_package(package: str) -> SpecifierSet:
-    try:
-        module = importlib.import_module(package)
-    except ImportError as e:
-        raise e
 
+def _get_supported_versions_from_policy_package(module: 'ModuleType') -> SpecifierSet:
     if not hasattr(module, 'SUPPORTED_VERSION'):
-        raise PolicyPackageIsNotVersioned(package)
+        raise PolicyPackageIsNotVersioned(module.__name__)
 
     supported_versionset = module.SUPPORTED_VERSION
 
@@ -160,8 +153,8 @@ class PolicyPackageAlgorithms:
             if not package:
                 package = str(config.config_get('policy', 'package' + ('' if not vo else '-' + vo)))
 
-            check_policy_package_version(package)
             module = importlib.import_module(package)
+            check_policy_module_version(module)
 
             if hasattr(module, 'get_algorithms'):
                 all_algorithms = module.get_algorithms()
diff --git a/lib/rucio/common/schema/__init__.py b/lib/rucio/common/schema/__init__.py
index 84a015a35..43115e95c 100644
--- a/lib/rucio/common/schema/__init__.py
+++ b/lib/rucio/common/schema/__init__.py
@@ -22,7 +22,7 @@ from typing import TYPE_CHECKING, Any
 from jsonschema import ValidationError, validate
 
 from rucio.common import config, exception
-from rucio.common.plugins import check_policy_package_version
+from rucio.common.plugins import check_policy_module_version
 
 if TYPE_CHECKING:
     from types import ModuleType
@@ -64,9 +64,10 @@ if not _is_multivo():
                 policy = environ['RUCIO_POLICY_PACKAGE']
             else:
                 policy = config.config_get('policy', 'package', check_config_table=False)
-            check_policy_package_version(policy)
+            package_module = importlib.import_module(policy)
+            check_policy_module_version(package_module)
             policy = policy + ".schema"
-        except (NoOptionError, NoSectionError):
+        except (NoOptionError, NoSectionError, ModuleNotFoundError):
             # fall back to old system for now
             try:
                 policy = config.config_get('policy', 'schema', check_config_table=False)
@@ -107,9 +108,10 @@ def load_schema_for_vo(vo: str) -> None:
                 policy = environ[env_name]
             else:
                 policy = config.config_get('policy', 'package-' + vo, check_config_table=False)
-            check_policy_package_version(policy)
+            package_module = importlib.import_module(policy)
+            check_policy_module_version(package_module)
             policy = policy + ".schema"
-        except (NoOptionError, NoSectionError):
+        except (NoOptionError, NoSectionError, ModuleNotFoundError):
             # fall back to old system for now
             try:
                 policy = config.config_get('policy', 'schema', check_config_table=False)
diff --git a/lib/rucio/core/permission/__init__.py b/lib/rucio/core/permission/__init__.py
index 129d7fec7..6d614db4b 100644
--- a/lib/rucio/core/permission/__init__.py
+++ b/lib/rucio/core/permission/__init__.py
@@ -20,7 +20,7 @@ from typing import TYPE_CHECKING, Any
 
 import rucio.core.permission.generic
 from rucio.common import config, exception
-from rucio.common.plugins import check_policy_package_version
+from rucio.common.plugins import check_policy_module_version
 from rucio.common.policy import get_policy
 
 if TYPE_CHECKING:
@@ -54,9 +54,10 @@ if not multivo:
                 policy = environ['RUCIO_POLICY_PACKAGE']
             else:
                 policy = config.config_get('policy', 'package', check_config_table=False)
-            check_policy_package_version(policy)
+            package_module = importlib.import_module(policy)
+            check_policy_module_version(package_module)
             policy = policy + ".permission"
-        except (NoOptionError, NoSectionError):
+        except (NoOptionError, NoSectionError, ModuleNotFoundError):
             # fall back to old system for now
             policy = 'rucio.core.permission.' + fallback_policy.lower()
     else:
@@ -91,9 +92,10 @@ def load_permission_for_vo(vo: str) -> None:
                 policy = environ[env_name]
             else:
                 policy = config.config_get('policy', 'package-' + vo)
-            check_policy_package_version(policy)
+            package_module = importlib.import_module(policy)
+            check_policy_module_version(package_module)
             policy = policy + ".permission"
-        except (NoOptionError, NoSectionError):
+        except (NoOptionError, NoSectionError, ModuleNotFoundError):
             # fall back to old system for now
             try:
                 policy = config.config_get('policy', 'permission')


Test patch:
diff --git a/tests/rucio/common/test_plugins.py b/tests/rucio/common/test_plugins.py
index ddec8a150..737a05c20 100644
--- a/tests/rucio/common/test_plugins.py
+++ b/tests/rucio/common/test_plugins.py
@@ -17,24 +17,18 @@ import pytest
 from packaging.specifiers import SpecifierSet
 
 from rucio.common.exception import PolicyPackageIsNotVersioned, PolicyPackageVersionError
-from rucio.common.plugins import _get_supported_versions_from_policy_package, check_policy_package_version
+from rucio.common.plugins import _get_supported_versions_from_policy_package, check_policy_module_version
 
 
 class TestPolicyPackageVersion:
-    def test_get_supported_versions_from_policy_package_importerror(self):
-        package = 'bad_package'
-        with patch('importlib.import_module', side_effect=ImportError):
-            with pytest.raises(ImportError):
-                _get_supported_versions_from_policy_package(package)
-
     def test_get_supported_versions_from_policy_package_not_versioned(self):
         package = 'unversioned_package'
         module = Mock()
+        module.__name__ = package
         delattr(module, 'SUPPORTED_VERSION')
         assert not hasattr(module, 'SUPPORTED_VERSION')
-        with patch('importlib.import_module', return_value=module):
-            with pytest.raises(PolicyPackageIsNotVersioned) as e:
-                _get_supported_versions_from_policy_package(package)
+        with pytest.raises(PolicyPackageIsNotVersioned) as e:
+            _get_supported_versions_from_policy_package(module)
         assert e.value.package == package
 
     @pytest.mark.parametrize(
@@ -46,35 +40,28 @@ class TestPolicyPackageVersion:
         ids=['version_as_str', 'version_as_list']
     )
     def test_get_supported_versions_from_policy_package(self, module_version, expected_version):
-        package = 'versioned_package'
         module = MagicMock()
         module.SUPPORTED_VERSION = module_version
-        with patch('importlib.import_module', return_value=module):
-            assert _get_supported_versions_from_policy_package(package) == expected_version
-
-    @pytest.mark.parametrize('raised_exception', [
-        ImportError,
-        PolicyPackageIsNotVersioned('bad_package')
-    ])
-    def test_check_policy_package_version_exceptions(self, raised_exception):
-        package = 'bad_package'
-        with patch('rucio.common.plugins._get_supported_versions_from_policy_package', side_effect=raised_exception):
-            assert check_policy_package_version(package) is None
+        assert _get_supported_versions_from_policy_package(module) == expected_version
 
-    def test_check_policy_package_version_supported(self):
+    def test_check_policy_module_version_supported(self):
         package = 'supported_package'
+        module = Mock()
+        module.__name__ = package
         with patch('rucio.common.plugins._get_supported_versions_from_policy_package', return_value=SpecifierSet('>=1.0,!=2.0')):
             with patch('rucio.common.plugins.current_version', return_value='1.7'):
-                assert check_policy_package_version(package) is None
+                assert check_policy_module_version(module) is None
 
-    def test_check_policy_package_version_unsupported(self):
+    def test_check_policy_module_version_unsupported(self):
         package = 'unsupported_package'
+        supported_versions = '>=1.0,!=3.0'
         rucio_version = '3.0'
-        supported_versions = SpecifierSet('>=1.0,!=3.0')
-        with patch('rucio.common.plugins._get_supported_versions_from_policy_package', return_value=supported_versions):
-            with patch('rucio.common.plugins.current_version', return_value=rucio_version):
-                with pytest.raises(PolicyPackageVersionError) as e:
-                    check_policy_package_version(package)
-                assert e.value.package == package
-                assert e.value.rucio_version == rucio_version
-                assert e.value.supported_versionset == supported_versions
+        module = Mock()
+        module.__name__ = package
+        module.SUPPORTED_VERSION = supported_versions
+        with patch('rucio.common.plugins.current_version', return_value=rucio_version):
+            with pytest.raises(PolicyPackageVersionError) as e:
+                check_policy_module_version(module)
+            assert e.value.package == package
+            assert e.value.rucio_version == rucio_version
+            assert e.value.supported_versionset == SpecifierSet(supported_versions)