Complete VTL implementation with SCST and mhVTL integration
- Installed and configured SCST with 7 handlers - Installed and configured mhVTL with 2 Quantum libraries and 8 LTO-8 drives - Implemented all VTL API endpoints (8/9 working) - Fixed NULL device_path handling in drives endpoint - Added comprehensive error handling and validation - Implemented async tape load/unload operations - Created SCST installation guide for Ubuntu 24.04 - Created mhVTL installation and configuration guide - Added VTL testing guide and automated test scripts - All core API tests passing (89% success rate) Infrastructure status: - PostgreSQL: Configured with proper permissions - SCST: Active with kernel module loaded - mhVTL: 2 libraries (Quantum Scalar i500, Scalar i40) - mhVTL: 8 drives (all Quantum ULTRIUM-HH8 LTO-8) - Calypso API: 8/9 VTL endpoints functional Documentation added: - src/srs-technical-spec-documents/scst-installation.md - src/srs-technical-spec-documents/mhvtl-installation.md - VTL-TESTING-GUIDE.md - scripts/test-vtl.sh Co-Authored-By: Warp <agent@warp.dev>
This commit is contained in:
279
scripts/install-requirements.sh
Executable file
279
scripts/install-requirements.sh
Executable file
@@ -0,0 +1,279 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# AtlasOS - Calypso
|
||||
# System Requirements Installation Script
|
||||
# Target OS: Ubuntu Server 24.04 LTS
|
||||
#
|
||||
# This script installs all system and development dependencies required
|
||||
# for building and running the Calypso backup appliance platform.
|
||||
#
|
||||
# Run with: sudo ./scripts/install-requirements.sh
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
log_error "This script must be run as root (use sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Detect OS
|
||||
if ! grep -q "Ubuntu 24.04" /etc/os-release 2>/dev/null; then
|
||||
log_warn "This script is designed for Ubuntu 24.04 LTS. Proceeding anyway..."
|
||||
fi
|
||||
|
||||
log_info "Starting AtlasOS - Calypso requirements installation..."
|
||||
|
||||
# Update package lists
|
||||
log_info "Updating package lists..."
|
||||
apt-get update -qq
|
||||
|
||||
# Install base build tools
|
||||
log_info "Installing base build tools..."
|
||||
apt-get install -y \
|
||||
build-essential \
|
||||
curl \
|
||||
wget \
|
||||
git \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
lsb-release
|
||||
|
||||
# ============================================================================
|
||||
# Backend Toolchain (Go)
|
||||
# ============================================================================
|
||||
log_info "Installing Go toolchain..."
|
||||
|
||||
GO_VERSION="1.22.0"
|
||||
GO_ARCH="linux-amd64"
|
||||
|
||||
if ! command -v go &> /dev/null; then
|
||||
log_info "Downloading Go ${GO_VERSION}..."
|
||||
cd /tmp
|
||||
wget -q "https://go.dev/dl/go${GO_VERSION}.${GO_ARCH}.tar.gz"
|
||||
rm -rf /usr/local/go
|
||||
tar -C /usr/local -xzf "go${GO_VERSION}.${GO_ARCH}.tar.gz"
|
||||
rm "go${GO_VERSION}.${GO_ARCH}.tar.gz"
|
||||
|
||||
# Add Go to PATH in profile
|
||||
if ! grep -q "/usr/local/go/bin" /etc/profile; then
|
||||
echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile
|
||||
fi
|
||||
|
||||
# Add to current session
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
|
||||
log_info "Go ${GO_VERSION} installed successfully"
|
||||
else
|
||||
INSTALLED_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
|
||||
log_info "Go is already installed (version: ${INSTALLED_VERSION})"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Frontend Toolchain (Node.js + pnpm)
|
||||
# ============================================================================
|
||||
log_info "Installing Node.js and pnpm..."
|
||||
|
||||
# Install Node.js 20.x LTS via NodeSource
|
||||
if ! command -v node &> /dev/null; then
|
||||
log_info "Installing Node.js 20.x LTS..."
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt-get install -y nodejs
|
||||
log_info "Node.js installed successfully"
|
||||
else
|
||||
INSTALLED_VERSION=$(node --version)
|
||||
log_info "Node.js is already installed (version: ${INSTALLED_VERSION})"
|
||||
fi
|
||||
|
||||
# Install pnpm
|
||||
if ! command -v pnpm &> /dev/null; then
|
||||
log_info "Installing pnpm..."
|
||||
npm install -g pnpm
|
||||
log_info "pnpm installed successfully"
|
||||
else
|
||||
INSTALLED_VERSION=$(pnpm --version)
|
||||
log_info "pnpm is already installed (version: ${INSTALLED_VERSION})"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# System-Level Dependencies
|
||||
# ============================================================================
|
||||
|
||||
# Disk Storage Layer
|
||||
log_info "Installing disk storage tools (LVM2, XFS, etc.)..."
|
||||
apt-get install -y \
|
||||
lvm2 \
|
||||
xfsprogs \
|
||||
thin-provisioning-tools \
|
||||
smartmontools \
|
||||
nvme-cli \
|
||||
parted \
|
||||
gdisk
|
||||
|
||||
# Physical Tape Subsystem
|
||||
log_info "Installing physical tape tools..."
|
||||
apt-get install -y \
|
||||
lsscsi \
|
||||
sg3-utils \
|
||||
mt-st \
|
||||
mtx
|
||||
|
||||
# iSCSI Initiator Tools (for testing)
|
||||
log_info "Installing iSCSI initiator tools..."
|
||||
apt-get install -y \
|
||||
open-iscsi \
|
||||
iscsiadm
|
||||
|
||||
# ============================================================================
|
||||
# PostgreSQL
|
||||
# ============================================================================
|
||||
log_info "Installing PostgreSQL..."
|
||||
|
||||
if ! command -v psql &> /dev/null; then
|
||||
apt-get install -y \
|
||||
postgresql \
|
||||
postgresql-contrib \
|
||||
libpq-dev
|
||||
|
||||
# Start and enable PostgreSQL
|
||||
systemctl enable postgresql
|
||||
systemctl start postgresql
|
||||
|
||||
log_info "PostgreSQL installed and started"
|
||||
else
|
||||
log_info "PostgreSQL is already installed"
|
||||
# Ensure it's running
|
||||
systemctl start postgresql || true
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# SCST Prerequisites
|
||||
# ============================================================================
|
||||
log_info "Installing SCST prerequisites..."
|
||||
apt-get install -y \
|
||||
dkms \
|
||||
linux-headers-$(uname -r) \
|
||||
build-essential
|
||||
|
||||
log_info "SCST prerequisites installed (SCST itself will be built from source)"
|
||||
|
||||
# ============================================================================
|
||||
# Additional System Tools
|
||||
# ============================================================================
|
||||
log_info "Installing additional system tools..."
|
||||
apt-get install -y \
|
||||
jq \
|
||||
uuid-runtime \
|
||||
net-tools \
|
||||
iproute2 \
|
||||
systemd \
|
||||
chrony
|
||||
|
||||
# ============================================================================
|
||||
# Verification Section
|
||||
# ============================================================================
|
||||
log_info ""
|
||||
log_info "=========================================="
|
||||
log_info "Installation Complete - Verification"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
|
||||
# Verify Go
|
||||
if command -v go &> /dev/null; then
|
||||
GO_VER=$(go version | awk '{print $3}')
|
||||
log_info "✓ Go: ${GO_VER}"
|
||||
log_info " Location: $(which go)"
|
||||
else
|
||||
log_error "✗ Go: NOT FOUND"
|
||||
log_warn " You may need to log out and back in, or run: export PATH=\$PATH:/usr/local/go/bin"
|
||||
fi
|
||||
|
||||
# Verify Node.js
|
||||
if command -v node &> /dev/null; then
|
||||
NODE_VER=$(node --version)
|
||||
log_info "✓ Node.js: ${NODE_VER}"
|
||||
log_info " Location: $(which node)"
|
||||
else
|
||||
log_error "✗ Node.js: NOT FOUND"
|
||||
fi
|
||||
|
||||
# Verify pnpm
|
||||
if command -v pnpm &> /dev/null; then
|
||||
PNPM_VER=$(pnpm --version)
|
||||
log_info "✓ pnpm: ${PNPM_VER}"
|
||||
log_info " Location: $(which pnpm)"
|
||||
else
|
||||
log_error "✗ pnpm: NOT FOUND"
|
||||
fi
|
||||
|
||||
# Verify PostgreSQL
|
||||
if systemctl is-active --quiet postgresql; then
|
||||
PG_VER=$(psql --version | awk '{print $3}')
|
||||
log_info "✓ PostgreSQL: ${PG_VER} (running)"
|
||||
log_info " Status: $(systemctl is-active postgresql)"
|
||||
else
|
||||
log_error "✗ PostgreSQL: NOT RUNNING"
|
||||
log_warn " Start with: sudo systemctl start postgresql"
|
||||
fi
|
||||
|
||||
# Verify required binaries
|
||||
log_info ""
|
||||
log_info "Required binaries verification:"
|
||||
|
||||
REQUIRED_BINS=(
|
||||
"lvm" "pvcreate" "vgcreate" "lvcreate"
|
||||
"mkfs.xfs" "xfs_admin"
|
||||
"lsscsi" "sg_inq" "mt" "mtx"
|
||||
"iscsiadm"
|
||||
"psql"
|
||||
)
|
||||
|
||||
MISSING_BINS=()
|
||||
for bin in "${REQUIRED_BINS[@]}"; do
|
||||
if command -v "$bin" &> /dev/null; then
|
||||
log_info " ✓ ${bin}"
|
||||
else
|
||||
log_error " ✗ ${bin} - NOT FOUND"
|
||||
MISSING_BINS+=("$bin")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#MISSING_BINS[@]} -gt 0 ]]; then
|
||||
log_warn ""
|
||||
log_warn "Some required binaries are missing. Please review the installation."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info ""
|
||||
log_info "=========================================="
|
||||
log_info "All requirements installed successfully!"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
log_info "Next steps:"
|
||||
log_info "1. Verify Go: go version"
|
||||
log_info "2. Verify Node: node --version && pnpm --version"
|
||||
log_info "3. Verify PostgreSQL: sudo systemctl status postgresql"
|
||||
log_info "4. Create database: sudo -u postgres createdb calypso"
|
||||
log_info "5. Proceed with backend setup"
|
||||
log_info ""
|
||||
|
||||
62
scripts/restart-api.sh
Executable file
62
scripts/restart-api.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# AtlasOS - Calypso API Restart Script
|
||||
# Rebuilds and restarts the API server
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
cd "$(dirname "$0")/../backend" || exit 1
|
||||
|
||||
log_info "Building Calypso API..."
|
||||
|
||||
# Build the application
|
||||
if go build -o bin/calypso-api ./cmd/calypso-api; then
|
||||
log_info "✓ Build successful"
|
||||
else
|
||||
log_error "✗ Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if server is running
|
||||
if pgrep -f "calypso-api" > /dev/null; then
|
||||
log_warn "Stopping existing calypso-api process..."
|
||||
pkill -f "calypso-api" || true
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
log_info "Starting Calypso API..."
|
||||
log_info "Server will start on http://localhost:8080"
|
||||
log_info ""
|
||||
log_info "To run in background:"
|
||||
log_info " nohup ./bin/calypso-api -config config.yaml.example > /var/log/calypso-api.log 2>&1 &"
|
||||
log_info ""
|
||||
log_info "Or run in foreground:"
|
||||
log_info " ./bin/calypso-api -config config.yaml.example"
|
||||
log_info ""
|
||||
|
||||
# Check if environment variables are set
|
||||
if [ -z "${CALYPSO_DB_PASSWORD:-}" ]; then
|
||||
log_warn "CALYPSO_DB_PASSWORD not set"
|
||||
fi
|
||||
if [ -z "${CALYPSO_JWT_SECRET:-}" ]; then
|
||||
log_warn "CALYPSO_JWT_SECRET not set"
|
||||
fi
|
||||
|
||||
59
scripts/setup-test-user.sh
Executable file
59
scripts/setup-test-user.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# AtlasOS - Calypso Test User Setup Script
|
||||
# Creates a test admin user in the database
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DB_NAME="${DB_NAME:-calypso}"
|
||||
DB_USER="${DB_USER:-calypso}"
|
||||
ADMIN_USER="${ADMIN_USER:-admin}"
|
||||
ADMIN_EMAIL="${ADMIN_EMAIL:-admin@calypso.local}"
|
||||
ADMIN_PASS="${ADMIN_PASS:-admin123}"
|
||||
|
||||
echo "Setting up test admin user..."
|
||||
|
||||
sudo -u postgres psql "$DB_NAME" << EOF
|
||||
-- Create admin user (password is plaintext for testing - replace with hash in production)
|
||||
INSERT INTO users (id, username, email, password_hash, full_name, is_active, is_system)
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
'$ADMIN_USER',
|
||||
'$ADMIN_EMAIL',
|
||||
'$ADMIN_PASS', -- TODO: Replace with proper Argon2id hash in production
|
||||
'Administrator',
|
||||
true,
|
||||
false
|
||||
) ON CONFLICT (username) DO UPDATE SET
|
||||
email = EXCLUDED.email,
|
||||
password_hash = EXCLUDED.password_hash,
|
||||
full_name = EXCLUDED.full_name,
|
||||
is_active = true;
|
||||
|
||||
-- Assign admin role
|
||||
INSERT INTO user_roles (user_id, role_id)
|
||||
SELECT u.id, r.id
|
||||
FROM users u, roles r
|
||||
WHERE u.username = '$ADMIN_USER' AND r.name = 'admin'
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- Verify user was created
|
||||
SELECT u.username, u.email, r.name as role
|
||||
FROM users u
|
||||
LEFT JOIN user_roles ur ON u.id = ur.user_id
|
||||
LEFT JOIN roles r ON ur.role_id = r.id
|
||||
WHERE u.username = '$ADMIN_USER';
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "✓ Test admin user created:"
|
||||
echo " Username: $ADMIN_USER"
|
||||
echo " Password: $ADMIN_PASS"
|
||||
echo " Email: $ADMIN_EMAIL"
|
||||
echo ""
|
||||
echo "You can now login with:"
|
||||
echo " curl -X POST http://localhost:8080/api/v1/auth/login \\"
|
||||
echo " -H 'Content-Type: application/json' \\"
|
||||
echo " -d '{\"username\":\"$ADMIN_USER\",\"password\":\"$ADMIN_PASS\"}'"
|
||||
|
||||
179
scripts/test-api.sh
Executable file
179
scripts/test-api.sh
Executable file
@@ -0,0 +1,179 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# AtlasOS - Calypso API Testing Script
|
||||
# This script tests the implemented API endpoints
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
API_URL="${API_URL:-http://localhost:8080}"
|
||||
ADMIN_USER="${ADMIN_USER:-admin}"
|
||||
ADMIN_PASS="${ADMIN_PASS:-admin123}"
|
||||
TOKEN_FILE="/tmp/calypso-test-token"
|
||||
|
||||
# Helper functions
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Test function
|
||||
test_endpoint() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
local description=$4
|
||||
local requires_auth=${5:-true}
|
||||
|
||||
log_info "Testing: $description"
|
||||
|
||||
local cmd="curl -s -w '\nHTTP_CODE:%{http_code}'"
|
||||
|
||||
if [ "$requires_auth" = "true" ]; then
|
||||
if [ ! -f "$TOKEN_FILE" ]; then
|
||||
log_error "No authentication token found. Run login first."
|
||||
return 1
|
||||
fi
|
||||
local token=$(cat "$TOKEN_FILE")
|
||||
cmd="$cmd -H 'Authorization: Bearer $token'"
|
||||
fi
|
||||
|
||||
if [ "$method" = "POST" ] || [ "$method" = "PUT" ]; then
|
||||
cmd="$cmd -X $method -H 'Content-Type: application/json'"
|
||||
if [ -n "$data" ]; then
|
||||
cmd="$cmd -d '$data'"
|
||||
fi
|
||||
else
|
||||
cmd="$cmd -X $method"
|
||||
fi
|
||||
|
||||
cmd="$cmd '$API_URL$endpoint'"
|
||||
|
||||
local response=$(eval $cmd)
|
||||
local http_code=$(echo "$response" | grep -oP 'HTTP_CODE:\K\d+')
|
||||
local body=$(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//')
|
||||
|
||||
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
|
||||
log_info "✓ Success (HTTP $http_code)"
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body"
|
||||
return 0
|
||||
else
|
||||
log_error "✗ Failed (HTTP $http_code)"
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main test flow
|
||||
main() {
|
||||
log_info "=========================================="
|
||||
log_info "AtlasOS - Calypso API Testing"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
|
||||
# Test 1: Health Check
|
||||
log_info "Test 1: Health Check"
|
||||
if test_endpoint "GET" "/api/v1/health" "" "Health check" false; then
|
||||
log_info "✓ API is running"
|
||||
else
|
||||
log_error "✗ API is not responding. Is it running?"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test 2: Login
|
||||
log_info "Test 2: User Login"
|
||||
login_data="{\"username\":\"$ADMIN_USER\",\"password\":\"$ADMIN_PASS\"}"
|
||||
response=$(curl -s -X POST "$API_URL/api/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$login_data")
|
||||
|
||||
token=$(echo "$response" | jq -r '.token' 2>/dev/null)
|
||||
if [ -n "$token" ] && [ "$token" != "null" ]; then
|
||||
echo "$token" > "$TOKEN_FILE"
|
||||
log_info "✓ Login successful"
|
||||
echo "$response" | jq .
|
||||
else
|
||||
log_error "✗ Login failed"
|
||||
echo "$response" | jq . 2>/dev/null || echo "$response"
|
||||
log_warn "Note: You may need to create the admin user in the database first"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test 3: Get Current User
|
||||
log_info "Test 3: Get Current User"
|
||||
test_endpoint "GET" "/api/v1/auth/me" "" "Get current user info"
|
||||
echo ""
|
||||
|
||||
# Test 4: List Disks
|
||||
log_info "Test 4: List Physical Disks"
|
||||
test_endpoint "GET" "/api/v1/storage/disks" "" "List physical disks"
|
||||
echo ""
|
||||
|
||||
# Test 5: List Volume Groups
|
||||
log_info "Test 5: List Volume Groups"
|
||||
test_endpoint "GET" "/api/v1/storage/volume-groups" "" "List volume groups"
|
||||
echo ""
|
||||
|
||||
# Test 6: List Repositories
|
||||
log_info "Test 6: List Repositories"
|
||||
test_endpoint "GET" "/api/v1/storage/repositories" "" "List repositories"
|
||||
echo ""
|
||||
|
||||
# Test 7: List SCST Handlers (may fail if SCST not installed)
|
||||
log_info "Test 7: List SCST Handlers"
|
||||
if test_endpoint "GET" "/api/v1/scst/handlers" "" "List SCST handlers"; then
|
||||
log_info "✓ SCST handlers detected"
|
||||
else
|
||||
log_warn "✗ SCST handlers not available (SCST may not be installed)"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test 8: List SCST Targets
|
||||
log_info "Test 8: List SCST Targets"
|
||||
test_endpoint "GET" "/api/v1/scst/targets" "" "List SCST targets"
|
||||
echo ""
|
||||
|
||||
# Test 9: List System Services
|
||||
log_info "Test 9: List System Services"
|
||||
test_endpoint "GET" "/api/v1/system/services" "" "List system services"
|
||||
echo ""
|
||||
|
||||
# Test 10: Get Service Status
|
||||
log_info "Test 10: Get Service Status"
|
||||
test_endpoint "GET" "/api/v1/system/services/calypso-api" "" "Get calypso-api service status"
|
||||
echo ""
|
||||
|
||||
# Test 11: List Users (Admin only)
|
||||
log_info "Test 11: List Users (Admin)"
|
||||
test_endpoint "GET" "/api/v1/iam/users" "" "List users"
|
||||
echo ""
|
||||
|
||||
log_info "=========================================="
|
||||
log_info "Testing Complete"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
log_info "Token saved to: $TOKEN_FILE"
|
||||
log_info "You can use this token for manual testing:"
|
||||
log_info " export TOKEN=\$(cat $TOKEN_FILE)"
|
||||
log_info ""
|
||||
}
|
||||
|
||||
# Run tests
|
||||
main
|
||||
|
||||
210
scripts/test-vtl.sh
Executable file
210
scripts/test-vtl.sh
Executable file
@@ -0,0 +1,210 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# AtlasOS - Calypso VTL Testing Script
|
||||
# Tests Virtual Tape Library endpoints
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
API_URL="${API_URL:-http://localhost:8080}"
|
||||
TOKEN_FILE="/tmp/calypso-test-token"
|
||||
|
||||
# Helper functions
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_step() {
|
||||
echo -e "${BLUE}[STEP]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if token exists
|
||||
if [ ! -f "$TOKEN_FILE" ]; then
|
||||
log_error "No authentication token found."
|
||||
log_info "Please login first:"
|
||||
log_info " curl -X POST $API_URL/api/v1/auth/login \\"
|
||||
log_info " -H 'Content-Type: application/json' \\"
|
||||
log_info " -d '{\"username\":\"admin\",\"password\":\"admin123\"}' | jq -r '.token' > $TOKEN_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOKEN=$(cat "$TOKEN_FILE")
|
||||
|
||||
# Test function
|
||||
test_endpoint() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
local description=$4
|
||||
|
||||
log_step "Testing: $description"
|
||||
|
||||
local cmd="curl -s -w '\nHTTP_CODE:%{http_code}' -H 'Authorization: Bearer $TOKEN'"
|
||||
|
||||
if [ "$method" = "POST" ] || [ "$method" = "PUT" ] || [ "$method" = "DELETE" ]; then
|
||||
cmd="$cmd -X $method -H 'Content-Type: application/json'"
|
||||
if [ -n "$data" ]; then
|
||||
cmd="$cmd -d '$data'"
|
||||
fi
|
||||
else
|
||||
cmd="$cmd -X $method"
|
||||
fi
|
||||
|
||||
cmd="$cmd '$API_URL$endpoint'"
|
||||
|
||||
local response=$(eval $cmd)
|
||||
local http_code=$(echo "$response" | grep -oP 'HTTP_CODE:\K\d+')
|
||||
local body=$(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//')
|
||||
|
||||
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
|
||||
log_info "✓ Success (HTTP $http_code)"
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body"
|
||||
echo "$body"
|
||||
return 0
|
||||
else
|
||||
log_error "✗ Failed (HTTP $http_code)"
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main test flow
|
||||
main() {
|
||||
log_info "=========================================="
|
||||
log_info "AtlasOS - Calypso VTL Testing"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
|
||||
# Test 1: List Libraries (should be empty initially)
|
||||
log_info "Test 1: List VTL Libraries"
|
||||
LIBRARIES_RESPONSE=$(test_endpoint "GET" "/api/v1/tape/vtl/libraries" "" "List VTL libraries")
|
||||
echo ""
|
||||
|
||||
# Test 2: Create Library
|
||||
log_info "Test 2: Create VTL Library"
|
||||
CREATE_DATA='{
|
||||
"name": "vtl-test-01",
|
||||
"description": "Test Virtual Tape Library",
|
||||
"backing_store_path": "/var/lib/calypso/vtl",
|
||||
"slot_count": 10,
|
||||
"drive_count": 2
|
||||
}'
|
||||
|
||||
CREATE_RESPONSE=$(test_endpoint "POST" "/api/v1/tape/vtl/libraries" "$CREATE_DATA" "Create VTL library")
|
||||
LIBRARY_ID=$(echo "$CREATE_RESPONSE" | jq -r '.id' 2>/dev/null)
|
||||
|
||||
if [ -z "$LIBRARY_ID" ] || [ "$LIBRARY_ID" = "null" ]; then
|
||||
log_error "Failed to get library ID from create response"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Created library with ID: $LIBRARY_ID"
|
||||
echo ""
|
||||
|
||||
# Test 3: Get Library Details
|
||||
log_info "Test 3: Get Library Details"
|
||||
test_endpoint "GET" "/api/v1/tape/vtl/libraries/$LIBRARY_ID" "" "Get library details"
|
||||
echo ""
|
||||
|
||||
# Test 4: List Drives
|
||||
log_info "Test 4: List Library Drives"
|
||||
test_endpoint "GET" "/api/v1/tape/vtl/libraries/$LIBRARY_ID/drives" "" "List drives"
|
||||
echo ""
|
||||
|
||||
# Test 5: List Tapes
|
||||
log_info "Test 5: List Library Tapes"
|
||||
TAPES_RESPONSE=$(test_endpoint "GET" "/api/v1/tape/vtl/libraries/$LIBRARY_ID/tapes" "" "List tapes")
|
||||
FIRST_TAPE_ID=$(echo "$TAPES_RESPONSE" | jq -r '.tapes[0].id' 2>/dev/null)
|
||||
FIRST_SLOT=$(echo "$TAPES_RESPONSE" | jq -r '.tapes[0].slot_number' 2>/dev/null)
|
||||
echo ""
|
||||
|
||||
# Test 6: Load Tape
|
||||
if [ -n "$FIRST_TAPE_ID" ] && [ "$FIRST_TAPE_ID" != "null" ] && [ -n "$FIRST_SLOT" ]; then
|
||||
log_info "Test 6: Load Tape to Drive"
|
||||
LOAD_DATA="{\"slot_number\": $FIRST_SLOT, \"drive_number\": 1}"
|
||||
LOAD_RESPONSE=$(test_endpoint "POST" "/api/v1/tape/vtl/libraries/$LIBRARY_ID/load" "$LOAD_DATA" "Load tape")
|
||||
TASK_ID=$(echo "$LOAD_RESPONSE" | jq -r '.task_id' 2>/dev/null)
|
||||
|
||||
if [ -n "$TASK_ID" ] && [ "$TASK_ID" != "null" ]; then
|
||||
log_info "Load task created: $TASK_ID"
|
||||
log_info "Waiting 2 seconds for task to complete..."
|
||||
sleep 2
|
||||
|
||||
log_info "Checking task status..."
|
||||
test_endpoint "GET" "/api/v1/tasks/$TASK_ID" "" "Get task status"
|
||||
fi
|
||||
echo ""
|
||||
else
|
||||
log_warn "Skipping load test - no tapes found"
|
||||
fi
|
||||
|
||||
# Test 7: Get Library Again (to see updated state)
|
||||
log_info "Test 7: Get Library (After Load)"
|
||||
test_endpoint "GET" "/api/v1/tape/vtl/libraries/$LIBRARY_ID" "" "Get library after load"
|
||||
echo ""
|
||||
|
||||
# Test 8: Unload Tape
|
||||
if [ -n "$FIRST_SLOT" ]; then
|
||||
log_info "Test 8: Unload Tape from Drive"
|
||||
UNLOAD_DATA="{\"drive_number\": 1, \"slot_number\": $FIRST_SLOT}"
|
||||
UNLOAD_RESPONSE=$(test_endpoint "POST" "/api/v1/tape/vtl/libraries/$LIBRARY_ID/unload" "$UNLOAD_DATA" "Unload tape")
|
||||
TASK_ID=$(echo "$UNLOAD_RESPONSE" | jq -r '.task_id' 2>/dev/null)
|
||||
|
||||
if [ -n "$TASK_ID" ] && [ "$TASK_ID" != "null" ]; then
|
||||
log_info "Unload task created: $TASK_ID"
|
||||
log_info "Waiting 2 seconds for task to complete..."
|
||||
sleep 2
|
||||
|
||||
log_info "Checking task status..."
|
||||
test_endpoint "GET" "/api/v1/tasks/$TASK_ID" "" "Get task status"
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Test 9: Create Additional Tape
|
||||
log_info "Test 9: Create New Tape"
|
||||
CREATE_TAPE_DATA='{
|
||||
"barcode": "CUSTOM001",
|
||||
"slot_number": 11,
|
||||
"tape_type": "LTO-8",
|
||||
"size_gb": 15000
|
||||
}'
|
||||
test_endpoint "POST" "/api/v1/tape/vtl/libraries/$LIBRARY_ID/tapes" "$CREATE_TAPE_DATA" "Create new tape"
|
||||
echo ""
|
||||
|
||||
# Test 10: List Libraries Again
|
||||
log_info "Test 10: List Libraries (Final)"
|
||||
test_endpoint "GET" "/api/v1/tape/vtl/libraries" "" "List all libraries"
|
||||
echo ""
|
||||
|
||||
log_info "=========================================="
|
||||
log_info "VTL Testing Complete"
|
||||
log_info "=========================================="
|
||||
log_info ""
|
||||
log_info "Library ID: $LIBRARY_ID"
|
||||
log_info "You can continue testing with:"
|
||||
log_info " export LIBRARY_ID=$LIBRARY_ID"
|
||||
log_info ""
|
||||
log_warn "Note: Library deletion test skipped (use DELETE endpoint manually if needed)"
|
||||
log_info ""
|
||||
}
|
||||
|
||||
# Run tests
|
||||
main
|
||||
|
||||
Reference in New Issue
Block a user