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

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 5b890f91070864c5eefc45f974298756e39c53a5
Merge reported by: Ines Almeida
Merged at revision: 3618c237db8fd7a7d44f8872d27e7b6b22b703ab
Proposed branch: ~ines-almeida/launchpad-layers:add-pkgupload-interface
Merge into: launchpad-layers:main
Diff against target: 109 lines (+91/-0)
3 files modified
upload-queue-processor/interface.yaml (+3/-0)
upload-queue-processor/provides.py (+37/-0)
upload-queue-processor/requires.py (+51/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+445989@code.launchpad.net

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.

Description of the change

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

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) :
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Added some of my own thoughts and questions about the code

Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Since we are on it, I'll wait for the txpkgupload charm MP to be ready for approval before merging this one, in case we want to make any changes. I'll leave it open for review in the meantime

Revision history for this message
Guruprasad (lgp171188) :
Revision history for this message
Ines Almeida (ines-almeida) wrote :

I addressed your comments Guruprasad. Good thing this didn't merge automatically when I hit approve :)

Revision history for this message
Guruprasad (lgp171188) wrote :

Thanks Inês!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/upload-queue-processor/interface.yaml b/upload-queue-processor/interface.yaml
0new file mode 1006440new file mode 100644
index 0000000..2442dd8
--- /dev/null
+++ b/upload-queue-processor/interface.yaml
@@ -0,0 +1,3 @@
1name: upload-queue-processor
2summary: Package Uploader interface
3version: 1
diff --git a/upload-queue-processor/provides.py b/upload-queue-processor/provides.py
0new file mode 1006444new file mode 100644
index 0000000..1c0c05b
--- /dev/null
+++ b/upload-queue-processor/provides.py
@@ -0,0 +1,37 @@
1# Copyright 2023 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4from charmhelpers.core import hookenv
5from charms.reactive import Endpoint, clear_flag, set_flag, when
6
7
8class UploadProcessorProvides(Endpoint):
9 @when("endpoint.{endpoint_name}.joined")
10 def handle_joined_unit(self):
11 set_flag(self.expand_name("{endpoint_name}.available"))
12
13 @when("endpoint.{endpoint_name}.changed")
14 def handle_changed_unit(self):
15 set_flag(self.expand_name("{endpoint_name}.available"))
16 clear_flag(self.expand_name("changed"))
17
18 @when("endpoint.{endpoint_name}.departed")
19 def handle_departed_unit(self):
20 clear_flag(self.expand_name("{endpoint_name}.available"))
21 self.all_departed_units.clear()
22 clear_flag(self.expand_name("departed"))
23
24 def set_config(self, fsroot: str):
25 """Called from the provider of the interface to configure txpkgupload.
26 This will trigger a 'changed' flag in the `requires` side of the
27 relation.
28
29 :param fsroot: directory for the uploads to live within the filesystem
30 """
31 hookenv.log("Publishing configuration data txpkgupload interface")
32 for relation in self.relations:
33 relation.to_publish.update(
34 {
35 "fsroot": fsroot,
36 }
37 )
diff --git a/upload-queue-processor/requires.py b/upload-queue-processor/requires.py
0new file mode 10064438new file mode 100644
index 0000000..3f3df36
--- /dev/null
+++ b/upload-queue-processor/requires.py
@@ -0,0 +1,51 @@
1# Copyright 2023 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4from charmhelpers.core import hookenv
5from charms.reactive import Endpoint, clear_flag, set_flag, when
6
7
8class UploadProcessorRequires(Endpoint):
9 def __init__(self, *args, **kwargs):
10 super().__init__(*args, **kwargs)
11 self.fsroot = None
12
13 @when("endpoint.{endpoint_name}.joined")
14 def handle_joined_unit(self):
15 # We don't want to make it available before it's configured
16 # It is configured, when data is added from the provider side,
17 # triggering the 'changed' endpoint
18 hookenv.log("Txpkgupload interface available.")
19
20 @when("endpoint.{endpoint_name}.changed")
21 def handle_changed_unit(self):
22 clear_flag(self.expand_name("{endpoint_name}.configured"))
23
24 # We expect exactly one relation between a txpkgupload and a queue
25 # processor (where the txpkgupload a subordinate to the latter)
26 if len(self.relations) != 1:
27 endpoint_name = self.expand_name("{endpoint_name}")
28 clear_flag(self.expand_name("changed"))
29 raise Exception(
30 f"Expected exactly 1 relation in {endpoint_name} but found "
31 f"{len(self.relations)} instead."
32 )
33
34 # Use `fsroot` values received from the queue processor
35 # If none were received, use the ones received previously
36 received_data = self.relations[0].units.received
37 self.fsroot = received_data.get("fsroot", self.fsroot)
38
39 if self.fsroot:
40 hookenv.log("Configuration from queue processor received")
41 set_flag(self.expand_name("{endpoint_name}.configured"))
42 else:
43 hookenv.log("Waiting for configuration from queue processor")
44
45 clear_flag(self.expand_name("changed"))
46
47 @when("endpoint.{endpoint_name}.departed")
48 def handle_departed_unit(self):
49 clear_flag(self.expand_name("{endpoint_name}.configured"))
50 self.all_departed_units.clear()
51 clear_flag(self.expand_name("departed"))

Subscribers

People subscribed via source and target branches