Repository: pulp/pulpcore

Issue:
Pulp users don't understand app labels in the status api/cli
Author: daviddavis (daviddavis)


Redmine Issue: 8434, https://pulp.plan.io/issues/8434

---

It's kind of confusing and perhaps nonobvious what the components in the status api mean. Suppose for example you have a package/plugin called pulp_foo that has app labels bar and baz. Users may not understand what bar and baz come from or what they mean. 

I think this may have contributed to this user's confusion: https://github.com/pulp/pulp-cli/issues/184





Discussion:
From: daviddavis (daviddavis)
Date: 2021-03-22T14:02:52Z

---

One possible solution is to show the package name with the app label:

```
{                                                                                                                                                                                             
  "versions": [                                                                                                                                                                               
    {                                                                                                                                                                                         
      "component": "core", 
      "package": "pulpcore",                                                                                                                                                                   
      "version": "3.12.0.dev"                                                                                                                                                                 
    },                                                                                                                                                                                        
    {                                                                                                                                                                                         
      "component": "bar",
      "package": "pulp_foo",
      "version": "5.6.0.dev"
    },
...
```
From: @bmbouter (bmbouter)
Date: 2021-03-23T14:40:34Z

---

I'm reading that it would be helpful for the status API to list the actual python package providing the Django app name. That makes sense to me. That field could be added whereby the plugin provides that data explicitly.

Is there any concern about a django app being packaged multiple times? I don't think that would happen par-se, but if it did, the repackager would have to modify the code during packaging. I think that's ok tho, but I wanted to share it here.
From: daviddavis (daviddavis)
Date: 2021-03-26T13:39:46Z

---

> I'm reading that it would be helpful for the status API to list the actual python package providing the Django app name. That makes sense to me. That field could be added whereby the plugin provides that data explicitly.

That sounds great.

> Is there any concern about a django app being packaged multiple times? I don't think that would happen par-se, but if it did, the repackager would have to modify the code during packaging. I think that's ok tho, but I wanted to share it here.

Hmm, I can't think of a case where a django app would be shipped in two different packages. It seems theoretically but perhaps not practically possible. Then again, I am not super familiar with django app stuff.
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
I think we should consider requiring plugins to start providing this in 3.20+. I put onto the 3.20 milestone for discussion.

Resolving patch:
diff --git a/pulpcore/app/apps.py b/pulpcore/app/apps.py
--- a/pulpcore/app/apps.py
+++ b/pulpcore/app/apps.py
@@ -70,6 +70,17 @@ def __init__(self, app_name, app_module):
             )
             raise ImproperlyConfigured(msg.format(self.label))
 
+        try:
+            self.python_package_name
+        except AttributeError:
+            msg = (
+                "The plugin `{}` is missing a `python_package_name` declaration. Starting with "
+                "pulpcore==3.20, plugins are required to define the python package name providing "
+                "the Pulp plugin on the PulpPluginAppConfig subclass as the `python_package_name` "
+                "attribute."
+            )
+            raise ImproperlyConfigured(msg.format(self.label))
+
         # Module containing viewsets eg. <module 'pulp_plugin.app.viewsets'
         # from 'pulp_plugin/app/viewsets.py'>. Set by import_viewsets().
         # None if the application doesn't have a viewsets module, automatically set
@@ -192,6 +203,9 @@ class PulpAppConfig(PulpPluginAppConfig):
     # The version of this app
     version = "3.20.0.dev"
 
+    # The python package name providing this app
+    python_package_name = "pulpcore"
+
     def ready(self):
         super().ready()
         from . import checks  # noqa
diff --git a/pulpcore/app/serializers/status.py b/pulpcore/app/serializers/status.py
--- a/pulpcore/app/serializers/status.py
+++ b/pulpcore/app/serializers/status.py
@@ -14,6 +14,8 @@ class VersionSerializer(serializers.Serializer):
 
     version = serializers.CharField(help_text=_("Version of the component (e.g. 3.0.0)"))
 
+    package = serializers.CharField(help_text=_("Python package name providing the component"))
+
 
 class DatabaseConnectionSerializer(serializers.Serializer):
     """
diff --git a/pulpcore/app/views/status.py b/pulpcore/app/views/status.py
--- a/pulpcore/app/views/status.py
+++ b/pulpcore/app/views/status.py
@@ -55,7 +55,9 @@ def get(self, request):
         """
         versions = []
         for app in pulp_plugin_configs():
-            versions.append({"component": app.label, "version": app.version})
+            versions.append(
+                {"component": app.label, "version": app.version, "package": app.python_package_name}
+            )
 
         if settings.CACHE_ENABLED:
             redis_status = {"connected": self._get_redis_conn_status()}


Test patch:
diff --git a/pulpcore/tests/functional/api/test_status.py b/pulpcore/tests/functional/api/test_status.py
--- a/pulpcore/tests/functional/api/test_status.py
+++ b/pulpcore/tests/functional/api/test_status.py
@@ -28,7 +28,11 @@
             "type": "array",
             "items": {
                 "type": "object",
-                "properties": {"component": {"type": "string"}, "version": {"type": "string"}},
+                "properties": {
+                    "component": {"type": "string"},
+                    "version": {"type": "string"},
+                    "package": {"type": "string"},
+                },
             },
         },
         "storage": {