On 18/11/2011, at 08:50, Michael Mraka wrote:

> Hello Marcello,
> 
> I'm confused by this patch... what's the problem it should solve?
> 
> Regads,
> 
> --
> Michael Mráka
> Satellite Engineering, Red Hat

 Hello Michael, 

  Basically the problem happens when you have a configuration channel which 
provides a directory as a symlink, the rhncfg-client get command works for the 
first time. When trying to redeploy the files again, rhncfg-client get fails 
and rollback the files since since shutil.copy() fails to overwrite the 
existing symlink directory. The issue does not happen when the symlink is a 
file. 

--> Files provided
root@dhcp235 ~]# rhncfg-client elist
Mode          Owner Group          Size Rev      Config Channel    File
lrwxrwxrwx     root root             14   1               teste    
/boot/cross-dir -> /usr/local/bin
lrwxrwxrwx     root root             11   2               teste    
/boot/cross-link -> /etc/passwd
lrwxrwxrwx     root root             10   2               teste    
/root/sym-link-same-part -> /etc/hosts
lrwxrwxrwx     root root              4   1                teste    /teste -> 
/tmp
 
---> Checking files
[root@dhcp235 ~]# rhncfg-client verify
 missing /boot/cross-dir
 missing /boot/cross-link
 missing /root/sym-link-same-part
 missing /teste

---> Deploying files
[root@dhcp235 ~]# rhncfg-client get
Deploying /boot/cross-link
Deploying /root/sym-link-same-part
Deploying /teste
Deploying /boot/cross-dir

---> Checking files: All files were deployed as expected
[root@dhcp235 ~]# rhncfg-client verify
  /boot/cross-dir
  /boot/cross-link
  /root/sym-link-same-part
  /teste

--> Symlink directory were deployed as expected
[root@dhcp235 ~]# ls -lad /teste
lrwxrwxrwx 1 root root 4 Nov 14 12:37 /teste -> /tmp

----> Re-deployment failed
[root@dhcp235 ~]# rhncfg-client get
Deploy failed, rollback successful

  Basically we followed the steps below to debug the issue: 

 Looking the code:

                try:
                    log_debug(9, "trying to use os.renames")
                    oumask = os.umask(022)
                    os.renames(path, new_path)
                    os.umask(oumask)
                except OSError, e:
                    if e.errno == 18:
                        log_debug(9, "os.renames failed, using shutil 
functions")
                        path_dir, path_file = os.path.split(path)
                        log_debug(9, "mmello --> path_dir --> %s path_file --> 
%s" % (path_dir,path_file))
                        new_path_dir, new_path_file = os.path.split(new_path)
                        log_debug(9, "mmello --> new_path_dir --> %s 
new_path_file --> %s" % (new_path_dir, new_path_file))
                        if os.path.isdir(new_path_dir):
                            log_debug(9, "backup directory %s exists, copying 
%s to it" % (new_path_dir, new_path_file))
                            log_debug(9, "mmello -> trying to copy %s to %s" % 
(path,new_path))
                            shutil.copy(path, new_path)
                        else:
                            log_debug(9, "backup directory does not exist, 
creating the tree now")
                            shutil.copytree(path_dir, new_path_dir, symlinks=0)
                            shutil.copy(path, new_path)
                    else:
                        raise
                self.backup_by_path[path] = new_path
                log_debug(9, "backed up to %s" % new_path)
            else:
                raise TargetNotFile("Error: %s is not a valid file, cannot 
create backup copy" % path)
        return new_path


  Looking the logs:

# rhncfg-client get
{ … SNIP … }
2011-11-14 13:20:36 transactions._rename_to_backup: renaming /teste to backup 
/var/lib/rhncfg/backups/teste.rhn-cfg-backup ...
2011-11-14 13:20:36 transactions._rename_to_backup: trying to use os.renames
2011-11-14 13:20:36 transactions._rename_to_backup: os.renames failed, using 
shutil functions
2011-11-14 13:20:36 transactions._rename_to_backup: mmello --> path_dir --> / 
path_file --> teste
2011-11-14 13:20:36 transactions._rename_to_backup: mmello --> new_path_dir --> 
/var/lib/rhncfg/backups new_path_file --> teste.rhn-cfg-backup
2011-11-14 13:20:36 transactions._rename_to_backup: backup directory 
/var/lib/rhncfg/backups exists, copying teste.rhn-cfg-backup to it
2011-11-14 13:20:36 transactions._rename_to_backup: mmello -> trying to copy 
/teste to /var/lib/rhncfg/backups/teste.rhn-cfg-backup
2011-11-14 13:20:36 transactions.rollback: rolling back

 
   Running manually: 
[root@dhcp235 backups]# python
Python 2.4.3 (#1, Aug 29 2011, 10:55:55) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.copy("/teste","/var/lib/rhncfg/backups/teste.rhn-cfg-backup")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib64/python2.4/shutil.py", line 81, in copy
    copyfile(src, dst)
  File "/usr/lib64/python2.4/shutil.py", line 47, in copyfile
    fsrc = open(src, 'rb')
IOError: [Errno 21] Is a directory

  Please, let me know if you have other doubts around this issue. 
 
 Best Regards, 
mmello

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to