Merge ~ines-almeida/launchpad:fetch-service-add-get-data-endpoint into launchpad:master

Proposed by Ines Almeida
Status: Rejected
Rejected by: Ines Almeida
Proposed branch: ~ines-almeida/launchpad:fetch-service-add-get-data-endpoint
Merge into: launchpad:master
Diff against target: 159 lines (+50/-15)
4 files modified
lib/lp/buildmaster/builderproxy.py (+4/-4)
lib/lp/buildmaster/interfaces/buildfarmjobbehaviour.py (+4/-0)
lib/lp/buildmaster/tests/fetchservice.py (+24/-9)
lib/lp/snappy/tests/test_snapbuildbehaviour.py (+18/-2)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+463145@code.launchpad.net

Commit message

Send end_session_endpoint to build manager when using fetch service

The fetch service will require 2 endpoints: one for revoking the token (as the old builder proxy did) and one for ending the session and gathering the data - that we are adding in this MP

To post a comment you must log in.
2786cfb... by Ines Almeida

tests: small fix to test matchers import

1129639... by Ines Almeida

test: update regex fetch service matchers to check begining and end of line

Unmerged commits

1129639... by Ines Almeida

test: update regex fetch service matchers to check begining and end of line

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results
2786cfb... by Ines Almeida

tests: small fix to test matchers import

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results
320b0a5... by Ines Almeida

Send end_session_endpoint to build manager when using fetch service

