client/tools/rhncfg/config_client/rhncfgcli_diff.py | 15 -
client/tools/rhncfg/config_client/rhncfgcli_elist.py | 3
client/tools/rhncfg/config_client/rhncfgcli_verify.py | 165 +++++++++---------
client/tools/rhncfg/config_common/file_utils.py | 2
4 files changed, 94 insertions(+), 91 deletions(-)
New commits:
commit a98d14e554101131374fa2a740aa3651bbfd6578
Author: Partha Aji <paji(a)redhat.com>
Date: Mon Aug 2 18:36:37 2010 -0400
Changes to rhncfg verify and diff to get symlinks working
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_diff.py
b/client/tools/rhncfg/config_client/rhncfgcli_diff.py
index 10c928a..26ea026 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_diff.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_diff.py
@@ -31,20 +31,13 @@ class Handler(handler_base.HandlerBase):
# output. also gets rid of /tmp/@blah in diff output.
label = dst
- if type == 'directory':
- #dst is a directory, so just tell the user we're skipping the entry
- print "Entry \'%s\' is a directory, skipping" % dst
- elif type == 'symlink':
+ if type == 'symlink':
#dst is a symlink, so just tell the user we're skipping the entry
srclink = os.path.abspath(os.readlink(src))
destlink = os.path.abspath(os.readlink(dst))
- if srclink == destlink:
- print "No change between the symbolic links '%s' " %
dst
- else:
- print "Symbolic link targets are different."
- print "Channel: '%s' -> '%s' System:
'%s' -> '%s' " % (dst,srclink, dst, destlink)
-
- else:
+ if srclink != destlink:
+ print "Symbolic links differ. Channel: '%s' ->
'%s' System: '%s' -> '%s' " % (dst,srclink, dst,
destlink)
+ elif type == 'file':
# if file isn't present, compare to /dev/null so we see the
# whole thing in the diff
if not os.access(dst, os.R_OK):
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_elist.py
b/client/tools/rhncfg/config_client/rhncfgcli_elist.py
index dcb5102..a88822f 100755
--- a/client/tools/rhncfg/config_client/rhncfgcli_elist.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_elist.py
@@ -101,5 +101,6 @@ class Handler(handler_base.HandlerBase):
fsize = '*' + str(len(finfo['file_contents']))
permstr = finfo['filetype'] != 'symlink' and
self.ostr_to_sym(finfo['filemode'], finfo['filetype']) or ''
- print "%10s %8s %-8s %10s %+3s %*s %s" % (permstr,
finfo['username'], finfo['groupname'], fsize, finfo['revision'],
maxlen, file[0], file[1])
+ dest = finfo['filetype'] != 'symlink' and file[1] or "%s
-> %s" % (file[1], finfo['symlink'])
+ print "%10s %8s %-8s %10s %+3s %*s %s" % (permstr,
finfo['username'], finfo['groupname'], fsize, finfo['revision'],
maxlen, file[0], dest)
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_verify.py
b/client/tools/rhncfg/config_client/rhncfgcli_verify.py
index caa30b5..3fbddf3 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_verify.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_verify.py
@@ -169,95 +169,104 @@ class Handler(handler_base.HandlerBase):
selinux_report = "%s|%s"
src, dst, file, type, info = args[:5]
+ owner_status = ""
+ group_status = ""
+ perm_status = ""
+ selinux_status = ""
status = []
stat_err = 0
-
- #Stat the destination file
- try:
- dst_stat = os.lstat(dst)
- except:
- stat_err = 1
-
- src_user = info['username']
- if not stat_err:
- #check for owner differences
- dst_uid = dst_stat[stat.ST_UID]
- try:
- dst_user = pwd.getpwuid(dst_uid)[0]
- except KeyError:
- # Orphan UID with no name,return unknown
- dst_user = "unknown(UID %d)" % (dst_uid,)
- else:
- dst_user = "missing"
-
- #owner_status gets displayed with the verbose option.
- if src_user == dst_user:
- owner_status = ""
- else:
- owner_status = owner_report % (src_user, dst_user)
- status.append('user')
-
- src_group = info['groupname']
- if not stat_err:
- #check for group differences
- dst_gid = dst_stat[stat.ST_GID]
+ if type != 'symlink':
+ #Stat the destination file
try:
- dst_group = grp.getgrgid(dst_gid)[0]
- except KeyError:
- # Orphan GID with no name,return unknown
- dst_group = "unknown(GID %d)" % (dst_gid,)
- else:
- dst_group = "missing"
-
- #group_status gets displayed with the verbose option.
- if src_group == dst_group:
- group_status = ""
- else:
- group_status = group_report % (src_group, dst_group)
- status.append('group')
-
- #check for permissions differences
- src_perm = str(info['filemode'])
- if not stat_err:
- #The mode returned by stat is decimal, but won't match the value in
file_info unless it's octal.
- #Unfortunately, the mode in file_info looks like the octal value of the mode,
except it's in decimal.
- #The solution I came up with is to convert them both into strings, rip off
the leading '0' from the
- #mode returned by stat, use the resulting strings. It sucks, but it seems to
work (for now).
- dst_perm = str(oct(stat.S_IMODE(dst_stat[stat.ST_MODE])))
- else:
- dst_perm = "missing"
-
- #rip off the leading '0' from the mode returned by stat()
- if dst_perm[0] == '0':
- dst_perm = dst_perm[1:]
-
- #perm_status gets displayed with the verbose option.
- if src_perm == dst_perm:
- perm_status = ""
- else:
- perm_status = perm_report % (src_perm, dst_perm)
- status.append('mode')
+ dst_stat = os.lstat(dst)
+ except:
+ stat_err = 1
+
+ src_user = info['username']
+ if not stat_err:
+ #check for owner differences
+ dst_uid = dst_stat[stat.ST_UID]
+ try:
+ dst_user = pwd.getpwuid(dst_uid)[0]
+ except KeyError:
+ # Orphan UID with no name,return unknown
+ dst_user = "unknown(UID %d)" % (dst_uid,)
+ else:
+ dst_user = "missing"
+
+ #owner_status gets displayed with the verbose option.
+ if src_user == dst_user:
+ owner_status = ""
+ else:
+ owner_status = owner_report % (src_user, dst_user)
+ status.append('user')
+
+ src_group = info['groupname']
+ if not stat_err:
+ #check for group differences
+ dst_gid = dst_stat[stat.ST_GID]
+ try:
+ dst_group = grp.getgrgid(dst_gid)[0]
+ except KeyError:
+ # Orphan GID with no name,return unknown
+ dst_group = "unknown(GID %d)" % (dst_gid,)
+ else:
+ dst_group = "missing"
+
+ #group_status gets displayed with the verbose option.
+ if src_group == dst_group:
+ group_status = ""
+ else:
+ group_status = group_report % (src_group, dst_group)
+ status.append('group')
+
+ #check for permissions differences
+ src_perm = str(info['filemode'])
+ if not stat_err:
+ #The mode returned by stat is decimal, but won't match the value in
file_info unless it's octal.
+ #Unfortunately, the mode in file_info looks like the octal value of the
mode, except it's in decimal.
+ #The solution I came up with is to convert them both into strings, rip
off the leading '0' from the
+ #mode returned by stat, use the resulting strings. It sucks, but it seems
to work (for now).
+ dst_perm = str(oct(stat.S_IMODE(dst_stat[stat.ST_MODE])))
+ else:
+ dst_perm = "missing"
+
+ #rip off the leading '0' from the mode returned by stat()
+ if dst_perm[0] == '0':
+ dst_perm = dst_perm[1:]
+
+ #perm_status gets displayed with the verbose option.
+ if src_perm == dst_perm:
+ perm_status = ""
+ else:
+ perm_status = perm_report % (src_perm, dst_perm)
+ status.append('mode')
# compare selinux contexts
src_selinux = info['selinux_ctx']
- if not stat_err:
- dst_selinux = lgetfilecon(dst)[1]
- if dst_selinux == None:
- dst_selinux = ""
- else:
- dst_selinux = "missing"
-
- if src_selinux == dst_selinux:
- selinux_status = ""
- else:
- selinux_status = selinux_report % (src_selinux, dst_selinux)
- status.append('selinux')
+ if src_selinux:
+ if not stat_err:
+ dst_selinux = lgetfilecon(dst)[1]
+ if dst_selinux == None:
+ dst_selinux = ""
+ else:
+ dst_selinux = "missing"
+
+ if src_selinux == dst_selinux:
+ selinux_status = ""
+ else:
+ selinux_status = selinux_report % (src_selinux, dst_selinux)
+ status.append('selinux')
#figure out the ultimate value of status.
if stat_err:
status = ["missing"]
-
+ elif type == 'symlink':
+ if not os.path.islink(file):
+ status = ["missing"]
+ elif os.readlink(file) != info['symlink']:
+ status.append('target-link-modified')
elif type == 'directory':
if not os.path.isdir(file):
status = ["missing"]
diff --git a/client/tools/rhncfg/config_common/file_utils.py
b/client/tools/rhncfg/config_common/file_utils.py
index 6325c39..1a1b333 100644
--- a/client/tools/rhncfg/config_common/file_utils.py
+++ b/client/tools/rhncfg/config_common/file_utils.py
@@ -98,7 +98,7 @@ class FileProcessor:
cur_sectx = lgetfilecon(path)[1]
if cur_sectx == None:
cur_sectx = ''
- if file_struct.has_key('selinux_ctx'):
+ if file_struct.has_key('selinux_ctx') and
file_struct['selinux_ctx']:
if cur_sectx != file_struct['selinux_ctx']:
sectx_result = "SELinux contexts differ: actual: [%s], expected:
[%s]\n" % (cur_sectx, file_struct['selinux_ctx'])