Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 62fdead139edb0f29b2f222efcb8f39be15b057e Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Hongxu Jia <hongxu.jia@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 3 | Date: Mon, 30 Jul 2018 15:47:13 +0800 |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 4 | Subject: [PATCH 2/4] pykickstart/parser.py: add lock for readKickstart and |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | support https without certification |
| 6 | |
| 7 | - Add lock for readKickstart to fix race issue |
| 8 | |
| 9 | - Support to download kickstart file through https without certification |
| 10 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 12 | Signed-off-by: Wang Mingyu <wangmy@fujitsu.com> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 13 | --- |
| 14 | pykickstart/load.py | 2 +- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 15 | pykickstart/parser.py | 18 ++++++++++++++++++ |
| 16 | 2 files changed, 19 insertions(+), 1 deletion(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | |
| 18 | diff --git a/pykickstart/load.py b/pykickstart/load.py |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 19 | index 8da8051..e856c8d 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 20 | --- a/pykickstart/load.py |
| 21 | +++ b/pykickstart/load.py |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 22 | @@ -32,7 +32,7 @@ log = logging.getLogger("anaconda.main") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 24 | is_url = lambda location: '://' in location # RFC 3986 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | |
| 26 | -SSL_VERIFY = True |
| 27 | +SSL_VERIFY = False |
| 28 | |
| 29 | def load_to_str(location, user=None, passwd=None): |
| 30 | '''Load a destination URL or file into a string. |
| 31 | diff --git a/pykickstart/parser.py b/pykickstart/parser.py |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 32 | index b95ba90..a55a9a3 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | --- a/pykickstart/parser.py |
| 34 | +++ b/pykickstart/parser.py |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 35 | @@ -51,6 +51,20 @@ from pykickstart.i18n import _ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 36 | STATE_END = "end" |
| 37 | STATE_COMMANDS = "commands" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 39 | +import threading |
| 40 | +_private_ks_lock = threading.RLock() |
| 41 | + |
| 42 | +class KsLock(object): |
| 43 | + def __enter__(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | + _private_ks_lock.acquire() |
| 45 | + return _private_ks_lock |
| 46 | + |
| 47 | + def __exit__(self, exc_type, exc_val, exc_tb): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 48 | + _private_ks_lock.release() |
| 49 | + |
| 50 | + |
| 51 | +_ks_lock = KsLock() |
| 52 | + |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | def _preprocessStateMachine(lineIter): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 54 | l = None |
| 55 | lineno = 0 |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 56 | @@ -791,6 +805,10 @@ class KickstartParser(object): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 57 | self._stateMachine(i) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 58 | |
| 59 | def readKickstart(self, f, reset=True, username=None, password=None): |
| 60 | + with _ks_lock: |
| 61 | + self._readKickstart(f, reset=reset, username=username, password=password) |
| 62 | + |
| 63 | + def _readKickstart(self, f, reset=True, username=None, password=None): |
| 64 | """Process a kickstart file, given by the filename f.""" |
| 65 | if reset: |
| 66 | self._reset() |
| 67 | -- |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 68 | 2.34.1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 69 | |