77from leapp import reporting
88from leapp .reporting import Report
99from leapp .libraries .common .cllaunch import run_on_cloudlinux
10+ from leapp .libraries .common .backup import backup_and_remove , LEAPP_BACKUP_SUFFIX
1011
1112REPO_DIR = '/etc/yum.repos.d'
12- REPO_DELETE_MARKERS = ['cloudlinux' , 'imunify' , 'epel' ]
13+ # These markers are used to identify which repository files should be directly replaced with new versions.
14+ REPO_DELETE_MARKERS = ['cloudlinux' , 'imunify' ]
15+ # These markers are used to identify which repository files should be replaced with new versions and backed up.
1316REPO_BACKUP_MARKERS = []
17+ # This suffix is used to identify .rpmnew files that appear after package upgrade.
1418RPMNEW = '.rpmnew'
15- LEAPP_BACKUP_SUFFIX = '.leapp-backup'
1619
1720
1821class ReplaceRpmnewConfigs (Actor ):
@@ -30,32 +33,31 @@ def process(self):
3033 deleted_repofiles = []
3134 renamed_repofiles = []
3235
33- for reponame in os .listdir (REPO_DIR ):
34- if any (mark in reponame for mark in REPO_DELETE_MARKERS ) and RPMNEW in reponame :
35- base_reponame = reponame [:- len (RPMNEW )]
36- base_path = os .path .join (REPO_DIR , base_reponame )
37- new_file_path = os .path .join (REPO_DIR , reponame )
36+ for rpmnew_filename in os .listdir (REPO_DIR ):
37+ if any (mark in rpmnew_filename for mark in REPO_DELETE_MARKERS ) and rpmnew_filename . endswith ( RPMNEW ) :
38+ main_reponame = rpmnew_filename [:- len (RPMNEW )]
39+ main_file_path = os .path .join (REPO_DIR , main_reponame )
40+ rpmnew_file_path = os .path .join (REPO_DIR , rpmnew_filename )
3841
39- os .unlink (base_path )
40- os .rename (new_file_path , base_path )
41- deleted_repofiles .append (base_reponame )
42- self .log .debug ('Yum repofile replaced: {}' .format (base_path ))
42+ os .unlink (main_file_path )
43+ os .rename (rpmnew_file_path , main_file_path )
44+ deleted_repofiles .append (main_reponame )
45+ self .log .debug ('Yum repofile replaced: {}' .format (main_file_path ))
4346
44- if any (mark in reponame for mark in REPO_BACKUP_MARKERS ) and RPMNEW in reponame :
45- base_reponame = reponame [:- len (RPMNEW )]
46- base_path = os .path .join (REPO_DIR , base_reponame )
47- new_file_path = os .path .join (REPO_DIR , reponame )
48- backup_path = os .path .join (REPO_DIR , base_reponame + LEAPP_BACKUP_SUFFIX )
47+ if any (mark in rpmnew_filename for mark in REPO_BACKUP_MARKERS ) and rpmnew_filename .endswith (RPMNEW ):
48+ main_reponame = rpmnew_filename [:- len (RPMNEW )]
49+ main_file_path = os .path .join (REPO_DIR , main_reponame )
50+ rpmnew_file_path = os .path .join (REPO_DIR , rpmnew_filename )
4951
50- os . rename ( base_path , backup_path )
51- os .rename (new_file_path , base_path )
52- renamed_repofiles .append (base_reponame )
53- self .log .debug ('Yum repofile replaced with backup: {}' .format (base_path ))
52+ backup_and_remove ( main_file_path )
53+ os .rename (rpmnew_file_path , main_file_path )
54+ renamed_repofiles .append (main_reponame )
55+ self .log .debug ('Yum repofile replaced with backup: {}' .format (main_file_path ))
5456
5557 # Disable any old repositories.
56- for reponame in os .listdir (REPO_DIR ):
57- if LEAPP_BACKUP_SUFFIX in reponame :
58- repofile_path = os .path .join (REPO_DIR , reponame )
58+ for repofile_name in os .listdir (REPO_DIR ):
59+ if LEAPP_BACKUP_SUFFIX in repofile_name :
60+ repofile_path = os .path .join (REPO_DIR , repofile_name )
5961 for line in fileinput .input (repofile_path , inplace = True ):
6062 if line .startswith ('enabled' ):
6163 print ("enabled = 0" )
@@ -66,7 +68,7 @@ def process(self):
6668 deleted_string = '\n ' .join (['{}' .format (repofile_name ) for repofile_name in deleted_repofiles ])
6769 replaced_string = '\n ' .join (['{}' .format (repofile_name ) for repofile_name in renamed_repofiles ])
6870 reporting .create_report ([
69- reporting .Title ('CloudLinux repository config files replaced by updated versions' ),
71+ reporting .Title ('Repository config files replaced by updated versions' ),
7072 reporting .Summary (
7173 'One or more RPM repository configuration files '
7274 'have been replaced with new versions provided by the upgraded packages. '
0 commit comments