shutil.copystat()在Azure上的Docker内部失败 [英] shutil.copystat() fails inside Docker on Azure

查看:106
本文介绍了shutil.copystat()在Azure上的Docker内部失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

失败的代码在基于python:3.6-stretch debian的Docker容器中运行. 这是在Django将文件从一个Docker卷移动到另一个Docker卷时发生的.

The failing code runs inside a Docker container based on python:3.6-stretch debian. It happens while Django moves a file from one Docker volume to another.

当我在MacOS 10上进行测试时,它可以正常工作.在这里,Docker容器从docker-compose开始,并在本地计算机上使用常规Docker卷.

When I test on MacOS 10, it works without error. Here, the Docker containers are started with docker-compose and use regular Docker volumes on the local machine.

成功将文件部署到Azure(AKS-Azure上的Kubernetes),但复制统计信息失败,并出现以下错误:

Deployed into Azure (AKS - Kubernetes on Azure), moving the file succeeds but copying the stats fails with the following error:

  File "/usr/local/lib/python3.6/site-packages/django/core/files/move.py", line 70, in file_move_safe
    copystat(old_file_name, new_file_name)
  File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
    _copyxattr(src, dst, follow_symlinks=follow)
  File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
    names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: '/some/path/file.pdf'

Azure上的卷是具有ReadWriteMany访问模式的持久卷声明.

The volumes on Azure are persistent volume claims with ReadWriteMany access mode.

现在,copystat记录为:

copystat()从不返回失败.

copystat() never returns failure.

https://docs.python.org/3/library/shutil.html

我的问题是:

  • 这是错误",因为文档说它应该永不返回失败"吗?
  • 我能否省力地尝试/排除此错误,因为相关文件已移动(它只会在稍后尝试复制统计信息时失败)
  • 我可以更改一些有关Azure设置的方法来解决此问题吗? (可能不是)

在Azure本身的计算机上进行一些小测试:

Here some small test on the machine in Azure itself:

root:/media/documents# ls -al
insgesamt 267
drwxrwxrwx 2 1000 1000      0 Jul 31 15:29 .
drwxrwxrwx 2 1000 1000      0 Jul 31 15:29 ..
-rwxrwxrwx 1 1000 1000 136479 Jul 31 16:48 orig.pdf
-rwxrwxrwx 1 1000 1000 136479 Jul 31 15:29 testfile
root:/media/documents# lsattr 
--S-----c-jI------- ./orig.pdf
--S-----c-jI------- ./testfile
root:/media/documents# python
Python 3.6.6 (default, Jul 17 2018, 11:12:33) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.copystat('orig.pdf', 'testfile')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
    _copyxattr(src, dst, follow_symlinks=follow)
  File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
    names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: 'orig.pdf'
>>> shutil.copystat('orig.pdf', 'testfile', follow_symlinks=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/shutil.py", line 225, in copystat
    _copyxattr(src, dst, follow_symlinks=follow)
  File "/usr/local/lib/python3.6/shutil.py", line 157, in _copyxattr
    names = os.listxattr(src, follow_symlinks=follow_symlinks)
OSError: [Errno 38] Function not implemented: 'orig.pdf'
>>> 

推荐答案

以下解决方案是一个修补程序.必须将其应用于直接或间接调用copystat任何方法(或产生可忽略的errno.ENOSYS的任何shutil方法).

The following solution is a hotfix. It would have to be applied to any method that calls copystat directly or indirectly (or any shutil method that produces an ignorable errno.ENOSYS).

if hasattr(os, 'listxattr'):
    LOGGER.warning('patching listxattr to avoid ERROR 38 (errno.ENOSYS)')
    # avoid "ERROR 38 function not implemented on Azure"
    with mock.patch('os.listxattr', return_value=[]):
        file_field.save(name=name, content=GeneratedFile(fresh, content_type=content_type), save=True)
else:
    file_field.save(name=name, content=GeneratedFile(fresh, content_type=content_type), save=True)

file_field.save是调用有问题的shutil代码的Django方法.这是错误之前我代码中的最后一个位置.

file_field.save is the Django method that calls the shutil code in question. It's the last location in my code before the error.

这篇关于shutil.copystat()在Azure上的Docker内部失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