From 4750fa4767619633cecdd6b5754592999d633e5a Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:05:01 +0100 Subject: [PATCH] 3.6.0 --- linupdate.py | 2 +- src/controllers/App/Utils.py | 11 +++++++ src/controllers/Args.py | 12 ++++---- src/controllers/Module/Reposerver/Agent.py | 35 +++++++++++++++++----- src/controllers/Package/Apt.py | 2 +- src/controllers/Package/Dnf.py | 2 +- src/controllers/Package/Package.py | 10 +++---- version | 2 +- 8 files changed, 53 insertions(+), 23 deletions(-) diff --git a/linupdate.py b/linupdate.py index d0073de..fa09cfb 100755 --- a/linupdate.py +++ b/linupdate.py @@ -101,7 +101,7 @@ def main(): # Execute packages update my_package.update(my_args.packages_to_update, my_args.assume_yes, - my_args.ignore_exclude, + my_args.ignore_exclusions, my_args.check_updates, my_args.dist_upgrade, my_args.keep_oldconf, diff --git a/src/controllers/App/Utils.py b/src/controllers/App/Utils.py index 14feafb..4d9f1c5 100644 --- a/src/controllers/App/Utils.py +++ b/src/controllers/App/Utils.py @@ -49,3 +49,14 @@ def clean_log(self, text): text = text.strip() return text + + #----------------------------------------------------------------------------------------------- + # + # Convert a string to a boolean + # + #----------------------------------------------------------------------------------------------- + def stringToBoolean(self, value: str): + if value == 'true' or value == 'True': + return True + + return False diff --git a/src/controllers/Args.py b/src/controllers/Args.py index 1e4803c..826622e 100644 --- a/src/controllers/Args.py +++ b/src/controllers/Args.py @@ -40,7 +40,7 @@ def parse(self): # Default values Args.assume_yes = False Args.check_updates = False - Args.ignore_exclude = False + Args.ignore_exclusions = False Args.packages_to_update = [] Args.dist_upgrade = False Args.keep_oldconf = True @@ -95,7 +95,7 @@ def parse(self): # Check updates parser.add_argument("--check-updates", "-cu", action="store_true", default="null") # Ignore exclude - parser.add_argument("--ignore-exclude", "-ie", action="store_true", default="null") + parser.add_argument("--ignore-exclusions", "-ie", action="store_true", default="null") # Exit on package update error parser.add_argument("--exit-on-package-update-error", action="store", nargs='?', default="null") @@ -367,10 +367,10 @@ def parse(self): Args.dry_run = True # - # If --ignore-exclude param has been set + # If --ignore-exclusions param has been set # - if args.ignore_exclude != "null": - Args.ignore_exclude = True + if args.ignore_exclusions != "null": + Args.ignore_exclusions = True # # If --check-updates param has been set @@ -742,7 +742,7 @@ def help(self): }, { 'args': [ - '--ignore-exclude', + '--ignore-exclusions', '-ie' ], 'description': 'Ignore all package exclusions' diff --git a/src/controllers/Module/Reposerver/Agent.py b/src/controllers/Module/Reposerver/Agent.py index 75683ec..f9de539 100644 --- a/src/controllers/Module/Reposerver/Agent.py +++ b/src/controllers/Module/Reposerver/Agent.py @@ -259,6 +259,12 @@ def websocket_on_message(self, ws, message): status = None error = None + # Update parameters default values + dry_run = False + ignore_exclusions = False + keep_oldconf = True + full_upgrade = False + # Decode JSON message message = json.loads(message) @@ -327,8 +333,8 @@ def websocket_on_message(self, ws, message): with Log(log): self.reposerverStatusController.send_packages_info() - # Case the request is 'update-all-packages', then update all packages - elif message['request'] == 'update-all-packages': + # Case the request is 'request-all-packages-update', then update all packages + elif message['request'] == 'request-all-packages-update': print('[reposerver-agent] Reposerver requested all packages update') # Send a response to the reposerver to make the request as running @@ -346,11 +352,23 @@ def websocket_on_message(self, ws, message): # Send a summary to the reposerver, with the summary of the update (number of packages updated or failed) summary = self.packageController.summary - # Case the request is 'request-specific-packages-installation', then update a list of packages + # Case the request is 'request-packages-update', then update a list of specific packages # A list of packages must be provided in the message - elif message['request'] == 'request-specific-packages-installation': + elif message['request'] == 'request-packages-update': if 'data' in message: + # If a list of packages is provided, then the update can be performed if 'packages' in message['data'] and len(message['data']['packages']) > 0: + # Try to retrieve the update params + if 'update-params' in message['data']: + if 'dry-run' in message['data']['update-params']: + dry_run = Utils().stringToBoolean(message['data']['update-params']['dry-run']) + if 'ignore-exclusions' in message['data']['update-params']: + ignore_exclusions = Utils().stringToBoolean(message['data']['update-params']['ignore-exclusions']) + if 'keep-config-files' in message['data']['update-params']: + keep_oldconf = Utils().stringToBoolean(message['data']['update-params']['keep-config-files']) + if 'full-upgrade' in message['data']['update-params']: + full_upgrade = Utils().stringToBoolean(message['data']['update-params']['full-upgrade']) + print('[reposerver-agent] Reposerver requested to update a list of packages') # Send a response to the reposerver to make the request as running @@ -358,7 +376,7 @@ def websocket_on_message(self, ws, message): # Log everything to the log file with Log(log): - self.packageController.update(message['data']['packages'], True) + self.packageController.update(message['data']['packages'], True, ignore_exclusions, False, full_upgrade, keep_oldconf, dry_run) # Send a summary to the reposerver, with the summary of the installation (number of packages installed or failed) summary = self.packageController.summary @@ -555,9 +573,10 @@ def main(self): # 3600 / 5sec (sleep 5) = 720 if counter == 0 or counter == 720: # Sending full status - print('[reposerver-agent] Periodically sending informations about this host to the repomanager server') - self.reposerverStatusController.send_general_info() - self.reposerverStatusController.send_packages_info() + # TODO debug + # print('[reposerver-agent] Periodically sending informations about this host to the repomanager server') + # self.reposerverStatusController.send_general_info() + # self.reposerverStatusController.send_packages_info() # Reset counter counter = 0 diff --git a/src/controllers/Package/Apt.py b/src/controllers/Package/Apt.py index fa9a2cf..910ca27 100644 --- a/src/controllers/Package/Apt.py +++ b/src/controllers/Package/Apt.py @@ -342,7 +342,7 @@ def update(self, packagesList, exit_on_package_update_error: bool = True, dry_ru cmd = ['apt-get', 'install', pkg['name'] + '=' + pkg['available_version'], '-y'] # If --dry-run is True, then simulate the update - if dry_run: + if dry_run == True: cmd.append('--dry-run') popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) diff --git a/src/controllers/Package/Dnf.py b/src/controllers/Package/Dnf.py index 3e9e69a..f0ce176 100644 --- a/src/controllers/Package/Dnf.py +++ b/src/controllers/Package/Dnf.py @@ -346,7 +346,7 @@ def update(self, packagesList, exit_on_package_update_error: bool = True, dry_ru cmd = ['dnf', 'update', pkg['name'] + '-' + pkg['available_version'], '-y'] # If dry_run is True, add the --setopt tsflags=test option to simulate the update - if dry_run: + if dry_run == True: cmd.append('--setopt') cmd.append('tsflags=test') diff --git a/src/controllers/Package/Package.py b/src/controllers/Package/Package.py index c0dd519..51e018e 100644 --- a/src/controllers/Package/Package.py +++ b/src/controllers/Package/Package.py @@ -36,7 +36,7 @@ def __init__(self): # Check for package exclusions # #----------------------------------------------------------------------------------------------- - def exclude(self, ignore_exclude): + def exclude(self, ignore_exclusions): try: # Create a new empty list of packages to update packagesToUpdateList = [] @@ -50,8 +50,8 @@ def exclude(self, ignore_exclude): for package in self.packagesToUpdateList: excluded = False - # Check for exclusions and exclude packages only if the ignore_exclude parameter is False - if not ignore_exclude: + # Check for exclusions and exclude packages only if the ignore_exclusions parameter is False + if not ignore_exclusions: # If the package is in the list of packages to exclude (on major update), check if the available version is a major update if excludeOnMajorUpdate: # There can be regex in the excludeOnMajorUpdate list (e.g. apache.*), so we need to convert it to a regex pattern @@ -140,7 +140,7 @@ def get_available_packages(self, dist_upgrade: bool = False): # This can be a list of specific packages or all packages # #----------------------------------------------------------------------------------------------- - def update(self, packages_list: list = [], assume_yes: bool = False, ignore_exclude: bool = False, check_updates: bool = False, dist_upgrade: bool = False, keep_oldconf: bool = True, dry_run: bool = False): + def update(self, packages_list: list = [], assume_yes: bool = False, ignore_exclusions: bool = False, check_updates: bool = False, dist_upgrade: bool = False, keep_oldconf: bool = True, dry_run: bool = False): restart_file = '/tmp/linupdate.restart-needed' # Package update summary @@ -206,7 +206,7 @@ def update(self, packages_list: list = [], assume_yes: bool = False, ignore_excl self.packagesToUpdateList = self.get_available_packages(dist_upgrade) # Check for package exclusions - self.exclude(ignore_exclude) + self.exclude(ignore_exclusions) # Count packages to update and packages excluded self.packagesToUpdateCount = 0 diff --git a/version b/version index e5b8203..084e244 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.5.0 \ No newline at end of file +3.6.0 \ No newline at end of file