Merge ~thogarre/charm-canonical-livepatch:LP1892360 into charm-canonical-livepatch:master

Proposed by Garrett Neugent
Status: Rejected
Rejected by: Andrea Ieri
Proposed branch: ~thogarre/charm-canonical-livepatch:LP1892360
Merge into: charm-canonical-livepatch:master
Diff against target: 78 lines (+45/-0)
2 files modified
src/config.yaml (+5/-0)
src/reactive/canonical_livepatch.py (+40/-0)
Reviewer Review Type Date Requested Status
Andrea Ieri Needs Resubmitting
Joe Guo (community) Needs Fixing
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
Review via email: mp+402291@code.launchpad.net

Commit message

add remote-server config option

To post a comment you must log in.
Revision history for this message
Garrett Neugent (thogarre) wrote :
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Joe Guo (guoqiao) wrote :

A few issues:

0) `remove-server` is not valid envvar name, for the `-`

1) code in remote_server_settings can be simplified. e.g.:

remove_server = config.get("remote_server") or os.getenv("remote_server")

3) when configure_remote_server failed, maybe we need to set status to block ?

4) in current logic, even configure_remote_server failed, set_flag("remote-server.configured") will still be called, which is wrong.

review: Needs Fixing
Revision history for this message
Andrea Ieri (aieri) wrote :

This merge proposal has not seen updates in over 2 years. I'll close it for now.

review: Needs Resubmitting

Unmerged commits

3de3655... by Garrett Neugent

LP#1892360 add config option for remote-server

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/config.yaml b/src/config.yaml
2index 1afa024..311db1c 100644
3--- a/src/config.yaml
4+++ b/src/config.yaml
5@@ -24,3 +24,8 @@ options:
6 type: boolean
7 description: |
8 Enable installation on container for testing purpose.
9+ remote_server:
10+ default: "https://livepatch.canonical.com"
11+ type: string
12+ description: |
13+ The upstream address for fetching patches.
14diff --git a/src/reactive/canonical_livepatch.py b/src/reactive/canonical_livepatch.py
15index e4a8540..3b87094 100644
16--- a/src/reactive/canonical_livepatch.py
17+++ b/src/reactive/canonical_livepatch.py
18@@ -168,6 +168,19 @@ def configure_proxies(proxy=None):
19 hookenv.log("Failed to set proxy", hookenv.ERROR)
20
21
22+def configure_remote_server(server=None):
23+ """Configure remote-server."""
24+ key = "remote-server"
25+ if server is None:
26+ server = "https://livepatch.canonical.com"
27+ cmd = ["/snap/bin/canonical-livepatch", "config", "{}={}".format(key, server)]
28+ hookenv.log("Configuring {} as {}".format(key, server))
29+ try:
30+ check_call(cmd, universal_newlines=True)
31+ except CalledProcessError:
32+ hookenv.log("Failed to set remote-server", hookenv.ERROR)
33+
34+
35 def activate_livepatch():
36 """Activate livepatch."""
37 unit_update("maintenance", "Updating API key")
38@@ -209,6 +222,10 @@ register_trigger(
39 when="config.changed.livepatch_proxy", clear_flag="livepatch-proxy.configured"
40 )
41
42+register_trigger(
43+ when="config.changed.remote_server", clear_flag="remote-server.configured"
44+)
45+
46
47 @when_not("canonical-livepatch.supported")
48 def livepatch_supported():
49@@ -266,6 +283,29 @@ def proxy_settings():
50
51
52 @when("snap.installed.canonical-livepatch")
53+@when_not("remote-server.configured")
54+def remote_server_settings():
55+ """Get remote-server setting and configure it."""
56+ remote_server = None
57+
58+ for key, value in environ.items():
59+ # use environment's remote-server if it is set
60+ if key == "remote-server":
61+ remote_server = value
62+
63+ # but if we have a charm configured remote-server, prefer that
64+ config = hookenv.config()
65+ charm_config_remote_server = config.get("remote_server")
66+ if charm_config_remote_server:
67+ remote_server = charm_config_remote_server
68+
69+ # whatever we prefer (or None), configure it!
70+ configure_remote_server(remote_server)
71+
72+ set_flag("remote-server.configured")
73+
74+
75+@when("snap.installed.canonical-livepatch")
76 @when("livepatch-proxy.configured")
77 @when_not("canonical-livepatch.connected")
78 def canonical_livepatch_connect():

Subscribers

People subscribed via source and target branches

to all changes: