Skip to content

test: add hive_lib, unit and smoke tests#6

Open
alexandremattioli wants to merge 8 commits intofeature/ubuntu24-bootstrapfrom
feature/hive-tests
Open

test: add hive_lib, unit and smoke tests#6
alexandremattioli wants to merge 8 commits intofeature/ubuntu24-bootstrapfrom
feature/hive-tests

Conversation

@alexandremattioli
Copy link
Copy Markdown
Owner

Adds:

  • scripts/bootstrap/ubuntu24/hive_lib.py for isolated role suggestion and signing helpers
  • Unit tests for role suggestion and HMAC signing/validation
  • Smoke tests: py_compile of key scripts and advisor --help, message bridge invocation
  • pyproject.toml configuring pytest addopts
  • scripts/test/run_tests.sh convenience runner

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:

  • Introduce .github/workflows/tests.yml once directory availability confirmed
  • Expand smoke tests to simulate IDENTIFY -> ADVICE roundtrip with ephemeral sockets
  • Add negative tests for malformed envelopes.

Copilot AI review requested due to automatic review settings November 8, 2025 02:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.py for 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'} ]
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

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'}].

Suggested change
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'}]

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +48
'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'],
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['mysql-server', 'nfs-kernel-server', 'openjdk-17-jdk', 'git'].

Suggested change
'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'],

Copilot uses AI. Check for mistakes.
if vnf_available and roles.get('vnf-tester', 0) == 0:
return {
'role': 'vnf-tester',
'packages': ['python3-requests','docker.io'],
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['python3-requests', 'docker.io'].

Suggested change
'packages': ['python3-requests','docker.io'],
'packages': ['python3-requests', 'docker.io'],

Copilot uses AI. Check for mistakes.
sig = message.get('sig', '')
if not isinstance(pl, dict):
return False
raw = json.dumps(pl, separators=(',',':')).encode('utf-8')
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').

Suggested change
raw = json.dumps(pl, separators=(',',':')).encode('utf-8')
raw = json.dumps(pl, separators=(', ', ':')).encode('utf-8')

Copilot uses AI. Check for mistakes.

def test_sign_and_valid_roundtrip():
pl = make_payload()
raw = json.dumps(pl, separators=(',',':')).encode('utf-8')
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').

Copilot uses AI. Check for mistakes.
if roles.get('cloudstack-builder', 0) < 2:
return {
'role': 'cloudstack-builder',
'packages': ['openjdk-17-jdk','maven','git','build-essential'],
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['openjdk-17-jdk', 'maven', 'git', 'build-essential'].

Suggested change
'packages': ['openjdk-17-jdk','maven','git','build-essential'],
'packages': ['openjdk-17-jdk', 'maven', 'git', 'build-essential'],

Copilot uses AI. Check for mistakes.
if roles.get('kvm-hypervisor', 0) == 0:
return {
'role': 'kvm-hypervisor',
'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'],
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['qemu-kvm', 'libvirt-daemon-system', 'bridge-utils'].

Suggested change
'packages': ['qemu-kvm','libvirt-daemon-system','bridge-utils'],
'packages': ['qemu-kvm', 'libvirt-daemon-system', 'bridge-utils'],

Copilot uses AI. Check for mistakes.
}
return {
'role': 'test-runner',
'packages': ['python3-pytest','curl','git'],
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing spaces after commas in list literal. Per PEP 8, add spaces after commas: ['python3-pytest', 'curl', 'git'].

Suggested change
'packages': ['python3-pytest','curl','git'],
'packages': ['python3-pytest', 'curl', 'git'],

Copilot uses AI. Check for mistakes.

def test_invalid_magic():
pl = make_payload()
raw = json.dumps(pl, separators=(',',':')).encode('utf-8')
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

Missing space after comma in tuple literal. Per PEP 8, add space after comma: separators=(',', ':').

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +26
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'} ]
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

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'}].

Suggested change
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'}]

Copilot uses AI. Check for mistakes.
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.

2 participants