Python:尽管明显存在但未看到函数

标签 python

下面的代码调用了一个名为lago的方法。

#!/usr/bin/env python
#
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
#

import sys

class InstallTest():
    """Ru Ovirt System Tests"""


    def run_command_checking_exit_code(command):
        """ Runs a command"""
        print("Command is " + str(command))
        print(command.read())
        print(command.close())

    def lago():
        """run the conductor profiles required to install OLVM """
        Log.test_objective('TODO')
        run_command_checking_exit_code('ls -al')
        """
        yum_list = ["epel-release", "centos-release-qemu-ev", "python-devel", "libvirt", "libvirt-devel", "libguestfs-tools", "libguestfs-devel", "gcc", "libffi-devel", "openssl-devel", "qemu-kvm-ev"]
        for yum in yum_list

        ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST + ' -t OS_OL7U6_X86_64_PVHVM_30GB -c 10.1.0.10 -o ' + self.log_jobdir_cc +'/vm_install_ol7.6', timeout=1000000)
        if ret:
            self.tc_fail('Creation of OLV Engine VM failed')
        ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST +' -p ovirt-engine -c 10.1.0.10 -o ' + self.log_jobdir_cc + '/engine_deploy', timeout=1000000)
        if ret:
            self.tc_fail('Install of OLV Engine Host failed')
        self.tc_pass('OLV Engine Host installed')
        """

    def main():
        lago()

    main()

但是,输出中显示它不存在

Traceback (most recent call last):
  File "C:/Users/rafranci/Downloads/ovirt_st_setup.py", line 20, in <module>
    class InstallTest():
  File "C:/Users/rafranci/Downloads/ovirt_st_setup.py", line 65, in InstallTest
    main()
  File "C:/Users/rafranci/Downloads/ovirt_st_setup.py", line 63, in main
    lago()
NameError: name 'lago' is not defined

据我所知,这没有任何理由 - 想法?

最佳答案

检查代码的变化:

class InstallTest():
    """Ru Ovirt System Tests"""


    def run_command_checking_exit_code(command):
        """ Runs a command"""
        print("Command is " + str(command))
        print(command.read())
        print(command.close())

    def lago(self):
        """run the conductor profiles required to install OLVM """
        #Log.test_objective('TODO')
        #run_command_checking_exit_code('ls -al')
        """
        yum_list = ["epel-release", "centos-release-qemu-ev", "python-devel", "libvirt", "libvirt-devel", "libguestfs-tools", "libguestfs-devel", "gcc", "libffi-devel", "openssl-devel", "qemu-kvm-ev"]
        for yum in yum_list

        ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST + ' -t OS_OL7U6_X86_64_PVHVM_30GB -c 10.1.0.10 -o ' + self.log_jobdir_cc +'/vm_install_ol7.6', timeout=1000000)
        if ret:
            self.tc_fail('Creation of OLV Engine VM failed')
        ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST +' -p ovirt-engine -c 10.1.0.10 -o ' + self.log_jobdir_cc + '/engine_deploy', timeout=1000000)
        if ret:
            self.tc_fail('Install of OLV Engine Host failed')
        self.tc_pass('OLV Engine Host installed')
        """

    def main(self):
        self.lago()

    def __init__(self):
        self.main()
InstallTest()

关于Python:尽管明显存在但未看到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59407592/

相关文章:

python - 使用 Python 直接从 SFTP 服务器上传文件到 Box,无需保存中间文件

python Selenium : click() cannot trigger event

python - 如何在列表中获取生成器的下一个值(python)

python - 如何在Python中进行安全的二进制比较?

python - 如何在 django 模板中运行此代码

python - 如何在 matplotlib 的折线图上绘制最大值点?

python - 如何在注册时实现电子邮件验证,而不是 Django 中的社交帐户?

Python:检查每个用户的唯一类别

php - 与 PHP 相比,Python 'flow' 与 HTML 的表现如何?

Python 2.6 xml.dom.ext 对象丢失?