The fetch service will require 2 endpoints: one for revoking the token (as the old builder proxy did) and one for ending the session and gathering the data - that we are adding in this MP

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/buildmaster/builderproxy.py b/lib/lp/buildmaster/builderproxy.py
2index 3375042..9309246 100644
3--- a/lib/lp/buildmaster/builderproxy.py
4+++ b/lib/lp/buildmaster/builderproxy.py
5@@ -77,10 +77,10 @@ class BuilderProxyMixin:
6 port=_get_proxy_config("fetch_service_port"),
7 )
8 )
9- args["revocation_endpoint"] = "{endpoint}/{session_id}".format(
10- endpoint=_get_proxy_config("fetch_service_control_endpoint"),
11- session_id=session["id"],
12- )
13+ endpoint = _get_proxy_config("fetch_service_control_endpoint")
14+ session_id = session["id"]
15+ args["revocation_endpoint"] = f"{endpoint}/{session_id}/token"
16+ args["end_session_endpoint"] = f"{endpoint}/{session_id}"
17
18 @defer.inlineCallbacks
19 def _requestProxyToken(self):
20diff --git a/lib/lp/buildmaster/interfaces/buildfarmjobbehaviour.py b/lib/lp/buildmaster/interfaces/buildfarmjobbehaviour.py
21index 6a808b3..2afb876 100644
22--- a/lib/lp/buildmaster/interfaces/buildfarmjobbehaviour.py
23+++ b/lib/lp/buildmaster/interfaces/buildfarmjobbehaviour.py
24@@ -128,6 +128,10 @@ class BuildArgs(TypedDict, total=False):
25 # The URL for revoking proxy authorization tokens [charm, ci, oci,
26 # snap].
27 revocation_endpoint: str
28+ # The URL for ending a fetch service session (separate from the
29+ # 'revocation_endpoint, as is certain cases want to revoke the token before
30+ # closing the session)
31+ end_session_endpoint: str
32 # If True, scan job output for malware [ci].
33 scan_malware: bool
34 # A dictionary of secrets to pass to the CI build runner [ci].
35diff --git a/lib/lp/buildmaster/tests/fetchservice.py b/lib/lp/buildmaster/tests/fetchservice.py
36index 3fd879c..c5864c0 100644
37--- a/lib/lp/buildmaster/tests/fetchservice.py
38+++ b/lib/lp/buildmaster/tests/fetchservice.py
39@@ -9,7 +9,12 @@ from textwrap import dedent
40 from urllib.parse import urlsplit
41
42 import fixtures
43-from testtools.matchers import Equals, HasLength, MatchesStructure
44+from testtools.matchers import (
45+ Equals,
46+ HasLength,
47+ MatchesRegex,
48+ MatchesStructure,
49+)
50 from twisted.internet import defer, endpoints, reactor
51 from twisted.python.compat import nativeString
52 from twisted.web import resource, server
53@@ -110,15 +115,25 @@ class FetchServiceURLMatcher(MatchesStructure):
54 super().match(urlsplit(matchee))
55
56
57-class RevocationEndpointMatcher(Equals):
58+class FetchServiceRevocationEndpointMatcher(MatchesRegex):
59 """Check that a string is a valid endpoint for fetch
60 service session revocation.
61+
62+ Expected type: {endpoint}/{session_id:any digit}/{token}
63 """
64
65- def __init__(self, session_id):
66- super().__init__(
67- "{endpoint}/{session_id}".format(
68- endpoint=config.builddmaster.fetch_service_control_endpoint,
69- session_id=session_id,
70- )
71- )
72+ def __init__(self):
73+ endpoint = config.builddmaster.fetch_service_control_endpoint
74+ super().__init__(r"^%s/\d/token$" % (endpoint))
75+
76+
77+class FetchServiceEndSessionEndpointMatcher(MatchesRegex):
78+ """Check that a string is a valid endpoint for the fetch service session
79+ closing.
80+
81+ Expected type: {endpoint}/{session_id:any digit}
82+ """
83+
84+ def __init__(self):
85+ endpoint = config.builddmaster.fetch_service_control_endpoint
86+ super().__init__(r"^%s/\d$" % (endpoint))
87diff --git a/lib/lp/snappy/tests/test_snapbuildbehaviour.py b/lib/lp/snappy/tests/test_snapbuildbehaviour.py
88index 2ccc18d..0218ee3 100644
89--- a/lib/lp/snappy/tests/test_snapbuildbehaviour.py
90+++ b/lib/lp/snappy/tests/test_snapbuildbehaviour.py
91@@ -52,6 +52,8 @@ from lp.buildmaster.tests.builderproxy import (
92 RevocationEndpointMatcher,
93 )
94 from lp.buildmaster.tests.fetchservice import (
95+ FetchServiceEndSessionEndpointMatcher,
96+ FetchServiceRevocationEndpointMatcher,
97 InProcessFetchServiceAuthAPIFixture,
98 )
99 from lp.buildmaster.tests.mock_workers import (
100@@ -287,7 +289,8 @@ class TestAsyncSnapBuildBehaviourFetchService(
101 configuration.
102
103 If `fetch_service_host` is not provided the function will return
104- without populating `proxy_url` and `revocation_endpoint`.
105+ without populating `proxy_url`, `revocation_endpoint` and
106+ `end_session_endpoint`.
107 """
108 self.pushConfig("builddmaster", fetch_service_host=None)
109 self.useFixture(
110@@ -301,6 +304,7 @@ class TestAsyncSnapBuildBehaviourFetchService(
111 self.assertEqual([], self.fetch_service_api.sessions.requests)
112 self.assertNotIn("proxy_url", args)
113 self.assertNotIn("revocation_endpoint", args)
114+ self.assertNotIn("end_session_endpoint", args)
115
116 @defer.inlineCallbacks
117 def test_requestFetchServiceSession_no_secret(self):
118@@ -330,7 +334,8 @@ class TestAsyncSnapBuildBehaviourFetchService(
119 """Create a snap build request with a successful fetch service
120 configuration.
121
122- `proxy_url` and `revocation_endpoint` are correctly populated.
123+ `proxy_url`, `revocation_endpoint` and `end_session_endpoint` are
124+ correctly populated.
125 """
126 self.useFixture(
127 FeatureFixture({SNAP_USE_FETCH_SERVICE_FEATURE_FLAG: "on"})
128@@ -379,6 +384,15 @@ class TestAsyncSnapBuildBehaviourFetchService(
129 )
130 self.assertIn("proxy_url", args)
131 self.assertIn("revocation_endpoint", args)
132+ self.assertThat(
133+ args["revocation_endpoint"],
134+ FetchServiceRevocationEndpointMatcher(),
135+ )
136+ self.assertIn("end_session_endpoint", args)
137+ self.assertThat(
138+ args["end_session_endpoint"],
139+ FetchServiceEndSessionEndpointMatcher(),
140+ )
141
142 @defer.inlineCallbacks
143 def test_requestFetchServiceSession_flag_off(self):
144@@ -465,6 +479,7 @@ class TestAsyncSnapBuildBehaviourBuilderProxy(
145 self.assertEqual([], self.proxy_api.tokens.requests)
146 self.assertNotIn("proxy_url", args)
147 self.assertNotIn("revocation_endpoint", args)
148+ self.assertNotIn("end_session_endpoint", args)
149
150 @defer.inlineCallbacks
151 def test_requestProxyToken_no_secret(self):
152@@ -1321,6 +1336,7 @@ class TestAsyncSnapBuildBehaviourBuilderProxy(
153 args = yield job.extraBuildArgs()
154 self.assertNotIn("proxy_url", args)
155 self.assertNotIn("revocation_endpoint", args)
156+ self.assertNotIn("revocation_endpoint", args)
157
158 @defer.inlineCallbacks
159 def test_extraBuildArgs_build_source_tarball(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: