1. 程式人生 > >salt 2016.3.3版本 cp.push拉取minion端檔案異常問題

salt 2016.3.3版本 cp.push拉取minion端檔案異常問題

今天在線上環境使用cp.push模組拉取minion端檔案時,出現如下錯誤

# salt 192.168.xxx.xxx cp.push   /etc/fstab
192.168.xxx.xxx:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.6/site-packages/salt/minion.py", line 1332, in _thread_return
        return_data = executor.execute()
      File 
"/usr/lib/python2.6/site-packages/salt/executors/direct_call.py", line 28, in execute return self.func(*self.args, **self.kwargs) File "/usr/lib/python2.6/site-packages/salt/modules/cp.py", line 876, in push_dir ret = push(tmpfile, upload_path=tmpupload_path) File "/usr/lib/python2.6/site-packages/salt/modules/cp.py
", line 799, in push load_path_list = os.path.split(load_path_split_drive) File "/usr/lib64/python2.6/posixpath.py", line 82, in split i = p.rfind('/') + 1 AttributeError: 'tuple' object has no attribute 'rfind'

然後在測試環境使用cp.push模組正常,

# salt 192.168.62.200  cp.push /etc/fstab 
192.168.62.200: True

對比測試環境跟線上環境salt版本,

線上環境

# salt --version
salt 2016.3.3 (Boron)

測試環境

# salt --version
salt 2016.11.3 (Carbon)

版本不一致,對比cp模組原始碼,發現報錯程式碼行前後有一些差異

image

將線上環境/usr/lib/python2.6/site-packages/salt/modules/cp.py 備份並刪除799行程式碼中的冒號(:) 重新執行命令發現正常拉去minion檔案

# salt 192.168.xxx.xxx cp.push   /etc/fstab  
192.168.xxx.xxx:
    True
# ll /var/cache/salt/master/minions/192.168.xxx.xxx/files/etc/fstab 
-rw-r--r-- 1 root root 899 3月  24 15:07 /var/cache/salt/master/minions/192.168.xxx.xxx/files/etc/fstab
# cat /var/cache/salt/master/minions/192.168.xxx.xxx/files/etc/fstab   

#
# /etc/fstab
# Created by anaconda on Tue Jan 12 10:03:54 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=982e2171-f59c-406e-8323-8164fd44e2bd /                       ext4    defaults        1 1
UUID=add25ef6-0d8c-45b9-a8a0-b68356057137 /boot                   ext4    defaults        1 2
UUID=186ec6e3-0988-437f-b7f7-592efedfe8e4 swap                    swap    defaults        0 0
/dev/vg_data/data1                        /data                   ext4    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

將cp.py模組推送到各個minion

# cat minion_cp.sls 
/usr/lib/python2.6/site-packages/salt/modules/cp.py: 
  file.managed:
    - source: salt://files/cp.py
    - backup: minion
# salt 192.168.* state.sls minion_cp
192.168.xxx.xxx:
----------
          ID: /usr/lib/python2.6/site-packages/salt/modules/cp.py
    Function: file.managed
      Result: True
     Comment: File /usr/lib/python2.6/site-packages/salt/modules/cp.py updated
     Started: 12:06:19.951990
    Duration: 110.057 ms
     Changes:   
              ----------
              diff:
                  ---  
                  +++  
                  @@ -793,10 +793,11 @@
                       load_path_normal = os.path.normpath(load_path)
                   
                       # If this is Windows and a drive letter is present, remove it
                  -    load_path_split_drive = os.path.splitdrive(load_path_normal)[1:]
                  +    load_path_split_drive = os.path.splitdrive(load_path_normal)[1]
                   
                       # Finally, split the remaining path into a list for delivery to the master
                  -    load_path_list = os.path.split(load_path_split_drive)
                  +    #load_path_list = os.path.split(load_path_split_drive)
                  +    load_path_list = [_f for _f in load_path_split_drive.split(os.sep) if _f]
                   
                       load = {'cmd': '_file_recv',
                               'id': __opts__['id'],

Summary for 192.168.xxx.xxx
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time: 110.057 ms