Loading...
Loading...
Guides testing and code quality for kcli. Use when writing tests, running linting, or validating changes before committing.
npx skill4agent add karmab/kcli kcli-testing# Create virtual environment
python3 -m venv venv
. venv/bin/activate
# Install in development mode
pip install -e .
# Install with all provider dependencies
pip install -e ".[all]"# Lint all Python files
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/
# Lint specific file
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/config.pyE402W504E721E722E741# Check spelling
codespell kvirt/ -L "aks"
# The -L flag ignores specific words (aks is Azure Kubernetes Service)# Run the same linting as CI
.github/linting.shkvirt/bottle.py~/.kcli/# Setup for testing
sudo mkdir -p /var/lib/libvirt/images
sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images
mkdir -p ~/.kcli
ssh-keygen -t rsa -N '' -f ~/.kcli/id_rsa
kcli create pool -p /var/lib/libvirt/images default# Run all tests
python -m pytest tests/test_kvirt.py -v
# Run specific test class
python -m pytest tests/test_kvirt.py::TestK -v
# Run specific test method
python -m pytest tests/test_kvirt.py::TestK::test_create_vm -v
# Run with output capture disabled
python -m pytest tests/test_kvirt.py -v -s# Full integration test (used in CI)
.github/testing.shtests/test_kvirt.pyclass TestK:
@classmethod
def setup_class(self):
# Initialize Kconfig and provider
self.config = Kconfig()
self.k = self.config.k
def test_list(self):
result = self.k.list()
assert result is not None
def test_create_vm(self):
result = self.config.create_vm(...)
assert result["result"] == "success"
@classmethod
def teardown_class(self):
# Cleanup resources
self.k.delete_network(...)
self.k.delete_pool(...).github/test_plan.ymlparameters:
pool: default
image: cirros
network: mynetwork
profile: myprofile
{{ image }}:
type: image
pool: {{ pool }}
{{ network }}:
type: network
cidr: 192.168.125.0/24
dhcp: true
{{ profile }}:
type: profile
image: {{ image }}
memory: 2048
numcpus: 2
myvm:
profile: {{ profile }}
pool: {{ pool }}kcli create plan -f .github/test_plan.yml test_plan
kcli list plan | grep test_plan
kcli delete plan --yes test_plan# 1. Run linting
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/
# 2. Check spelling
codespell kvirt/ -L "aks"
# 3. Run tests (if libvirt available)
python -m pytest tests/test_kvirt.py -v
# 4. Test your specific change manually
kcli <your-command># Test with debug output
kcli -d list vm
kcli -d create vm -i cirros testvm
kcli -d delete vm --yes testvm# Create minimal test plan
cat > /tmp/test.yml << 'EOF'
testvm:
image: cirros
memory: 512
EOF
kcli create plan -f /tmp/test.yml mytest
kcli info plan mytest
kcli delete plan --yes mytest.github/workflows/ci.yml.flake8[flake8]
max-line-length = 120
ignore = E722,E402,E741,W504,E721,E501E501TestK{'result': 'success'}{'result': 'failure', 'reason': ...}teardown_classdef test_new_feature(self):
# Setup
result = self.k.create_something(name="test-unique-name")
# Assert
assert result["result"] == "success"
# Cleanup (or use teardown_class)
self.k.delete_something("test-unique-name")