Skip to content

Conversation

@acefei
Copy link
Contributor

@acefei acefei commented Feb 4, 2024

Test case passed job: 3923182
Test suite passed job: 194221 (Dev Run)
The manual test follows:
image

@acefei acefei closed this Feb 4, 2024
@acefei acefei reopened this Feb 4, 2024
@codecov
Copy link

codecov bot commented Feb 4, 2024

Codecov Report

Merging #5424 (1a34e20) into feature/py3 (411ae6a) will increase coverage by 24.6%.
The diff coverage is 100.0%.

Additional details and impacted files
@@              Coverage Diff               @@
##           feature/py3   #5424      +/-   ##
==============================================
+ Coverage         55.2%   79.9%   +24.6%     
==============================================
  Files               18       5      -13     
  Lines             2075     419    -1656     
==============================================
- Hits              1147     335     -812     
+ Misses             928      84     -844     
Files Coverage Δ
python3/unittest/import_file.py 100.0% <100.0%> (ø)
python3/unittest/test_hfx_filename.py 100.0% <100.0%> (ø)
python3/unittest/test_usb_scan.py 99.2% <100.0%> (ø)

... and 13 files with indirect coverage changes

Flag Coverage Δ
python2.7 59.1% <ø> (+5.5%) ⬆️
python3.11 99.5% <100.0%> (-0.5%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@acefei acefei force-pushed the private/feis/CP-47389_v1 branch 3 times, most recently from 95ab5df to 2d31c26 Compare February 5, 2024 01:57
@acefei acefei force-pushed the private/feis/CP-47389_v1 branch 2 times, most recently from 09dc84f to c38c2cc Compare February 5, 2024 01:59
@acefei
Copy link
Contributor Author

acefei commented Feb 5, 2024

Rebase the feature branch and rebuild the package.
Test job: 3923331
Ring3 BVT + BST: 194240

@acefei acefei force-pushed the private/feis/CP-47389_v1 branch from c38c2cc to 2be1f82 Compare February 21, 2024 03:19
self.test_usb_common(devices, interfaces, results, path)
if msg:
self.assertIn(msg, cm.exception.code)
# cm.exception.code is int type whose format like "duplicated tag'vid' found, malformed line ALLOW:vid=056a vid=0314 class=03"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to resolve this pylint warning.

Copy link
Collaborator

@bernhardkaindl bernhardkaindl Mar 13, 2024

Choose a reason for hiding this comment

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

Unresolved this discussion because it was set to resolved without a comment.

  • This makes it hidden for review, and it causes that one cannot follow why this discussion was closed.

  • and, the type analysis warning was not resolved (fixed), but disabled (without an explanation)

  • This is an assertion function, and this assertion is in an if msg:. Such conditionals in assertion functions are not safe (e.g. passing msg just means there is no test of msg).

    • Instead, the original test cases that would want to check the content of msg should have this assertion instead.

Copy link
Contributor Author

@acefei acefei Mar 13, 2024

Choose a reason for hiding this comment

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

I have a comments there that is an explain why disable pytype error, pytype think cm.exception.code is int, but actually its output is a str.

with the original author's thoughts, if testing usb without config, there is no msg need to be checked (285). in the rest of testing, it'll verify the common testcase with usb-policy.conf, that would check the content of msg should have this assertion.
I think it worked well, we don't need to change here, so just disable the pytype rule here.

  284     def test_usb_config_missing(self):
  285         self.verify_usb_exit([], [], [], "not_exist.conf")
  286
  287     def verify_usb_config_error_common(self, content, msg):
  288         path = os.path.join(self.work_dir, "usb-policy.conf")
  289         with open(path, "w") as f:
  290             f.write(content)
  291         self.verify_usb_exit([], [], [], path, msg)

@acefei
Copy link
Contributor Author

acefei commented Feb 21, 2024

Rebased and Tested 3933165 and 194764 (Dev Run)

@gangj
Copy link
Contributor

gangj commented Feb 22, 2024

This script "usb_scan.py" is used in xapi just by executing it without arguments: https://github.com/xapi-project/xen-api/blob/master/ocaml/xapi/xapi_pusb_helpers.ml#L98, and @acefei have manually verified that the output from this updated py3 version script is the same as the output from the original py2 version, so the change here should be ok.

Copy link
Contributor

@gangj gangj left a comment

Choose a reason for hiding this comment

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

3933165 passed (build hash: 2be1f82).
And please squash the commits before merging.

@psafont
Copy link
Member

psafont commented Feb 23, 2024

There are some failre code paths that have been changed but are untested by unit-tests, have these been manually tested? (when usbs are overriden or removed)

@acefei
Copy link
Contributor Author

acefei commented Feb 26, 2024

There are some failre code paths that have been changed but are untested by unit-tests, have these been manually tested? (when usbs are overriden or removed)

Job 3933165 tested as the highlight below.
image

image

@psafont
Copy link
Member

psafont commented Feb 26, 2024

Looks good, only thing left is the removal of python2 tests

@acefei acefei force-pushed the private/feis/CP-47389_v1 branch 8 times, most recently from a85754a to a51d360 Compare February 27, 2024 06:20
@acefei acefei force-pushed the private/feis/CP-47389_v1 branch from 1d44a9c to 9cf04d9 Compare March 12, 2024 06:49
acefei added 13 commits March 12, 2024 14:54
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
…face

Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
We're moving the python code and unittest into python3 folder, that
would be resulting in a decrease in coverage rate in scripts folder

Signed-off-by: Fei Su <fei.su@cloud.com>
Signed-off-by: Fei Su <fei.su@cloud.com>
@acefei acefei force-pushed the private/feis/CP-47389_v1 branch from 9cf04d9 to 03e4743 Compare March 12, 2024 06:56
Signed-off-by: Fei Su <fei.su@cloud.com>
@acefei acefei force-pushed the private/feis/CP-47389_v1 branch from 03e4743 to 1a34e20 Compare March 12, 2024 07:53
@lindig
Copy link
Contributor

lindig commented Mar 12, 2024

This has two ✔️ - shall we merge it?

Copy link
Collaborator

@bernhardkaindl bernhardkaindl left a comment

Choose a reason for hiding this comment

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

I'm sorry, I was asked if all the pylint warnings that are disabled in this PR are safe to disable, and at least one is not safe:

"unspecified-encoding" is not safe to ignore blindly for all files.

The reason is that files can contain UTF-8 characters or even non UTF-8 bytes > ord(127), that are not valid UTF-8 and this caused crashing the auto-cert-kit XAPI plugin last year:

LC_ALL=C python3.6 -c 'open("/usr/share/hwdata/pci.ids").read()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 90372: ordinal not in range(128)

This was then fixed in the Python3 port of the XCP https://github.com/xenserver/python-libs:

The description of it's xenserver/python-libs#22 has all information for it.

The summary is: For XAPI plugins (and maybe other python that do not set a valid, working UTF-8 locale when calling it), it is not safe to ignore this warning.

If none of the files in this PR are XAPI plugins, then those files can decide to ignore this warning for themselves for their entire file, even.

The lessons learnt xenserver/python-libs#22 from are:

  • When it is ensured that a valid UTF-8 locale is always set when that code runs, it would be ok, to disable that warning in that module
  • or, When it is ensured that the files read by that module can never contain only non-ASCII
    characters, then it would be ok as well to ignore it for that module.
  • Otherwise, it's not safe to ignore.

Also:

  • As long as it is ensured that all files read in a module only containe valid UTF-8, just adding encoding="utf-8" to all open calls that open files as text (not an issue for binary mode open) is fine.

Whenever valid UTF-8 is not 100% certain:

  • In this cases, it is advised to ensure that decoding errors are handled.
  • The easiest case, which is to just skip the invalid UTF-8 sequences when decoding the file during reading it, is to just add 'errors="ignore".

This a safe way (that drops invalid non-UTF-8 sequences) when reading a file in Python 3.6 when it is not sure if a valid UTF-8 local is set is:

LC_ALL=C python3.6 -c 'open("/usr/share/hwdata/pci.ids", encoding="utf-8", errors="ignore").read()'

OTOH, when the data should be preserved as-is:

  • In these cases, it is best to open the file in binary mode and then convert the code to work with bytes instead of str type for the data from the file.

But, to disable this warning globally like this PR likes to do it, is not safe.

"invalid-name",
"import-error",
"unnecessary-pass",
"unspecified-encoding",
Copy link
Collaborator

@bernhardkaindl bernhardkaindl Mar 12, 2024

Choose a reason for hiding this comment

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

"unspecified-encoding" is not safe to ignore blindly for all files.

The reason is that files can contain UTF-8 characters or even non UTF-8 bytes > ord(127), that are not valid UTF-8 and this caused crashing the auto-cert-kit Xapi plugin last year:

LC_ALL=C python3.6 -c 'open("/usr/share/hwdata/pci.ids").read()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 90372: ordinal not in range(128)

See my review comment #5424 (review) for the further follow-up on this discussion.

# pass pusbs in json to XAPI
self.assertEqual(sorted(pusbs), sorted(moc_results))

@nottest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@nottest

I think when renaming the prefix of the affected functions not be test_ but verify_, the @nottest decorator can be fully removed from all utility functions in this test, pylint disable is then not needed and, the decorator itself can be removed as well.

@bernhardkaindl bernhardkaindl requested review from bernhardkaindl and removed request for bernhardkaindl March 12, 2024 15:17
Copy link
Collaborator

@bernhardkaindl bernhardkaindl left a comment

Choose a reason for hiding this comment

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

Since this is only for the feature branch, I don't want to block the collaboration on the feature branch, but a few of the changes in this PR should be improved.

I noted them with the evidence from xenserver/python-libs#22 that it is not safe to ignore "unspecified-encoding" in globally like this PR does.

Generic remarks would be:
It is not good practise to tie global changes with the port of a specific project into one PR.

Nonetheless it is good to see that static analysis typing checks are now done and not all the warning as are disabled. However, in the future, more could be done to:

  1. Fix the cause of the warning when it is actually even easier and safer to do
  2. Consider that the maximum number of commits in a simple PR like this should e for good review. In its current state, it has 14 commits and 8 files which appears to be to many in a single PR.
    • Such PRs may be better split into preparatory PRs that lay the groundwork and ask questions on which warnings should be globally disabled, all at once.

Comment on lines +140 to +143
# cm.exception.code is int type whose format
# looks like "duplicated tag'vid' found,
# malformed line ALLOW:vid=056a vid=0314 class=03"
self.assertIn(msg, cm.exception.code) # pytype: disable=wrong-arg-types
Copy link
Collaborator

@bernhardkaindl bernhardkaindl Mar 12, 2024

Choose a reason for hiding this comment

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

This is inside an if msg: so we don't actually know from the code if this assertIn() really runs when it should.

If the green bar Codecov I see in the review is not due to a glitch, I see that this line in the test is executed (which is why it is a good idea to have code coverage for tests).

In 57fffaa#r1497078077 @gangj wrote:

I think it would be better to resolve this pylint warning.

Maybe this is a language barrier issue, but "resolve" means to fix, and this warning is now disabled, not fixed.

It's not obvious to me that is going on as wrong-arg-types would mean that the args don't have the same type, so something should be better explained ere.
The comment says that cm.exception.code is an is int type whose format looks like, but that is likely just very confusing language is normally int would refer to an integer. Instead, it seems like this wants to say that exception code is really the string that is quoted afterwards.

But as can be seen also, this is not actually a test function but a helper function, that is called by multiple tests, so the code coverage just says that one test covers this line, not all.

That means to clear up this confusion, it would be great to split move the code of this test function to the locations where it was called, and then it will be actually shown where msg is checked correctly.

As it stands, an if msg in a test function called by other functions is not a good idea, as it does not tell which tests check the msg. It's better to move the assertIn() to those locations that passed msg to the function, and then the test will be clearer.

There are some things that should not be done in a test, like looping over a list whose contents are not known. Such test code can result in no execution of the checks in the loop. Such guidelines should be adopted and implemented here.

@acefei
Copy link
Contributor Author

acefei commented Mar 13, 2024

Since this is only for the feature branch, I don't want to block the collaboration on the feature branch, but a few of the changes in this PR should be improved.

I noted them with the evidence from xenserver/python-libs#22 that it is not safe to ignore "unspecified-encoding" in globally like this PR does.

Generic remarks would be: It is not good practise to tie global changes with the port of a specific project into one PR.

Nonetheless it is good to see that static analysis typing checks are now done and not all the warning as are disabled. However, in the future, more could be done to:

  1. Fix the cause of the warning when it is actually even easier and safer to do

  2. Consider that the maximum number of commits in a simple PR like this should e for good review. In its current state, it has 14 commits and 8 files which appears to be to many in a single PR.

    • Such PRs may be better split into preparatory PRs that lay the groundwork and ask questions on which warnings should be globally disabled, all at once.

Thanks for your comment, I will fix the request changes in the separated PR for good review.

@liulinC liulinC merged commit 9b73950 into xapi-project:feature/py3 Mar 13, 2024
@github-actions
Copy link

pytype_reporter extracted 38 problem reports from pytype output

.

You can check the results of the job here

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.

7 participants