7
7
from leapp import reporting
8
8
from leapp .reporting import Report
9
9
from leapp .libraries .common .cllaunch import run_on_cloudlinux
10
+ from leapp .libraries .common .backup import backup_and_remove , LEAPP_BACKUP_SUFFIX
10
11
11
12
REPO_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.
13
16
REPO_BACKUP_MARKERS = []
17
+ # This suffix is used to identify .rpmnew files that appear after package upgrade.
14
18
RPMNEW = '.rpmnew'
15
- LEAPP_BACKUP_SUFFIX = '.leapp-backup'
16
19
17
20
18
21
class ReplaceRpmnewConfigs (Actor ):
@@ -30,32 +33,31 @@ def process(self):
30
33
deleted_repofiles = []
31
34
renamed_repofiles = []
32
35
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 )
38
41
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 ))
43
46
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 )
49
51
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 ))
54
56
55
57
# 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 )
59
61
for line in fileinput .input (repofile_path , inplace = True ):
60
62
if line .startswith ('enabled' ):
61
63
print ("enabled = 0" )
@@ -66,7 +68,7 @@ def process(self):
66
68
deleted_string = '\n ' .join (['{}' .format (repofile_name ) for repofile_name in deleted_repofiles ])
67
69
replaced_string = '\n ' .join (['{}' .format (repofile_name ) for repofile_name in renamed_repofiles ])
68
70
reporting .create_report ([
69
- reporting .Title ('CloudLinux repository config files replaced by updated versions' ),
71
+ reporting .Title ('Repository config files replaced by updated versions' ),
70
72
reporting .Summary (
71
73
'One or more RPM repository configuration files '
72
74
'have been replaced with new versions provided by the upgraded packages. '
0 commit comments