Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automx fix #525

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Automx fix #525

wants to merge 6 commits into from

Conversation

fbfeix
Copy link

@fbfeix fbfeix commented Oct 22, 2023

Description of the issue/feature this PR addresses:
The _setup_venv method in the existing codebase has been experiencing intermittent SSL connection issues when attempting to download a file using wget. This problem has been causing the method to fail occasionally, preventing the successful setup of a virtual environment. Additionally, the method assumes the downloaded archive will be located in a certain directory without verifying the file's existence, leading to potential errors during the unzipping process.

Current behavior before PR:

  1. The _setup_venv method uses wget to download a file, but if an SSL connection issue occurs, the method fails without retrying the download.
  2. The method assumes the downloaded file will be located in a specific directory and proceeds to attempt unzipping the file without verifying its existence, which could lead to a failure if the file is not found.

Desired behavior after PR is merged:

  1. A new method download_remote_file has been introduced to handle file downloads, with the capability to retry the download a specified number of times in case of failures, mitigating the impact of intermittent SSL connection issues.
  2. The _setup_venv method now utilizes the download_remote_file method to handle the file download, ensuring that the file exists before proceeding to unzip it.
  3. The download_remote_file method ensures the target directory exists or creates it if necessary, and returns the absolute path of the downloaded file, providing more robust file handling and aiding in troubleshooting if issues arise in the future.

Felix Astner added 6 commits October 22, 2023 11:43
…script

Added zipfile and urllib.request in 'postwhite.py' to improve the handling of archive downloads and extractions from specified repositories. Refactored 'install_from_archive' to increase the script's portability by removing the 'wget' command, improving reliability across different systems. Included robust error handling to improve user experience and problem diagnosis in case of download or extraction failures.
Modified archive extraction process in automx.py to include verification and error handling functionality. Now, the output of the unzip command is captured to confirm that the directory was successfully created. An exception is raised if the directory is not created, allowing early detection and diagnosis of potential issues.
Enhanced modoboa_installer/utils.py to now include two new methods, info and warning, to print messages in different colors. Also added a more robust download_remote_file function that downloads a file from a remote server with specified retries and exceptional download failure handling. This function was then used to replace previous ad-hoc download implementations for improved code reusability and readability.
…raction

Modified the `utils.download_remote_file` function in `utils.py` to return the absolute path of the downloaded file instead of relative path. This change extends the robustness as it makes sure we are always unzipping the downloaded file even if cwd changes. Also, adjusted the `automx.py` script to use the absolute path returned from the download function when extracting the file. This ensures that the correct file gets extracted regardless of current working directory.
In utils.py, the wget command was updated in the exec_cmd function. Previously, the command did not specify the output file for the downloaded content. Now, a new target parameter has been added to the wget command to direct the download to a specific file. This change is done to provide more control over the file handling process within the function.
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (4a2e9f2) 54.40% compared to head (5aae454) 53.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
- Coverage   54.40%   53.73%   -0.67%     
==========================================
  Files          10       10              
  Lines         761      776      +15     
==========================================
+ Hits          414      417       +3     
- Misses        347      359      +12     
Files Coverage Δ
modoboa_installer/utils.py 54.48% <20.00%> (-1.75%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

printcolor(message, BLUE)


def warning(message):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at it, could change evey instance of utils.printcolor(*,YELLOW/BLUE) to these functions?

@@ -67,3 +86,6 @@ def restore(self):
if os.path.isfile(postwhite_backup_configuration):
utils.copy_file(postwhite_backup_configuration, self.config_dir)
utils.success("postwhite.conf restored from backup")

def download_file(self, url, destination):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you create a new function to download a file using urllib instead of using the function you're adding in the utils.py file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants