added my Recipes
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
From 3540ddcc7448dc784b65c74424c8a25132cb8534 Mon Sep 17 00:00:00 2001
|
||||
From: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
Date: Tue, 31 Jul 2018 17:24:47 +0800
|
||||
Subject: [PATCH] support authentication for kickstart
|
||||
|
||||
While download kickstart file from web server,
|
||||
we support basic/digest authentication.
|
||||
|
||||
Add KickstartAuthError to report authentication failure,
|
||||
which the invoker could parse this specific error.
|
||||
|
||||
Upstream-Status: Inappropriate [oe specific]
|
||||
|
||||
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
---
|
||||
pykickstart/errors.py | 17 +++++++++++++++++
|
||||
pykickstart/load.py | 32 +++++++++++++++++++++++++++-----
|
||||
pykickstart/parser.py | 4 ++--
|
||||
3 files changed, 46 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/pykickstart/errors.py b/pykickstart/errors.py
|
||||
index 8294f59..3d20bf8 100644
|
||||
--- a/pykickstart/errors.py
|
||||
+++ b/pykickstart/errors.py
|
||||
@@ -32,6 +32,9 @@ This module exports several exception classes:
|
||||
KickstartVersionError - An exception for errors relating to unsupported
|
||||
syntax versions.
|
||||
|
||||
+ KickstartAuthError - An exception for errors relating to authentication
|
||||
+ failed while downloading kickstart from web server
|
||||
+
|
||||
And some warning classes:
|
||||
|
||||
KickstartWarning - A generic warning class.
|
||||
@@ -125,3 +128,17 @@ class KickstartDeprecationWarning(KickstartParseWarning, DeprecationWarning):
|
||||
"""A class for warnings occurring during parsing related to using deprecated
|
||||
commands and options.
|
||||
"""
|
||||
+
|
||||
+class KickstartAuthError(KickstartError):
|
||||
+ """An exception for errors relating to authentication failed while
|
||||
+ downloading kickstart from web server
|
||||
+ """
|
||||
+ def __init__(self, msg):
|
||||
+ """Create a new KickstartAuthError exception instance with the
|
||||
+ descriptive message val. val should be the return value of
|
||||
+ formatErrorMsg.
|
||||
+ """
|
||||
+ KickstartError.__init__(self, msg)
|
||||
+
|
||||
+ def __str__(self):
|
||||
+ return self.value
|
||||
diff --git a/pykickstart/load.py b/pykickstart/load.py
|
||||
index eb76b65..f51cf08 100644
|
||||
--- a/pykickstart/load.py
|
||||
+++ b/pykickstart/load.py
|
||||
@@ -18,9 +18,11 @@
|
||||
# with the express permission of Red Hat, Inc.
|
||||
#
|
||||
import requests
|
||||
+from requests.auth import HTTPDigestAuth
|
||||
+from requests.auth import HTTPBasicAuth
|
||||
import shutil
|
||||
|
||||
-from pykickstart.errors import KickstartError
|
||||
+from pykickstart.errors import KickstartError, KickstartAuthError
|
||||
from pykickstart.i18n import _
|
||||
from requests.exceptions import SSLError, RequestException
|
||||
|
||||
@@ -28,7 +30,7 @@ is_url = lambda location: '://' in location # RFC 3986
|
||||
|
||||
SSL_VERIFY = True
|
||||
|
||||
-def load_to_str(location):
|
||||
+def load_to_str(location, user=None, passwd=None):
|
||||
'''Load a destination URL or file into a string.
|
||||
Type of input is inferred automatically.
|
||||
|
||||
@@ -39,7 +41,7 @@ def load_to_str(location):
|
||||
Raises: KickstartError on error reading'''
|
||||
|
||||
if is_url(location):
|
||||
- return _load_url(location)
|
||||
+ return _load_url(location, user=user, passwd=passwd)
|
||||
else:
|
||||
return _load_file(location)
|
||||
|
||||
@@ -69,11 +71,31 @@ def load_to_file(location, destination):
|
||||
_copy_file(location, destination)
|
||||
return destination
|
||||
|
||||
-def _load_url(location):
|
||||
+def _get_auth(location, user=None, passwd=None):
|
||||
+
|
||||
+ auth = None
|
||||
+ request = requests.get(location, verify=SSL_VERIFY)
|
||||
+ if request.status_code == requests.codes.unauthorized:
|
||||
+ if user is None or passwd is None:
|
||||
+ log.info("Require Authentication")
|
||||
+ raise KickstartAuthError("Require Authentication.\nAppend 'ksuser=<username> kspasswd=<password>' to boot command")
|
||||
+
|
||||
+ reasons = request.headers.get("WWW-Authenticate", "").split()
|
||||
+ if reasons:
|
||||
+ auth_type = reasons[0]
|
||||
+ if auth_type == "Basic":
|
||||
+ auth = HTTPBasicAuth(user, passwd)
|
||||
+ elif auth_type == "Digest":
|
||||
+ auth=HTTPDigestAuth(user, passwd)
|
||||
+
|
||||
+ return auth
|
||||
+
|
||||
+def _load_url(location, user=None, passwd=None):
|
||||
'''Load a location (URL or filename) and return contents as string'''
|
||||
+ auth = _get_auth(location, user=user, passwd=passwd)
|
||||
|
||||
try:
|
||||
- request = requests.get(location, verify=SSL_VERIFY)
|
||||
+ request = requests.get(location, verify=SSL_VERIFY, auth=auth)
|
||||
except SSLError as e:
|
||||
raise KickstartError(_('Error securely accessing URL "%s"') % location + ': {e}'.format(e=str(e)))
|
||||
except RequestException as e:
|
||||
diff --git a/pykickstart/parser.py b/pykickstart/parser.py
|
||||
index 7edf8aa..46c5299 100644
|
||||
--- a/pykickstart/parser.py
|
||||
+++ b/pykickstart/parser.py
|
||||
@@ -790,7 +790,7 @@ class KickstartParser(object):
|
||||
i = PutBackIterator(s.splitlines(True) + [""])
|
||||
self._stateMachine(i)
|
||||
|
||||
- def readKickstart(self, f, reset=True):
|
||||
+ def readKickstart(self, f, reset=True, username=None, password=None):
|
||||
"""Process a kickstart file, given by the filename f."""
|
||||
if reset:
|
||||
self._reset()
|
||||
@@ -811,7 +811,7 @@ class KickstartParser(object):
|
||||
self.currentdir[self._includeDepth] = cd
|
||||
|
||||
try:
|
||||
- s = load_to_str(f)
|
||||
+ s = load_to_str(f, user=username, passwd=password)
|
||||
except KickstartError as e:
|
||||
raise KickstartError(_("Unable to open input kickstart file: %s") % str(e), lineno=0)
|
||||
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
From 62fdead139edb0f29b2f222efcb8f39be15b057e Mon Sep 17 00:00:00 2001
|
||||
From: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
Date: Mon, 30 Jul 2018 15:47:13 +0800
|
||||
Subject: [PATCH 2/4] pykickstart/parser.py: add lock for readKickstart and
|
||||
support https without certification
|
||||
|
||||
- Add lock for readKickstart to fix race issue
|
||||
|
||||
- Support to download kickstart file through https without certification
|
||||
|
||||
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
|
||||
---
|
||||
pykickstart/load.py | 2 +-
|
||||
pykickstart/parser.py | 18 ++++++++++++++++++
|
||||
2 files changed, 19 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/pykickstart/load.py b/pykickstart/load.py
|
||||
index 8da8051..e856c8d 100644
|
||||
--- a/pykickstart/load.py
|
||||
+++ b/pykickstart/load.py
|
||||
@@ -32,7 +32,7 @@ log = logging.getLogger("anaconda.main")
|
||||
|
||||
is_url = lambda location: '://' in location # RFC 3986
|
||||
|
||||
-SSL_VERIFY = True
|
||||
+SSL_VERIFY = False
|
||||
|
||||
def load_to_str(location, user=None, passwd=None):
|
||||
'''Load a destination URL or file into a string.
|
||||
diff --git a/pykickstart/parser.py b/pykickstart/parser.py
|
||||
index b95ba90..a55a9a3 100644
|
||||
--- a/pykickstart/parser.py
|
||||
+++ b/pykickstart/parser.py
|
||||
@@ -51,6 +51,20 @@ from pykickstart.i18n import _
|
||||
STATE_END = "end"
|
||||
STATE_COMMANDS = "commands"
|
||||
|
||||
+import threading
|
||||
+_private_ks_lock = threading.RLock()
|
||||
+
|
||||
+class KsLock(object):
|
||||
+ def __enter__(self):
|
||||
+ _private_ks_lock.acquire()
|
||||
+ return _private_ks_lock
|
||||
+
|
||||
+ def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
+ _private_ks_lock.release()
|
||||
+
|
||||
+
|
||||
+_ks_lock = KsLock()
|
||||
+
|
||||
def _preprocessStateMachine(lineIter):
|
||||
l = None
|
||||
lineno = 0
|
||||
@@ -791,6 +805,10 @@ class KickstartParser(object):
|
||||
self._stateMachine(i)
|
||||
|
||||
def readKickstart(self, f, reset=True, username=None, password=None):
|
||||
+ with _ks_lock:
|
||||
+ self._readKickstart(f, reset=reset, username=username, password=password)
|
||||
+
|
||||
+ def _readKickstart(self, f, reset=True, username=None, password=None):
|
||||
"""Process a kickstart file, given by the filename f."""
|
||||
if reset:
|
||||
self._reset()
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
From 44226393812399c61de9ca9281efa002ad4f4c01 Mon Sep 17 00:00:00 2001
|
||||
From: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
Date: Thu, 1 Jun 2017 15:15:15 +0800
|
||||
Subject: [PATCH 3/4] comment out sections shutdown and environment in
|
||||
generated kickstart file
|
||||
|
||||
Both of them is disabled by default.
|
||||
|
||||
Upstream-Status: Inappropriate [oe specific]
|
||||
|
||||
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
|
||||
fixup! add comments of shutdown for user
|
||||
---
|
||||
pykickstart/commands/reboot.py | 3 +++
|
||||
pykickstart/parser.py | 2 +-
|
||||
2 files changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/pykickstart/commands/reboot.py b/pykickstart/commands/reboot.py
|
||||
index 75a6d916..edfe83ff 100644
|
||||
--- a/pykickstart/commands/reboot.py
|
||||
+++ b/pykickstart/commands/reboot.py
|
||||
@@ -43,6 +43,9 @@ class FC3_Reboot(KickstartCommand):
|
||||
elif self.action == KS_SHUTDOWN:
|
||||
retval += "# Shutdown after installation\nshutdown"
|
||||
retval += self._getArgsAsStr() + "\n"
|
||||
+ else:
|
||||
+ retval += "# Shutdown after installation\n#shutdown"
|
||||
+ retval += self._getArgsAsStr() + "\n"
|
||||
|
||||
return retval
|
||||
|
||||
diff --git a/pykickstart/parser.py b/pykickstart/parser.py
|
||||
index bc59131b..b2d09d45 100644
|
||||
--- a/pykickstart/parser.py
|
||||
+++ b/pykickstart/parser.py
|
||||
@@ -428,7 +428,7 @@ class Packages(KickstartObject):
|
||||
|
||||
if not self.default:
|
||||
if self.environment:
|
||||
- pkgs += "@^%s\n" % self.environment
|
||||
+ pkgs += "#@^%s\n" % self.environment
|
||||
|
||||
grps = self.groupList
|
||||
grps.sort()
|
||||
--
|
||||
2.7.4
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
From 737e9a7c11233183f48ce6c83d38b504c8ffed12 Mon Sep 17 00:00:00 2001
|
||||
From: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
Date: Mon, 30 Jul 2018 15:52:21 +0800
|
||||
Subject: [PATCH] load.py: retry to invoke request with timeout
|
||||
|
||||
While networkless, use request to fetch kickstart file from
|
||||
network, it failed and wait 300s to break, we should retry
|
||||
to invoke request with timeout explicitly. So if it the
|
||||
network is up, the fetch works.
|
||||
|
||||
Upstream-Status: Inappropriate [oe specific]
|
||||
|
||||
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
|
||||
---
|
||||
pykickstart/load.py | 31 +++++++++++++++++++++++++++++++
|
||||
1 file changed, 31 insertions(+)
|
||||
|
||||
diff --git a/pykickstart/load.py b/pykickstart/load.py
|
||||
index 58faba6..e856c8d 100644
|
||||
--- a/pykickstart/load.py
|
||||
+++ b/pykickstart/load.py
|
||||
@@ -20,12 +20,16 @@
|
||||
import requests
|
||||
from requests.auth import HTTPDigestAuth
|
||||
from requests.auth import HTTPBasicAuth
|
||||
+import time
|
||||
import shutil
|
||||
|
||||
from pykickstart.errors import KickstartError, KickstartAuthError
|
||||
from pykickstart.i18n import _
|
||||
from requests.exceptions import SSLError, RequestException
|
||||
|
||||
+import logging
|
||||
+log = logging.getLogger("anaconda.main")
|
||||
+
|
||||
is_url = lambda location: '://' in location # RFC 3986
|
||||
|
||||
SSL_VERIFY = False
|
||||
@@ -71,6 +75,29 @@ def load_to_file(location, destination):
|
||||
_copy_file(location, destination)
|
||||
return destination
|
||||
|
||||
+def _access_url(location):
|
||||
+ status = False
|
||||
+
|
||||
+ # Retry 45 times, wait 45s~135s
|
||||
+ i = 0
|
||||
+ while i < 45:
|
||||
+
|
||||
+ try:
|
||||
+ request = requests.get(location, verify=SSL_VERIFY, timeout=2)
|
||||
+ except RequestException as e:
|
||||
+ log.info("Try '%s' %d times, %s" % (location, i, str(e)))
|
||||
+ status = False
|
||||
+ i += 1
|
||||
+ time.sleep(1)
|
||||
+ continue
|
||||
+
|
||||
+ else:
|
||||
+ status = True
|
||||
+ return status
|
||||
+
|
||||
+ return status
|
||||
+
|
||||
+
|
||||
def _get_auth(location, user=None, passwd=None):
|
||||
|
||||
auth = None
|
||||
@@ -92,6 +119,10 @@ def _get_auth(location, user=None, passwd=None):
|
||||
|
||||
def _load_url(location, user=None, passwd=None):
|
||||
'''Load a location (URL or filename) and return contents as string'''
|
||||
+
|
||||
+ if not _access_url(location):
|
||||
+ raise KickstartError(_("Connection %s failed" % location))
|
||||
+
|
||||
auth = _get_auth(location, user=user, passwd=passwd)
|
||||
|
||||
try:
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
DESCRIPTION = "A python library for manipulating kickstart files"
|
||||
HOMEPAGE = "http://fedoraproject.org/wiki/pykickstart"
|
||||
LICENSE = "GPL-2.0-or-later"
|
||||
|
||||
LIC_FILES_CHKSUM = "file://COPYING;md5=8ca43cbc842c2336e835926c2166c28b"
|
||||
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
|
||||
|
||||
DEPENDS = "python3"
|
||||
RDEPENDS:${PN} = "python3 \
|
||||
python3-requests \
|
||||
python3-six \
|
||||
"
|
||||
|
||||
S = "${WORKDIR}/git"
|
||||
SRC_URI = "git://github.com/rhinstaller/pykickstart.git;protocol=https;branch=master \
|
||||
file://0001-support-authentication-for-kickstart.patch \
|
||||
file://0002-pykickstart-parser.py-add-lock-for-readKickstart-and.patch \
|
||||
file://0003-comment-out-sections-shutdown-and-environment-in-gen.patch \
|
||||
file://0004-load.py-retry-to-invoke-request-with-timeout.patch \
|
||||
"
|
||||
SRCREV = "fa2f233f735a082dccaf03c234238f7d8ce93fa1"
|
||||
|
||||
UPSTREAM_CHECK_GITTAGREGEX = "r(?P<pver>\d+(\.\d+)+(-\d+)*)"
|
||||
|
||||
inherit setuptools3
|
||||
PIP_INSTALL_PACKAGE = "pykickstart"
|
||||
PIP_INSTALL_DIST_PATH = "${S}/dist"
|
||||
Reference in New Issue
Block a user