Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix avocado-vt issue:https://github.com/avocado-framework/avocado-vt/… #3392

Conversation

chunfuwen
Copy link
Contributor

…issues/3391

Error running method "initialize" of plugin "vt-init": cannot import name 'log_line' when
import from virttest import utils_misc in python terminal

virttest/utils_logfile.py and virttest/utils_misc.py duplicate the same code :
def log_line(filename, line) implementation
need change virttest/ip_sniffing.py to import log_line from virttest/utils_logfile.py

Signed-off-by: chunfuwen [email protected]

Error running method "initialize" of plugin "vt-init": cannot import name 'log_line' when
import from virttest import utils_misc in python terminal

virttest/utils_logfile.py and virttest/utils_misc.py duplicate the same code :
def log_line(filename, line) implementation
need change virttest/ip_sniffing.py to import log_line from virttest/utils_logfile.py

Signed-off-by: chunfuwen <[email protected]>
@chunfuwen
Copy link
Contributor Author

Fix the issue:#3391

Copy link
Contributor

@smitterl smitterl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the manual test fails still for me, s. run below. I do not know which magic importlib does. Would it be safer to rename one of both log_line instances or if they are the same remove one of them?

Reproduced traceback from: /home/smitterl/NotBackedUp/avocado-tmp/avocado/avocado/core/extension_manager.py:216
Traceback (most recent call last):
  File "/home/smitterl/NotBackedUp/avocado-tmp/avocado-vt/avocado_vt/plugins/vt_init.py", line 276, in initialize
    virt_loader = getattr(importlib.import_module('avocado_vt.loader'),
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/smitterl/NotBackedUp/avocado-tmp/avocado-vt/avocado_vt/loader.py", line 33, in <module>
    from .test import VirtTest
  File "/home/smitterl/NotBackedUp/avocado-tmp/avocado-vt/avocado_vt/test.py", line 33, in <module>
    from virttest import utils_env
  File "/home/smitterl/NotBackedUp/avocado-tmp/avocado-vt/virttest/utils_env.py", line 19, in <module>
    from virttest import ip_sniffing
  File "/home/smitterl/NotBackedUp/avocado-tmp/avocado-vt/virttest/ip_sniffing.py", line 21, in <module>
    from virttest.utils_logfile import log_line
ImportError: cannot import name 'log_line'

Error running method "initialize" of plugin "vt-init": cannot import name 'log_line'

@smitterl
Copy link
Contributor

smitterl commented Apr 6, 2022

I compared both functions utils_log.log_line and utils_misc.log_line they have the same definition - I think we can just remove utils_misc.log_line and make sure it's not used anymore

https://github.com/avocado-framework/avocado-vt/blob/master/virttest/utils_logfile.py#L45
https://github.com/avocado-framework/avocado-vt/blob/master/virttest/utils_misc.py#L417

https://github.com/avocado-framework/avocado-vt/search?q=log_line

@smitterl
Copy link
Contributor

smitterl commented Apr 6, 2022

Looks like what happened was that we tried to remove dependency on utils_misc but instead of moving the code we duplicated it - 3dffc0b

@smitterl
Copy link
Contributor

smitterl commented Apr 6, 2022

Looks like what happened was that we tried to remove dependency on utils_misc but instead of moving the code we duplicated it - 3dffc0b

@luckyh - Some code consumed by tp-qemu seems to be consuming the log_line function from the utils_misc module for example https://github.com/avocado-framework/avocado-vt/blob/a13aa1e2f8bd115f6e87bce0efc59359d8d97901/virttest/qemu_io.py.

That function was moved to the module utils_log in referenced commit 3dffc0b. Do you have any concerns updating all code to use utils_log for this and remove it from utils_misc?

@luckyh
Copy link
Contributor

luckyh commented Apr 7, 2022

Unfortunately, the manual test fails still for me, s. run below. I do not know which magic importlib does. Would it be safer to rename one of both log_line instances or if they are the same remove one of them?

I just tried to modify the code as the following and seems it could work properly (no ideas about how importlib dealing with it.)

diff --git a/virttest/ip_sniffing.py b/virttest/ip_sniffing.py
index 5c711f21..acddf291 100644
--- a/virttest/ip_sniffing.py
+++ b/virttest/ip_sniffing.py
@@ -18,7 +18,7 @@ from avocado.utils import process
 
 import six
 
-from virttest.utils_misc import log_line
+from virttest import utils_misc
 from virttest.utils_version import VersionInterval
 
 LOG = logging.getLogger('avocado.' + __name__)
@@ -174,7 +174,7 @@ class Sniffer(object):
 
     def _output_logger_handler(self, line):
         try:
-            log_line(self._logfile, line)
+            utils_misc.log_line(self._logfile, line)
         except Exception as e:
             LOG.warn("Can't log ip sniffer output: '%s'", e)
         if self._output_handler(line):

and the interesting thing is that I supposed it should work as well with using the one provided by utils_logfile but it's not. After changing all the utils_misc to utils_logfile from the above patch, the importing stuff can work, tests can finished properly, however, no corresponding log file (ip-sniffer.log) was generated under the test result dir.

Do you have any concerns updating all code to use utils_log for this and remove it from utils_misc?

@smitterl so my concern is we need to ensure that utils_logfile.log_line would function in the exact same manner of utils_misc.log_line before we are going to do the update. Also, I'm not sure if there are other project rely on these APIs.

Thanks,

@luckyh luckyh closed this Apr 7, 2022
@luckyh luckyh reopened this Apr 7, 2022
@luckyh
Copy link
Contributor

luckyh commented Apr 7, 2022

Oops, just close this by mistaken, sorry for the inconvenience.

@dzhengfy dzhengfy self-requested a review April 14, 2022 02:57
@dzhengfy dzhengfy removed their request for review May 5, 2022 09:13
@chunfuwen
Copy link
Contributor Author

Close it firstly, since there is no further feedbacks

@chunfuwen chunfuwen closed this Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants