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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值