test: add hive_lib, unit and smoke tests#6
test: add hive_lib, unit and smoke tests#6alexandremattioli wants to merge 8 commits intofeature/ubuntu24-bootstrapfrom
Conversation
…mplementation checklist
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a test infrastructure for the build hive system, adding unit tests for cryptographic signing/validation and role suggestion logic, along with smoke tests for script compilation.
- Extracts shared utilities into
hive_lib.pyfor testability - Adds comprehensive unit tests for message signing and CloudStack role assignment
- Includes smoke tests to validate script compilation and basic functionality
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/bootstrap/ubuntu24/hive_lib.py | New shared library extracting role suggestion and message signing/validation logic for unit testing |
| tests/test_hive_lib_signing.py | Unit tests for HMAC-SHA256 message signing and validation, including tampering detection |
| tests/test_hive_lib_roles.py | Unit tests for CloudStack role suggestion logic based on peer configuration |
| tests/smoke/test_smoke_scripts.py | Smoke tests verifying Python script compilation and basic execution |
| tests/init.py | Test package marker file |
| pyproject.toml | Project configuration with pytest settings and Python path configuration |
| scripts/test/run_tests.sh | Test runner script for automated test execution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| def test_vnf_tester_when_broker_available(): | ||
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'} ] |
There was a problem hiding this comment.
Inconsistent spacing in list literal. Remove spaces after [ and before ] for consistency with PEP 8: [{'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'}].
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'} ] | |
| peers = [{'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'}] |
| 'packages': ['mysql-server','nfs-kernel-server','openjdk-17-jdk','git'], | ||
| 'config': {'db': 'mysql', 'nfs': True}, | ||
| 'reason': 'First management server needed' | ||
| } | ||
| if roles.get('cloudstack-builder', 0) < 2: | ||
| return { | ||
| 'role': 'cloudstack-builder', | ||
| 'packages': ['openjdk-17-jdk','maven','git','build-essential'], | ||
| 'config': {'build_threads': 8}, | ||
| 'reason': 'Increase build capacity' | ||
| } | ||
| if roles.get('kvm-hypervisor', 0) == 0: | ||
| return { | ||
| 'role': 'kvm-hypervisor', | ||
| 'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'], | ||
| 'config': {'virt_network': 'default'}, | ||
| 'reason': 'Provide hypervisor for functional tests' | ||
| } | ||
| if vnf_available and roles.get('vnf-tester', 0) == 0: | ||
| return { | ||
| 'role': 'vnf-tester', | ||
| 'packages': ['python3-requests','docker.io'], | ||
| 'config': {'broker_port': 8443}, | ||
| 'reason': 'Validate VNF broker operations' | ||
| } | ||
| return { | ||
| 'role': 'test-runner', | ||
| 'packages': ['python3-pytest','curl','git'], |
There was a problem hiding this comment.
Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['mysql-server', 'nfs-kernel-server', 'openjdk-17-jdk', 'git'].
| 'packages': ['mysql-server','nfs-kernel-server','openjdk-17-jdk','git'], | |
| 'config': {'db': 'mysql', 'nfs': True}, | |
| 'reason': 'First management server needed' | |
| } | |
| if roles.get('cloudstack-builder', 0) < 2: | |
| return { | |
| 'role': 'cloudstack-builder', | |
| 'packages': ['openjdk-17-jdk','maven','git','build-essential'], | |
| 'config': {'build_threads': 8}, | |
| 'reason': 'Increase build capacity' | |
| } | |
| if roles.get('kvm-hypervisor', 0) == 0: | |
| return { | |
| 'role': 'kvm-hypervisor', | |
| 'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'], | |
| 'config': {'virt_network': 'default'}, | |
| 'reason': 'Provide hypervisor for functional tests' | |
| } | |
| if vnf_available and roles.get('vnf-tester', 0) == 0: | |
| return { | |
| 'role': 'vnf-tester', | |
| 'packages': ['python3-requests','docker.io'], | |
| 'config': {'broker_port': 8443}, | |
| 'reason': 'Validate VNF broker operations' | |
| } | |
| return { | |
| 'role': 'test-runner', | |
| 'packages': ['python3-pytest','curl','git'], | |
| 'packages': ['mysql-server', 'nfs-kernel-server', 'openjdk-17-jdk', 'git'], | |
| 'config': {'db': 'mysql', 'nfs': True}, | |
| 'reason': 'First management server needed' | |
| } | |
| if roles.get('cloudstack-builder', 0) < 2: | |
| return { | |
| 'role': 'cloudstack-builder', | |
| 'packages': ['openjdk-17-jdk', 'maven', 'git', 'build-essential'], | |
| 'config': {'build_threads': 8}, | |
| 'reason': 'Increase build capacity' | |
| } | |
| if roles.get('kvm-hypervisor', 0) == 0: | |
| return { | |
| 'role': 'kvm-hypervisor', | |
| 'packages': ['qemu-kvm', 'libvirt-daemon-system', 'bridge-utils'], | |
| 'config': {'virt_network': 'default'}, | |
| 'reason': 'Provide hypervisor for functional tests' | |
| } | |
| if vnf_available and roles.get('vnf-tester', 0) == 0: | |
| return { | |
| 'role': 'vnf-tester', | |
| 'packages': ['python3-requests', 'docker.io'], | |
| 'config': {'broker_port': 8443}, | |
| 'reason': 'Validate VNF broker operations' | |
| } | |
| return { | |
| 'role': 'test-runner', | |
| 'packages': ['python3-pytest', 'curl', 'git'], |
| if vnf_available and roles.get('vnf-tester', 0) == 0: | ||
| return { | ||
| 'role': 'vnf-tester', | ||
| 'packages': ['python3-requests','docker.io'], |
There was a problem hiding this comment.
Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['python3-requests', 'docker.io'].
| 'packages': ['python3-requests','docker.io'], | |
| 'packages': ['python3-requests', 'docker.io'], |
| sig = message.get('sig', '') | ||
| if not isinstance(pl, dict): | ||
| return False | ||
| raw = json.dumps(pl, separators=(',',':')).encode('utf-8') |
There was a problem hiding this comment.
Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').
| raw = json.dumps(pl, separators=(',',':')).encode('utf-8') | |
| raw = json.dumps(pl, separators=(', ', ':')).encode('utf-8') |
|
|
||
| def test_sign_and_valid_roundtrip(): | ||
| pl = make_payload() | ||
| raw = json.dumps(pl, separators=(',',':')).encode('utf-8') |
There was a problem hiding this comment.
Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').
| if roles.get('cloudstack-builder', 0) < 2: | ||
| return { | ||
| 'role': 'cloudstack-builder', | ||
| 'packages': ['openjdk-17-jdk','maven','git','build-essential'], |
There was a problem hiding this comment.
Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['openjdk-17-jdk', 'maven', 'git', 'build-essential'].
| 'packages': ['openjdk-17-jdk','maven','git','build-essential'], | |
| 'packages': ['openjdk-17-jdk', 'maven', 'git', 'build-essential'], |
| if roles.get('kvm-hypervisor', 0) == 0: | ||
| return { | ||
| 'role': 'kvm-hypervisor', | ||
| 'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'], |
There was a problem hiding this comment.
Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['qemu-kvm', 'libvirt-daemon-system', 'bridge-utils'].
| 'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'], | |
| 'packages': ['qemu-kvm', 'libvirt-daemon-system', 'bridge-utils'], |
| } | ||
| return { | ||
| 'role': 'test-runner', | ||
| 'packages': ['python3-pytest','curl','git'], |
There was a problem hiding this comment.
Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['python3-pytest', 'curl', 'git'].
| 'packages': ['python3-pytest','curl','git'], | |
| 'packages': ['python3-pytest', 'curl', 'git'], |
|
|
||
| def test_invalid_magic(): | ||
| pl = make_payload() | ||
| raw = json.dumps(pl, separators=(',',':')).encode('utf-8') |
There was a problem hiding this comment.
Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').
| peers = [ {'role': 'management-server'} ] | ||
| advice = suggest_cloudstack_role(peers) | ||
| assert advice['role'] == 'cloudstack-builder' | ||
| assert 'maven' in advice['packages'] | ||
|
|
||
|
|
||
| def test_hypervisor_after_two_builders(): | ||
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'} ] | ||
| advice = suggest_cloudstack_role(peers) | ||
| assert advice['role'] == 'kvm-hypervisor' | ||
| assert 'qemu-kvm' in advice['packages'] | ||
|
|
||
|
|
||
| def test_vnf_tester_when_broker_available(): | ||
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'} ] |
There was a problem hiding this comment.
Inconsistent spacing in list literals. Lines 12, 19, and 26 have spaces after [ and before ] (e.g., [ {...} ]), while line 5 uses no spaces ([]). For consistency with PEP 8 and the multi-line list at lines 33-39, remove the extra spaces: [{'role': 'management-server'}].
| peers = [ {'role': 'management-server'} ] | |
| advice = suggest_cloudstack_role(peers) | |
| assert advice['role'] == 'cloudstack-builder' | |
| assert 'maven' in advice['packages'] | |
| def test_hypervisor_after_two_builders(): | |
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'} ] | |
| advice = suggest_cloudstack_role(peers) | |
| assert advice['role'] == 'kvm-hypervisor' | |
| assert 'qemu-kvm' in advice['packages'] | |
| def test_vnf_tester_when_broker_available(): | |
| peers = [ {'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'} ] | |
| peers = [{'role': 'management-server'}] | |
| advice = suggest_cloudstack_role(peers) | |
| assert advice['role'] == 'cloudstack-builder' | |
| assert 'maven' in advice['packages'] | |
| def test_hypervisor_after_two_builders(): | |
| peers = [{'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}] | |
| advice = suggest_cloudstack_role(peers) | |
| assert advice['role'] == 'kvm-hypervisor' | |
| assert 'qemu-kvm' in advice['packages'] | |
| def test_vnf_tester_when_broker_available(): | |
| peers = [{'role': 'management-server'}, {'role': 'cloudstack-builder'}, {'role': 'cloudstack-builder'}, {'role': 'kvm-hypervisor'}] |
Adds:
CI workflow deferred due to path creation issues (.github/workflows 404) — recommend creating directory and adding workflow next.
All tests pass locally (module-level compile + logic assertions).
Follow-ups: