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 |
| 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> |
| 12 | --- |
| 13 | pykickstart/load.py | 2 +- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 14 | pykickstart/parser.py | 18 ++++++++++++++++++ |
| 15 | 2 files changed, 19 insertions(+), 1 deletion(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | |
| 17 | diff --git a/pykickstart/load.py b/pykickstart/load.py |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | index c6f013f..7adb751 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | --- a/pykickstart/load.py |
| 20 | +++ b/pykickstart/load.py |
| 21 | @@ -30,7 +30,7 @@ from requests.exceptions import SSLError, RequestException |
| 22 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 23 | _is_url = lambda location: '://' in location # RFC 3986 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 24 | |
| 25 | -SSL_VERIFY = True |
| 26 | +SSL_VERIFY = False |
| 27 | |
| 28 | def load_to_str(location, user=None, passwd=None): |
| 29 | '''Load a destination URL or file into a string. |
| 30 | diff --git a/pykickstart/parser.py b/pykickstart/parser.py |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 31 | index e44099b..e68174d 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 32 | --- a/pykickstart/parser.py |
| 33 | +++ b/pykickstart/parser.py |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 34 | @@ -55,6 +55,20 @@ from pykickstart.i18n import _ |
| 35 | STATE_END = "end" |
| 36 | STATE_COMMANDS = "commands" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 37 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | +import threading |
| 39 | +_private_ks_lock = threading.RLock() |
| 40 | + |
| 41 | +class KsLock(object): |
| 42 | + def __enter__(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 43 | + _private_ks_lock.acquire() |
| 44 | + return _private_ks_lock |
| 45 | + |
| 46 | + def __exit__(self, exc_type, exc_val, exc_tb): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 47 | + _private_ks_lock.release() |
| 48 | + |
| 49 | + |
| 50 | +_ks_lock = KsLock() |
| 51 | + |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 52 | def _preprocessStateMachine(lineIter): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 53 | l = None |
| 54 | lineno = 0 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | @@ -788,6 +802,10 @@ class KickstartParser(object): |
| 56 | self._stateMachine(i) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | |
| 58 | def readKickstart(self, f, reset=True, username=None, password=None): |
| 59 | + with _ks_lock: |
| 60 | + self._readKickstart(f, reset=reset, username=username, password=password) |
| 61 | + |
| 62 | + def _readKickstart(self, f, reset=True, username=None, password=None): |
| 63 | """Process a kickstart file, given by the filename f.""" |
| 64 | if reset: |
| 65 | self._reset() |
| 66 | -- |
| 67 | 2.7.4 |
| 68 | |