Skip to content

Fix xenopsd common.py's VIF.get_ethtool() passing two args to list().append() #5922

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

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Aug 8, 2024

Follow-up of #5921 that includes #5921 (please merge first) as it depends on it:

For @stephenchengCloud:
FYI: @ashwin9390

In #5896 (review), changes were requested:

Before merging feature/py3 into master, certain warnings in files that weren't checked so far should be fixed.

This PR fixes two of the mentioned pytype warnings:

pytype ocaml/xenopsd/scripts/common.py
File "ocaml/xenopsd/scripts/common.py", line 163, in get_ethtool: Function list.append expects 2 arg(s), got 3 [wrong-arg-count]
         Expected: (self, object)
  Actually passed: (self, object, _)
File "ocaml/xenopsd/scripts/common.py", line 165, in get_ethtool: Function list.append expects 2 arg(s), got 3 [wrong-arg-count]
         Expected: (self, object)
  Actually passed: (self, object, _)

These are from these lines:

                if v == "true" or v == "on":
                    results.append(k, True)
                elif v == "false" or v == "off":
                    results.append(k, False)

These ethtool settings are documented in the document Develop for XenServer starting at page 75.

As can be seen on the blame view, these two arguments have been there for 12 years. Maybe they worked in Python versions before Python2.7, but they did not even work in Python2.7.

Reaching such append(a, b) would raise a TypeError with any Interpreter that I can find:

python2 -c '[].append(1, True)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: append() takes exactly one argument (2 given)

This PR adds a test to cover the method containing them and then fixes the bug.

The only call site of VIF().get_ethtool() is at https://github.com/xapi-project/xen-api/blob/feature/py3/ocaml/xenopsd/scripts/common.py#L229.

It expects that get_ethtool() returns a list of key/value sets like so: [(k, True), (k, False)], so pass (and return) k, bool as a set: .append((k, bool)).

Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
@bernhardkaindl bernhardkaindl changed the title Fix xenopsd passing two args to append Fix xenopsd common.py's VIF.get_ethtool() passing two args to list().append() Aug 8, 2024
@bernhardkaindl
Copy link
Collaborator Author

Closing in favour of #5923 which deletes the broken VIF.get_ethtool() code:

VIF.get_ethtool() was only used by Interface.online() which would be removed as the only user I could find was qemu-vif-script but that instantiated Interface() using only one argument, while it now takes 3 arguments.

This means that qemu-vif-script cannot work and as apparently nothing references it, we can thus remove the code only used by it. So I suggest removing the old code in #5923 instead.

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.

2 participants