summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2024-04-12 09:57:09 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-04-12 18:04:00 +0100
commite1645c1b2e3f4dea55a48e8f6ebb15e3608bec63 (patch)
treefac09c86e3560276eb4bf4468a74b14f53859547
parent2081715ce8a40e4652a4c62ea87c6ee772e6fc80 (diff)
downloadpoky-e1645c1b2e3f4dea55a48e8f6ebb15e3608bec63.tar.gz
bitbake: siggen: Capture SSL environment for hashserver
Now that the bitbake hash server supports SSL connections, we need to capture a few environment variables which can affect the ability to connect via SSL. Note that the variables are only put in place to affect the environment while actually invoking the server [RP: Tweak to use BB_ORIGENV as well] (Bitbake rev: 62e08d96aa221dd218769abdad6e0171fcf8879a) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/siggen.py90
1 files changed, 66 insertions, 24 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py
index 2a0ecf57e1..0421885306 100644
--- a/bitbake/lib/bb/siggen.py
+++ b/bitbake/lib/bb/siggen.py
@@ -15,6 +15,7 @@ import difflib
15import simplediff 15import simplediff
16import json 16import json
17import types 17import types
18from contextlib import contextmanager
18import bb.compress.zstd 19import bb.compress.zstd
19from bb.checksum import FileChecksumCache 20from bb.checksum import FileChecksumCache
20from bb import runqueue 21from bb import runqueue
@@ -28,6 +29,14 @@ hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv')
28# The minimum version of the find_siginfo function we need 29# The minimum version of the find_siginfo function we need
29find_siginfo_minversion = 2 30find_siginfo_minversion = 2
30 31
32HASHSERV_ENVVARS = [
33 "SSL_CERT_DIR",
34 "SSL_CERT_FILE",
35 "NO_PROXY",
36 "HTTPS_PROXY",
37 "HTTP_PROXY"
38]
39
31def check_siggen_version(siggen): 40def check_siggen_version(siggen):
32 if not hasattr(siggen, "find_siginfo_version"): 41 if not hasattr(siggen, "find_siginfo_version"):
33 bb.fatal("Siggen from metadata (OE-Core?) is too old, please update it (no version found)") 42 bb.fatal("Siggen from metadata (OE-Core?) is too old, please update it (no version found)")
@@ -537,14 +546,23 @@ class SignatureGeneratorUniHashMixIn(object):
537 self.unihash_exists_cache = set() 546 self.unihash_exists_cache = set()
538 self.username = None 547 self.username = None
539 self.password = None 548 self.password = None
549 self.env = {}
550
551 origenv = data.getVar("BB_ORIGENV")
552 for e in HASHSERV_ENVVARS:
553 value = data.getVar(e)
554 if not value and origenv:
555 value = origenv.getVar(e)
556 if value:
557 self.env[e] = value
540 super().__init__(data) 558 super().__init__(data)
541 559
542 def get_taskdata(self): 560 def get_taskdata(self):
543 return (self.server, self.method, self.extramethod, self.max_parallel, self.username, self.password) + super().get_taskdata() 561 return (self.server, self.method, self.extramethod, self.max_parallel, self.username, self.password, self.env) + super().get_taskdata()
544 562
545 def set_taskdata(self, data): 563 def set_taskdata(self, data):
546 self.server, self.method, self.extramethod, self.max_parallel, self.username, self.password = data[:6] 564 self.server, self.method, self.extramethod, self.max_parallel, self.username, self.password, self.env = data[:7]
547 super().set_taskdata(data[6:]) 565 super().set_taskdata(data[7:])
548 566
549 def get_hashserv_creds(self): 567 def get_hashserv_creds(self):
550 if self.username and self.password: 568 if self.username and self.password:
@@ -555,15 +573,30 @@ class SignatureGeneratorUniHashMixIn(object):
555 573
556 return {} 574 return {}
557 575
576 @contextmanager
577 def _client_env(self):
578 orig_env = os.environ.copy()
579 try:
580 for k, v in self.env.items():
581 os.environ[k] = v
582
583 yield
584 finally:
585 os.environ = orig_env
586
587 @contextmanager
558 def client(self): 588 def client(self):
559 if getattr(self, '_client', None) is None: 589 with self._client_env():
560 self._client = hashserv.create_client(self.server, **self.get_hashserv_creds()) 590 if getattr(self, '_client', None) is None:
561 return self._client 591 self._client = hashserv.create_client(self.server, **self.get_hashserv_creds())
592 yield self._client
562 593
594 @contextmanager
563 def client_pool(self): 595 def client_pool(self):
564 if getattr(self, '_client_pool', None) is None: 596 with self._client_env():
565 self._client_pool = hashserv.client.ClientPool(self.server, self.max_parallel, **self.get_hashserv_creds()) 597 if getattr(self, '_client_pool', None) is None:
566 return self._client_pool 598 self._client_pool = hashserv.client.ClientPool(self.server, self.max_parallel, **self.get_hashserv_creds())
599 yield self._client_pool
567 600
568 def reset(self, data): 601 def reset(self, data):
569 self.__close_clients() 602 self.__close_clients()
@@ -574,12 +607,13 @@ class SignatureGeneratorUniHashMixIn(object):
574 return super().exit() 607 return super().exit()
575 608
576 def __close_clients(self): 609 def __close_clients(self):
577 if getattr(self, '_client', None) is not None: 610 with self._client_env():
578 self._client.close() 611 if getattr(self, '_client', None) is not None:
579 self._client = None 612 self._client.close()
580 if getattr(self, '_client_pool', None) is not None: 613 self._client = None
581 self._client_pool.close() 614 if getattr(self, '_client_pool', None) is not None:
582 self._client_pool = None 615 self._client_pool.close()
616 self._client_pool = None
583 617
584 def get_stampfile_hash(self, tid): 618 def get_stampfile_hash(self, tid):
585 if tid in self.taskhash: 619 if tid in self.taskhash:
@@ -650,11 +684,13 @@ class SignatureGeneratorUniHashMixIn(object):
650 684
651 if self.max_parallel <= 1 or len(uncached_query) <= 1: 685 if self.max_parallel <= 1 or len(uncached_query) <= 1:
652 # No parallelism required. Make the query serially with the single client 686 # No parallelism required. Make the query serially with the single client
653 uncached_result = { 687 with self.client() as client:
654 key: self.client().unihash_exists(value) for key, value in uncached_query.items() 688 uncached_result = {
655 } 689 key: client.unihash_exists(value) for key, value in uncached_query.items()
690 }
656 else: 691 else:
657 uncached_result = self.client_pool().unihashes_exist(uncached_query) 692 with self.client_pool() as client_pool:
693 uncached_result = client_pool.unihashes_exist(uncached_query)
658 694
659 for key, exists in uncached_result.items(): 695 for key, exists in uncached_result.items():
660 if exists: 696 if exists:
@@ -687,10 +723,12 @@ class SignatureGeneratorUniHashMixIn(object):
687 723
688 if self.max_parallel <= 1 or len(queries) <= 1: 724 if self.max_parallel <= 1 or len(queries) <= 1:
689 # No parallelism required. Make the query serially with the single client 725 # No parallelism required. Make the query serially with the single client
690 for tid, args in queries.items(): 726 with self.client() as client:
691 query_result[tid] = self.client().get_unihash(*args) 727 for tid, args in queries.items():
728 query_result[tid] = client.get_unihash(*args)
692 else: 729 else:
693 query_result = self.client_pool().get_unihashes(queries) 730 with self.client_pool() as client_pool:
731 query_result = client_pool.get_unihashes(queries)
694 732
695 for tid, unihash in query_result.items(): 733 for tid, unihash in query_result.items():
696 # In the absence of being able to discover a unique hash from the 734 # In the absence of being able to discover a unique hash from the
@@ -785,7 +823,9 @@ class SignatureGeneratorUniHashMixIn(object):
785 if tid in self.extramethod: 823 if tid in self.extramethod:
786 method = method + self.extramethod[tid] 824 method = method + self.extramethod[tid]
787 825
788 data = self.client().report_unihash(taskhash, method, outhash, unihash, extra_data) 826 with self.client() as client:
827 data = client.report_unihash(taskhash, method, outhash, unihash, extra_data)
828
789 new_unihash = data['unihash'] 829 new_unihash = data['unihash']
790 830
791 if new_unihash != unihash: 831 if new_unihash != unihash:
@@ -816,7 +856,9 @@ class SignatureGeneratorUniHashMixIn(object):
816 if tid in self.extramethod: 856 if tid in self.extramethod:
817 method = method + self.extramethod[tid] 857 method = method + self.extramethod[tid]
818 858
819 data = self.client().report_unihash_equiv(taskhash, method, wanted_unihash, extra_data) 859 with self.client() as client:
860 data = client.report_unihash_equiv(taskhash, method, wanted_unihash, extra_data)
861
820 hashequiv_logger.verbose('Reported task %s as unihash %s to %s (%s)' % (tid, wanted_unihash, self.server, str(data))) 862 hashequiv_logger.verbose('Reported task %s as unihash %s to %s (%s)' % (tid, wanted_unihash, self.server, str(data)))
821 863
822 if data is None: 864 if data is None: