Skip to content

cephfs-top, qa: Remove unnecessary global statements in tests#62567

Merged
tchaikov merged 2 commits intoceph:mainfrom
tchaikov:qa-remove-unused-global
Mar 31, 2025
Merged

cephfs-top, qa: Remove unnecessary global statements in tests#62567
tchaikov merged 2 commits intoceph:mainfrom
tchaikov:qa-remove-unused-global

Conversation

@tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Mar 30, 2025

Removes unused global statements to fix flake8 F824 errors.

Recent flake8 runs were failing with:

./tasks/radosgw_admin.py:330:5: F824 `global log` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:99:5: F824 `global incompat_paths` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:164:5: F824 `global backward_compat` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:165:5: F824 `global fast_shouldnt_skip` is unused: name is never assigned in scope

Since these variables are only being referenced and not assigned within their scopes, the global declarations are unnecessary and can be safely removed. This change:

  • Removes all flagged global statements
  • Fixes the failing flake8 checks in the CI pipeline
  • Maintains the original code behavior as variable references still work without the global keyword

The global keyword is only needed when assigning to global variables within a function scope, not when simply referencing them.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

Removes unused `global` statements from Python test files to fix flake8
F824 errors.

Recent flake8 runs were failing with:

```
./tasks/radosgw_admin.py:330:5: F824 `global log` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:99:5: F824 `global incompat_paths` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:164:5: F824 `global backward_compat` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:165:5: F824 `global fast_shouldnt_skip` is unused: name is never assigned in scope
```

Since these variables are only being referenced and not assigned within
their scopes, the `global` declarations are unnecessary and can be
safely removed. This change:

- Removes all flagged `global` statements
- Fixes the failing flake8 checks in the CI pipeline
- Maintains the original code behavior as variable references still work
  without the `global` keyword

The `global` keyword is only needed when assigning to global variables
within a function scope, not when simply referencing them.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@tchaikov tchaikov added the tests label Mar 30, 2025
@tchaikov
Copy link
Contributor Author

tchaikov commented Mar 30, 2025

for an instance of the test failure addressed by this change, see https://jenkins.ceph.com/job/ceph-pull-requests/154956/consoleFull#868021901e840cee4-f4a4-4183-81dd-42855615f2c1:

flake8: install_deps /home/jenkins-build/build/workspace/ceph-pull-requests/qa> python -I -m pip install flake8
flake8: freeze /home/jenkins-build/build/workspace/ceph-pull-requests/qa> python -m pip freeze --all
flake8: flake8==7.2.0,mccabe==0.7.0,pip==25.0.1,pycodestyle==2.13.0,pyflakes==3.3.0,setuptools==75.8.0,wheel==0.45.1
flake8: commands[0] /home/jenkins-build/build/workspace/ceph-pull-requests/qa> flake8 --select=F,E9 --exclude=venv,.tox
./tasks/radosgw_admin.py:330:5: F824 `global log` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:99:5: F824 `global incompat_paths` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:164:5: F824 `global backward_compat` is unused: name is never assigned in scope
./workunits/dencoder/test_readable.py:165:5: F824 `global fast_shouldnt_skip` is unused: name is never assigned in scope
flake8: exit 1 (3.86 seconds) /home/jenkins-build/build/workspace/ceph-pull-requests/qa> flake8 --select=F,E9 --exclude=venv,.tox pid=2309377
flake8: FAIL ✖ in 9.14 seconds
...
  flake8: FAIL code 1 (9.14=setup[5.28]+cmd[3.86] seconds)
  mypy: OK (32.21=setup[14.89]+cmd[17.31] seconds)
  deadsymlinks: OK (2.19=setup[2.04]+cmd[0.14] seconds)
  evaluation failed :( (43.85 seconds)
...
The following tests FAILED:
	 28 - run-tox-cephfs-top (Failed)
	289 - run-tox-qa (Failed)

Recent flake8 runs were failing with:
```
py3: flake8==7.2.0,mccabe==0.7.0,pip==25.0.1,pycodestyle==2.13.0,pyflakes==3.3.0,setuptools==75.8.0,wheel==0.45.1
py3: commands[0] /home/jenkins-build/build/workspace/ceph-pull-requests/src/tools/cephfs/top> flake8 --ignore=W503 --max-line-length=100 cephfs-top
cephfs-top:344:9: F824 `global fs_list` is unused: name is never assigned in scope
cephfs-top:466:13: F824 `global current_states` is unused: name is never assigned in scope
cephfs-top:872:9: F824 `global metrics_dict` is unused: name is never assigned in scope
cephfs-top:872:9: F824 `global current_states` is unused: name is never assigned in scope
cephfs-top:911:9: F824 `global fs_list` is unused: name is never assigned in scope
cephfs-top:981:9: F824 `global current_states` is unused: name is never assigned in scope
cephfs-top:1126:13: F824 `global current_states` is unused: name is never assigned in scope
py3: exit 1 (0.77 seconds) /home/jenkins-build/build/workspace/ceph-pull-requests/src/tools/cephfs/top> flake8 --ignore=W503 --max-line-length=100 cephfs-top pid=2309605
  py3: FAIL code 1 (8.15=setup[7.38]+cmd[0.77] seconds)
  evaluation failed :( (8.24 seconds)
```

Since these variables are only being referenced and not assigned within
their scopes, the `global` declarations are unnecessary and can be
safely removed. This change:

- Removes all flagged `global` statements
- Fixes the failing flake8 checks in the CI pipeline
- Maintains the original code behavior as variable references still work without the `global` keyword

The `global` keyword is only needed when assigning to global variables
within a function scope, not when simply referencing them.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@github-actions github-actions bot added the cephfs Ceph File System label Mar 30, 2025
@tchaikov tchaikov changed the title qa: Remove unnecessary global statements in tests cephfs-top, qa: Remove unnecessary global statements in tests Mar 30, 2025
@ronen-fr
Copy link
Contributor

LGTM (but I cannot approve a CephFS PR...)

@tchaikov
Copy link
Contributor Author

tchaikov commented Mar 31, 2025

LGTM (but I cannot approve a CephFS PR...)

@ronen-fr hi Ronen, thank you for your review and approval. i will wait for 2 more days before merging this change. it's urgent, because the CI tests in all PRs are now failing.

@phlogistonjohn
Copy link
Contributor

I think you should feel free to merge as soon as you are ready as tests continue to fail without these changes.

Copy link
Contributor

@cbodley cbodley left a comment

Choose a reason for hiding this comment

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

ack for rgw, thanks

@tchaikov tchaikov merged commit 72f4cc5 into ceph:main Mar 31, 2025
15 of 16 checks passed
@tchaikov tchaikov deleted the qa-remove-unused-global branch March 31, 2025 15:04
@cbodley
Copy link
Contributor

cbodley commented Apr 1, 2025

i believe this needs backports for reef:

The following tests FAILED:
28 - run-tox-cephfs-top (Failed)
34 - run-rbd-unit-tests-127.sh (Failed)
263 - run-tox-qa (Failed)

and squid:

The following tests FAILED:
28 - run-tox-cephfs-top (Failed)
273 - run-tox-qa (Failed)

edit: i'll prepare them

Copy link
Member

@joscollin joscollin left a comment

Choose a reason for hiding this comment

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

Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants