diff options
author | Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com> | 2022-01-13 01:22:32 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 13:52:32 -0600 |
commit | e3f3485d875f021915654bf2b64678e151a8d6f6 (patch) | |
tree | 564f89b77371edb01d20164758a073f56da45ea0 | |
parent | 88f38158fd432152b9fe341f270c4f52c657ef80 (diff) | |
download | vyos-cloud-init-e3f3485d875f021915654bf2b64678e151a8d6f6.tar.gz vyos-cloud-init-e3f3485d875f021915654bf2b64678e151a8d6f6.zip |
Remove distutils usage (#1177)
distutils is getting deprecated soon. Let's replace it with suggested
alternatives as suggested in:
https://www.python.org/dev/peps/pep-0632/
Remove `requests` version check and related code from url_helper.py
as the versions specified are old enough to no longer be relevant.
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
-rw-r--r-- | cloudinit/sources/DataSourceVMware.py | 5 | ||||
-rw-r--r-- | cloudinit/url_helper.py | 60 | ||||
-rwxr-xr-x | setup.py | 10 | ||||
-rw-r--r-- | tests/integration_tests/integration_settings.py | 12 |
4 files changed, 26 insertions, 61 deletions
diff --git a/cloudinit/sources/DataSourceVMware.py b/cloudinit/sources/DataSourceVMware.py index ed7f487a..6ef7c9d5 100644 --- a/cloudinit/sources/DataSourceVMware.py +++ b/cloudinit/sources/DataSourceVMware.py @@ -68,14 +68,13 @@ import json import os import socket import time -from distutils.spawn import find_executable import netifaces from cloudinit import dmi from cloudinit import log as logging from cloudinit import sources, util -from cloudinit.subp import ProcessExecutionError, subp +from cloudinit.subp import ProcessExecutionError, subp, which PRODUCT_UUID_FILE_PATH = "/sys/class/dmi/id/product_uuid" @@ -85,7 +84,7 @@ NOVAL = "No value found" DATA_ACCESS_METHOD_ENVVAR = "envvar" DATA_ACCESS_METHOD_GUESTINFO = "guestinfo" -VMWARE_RPCTOOL = find_executable("vmware-rpctool") +VMWARE_RPCTOOL = which("vmware-rpctool") REDACT = "redact" CLEANUP_GUESTINFO = "cleanup-guestinfo" VMX_GUESTINFO = "VMX_GUESTINFO" diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index 847e5379..790e2fbf 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -27,25 +27,7 @@ from cloudinit import version LOG = logging.getLogger(__name__) - -# Check if requests has ssl support (added in requests >= 0.8.8) -SSL_ENABLED = False -CONFIG_ENABLED = False # This was added in 0.7 (but taken out in >=1.0) -_REQ_VER = None REDACTED = "REDACTED" -try: - from distutils.version import LooseVersion - - import pkg_resources - - _REQ = pkg_resources.get_distribution("requests") - _REQ_VER = LooseVersion(_REQ.version) # pylint: disable=no-member - if _REQ_VER >= LooseVersion("0.8.8"): - SSL_ENABLED = True - if LooseVersion("0.7.0") <= _REQ_VER < LooseVersion("1.0.0"): - CONFIG_ENABLED = True -except ImportError: - pass def _cleanurl(url): @@ -175,24 +157,17 @@ def _get_ssl_args(url, ssl_details): ssl_args = {} scheme = urlparse(url).scheme if scheme == "https" and ssl_details: - if not SSL_ENABLED: - LOG.warning( - "SSL is not supported in requests v%s, " - "cert. verification can not occur!", - _REQ_VER, - ) + if "ca_certs" in ssl_details and ssl_details["ca_certs"]: + ssl_args["verify"] = ssl_details["ca_certs"] else: - if "ca_certs" in ssl_details and ssl_details["ca_certs"]: - ssl_args["verify"] = ssl_details["ca_certs"] - else: - ssl_args["verify"] = True - if "cert_file" in ssl_details and "key_file" in ssl_details: - ssl_args["cert"] = [ - ssl_details["cert_file"], - ssl_details["key_file"], - ] - elif "cert_file" in ssl_details: - ssl_args["cert"] = str(ssl_details["cert_file"]) + ssl_args["verify"] = True + if "cert_file" in ssl_details and "key_file" in ssl_details: + ssl_args["cert"] = [ + ssl_details["cert_file"], + ssl_details["key_file"], + ] + elif "cert_file" in ssl_details: + ssl_args["cert"] = str(ssl_details["cert_file"]) return ssl_args @@ -257,19 +232,6 @@ def readurl( req_args["timeout"] = max(float(timeout), 0) if headers_redact is None: headers_redact = [] - # It doesn't seem like config - # was added in older library versions (or newer ones either), thus we - # need to manually do the retries if it wasn't... - if CONFIG_ENABLED: - req_config = { - "store_cookies": False, - } - # Don't use the retry support built-in - # since it doesn't allow for 'sleep_times' - # in between tries.... - # if retries: - # req_config['max_retries'] = max(int(retries), 0) - req_args["config"] = req_config manual_tries = 1 if retries: manual_tries = max(int(retries) + 1, 1) @@ -358,7 +320,7 @@ def readurl( ) else: excps.append(UrlError(e, url=url)) - if SSL_ENABLED and isinstance(e, exceptions.SSLError): + if isinstance(e, exceptions.SSLError): # ssl exceptions are not going to get fixed by waiting a # few seconds break @@ -15,13 +15,17 @@ import shutil import subprocess import sys import tempfile -from distutils.errors import DistutilsArgError from glob import glob import setuptools from setuptools.command.egg_info import egg_info from setuptools.command.install import install +try: + from setuptools.errors import DistutilsError +except ImportError: + from distutils.errors import DistutilsArgError as DistutilsError + RENDERED_TMPD_PREFIX = "RENDERED_TEMPD" VARIANT = None @@ -245,9 +249,7 @@ class InitsysInstallData(install): bad = [f for f in self.init_system if f not in INITSYS_TYPES] if len(bad) != 0: - raise DistutilsArgError( - "Invalid --init-system: %s" % ",".join(bad) - ) + raise DistutilsError("Invalid --init-system: %s" % ",".join(bad)) for system in self.init_system: # add data files for anything that starts with '<system>.' diff --git a/tests/integration_tests/integration_settings.py b/tests/integration_tests/integration_settings.py index 641ce297..02037a88 100644 --- a/tests/integration_tests/integration_settings.py +++ b/tests/integration_tests/integration_settings.py @@ -1,6 +1,7 @@ # This file is part of cloud-init. See LICENSE file for license information. import os -from distutils.util import strtobool + +from cloudinit.util import is_false, is_true ################################################################## # LAUNCH SETTINGS @@ -126,8 +127,9 @@ for setting in current_settings: "CLOUD_INIT_{}".format(setting), globals()[setting] ) if isinstance(env_setting, str): - try: - env_setting = bool(strtobool(env_setting.strip())) - except ValueError: - pass + env_setting = env_setting.strip() + if is_true(env_setting): + env_setting = True + elif is_false(env_setting): + env_setting = False globals()[setting] = env_setting |