Skip to content

Commit

Permalink
passing pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Akm0d authored and dwoz committed Sep 30, 2024
1 parent 3bf8dda commit fa61bc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
3 changes: 2 additions & 1 deletion salt/client/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ def detect_os_arch(self):
f"Failed to detect OS and architecture. Commands failed with output: {stdout}, {stderr}"
)

log.info(f'Detected kernel "{kernel}" and architecture "{os_arch}" on target')
log.info('Detected kernel "{}" and architecture "{}" on target'.format(kernel, os_arch))

return kernel, os_arch

Expand Down Expand Up @@ -1510,6 +1510,7 @@ def run_wfunc(self):
self.args = mine_args
self.kwargs = {}

retcode = 0
try:
if self.mine:
result = wrapper[mine_fun](*self.args, **self.kwargs)
Expand Down
2 changes: 1 addition & 1 deletion salt/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,7 +3227,7 @@ def _mixin_setup(self):
"custom grains/modules/states have been added or updated."
),
)
self.add_option(
_ = self.add_option(
"--relenv",
dest="relenv",
default=False,
Expand Down
42 changes: 17 additions & 25 deletions salt/utils/relenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def gen_relenv(
os.makedirs(relenv_dir)

relenv_url = get_tarball(kernel, os_arch)
tarball_path = os.path.join(relenv_dir, f"salt-relenv.tar.xz")
tarball_path = os.path.join(relenv_dir, "salt-relenv.tar.xz")

# Download the tarball if it doesn't exist or overwrite is True
if overwrite or not os.path.exists(tarball_path):
Expand All @@ -52,18 +52,18 @@ def get_tarball(kernel, arch):
base_url = "https://repo.saltproject.io/salt/py3/onedir/latest/"
try:
# Request the page listing
response = requests.get(base_url)
response = requests.get(base_url, timeout=60)
response.raise_for_status()
except requests.RequestException as e:
log.error(f"Failed to retrieve tarball listing: {e}")
log.error("Failed to retrieve tarball listing: {}".format(e))
raise ValueError("Unable to fetch tarball list from repository")

# Search for tarball filenames that match the kernel and arch
pattern = re.compile(rf'href="(salt-.*-onedir-{kernel}-{arch}\.tar\.xz)"')
matches = pattern.findall(response.text)
if not matches:
log.error(f"No tarballs found for {kernel} and {arch}")
raise ValueError(f"No tarball found for {kernel} {arch}")
log.error("No tarballs found for {} and {}".format(kernel, arch))
raise ValueError("No tarball found for {} {}".format(kernel, arch))

# Return the latest tarball URL
matches.sort()
Expand All @@ -76,24 +76,16 @@ def download(cachedir, url, destination):
Download the salt artifact from the given destination to the cache.
"""
if not os.path.exists(destination):
log.info(f"Downloading from {url} to {destination}")
try:
with salt.utils.files.fopen(destination, "wb+") as dest_file:

def stream_callback(chunk):
dest_file.write(chunk)

result = salt.utils.http.query(
url=url,
method="GET",
stream=True,
streaming_callback=stream_callback,
raise_error=True,
)
if result.get("status") != 200:
log.error(f"Failed to download file from {url}")
return False
except Exception as e:
log.error(f"Error during file download: {e}")
return False
log.info("Downloading from {} to {}".format(url, destination))
with salt.utils.files.fopen(destination, "wb+") as dest_file:
result = salt.utils.http.query(
url=url,
method="GET",
stream=True,
streaming_callback=dest_file.write,
raise_error=True,
)
if result.get("status") != 200:
log.error("Failed to download file from {}".format(url))
return False
return True

0 comments on commit fa61bc3

Please sign in to comment.