Skip to content

Commit cb4c81b

Browse files
Merge pull request #196 from jweite-amazon/multi-vm-affinity-e2e
Multi-VM affinity e2e
2 parents 5ac795b + 0a65aaa commit cb4c81b

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,13 @@ e2e-essentials: $(GINKGO_V1) $(KUBECTL) e2e-cluster-templates kind-cluster ## Fu
280280
IMG=$(IMG_LOCAL) make generate-manifests docker-build docker-push
281281

282282
JOB ?= .*
283+
E2E_CONFIG ?= ${REPO_ROOT}/test/e2e/config/cloudstack.yaml
283284
run-e2e: e2e-essentials ## Run e2e testing. JOB is an optional REGEXP to select certainn test cases to run. e.g. JOB=PR-Blocking, JOB=Conformance
284285
$(KUBECTL) apply -f cloud-config.yaml && \
285286
cd test/e2e && \
286287
$(GINKGO_V1) -v -trace -tags=e2e -focus=$(JOB) -skip=Conformance -skipPackage=helpers -nodes=1 -noColor=false ./... -- \
287288
-e2e.artifacts-folder=${REPO_ROOT}/_artifacts \
288-
-e2e.config=${REPO_ROOT}/test/e2e/config/cloudstack.yaml \
289+
-e2e.config=${E2E_CONFIG} \
289290
-e2e.skip-resource-cleanup=false -e2e.use-existing-cluster=true
290291
kind delete clusters capi-test
291292

test/e2e/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,26 @@ The first step to running the e2e tests is setting up the required environment v
3333
| `CLOUDSTACK_TEMPLATE_NAME` | The machine template for both control plane and worke node VM instances | `kube-v1.20.10/ubuntu-2004` |
3434
| `CLOUDSTACK_SSH_KEY_NAME` | The name of SSH key added to the VM instances | `CAPCKeyPair6` |
3535

36-
You also have to export `CLOUDSTACK_B64ENCODED_SECRET` environment variable using this command `export CLOUDSTACK_B64ENCODED_SECRET=$(base64 -i cloud-config)` after creating `cloud-config` file with the following format.
36+
Default values for these variables are defined in *config/cloudstack.yaml*. This cloudstack.yaml can be completely overridden
37+
by providing make with the *fully qualified* path of another cloudstack.yaml via environment variable `E2E_CONFIG`
38+
39+
You will also have to define a k8s secret in a *cloud-config.yaml* file in the project root, containing a pointer to and
40+
credentials for the CloudStack backend that will be used for the test:
3741

3842
```
39-
[Global]
40-
api-key = XXXXX
41-
secret-key = XXXXX
42-
api-url = http://192.168.1.96:8080/client/api
43-
verify-ssl = true or false
43+
apiVersion: v1
44+
kind: Secret
45+
metadata:
46+
name: secret1
47+
namespace: default
48+
type: Opaque
49+
stringData:
50+
api-key: XXXX
51+
secret-key: XXXX
52+
api-url: http://1.2.3.4:8080/client/api
53+
verify-ssl: "false"
4454
```
45-
55+
This will be applied to the kind cluster that hosts CAPI/CAPC for the test, allowing CAPC to access the cluster.
4656
The api-key and secret-key can be found or generated at Home > Accounts > admin > Users > admin of the ACS management UI. `verify-ssl` is an optional flag and its default value is true. CAPC skips verifying the host SSL certificates when the flag is set to false.
4757

4858
### Running the e2e tests

test/e2e/affinity_group.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ func AffinityGroupSpec(ctx context.Context, inputGetter func() CommonSpecInput)
4545
BeforeEach(func() {
4646
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
4747
input = inputGetter()
48+
49+
csClient := CreateCloudStackClient(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
50+
zoneName := input.E2EConfig.GetVariable("CLOUDSTACK_ZONE_NAME")
51+
numHosts := GetHostCount(csClient, zoneName)
52+
if numHosts < 3 {
53+
Skip("Too few ACS hosts to run conclusive affinity tests. Please provision at least three for the zone.")
54+
}
55+
4856
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
4957
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
5058
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
@@ -91,8 +99,8 @@ func executeTest(ctx context.Context, input CommonSpecInput, namespace *corev1.N
9199
Namespace: namespace.Name,
92100
ClusterName: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
93101
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersion),
94-
ControlPlaneMachineCount: pointer.Int64Ptr(1),
95-
WorkerMachineCount: pointer.Int64Ptr(1),
102+
ControlPlaneMachineCount: pointer.Int64Ptr(3),
103+
WorkerMachineCount: pointer.Int64Ptr(2),
96104
},
97105
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"),
98106
WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),

test/e2e/common.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ func CheckAffinityGroupsDeleted(client *cloudstack.CloudStackClient, affinityIds
287287
return nil
288288
}
289289

290+
func GetHostCount(client *cloudstack.CloudStackClient, zoneName string) int {
291+
pz := client.Zone.NewListZonesParams()
292+
pz.SetName(zoneName)
293+
listZonesResponse, err := client.Zone.ListZones(pz)
294+
Expect(err).To(BeNil(), "error listing zones")
295+
Expect(listZonesResponse.Count).To(Equal(1), "no zones, or more than one zone resolve to zone name %s", zoneName)
296+
zoneId := listZonesResponse.Zones[0].Id
297+
298+
ph := client.Host.NewListHostsParams()
299+
ph.SetZoneid(zoneId)
300+
ph.SetHypervisor("KVM")
301+
ph.SetResourcestate("Enabled")
302+
ph.SetState("Up")
303+
listHostsResponse, err := client.Host.ListHosts(ph)
304+
Expect(err).To(BeNil(), "error listing hosts")
305+
return listHostsResponse.Count
306+
}
307+
290308
func CheckAffinityGroup(client *cloudstack.CloudStackClient, clusterName string, affinityType string) []string {
291309
By("Listing all machines")
292310
p := client.VirtualMachine.NewListVirtualMachinesParams()

0 commit comments

Comments
 (0)