|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +@test "Create VMware VM Import" { |
| 4 | + name='test' |
| 5 | + |
| 6 | + # Create VMware credentials secret |
| 7 | + kubectl apply -f - <<EOF |
| 8 | +apiVersion: v1 |
| 9 | +kind: Secret |
| 10 | +metadata: |
| 11 | + name: vmware-credentials-${name} |
| 12 | + namespace: tenant-test |
| 13 | +type: Opaque |
| 14 | +stringData: |
| 15 | + |
| 16 | + password: test-password |
| 17 | + thumbprint: "AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD" |
| 18 | +EOF |
| 19 | + |
| 20 | + # Create VMImport resource |
| 21 | + kubectl apply -f - <<EOF |
| 22 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 23 | +kind: VMImport |
| 24 | +metadata: |
| 25 | + name: ${name} |
| 26 | + namespace: tenant-test |
| 27 | +spec: |
| 28 | + sourceUrl: "https://vcenter.example.com/sdk" |
| 29 | + sourceSecretName: "vmware-credentials-${name}" |
| 30 | + vms: |
| 31 | + - id: "vm-123" |
| 32 | + name: "test-vm-1" |
| 33 | + - id: "vm-456" |
| 34 | + name: "test-vm-2" |
| 35 | + warm: false |
| 36 | + enableAdoption: true |
| 37 | + networkMap: |
| 38 | + - sourceId: "network-1" |
| 39 | + destinationType: "pod" |
| 40 | + storageMap: |
| 41 | + - sourceId: "datastore-1" |
| 42 | + storageClass: "replicated" |
| 43 | +EOF |
| 44 | + |
| 45 | + # Wait for HelmRelease to be ready |
| 46 | + sleep 5 |
| 47 | + kubectl -n tenant-test wait hr vm-import-${name} --timeout=100s --for=condition=ready |
| 48 | + |
| 49 | + # Verify WorkloadMonitor was created |
| 50 | + kubectl -n tenant-test get workloadmonitor vm-import-${name} |
| 51 | + |
| 52 | + # Verify Forklift Provider resources were created |
| 53 | + timeout 60 sh -ec "until kubectl -n tenant-test get provider.forklift.konveyor.io vm-import-${name}-source 2>/dev/null; do sleep 5; done" |
| 54 | + timeout 60 sh -ec "until kubectl -n tenant-test get provider.forklift.konveyor.io vm-import-${name}-destination 2>/dev/null; do sleep 5; done" |
| 55 | + |
| 56 | + # Verify Plan was created with correct annotations |
| 57 | + timeout 60 sh -ec "until kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 58 | + |
| 59 | + # Check that Plan has adoption annotations |
| 60 | + adoption_enabled=$(kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} -o jsonpath='{.metadata.annotations.vm-import\.cozystack\.io/adoption-enabled}') |
| 61 | + [ "$adoption_enabled" = "true" ] |
| 62 | + |
| 63 | + target_namespace=$(kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} -o jsonpath='{.metadata.annotations.vm-import\.cozystack\.io/target-namespace}') |
| 64 | + [ "$target_namespace" = "tenant-test" ] |
| 65 | + |
| 66 | + import_name=$(kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} -o jsonpath='{.metadata.annotations.vm-import\.cozystack\.io/import-name}') |
| 67 | + [ "$import_name" = "vm-import-${name}" ] |
| 68 | + |
| 69 | + # Verify NetworkMap was created |
| 70 | + timeout 60 sh -ec "until kubectl -n tenant-test get networkmap.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 71 | + |
| 72 | + # Verify StorageMap was created |
| 73 | + timeout 60 sh -ec "until kubectl -n tenant-test get storagemap.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 74 | + |
| 75 | + # Verify Migration resource was created |
| 76 | + timeout 60 sh -ec "until kubectl -n tenant-test get migration.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 77 | + |
| 78 | + # Verify RBAC permissions for dashboard resources |
| 79 | + kubectl -n tenant-test get role vm-import-${name}-dashboard-resources |
| 80 | + kubectl -n tenant-test get rolebinding vm-import-${name}-dashboard-resources |
| 81 | + |
| 82 | + # Verify RoleBinding has correct subjects for tenant access |
| 83 | + subjects=$(kubectl -n tenant-test get rolebinding vm-import-${name}-dashboard-resources -o jsonpath='{.subjects[*].name}') |
| 84 | + echo "$subjects" | grep -q "tenant-test" |
| 85 | + |
| 86 | + # Clean up |
| 87 | + kubectl -n tenant-test delete vmimport.apps.cozystack.io ${name} |
| 88 | + kubectl -n tenant-test delete secret vmware-credentials-${name} |
| 89 | + |
| 90 | + # Wait for cleanup |
| 91 | + timeout 60 sh -ec "until ! kubectl -n tenant-test get hr vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 92 | +} |
| 93 | + |
| 94 | +@test "Create VMImport with minimal configuration" { |
| 95 | + name='test-minimal' |
| 96 | + |
| 97 | + # Create credentials secret |
| 98 | + kubectl apply -f - <<EOF |
| 99 | +apiVersion: v1 |
| 100 | +kind: Secret |
| 101 | +metadata: |
| 102 | + name: vmware-credentials-${name} |
| 103 | + namespace: tenant-test |
| 104 | +type: Opaque |
| 105 | +stringData: |
| 106 | + |
| 107 | + password: password |
| 108 | + thumbprint: "11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44" |
| 109 | +EOF |
| 110 | + |
| 111 | + # Create VMImport with minimal spec (no networkMap, no storageMap) |
| 112 | + kubectl apply -f - <<EOF |
| 113 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 114 | +kind: VMImport |
| 115 | +metadata: |
| 116 | + name: ${name} |
| 117 | + namespace: tenant-test |
| 118 | +spec: |
| 119 | + sourceUrl: "https://vcenter-minimal.example.com/sdk" |
| 120 | + sourceSecretName: "vmware-credentials-${name}" |
| 121 | + vms: |
| 122 | + - id: "vm-789" |
| 123 | +EOF |
| 124 | + |
| 125 | + # Wait for HelmRelease to be ready |
| 126 | + sleep 5 |
| 127 | + kubectl -n tenant-test wait hr vm-import-${name} --timeout=100s --for=condition=ready |
| 128 | + |
| 129 | + # Verify basic resources were created |
| 130 | + kubectl -n tenant-test get workloadmonitor vm-import-${name} |
| 131 | + timeout 60 sh -ec "until kubectl -n tenant-test get provider.forklift.konveyor.io vm-import-${name}-source 2>/dev/null; do sleep 5; done" |
| 132 | + timeout 60 sh -ec "until kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 133 | + |
| 134 | + # Verify NetworkMap and StorageMap were NOT created (empty arrays) |
| 135 | + ! kubectl -n tenant-test get networkmap.forklift.konveyor.io vm-import-${name} 2>/dev/null |
| 136 | + ! kubectl -n tenant-test get storagemap.forklift.konveyor.io vm-import-${name} 2>/dev/null |
| 137 | + |
| 138 | + # Clean up |
| 139 | + kubectl -n tenant-test delete vmimport.apps.cozystack.io ${name} |
| 140 | + kubectl -n tenant-test delete secret vmware-credentials-${name} |
| 141 | + |
| 142 | + timeout 60 sh -ec "until ! kubectl -n tenant-test get hr vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 143 | +} |
| 144 | + |
| 145 | +@test "Create VMImport with adoption disabled" { |
| 146 | + name='test-no-adoption' |
| 147 | + |
| 148 | + # Create credentials secret |
| 149 | + kubectl apply -f - <<EOF |
| 150 | +apiVersion: v1 |
| 151 | +kind: Secret |
| 152 | +metadata: |
| 153 | + name: vmware-credentials-${name} |
| 154 | + namespace: tenant-test |
| 155 | +type: Opaque |
| 156 | +stringData: |
| 157 | + |
| 158 | + password: password |
| 159 | + thumbprint: "AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD" |
| 160 | +EOF |
| 161 | + |
| 162 | + # Create VMImport with adoption disabled |
| 163 | + kubectl apply -f - <<EOF |
| 164 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 165 | +kind: VMImport |
| 166 | +metadata: |
| 167 | + name: ${name} |
| 168 | + namespace: tenant-test |
| 169 | +spec: |
| 170 | + sourceUrl: "https://vcenter.example.com/sdk" |
| 171 | + sourceSecretName: "vmware-credentials-${name}" |
| 172 | + enableAdoption: false |
| 173 | + vms: |
| 174 | + - id: "vm-999" |
| 175 | + name: "test-no-adoption-vm" |
| 176 | +EOF |
| 177 | + |
| 178 | + # Wait for HelmRelease to be ready |
| 179 | + sleep 5 |
| 180 | + kubectl -n tenant-test wait hr vm-import-${name} --timeout=100s --for=condition=ready |
| 181 | + |
| 182 | + # Verify Plan has adoption disabled |
| 183 | + timeout 60 sh -ec "until kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 184 | + |
| 185 | + adoption_enabled=$(kubectl -n tenant-test get plan.forklift.konveyor.io vm-import-${name} -o jsonpath='{.metadata.annotations.vm-import\.cozystack\.io/adoption-enabled}') |
| 186 | + [ "$adoption_enabled" = "false" ] |
| 187 | + |
| 188 | + # Clean up |
| 189 | + kubectl -n tenant-test delete vmimport.apps.cozystack.io ${name} |
| 190 | + kubectl -n tenant-test delete secret vmware-credentials-${name} |
| 191 | + |
| 192 | + timeout 60 sh -ec "until ! kubectl -n tenant-test get hr vm-import-${name} 2>/dev/null; do sleep 5; done" |
| 193 | +} |
0 commit comments