blob: 4a001f3386bdb17ffdca337700a1f2cd11e5dd5d [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001From 62fdead139edb0f29b2f222efcb8f39be15b057e Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Mon, 30 Jul 2018 15:47:13 +0800
4Subject: [PATCH 2/4] pykickstart/parser.py: add lock for readKickstart and
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
11Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
12---
13 pykickstart/load.py | 2 +-
14 pykickstart/parser.py | 18 ++++++++++++++++++
15 2 files changed, 19 insertions(+), 1 deletion(-)
16
17diff --git a/pykickstart/load.py b/pykickstart/load.py
18index c6f013f..7adb751 100644
19--- a/pykickstart/load.py
20+++ b/pykickstart/load.py
21@@ -30,7 +30,7 @@ from requests.exceptions import SSLError, RequestException
22
23 _is_url = lambda location: '://' in location # RFC 3986
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.
30diff --git a/pykickstart/parser.py b/pykickstart/parser.py
31index e44099b..e68174d 100644
32--- a/pykickstart/parser.py
33+++ b/pykickstart/parser.py
34@@ -55,6 +55,20 @@ from pykickstart.i18n import _
35 STATE_END = "end"
36 STATE_COMMANDS = "commands"
37
38+import threading
39+_private_ks_lock = threading.RLock()
40+
41+class KsLock(object):
42+ def __enter__(self):
43+ _private_ks_lock.acquire()
44+ return _private_ks_lock
45+
46+ def __exit__(self, exc_type, exc_val, exc_tb):
47+ _private_ks_lock.release()
48+
49+
50+_ks_lock = KsLock()
51+
52 def _preprocessStateMachine(lineIter):
53 l = None
54 lineno = 0
55@@ -788,6 +802,10 @@ class KickstartParser(object):
56 self._stateMachine(i)
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--
672.7.4
68