小编Jos*_*idt的帖子

ansible:促进对错误的警告

我有一些持续的集成检查,它运行一些ansible-playbook命令.每个剧本可能正在运行许多剧本,包括许多大型角色.

每隔一段时间,有人会引入一些在ansible-playbook运行时引起警告的变化,例如:

[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout
Run Code Online (Sandbox Code Playgroud)

要么:

[WARNING]: Consider using unarchive module rather than running tar
Run Code Online (Sandbox Code Playgroud)

或者一些弃用警告,例如:

[DEPRECATION WARNING]: ec2_facts is kept for backwards compatibility but usage 
is discouraged. The module documentation details page may explain more about 
this rationale.. This feature will be removed in a future release. Deprecation 
warnings can be disabled by setting deprecation_warnings=False in …
Run Code Online (Sandbox Code Playgroud)

warnings ansible

11
推荐指数
1
解决办法
1218
查看次数

在指定 update_fields 时使用 pre_save

我在 MyModel 上定义了一个 pre_save ,它看起来像这样:

@receiver(pre_save, sender=MyModel)
def _mymodel_pre_save(sender, instance, **kwargs):
  if some_condition():
    instance.somecolumn = 'eggs'
Run Code Online (Sandbox Code Playgroud)

即它期望能够修改 MyModel 实例的某些属性,并且当然期望这些更改在 save() 调用期间保留。我相信这是 pre_save 函数的典型用法。只要 save() 调用不指定 update_fields ,这就可以正常工作。

我想知道此时是否有任何安全且合理的方法可以在 MyModel 实例的 save() 调用中使用 update_fields 。如果我天真地打电话:

myinstance = MyModel.objects.get(id=100)
myinstance.othercolumn = 'spam'
myinstance.save(update_fields=['othercolumn'])
Run Code Online (Sandbox Code Playgroud)

生成的 UPDATE 语句将如下所示:

UPDATE "myapp_mymodel" SET "othercolumn" = 'spam' WHERE "myapp_mymodel"."id" = 100
Run Code Online (Sandbox Code Playgroud)

缺少预保存中“somecolumn”的预期更新。我想可以通过查看可用于 pre_save 函数(作为冻结集)的 update_fields 从 pre_save 内部检测到这种情况,但我看不到 pre_save 有任何方法可以强制在以下情况下进行预期的更改:调用者有一组更具限制性的 update_fields,如上面的示例所示。或者有什么解决方法吗?

python django django-signals

5
推荐指数
1
解决办法
2525
查看次数

基于fixture的自动pytest.mark装饰

假设我在 conftest.py 文件中建立了一个 pytest 固定装置,如下所示:

def live_fixture():
    # network access here...
    pass
Run Code Online (Sandbox Code Playgroud)

我在许多测试函数中使用了这个相同的装置,比如 test_spam.py 有一些测试函数:

@pytest.mark.live
def test_one(live_fixture):
    assert 1


def test_one():
    assert 2 

@pytest.mark.live
def test_three(live_fixture):
    assert 3
Run Code Online (Sandbox Code Playgroud)

@pytest.mark.live在第一个和第三个测试函数上使用装饰,因为这两个测试都依赖于 fixture live_fixture,它通过网络发出并执行一些操作。理由:我喜欢让我的测试的可靠子集离线通过,例如

py.test -m "not live" test_spam.py --blockage
Run Code Online (Sandbox Code Playgroud)

将可靠地通过(使用漂亮的pytest-blockage模块来强制执行无网络访问限制)。

但是@pytest.mark.live在使用live_fixturehere 的每个测试函数上写出装饰是乏味且容易出错的。有没有办法让该夹具声明任何使用它的测试函数都应该自动对其@pytest.mark.live应用装饰,或者某种方法来检测文件 test_spam.py 中的那个test_onetest_three使用它live_fixture,因此应该被有效地装饰@pytest.mark.live

python pytest python-decorators

4
推荐指数
1
解决办法
1001
查看次数

S3对象:“到期”和“到期日期”之间的差异

我正在尝试遵循有关的AWS文档aws s3 cp,该文档将--expires标志记录为:

--expires(字符串)对象不再可缓存的日期和时间。

...

将具有到期日期的本地文件复制到S3

以下cp命令将单个文件复制到指定的存储桶和密钥,该文件在指定的ISO 8601时间戳记到期:

aws s3 cp test.txt s3://mybucket/test2.txt --expires 2014-10-01T20:30:00Z

因此,当我像上面的示例一样运行命令时,我在S3中得到一个文件,该文件的右侧具有“概述”窗格,如下所示:

概述窗格

概述窗格声称没有“到期日期”。好。但是,如果我单击该文件,然后单击“属性”->“元数据”,则会看到以下内容:

S3对象元数据

那么哪一个是对的?“到期”和“到期日期”时间戳在某种程度上表示不同的含义吗?还是它们是同一回事,而显示的只是越野车?

我已经在StackOverflow上搜索了几个类似的问题(hereherehere),但没有找到这个问题的答案。

amazon-s3 aws-cli

0
推荐指数
1
解决办法
755
查看次数