cleanup
Some checks failed
particle-os CI / Test particle-os (push) Failing after 1s
particle-os CI / Integration Test (push) Has been skipped
particle-os CI / Security & Quality (push) Failing after 1s
Test particle-os Basic Functionality / test-basic (push) Failing after 1s
particle-os CI / Build and Release (push) Has been skipped
Some checks failed
particle-os CI / Test particle-os (push) Failing after 1s
particle-os CI / Integration Test (push) Has been skipped
particle-os CI / Security & Quality (push) Failing after 1s
Test particle-os Basic Functionality / test-basic (push) Failing after 1s
particle-os CI / Build and Release (push) Has been skipped
This commit is contained in:
parent
d782a8a4fb
commit
126ee1a849
76 changed files with 1683 additions and 470 deletions
123
scripts/test-scripts/test-vm-with-virsh.sh
Executable file
123
scripts/test-scripts/test-vm-with-virsh.sh
Executable file
|
|
@ -0,0 +1,123 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Test VM with virsh script for debian-atomic-bootable image
|
||||
# This allows us to use virt-manager to monitor the boot process
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
VM_NAME="debian-atomic-test"
|
||||
IMAGE_PATH="./debian-atomic-bootable-test.img"
|
||||
VM_MEMORY="2048" # 2GB
|
||||
VM_VCPUS="2"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Functions
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if image exists
|
||||
if [[ ! -f "$IMAGE_PATH" ]]; then
|
||||
log_error "Image not found: $IMAGE_PATH"
|
||||
log_info "Please run the integration test first to generate the image"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if VM already exists
|
||||
if virsh list --all | grep -q "$VM_NAME"; then
|
||||
log_warning "VM '$VM_NAME' already exists"
|
||||
read -p "Do you want to remove it and create a new one? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
log_info "Removing existing VM..."
|
||||
virsh destroy "$VM_NAME" 2>/dev/null || true
|
||||
virsh undefine "$VM_NAME" 2>/dev/null || true
|
||||
else
|
||||
log_info "Using existing VM. You can start it with: virsh start $VM_NAME"
|
||||
log_info "Or view it in virt-manager"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get absolute path for image
|
||||
IMAGE_ABSOLUTE_PATH=$(realpath "$IMAGE_PATH")
|
||||
log_info "Using image: $IMAGE_ABSOLUTE_PATH"
|
||||
|
||||
# Create VM XML definition
|
||||
log_info "Creating VM '$VM_NAME' with virsh..."
|
||||
|
||||
# Create a temporary XML file for the VM
|
||||
TEMP_XML=$(mktemp)
|
||||
cat > "$TEMP_XML" << EOF
|
||||
<domain type='kvm'>
|
||||
<name>$VM_NAME</name>
|
||||
<memory unit='MiB'>$VM_MEMORY</memory>
|
||||
<vcpu>$VM_VCPUS</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-8.2'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<devices>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='$IMAGE_ABSOLUTE_PATH'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
<!-- Network interface removed for boot testing -->
|
||||
<graphics type='vnc' port='-1'/>
|
||||
<console type='pty'/>
|
||||
</devices>
|
||||
</domain>
|
||||
EOF
|
||||
|
||||
# Define the VM
|
||||
if virsh define "$TEMP_XML"; then
|
||||
log_info "✅ VM '$VM_NAME' defined successfully!"
|
||||
|
||||
# Clean up temp file
|
||||
rm "$TEMP_XML"
|
||||
|
||||
log_info ""
|
||||
log_info "To manage the VM:"
|
||||
log_info " - Start: virsh start $VM_NAME"
|
||||
log_info " - Stop: virsh shutdown $VM_NAME"
|
||||
log_info " - View: virt-manager"
|
||||
log_info " - Console: virsh console $VM_NAME"
|
||||
log_info ""
|
||||
log_info "The VM will use the raw disk image directly, so any changes"
|
||||
log_info "to the image will be reflected in the VM."
|
||||
log_info ""
|
||||
log_info "Starting VM now..."
|
||||
|
||||
if virsh start "$VM_NAME"; then
|
||||
log_info "VM started! You can now:"
|
||||
log_info "1. Open virt-manager to see the graphical console"
|
||||
log_info "2. Use 'virsh console $VM_NAME' for text console"
|
||||
log_info "3. Monitor with 'virsh list --all'"
|
||||
log_info ""
|
||||
log_info "Current VM status:"
|
||||
virsh list --all | grep "$VM_NAME"
|
||||
else
|
||||
log_error "Failed to start VM"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
log_error "Failed to define VM"
|
||||
rm "$TEMP_XML"
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue