← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ines-almeida/launchpad-layers:add-pkgupload-interface into launchpad-layers:main

 

Ines Almeida has proposed merging ~ines-almeida/launchpad-layers:add-pkgupload-interface into launchpad-layers:main.

Commit message:
Create interface for txpkgupload charm

This interface has 2 main goals:
 - Set the `<interface>.available` and `<interface>.configuration.available` flags within the charms
 - Send configuration data from the upload processor to the txpkgupload using `set_config()` in `provides.py`, and fetching it from the txpkgupload charm directly once the `<interface>.configuration.available` flag is on.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ines-almeida/launchpad-layers/+git/launchpad-layers/+merge/445989

This interface should be used between txpkgupload and the ppa/ftpmaster upload processors charms

Currently the ppa/ftpmaster upload processors are the providers of the interface, and the txpkgupload is the one that requires it
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad-layers:add-pkgupload-interface into launchpad-layers:main.
diff --git a/upload-queue-processor/interface.yaml b/upload-queue-processor/interface.yaml
new file mode 100644
index 0000000..2442dd8
--- /dev/null
+++ b/upload-queue-processor/interface.yaml
@@ -0,0 +1,3 @@
+name: upload-queue-processor
+summary: Package Uploader interface
+version: 1
diff --git a/upload-queue-processor/provides.py b/upload-queue-processor/provides.py
new file mode 100644
index 0000000..a084f1b
--- /dev/null
+++ b/upload-queue-processor/provides.py
@@ -0,0 +1,29 @@
+# Copyright (C) 2023 Canonical Ltd.
+from charmhelpers.core import hookenv
+from charms.reactive import Endpoint, clear_flag, set_flag, when
+
+
+class UploadProcessorProvides(Endpoint):
+    @when("endpoint.{endpoint_name}.joined")
+    def handle_joined_unit(self):
+        set_flag(self.expand_name("{endpoint_name}.available"))
+        hookenv.log(self.expand_name("provides: {endpoint_name}.available"))
+
+    @when("endpoint.{endpoint_name}.changed")
+    def handle_changed_unit(self):
+        set_flag(self.expand_name("{endpoint_name}.available"))
+        clear_flag(self.expand_name("changed"))
+
+    @when("endpoint.{endpoint_name}.departed")
+    def handle_departed_unit(self):
+        clear_flag(self.expand_name("{endpoint_name}.available"))
+        self.all_departed_units.clear()
+        clear_flag(self.expand_name("departed"))
+
+    # Called from the provider or the interface to configure txpkgupload
+    # This will trigger a 'changed' flag in the `requires` side of the relation
+    def set_config(self, config):
+        hookenv.log("Publishing configuration data txpkgupload interface")
+        for relation in self.relations:
+            hookenv.log(relation)
+            relation.to_publish.update(config)
diff --git a/upload-queue-processor/requires.py b/upload-queue-processor/requires.py
new file mode 100644
index 0000000..7e5add0
--- /dev/null
+++ b/upload-queue-processor/requires.py
@@ -0,0 +1,36 @@
+# Copyright (C) 2023 Canonical Ltd.
+
+from charmhelpers.core import hookenv
+from charms.reactive import Endpoint, clear_flag, set_flag, when
+
+
+class UploadProcessorRequires(Endpoint):
+    @when("endpoint.{endpoint_name}.joined")
+    def handle_joined_unit(self):
+        # We don't want to make ti available before it's configured
+        # It is configured, when data is added from the provider side,
+        # triggering the 'changed' endpoint
+        hookenv.log("requires:upload-queue-processor joined")
+
+    @when("endpoint.{endpoint_name}.changed")
+    def handle_changed_unit(self):
+        clear_flag(self.expand_name("{endpoint_name}.configuration.available"))
+
+        # Set trigger to configure txpkgupload if configuration from upload
+        # queueprocessor was received
+        # We use `fsroot`` here as a check because it's one of the main fields
+        # configured by the queue processor.
+        relation = self.relations[0]
+        if "fsroot" in relation.units.received:
+            set_flag(
+                self.expand_name("{endpoint_name}.configuration.available")
+            )
+        else:
+            hookenv.log("Waiting for config from the queue processor")
+        clear_flag(self.expand_name("changed"))
+
+    @when("endpoint.{endpoint_name}.departed")
+    def handle_departed_unit(self):
+        clear_flag(self.expand_name("{endpoint_name}.configuration.available"))
+        self.all_departed_units.clear()
+        clear_flag(self.expand_name("departed"))

Follow ups