小编Ngo*_*ran的帖子

如何在不指定库存但直接主机的情况下运行Ansible?

我想在Python中运行Ansible而不通过(ANSIBLE_HOST)指定库存文件,但只是通过:

ansible.run.Runner(
  module_name='ping',
  host='www.google.com'
)
Run Code Online (Sandbox Code Playgroud)

我实际上可以轻松地在Fabric中执行此操作,但只是想知道如何在Python中执行此操作.另一方面,用于python的Ansible API的文档并不完整.

python ansible

67
推荐指数
4
解决办法
7万
查看次数

如何在Python中的对象的模拟方法中调用self?

我尝试测试一些代码,这些代码不返回任何内容,只是将结果保存到数据库中.通过模拟save方法,我希望检查事情是否已正确处理:

def mock_save(self):
    assert(self.attr, 'dest_val')
with mock.patch.object(Item, "save", create=True) as save:
    save.side_effect = mock_save
    func_to_call() //in func_to_call, I call item.save()
Run Code Online (Sandbox Code Playgroud)

但是,似乎不允许这样做.它说参数数量不匹配.

如果我做def mock_save(),它将无法正常工作.

我怎样才能引用mock方法所依据的对象呢?(我在另一个适用于init方法的线程中看到它,可以直接从类中调用)

python mocking

18
推荐指数
1
解决办法
6218
查看次数

在JDK 6上运行Presto

我试图运行启动器但遇到此错误:

Exception in thread "main" java.lang.UnsupportedClassVersionError: sun/misc/FloatingDecimal : Unsupported major.minor version 51.0
    at java.lang.Double.toString(Double.java:196)
    at java.lang.String.valueOf(String.java:2985)
    at java.security.Provider.putId(Provider.java:433)
    at java.security.Provider.<init>(Provider.java:137)
    at sun.security.jca.ProviderList$1.<init>(ProviderList.java:71)
    at sun.security.jca.ProviderList.<clinit>(ProviderList.java:70)
    at sun.security.jca.Providers.<clinit>(Providers.java:56)
    at sun.security.util.ManifestEntryVerifier.<clinit>(ManifestEntryVerifier.java:47)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:335)
    at java.util.jar.JarFile.getInputStream(JarFile.java:410)
    at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:721)
    at sun.misc.Resource.cachedInputStream(Resource.java:77)
    at sun.misc.Resource.getByteBuffer(Resource.java:160)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:266)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.facebook.presto.server.PrestoServer. Program will exit.
Run Code Online (Sandbox Code Playgroud)

我认为这是因为我在JDK 6上运行启动器.(而它需要JDK 7.)是否有任何可以在JDK 6上运行的Presto版本?因为我目前想在我的Cloudera Hadoop集群上运行它,而Cloudera似乎只能与JDK 6一起运行.

谢谢.

jdk1.6 presto

3
推荐指数
1
解决办法
893
查看次数

标签 统计

python ×2

ansible ×1

jdk1.6 ×1

mocking ×1

presto ×1