Skip to content

KVM: remove unused methods, fields and PMD-reported private members - #14238

Open
wido wants to merge 5 commits into
apache:mainfrom
wido:kvm-remove-dead-methods
Open

wido wants to merge 5 commits into
apache:mainfrom
wido:kvm-remove-dead-methods

Conversation

@wido

@wido wido commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Description

This PR removes methods, fields and private members from the KVM agent plugin that have no callers anywhere in the tree, tests included. It is independent of the other two cleanup PRs and applies directly to main.

The commits are split per class so that individual pieces can be dropped in review:

  • LibvirtComputingResource: getHostDistro, isCentosHost, isDirectAttachedNetwork, isSnapshotSupported, post_default_network_rules, getPoolManager. The last one shares its name with a function in security_group.py; the script is still invoked through other paths, only the unused Java wrapper for that sub-command goes.
  • LibvirtVMDef: twelve getters and setters, plus the fields that only they touched and that the generated XML never read (_kernel, _initrd, _root, _cmdline, _shareable, _deferAttach, _hostNetType and the HostNicType enum, and the long unused _ipAddr).
  • KVMHABase: the four NfsStoragePool setters, getHBFile, getHBFolder and runScriptRetry.
  • Smaller removals in LibvirtSecretDef (three getters, the class itself is in use), LibvirtStorageVolumeXMLParser, LibvirtStorageAdaptor, KVMStorageProcessor, LibvirtMigrateCommandWrapper, the two multipath adapters, QemuImg and KVMHostInfo.
  • A final commit removes the private members reported by PMD's UnusedPrivateMethod, UnusedPrivateField and UnusedLocalVariable rules, each verified by hand. Two PMD findings were false positives (getPifs, getOvsPifs are called) and two write-only fields in LibvirtVMDef (_crash, _readonly) were deliberately kept because dropping them would silently turn their setters into no-ops.

Methods that are called only by unit tests were intentionally left alone. Removing them would mean removing test assertions, and two of them are recent CLVM helpers that may belong to in-flight work.

No functional behaviour changes.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Each candidate was checked with a whole-word search across every file type in the tree, and for same-named declarations elsewhere that could indicate a call through an interface or superclass. Two candidates had hits outside their file and both turned out to be unrelated (a local variable of the same name in StatsCollector, and the Python function in security_group.py).

After the removals every touched file was scanned for fields that had lost their last reference and for unused imports. The KVM plugin compiles with JDK 17, Checkstyle is clean and the unit tests pass (892 tests, 0 failures). A full-tree mvn -T 1C -Dsimulator test on the combined cleanup branches passes: 147 modules, 13,188 tests, 0 failures.

How did you try to break this feature and the system with this change?

Ran PMD over the module to cross-check the manual scan, and treated every PMD finding as a claim to verify rather than as ground truth; one finding (conn in KVMStorageProcessor) turned out to have a side-effecting assignment and was kept.

None of these has a caller anywhere in the tree, tests included:
getHostDistro, isCentosHost, isDirectAttachedNetwork,
isSnapshotSupported, post_default_network_rules and getPoolManager.

post_default_network_rules shares its name with a function in
security_group.py; the script is still invoked through other paths,
only the unused Java wrapper for that sub-command goes.
Getters and setters that nothing calls, tests included: getVcpu,
getEngine, setBootKernel, setSharable, setAttachDeferred,
isAttachDeferred, setHostNetType, getHostNetType, getNetSourceMode,
getVirtualPortType, getVirtualPortInterfaceId and isLinkStateUp.

With them go the fields that only they touched and that the generated
XML never read: _kernel, _initrd, _root, _cmdline, _shareable,
_deferAttach, _hostNetType and the HostNicType enum, plus the long
unused _ipAddr.
The four NfsStoragePool setters, getHBFile, getHBFolder and
runScriptRetry have no callers anywhere in the tree.
Each of these has no caller anywhere in the tree, tests included:

  LibvirtSecretDef: getEphemeral, getVolumeVolume, getCephName
  LibvirtStorageVolumeXMLParser: getBackingFileNameIfExists
  LibvirtStorageAdaptor: storagePoolRefresh
  KVMStorageProcessor: getDefaultStorageScriptsDir
  LibvirtMigrateCommandWrapper: hasClvmDestinationDisks
  MultipathSCSIAdapterBase / FiberChannelAdapter: isStoragePoolTypeSupported
  QemuImg: supportsSkipZeros
  KVMHostInfo: getTotalCpus
Running PMD's UnusedPrivateMethod, UnusedPrivateField and
UnusedLocalVariable rules over the module reported these, each verified
by hand against the sources and the tests:

  LibvirtComputingResource: field host, field gson, method
    executeBashScript, local devNum in configureIpAddresses, local
    brname in destroyNetworkRulesForVM
  LibvirtConnection: field s_connection
  LibvirtStorageAdaptor: field _manageSnapshotPath and its lookup of
    managesnapshot.sh, which the adaptor never ran
  LibvirtMigrateCommandWrapper: method isClvmBlockDevice
  LibvirtCopyToSecondaryStorageWrapper: local success
  LibvirtCreateDiskOnlyVMSnapshotCommandWrapper: two unused copies of
    the volume list

Left as reported: getPifs and getOvsPifs are called and were flagged in
error, and the write-only fields _crash and _readonly in LibvirtVMDef
are kept because dropping them would silently turn their setters into
no-ops.
@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 19.91%. Comparing base (602d9ec) to head (3f5f1cc).

Additional details and impacted files
@@            Coverage Diff             @@
##               main   #14238    +/-   ##
==========================================
  Coverage     19.91%   19.91%            
- Complexity    20200    20201     +1     
==========================================
  Files          6373     6373            
  Lines        577230   577025   -205     
  Branches      70696    70684    -12     
==========================================
- Hits         114974   114942    -32     
+ Misses       449690   449524   -166     
+ Partials      12566    12559     -7     
Flag Coverage Δ
uitests 3.71% <ø> (ø)
unittests 21.19% <ø> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

1 participant