diff options
author | Paul Barker <pbarker@konsulko.com> | 2021-02-05 11:26:07 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-02-10 23:48:16 +0000 |
commit | 3b559bb16df9c178401be49c9cb8130b7d7568fd (patch) | |
tree | fe989962d371476edbb7702ec83234b8b9d8bfe3 /bitbake/lib/hashserv/tests.py | |
parent | f5188da2f12bee03e087c20d90720250e65e2922 (diff) | |
download | poky-3b559bb16df9c178401be49c9cb8130b7d7568fd.tar.gz |
bitbake: hashserv: Support read-only server
The -r/--readonly argument is added to the bitbake-hashserv app. If this
argument is given then clients may only perform read operations against
the server. The read-only mode is implemented by simply not installing
handlers for write operations, this keeps the permission model simple
and reduces the risk of accidentally allowing write operations.
As a sqlite database can be safely opened by multiple processes in
parallel, it's possible to start two hashserv instances against a single
database if you wish to export both a read-only port and a read-write
port.
(Bitbake rev: 492bb02eb0e071c792407ac3113f92492da1a9cc)
Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/hashserv/tests.py')
-rw-r--r-- | bitbake/lib/hashserv/tests.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py index 77a19b8077..6f04e30d61 100644 --- a/bitbake/lib/hashserv/tests.py +++ b/bitbake/lib/hashserv/tests.py | |||
@@ -6,6 +6,7 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | from . import create_server, create_client | 8 | from . import create_server, create_client |
9 | from .client import HashConnectionError | ||
9 | import hashlib | 10 | import hashlib |
10 | import logging | 11 | import logging |
11 | import multiprocessing | 12 | import multiprocessing |
@@ -29,7 +30,7 @@ class HashEquivalenceTestSetup(object): | |||
29 | 30 | ||
30 | server_index = 0 | 31 | server_index = 0 |
31 | 32 | ||
32 | def start_server(self, dbpath=None, upstream=None): | 33 | def start_server(self, dbpath=None, upstream=None, read_only=False): |
33 | self.server_index += 1 | 34 | self.server_index += 1 |
34 | if dbpath is None: | 35 | if dbpath is None: |
35 | dbpath = os.path.join(self.temp_dir.name, "db%d.sqlite" % self.server_index) | 36 | dbpath = os.path.join(self.temp_dir.name, "db%d.sqlite" % self.server_index) |
@@ -38,7 +39,10 @@ class HashEquivalenceTestSetup(object): | |||
38 | thread.terminate() | 39 | thread.terminate() |
39 | thread.join() | 40 | thread.join() |
40 | 41 | ||
41 | server = create_server(self.get_server_addr(self.server_index), dbpath, upstream=upstream) | 42 | server = create_server(self.get_server_addr(self.server_index), |
43 | dbpath, | ||
44 | upstream=upstream, | ||
45 | read_only=read_only) | ||
42 | server.dbpath = dbpath | 46 | server.dbpath = dbpath |
43 | 47 | ||
44 | server.thread = multiprocessing.Process(target=_run_server, args=(server, self.server_index)) | 48 | server.thread = multiprocessing.Process(target=_run_server, args=(server, self.server_index)) |
@@ -242,6 +246,31 @@ class HashEquivalenceCommonTests(object): | |||
242 | self.assertClientGetHash(side_client, taskhash4, unihash4) | 246 | self.assertClientGetHash(side_client, taskhash4, unihash4) |
243 | self.assertClientGetHash(self.client, taskhash4, None) | 247 | self.assertClientGetHash(self.client, taskhash4, None) |
244 | 248 | ||
249 | def test_ro_server(self): | ||
250 | (ro_client, ro_server) = self.start_server(dbpath=self.server.dbpath, read_only=True) | ||
251 | |||
252 | # Report a hash via the read-write server | ||
253 | taskhash = '35788efcb8dfb0a02659d81cf2bfd695fb30faf9' | ||
254 | outhash = '2765d4a5884be49b28601445c2760c5f21e7e5c0ee2b7e3fce98fd7e5970796f' | ||
255 | unihash = 'f46d3fbb439bd9b921095da657a4de906510d2cd' | ||
256 | |||
257 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
258 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
259 | |||
260 | # Check the hash via the read-only server | ||
261 | self.assertClientGetHash(ro_client, taskhash, unihash) | ||
262 | |||
263 | # Ensure that reporting via the read-only server fails | ||
264 | taskhash2 = 'c665584ee6817aa99edfc77a44dd853828279370' | ||
265 | outhash2 = '3c979c3db45c569f51ab7626a4651074be3a9d11a84b1db076f5b14f7d39db44' | ||
266 | unihash2 = '90e9bc1d1f094c51824adca7f8ea79a048d68824' | ||
267 | |||
268 | with self.assertRaises(HashConnectionError): | ||
269 | ro_client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
270 | |||
271 | # Ensure that the database was not modified | ||
272 | self.assertClientGetHash(self.client, taskhash2, None) | ||
273 | |||
245 | 274 | ||
246 | class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase): | 275 | class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase): |
247 | def get_server_addr(self, server_idx): | 276 | def get_server_addr(self, server_idx): |