Skip to content

Commit

Permalink
e2e: bastion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilienM committed Feb 21, 2024
1 parent 2382d56 commit 00efecd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hack/ci/cloud-init/controller.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
openstack flavor create --ram 4192 --disk 20 --ephemeral 5 --vcpus 2 --public --id 2 m1.small --property hw_rng:allowed='True'
openstack flavor delete m1.medium
openstack flavor create --ram 6144 --disk 20 --ephemeral 5 --vcpus 2 --public --id 3 m1.medium --property hw_rng:allowed='True'
# Create an additional flavor for the e2e tests that will be used by the e2e bastion tests
openstack flavor create --ram 512 --disk 1 --ephemeral 1 --vcpus 1 --public --id 10 m1.tiny.alt --property hw_rng:allowed='True'

# Adjust the CPU quota
openstack quota set --cores 32 demo
Expand Down
1 change: 1 addition & 0 deletions test/e2e/data/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ variables:
EXP_CLUSTER_RESOURCE_SET: "true"
OPENSTACK_BASTION_IMAGE_NAME: "cirros-0.6.1-x86_64-disk"
OPENSTACK_BASTION_MACHINE_FLAVOR: "m1.tiny"
OPENSTACK_BASTION_MACHINE_FLAVOR_ALT: "m1.tiny.alt"
OPENSTACK_CLOUD: "capo-e2e"
OPENSTACK_CLOUD_ADMIN: "capo-e2e-admin"
OPENSTACK_CLOUD_CACERT_B64: "Cg=="
Expand Down
1 change: 1 addition & 0 deletions test/e2e/shared/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
KubernetesVersion = "KUBERNETES_VERSION"
CCMPath = "CCM"
CCMResources = "CCM_RESOURCES"
OpenStackBastionFlavorAlt = "OPENSTACK_BASTION_MACHINE_FLAVOR_ALT"
OpenStackCloudYAMLFile = "OPENSTACK_CLOUD_YAML_FILE"
OpenStackCloud = "OPENSTACK_CLOUD"
OpenStackCloudAdmin = "OPENSTACK_CLOUD_ADMIN"
Expand Down
84 changes: 84 additions & 0 deletions test/e2e/suites/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,90 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
// We expect 4 security group rules that allow Calico traffic on the control plane
// from both the control plane and worker machines and vice versa, that makes 8 rules.
Expect(calicoSGRules).To(Equal(8))

shared.Logf("Check the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
bastionSpec := openStackCluster.Spec.Bastion
bastionServerName := openStackCluster.Status.Bastion.Name
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName})
Expect(err).NotTo(HaveOccurred())
Expect(bastionServer).To(HaveLen(1))

shared.Logf("Disable the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterDisabledBastion := openStackCluster.DeepCopy()
openStackClusterDisabledBastion.Spec.Bastion.Enabled = false
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterDisabledBastion)).To(Succeed())
Eventually(
func() (bool, error) {
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName})
Expect(err).NotTo(HaveOccurred())
if len(bastionServer) == 0 {
return true, nil
}
return false, errors.New("bastion server still exists")
}, 2*time.Minute, 10*time.Second,
).Should(BeTrue())
Eventually(
func() (bool, error) {
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
if openStackCluster.Status.Bastion == nil {
return true, nil
}
return false, errors.New("bastion still exists in status")
}, 2*time.Minute, 10*time.Second,
).Should(BeTrue())

shared.Logf("Delete the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterWithoutBastion := openStackCluster.DeepCopy()
openStackClusterWithoutBastion.Spec.Bastion = nil
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterWithoutBastion)).To(Succeed())
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
Eventually(
func() (bool, error) {
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
if openStackCluster.Spec.Bastion == nil {
return true, nil
}
return false, errors.New("bastion still exists in spec")
}, 2*time.Minute, 10*time.Second,
).Should(BeTrue())

shared.Logf("Create the bastion with a new flavor")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterWithNewBastionFlavor := openStackCluster.DeepCopy()
openStackClusterWithNewBastionFlavor.Spec.Bastion = bastionSpec
openStackClusterWithNewBastionFlavor.Spec.Bastion.Instance.Flavor = e2eCtx.E2EConfig.GetVariable(shared.OpenStackBastionFlavorAlt)
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterWithNewBastionFlavor)).To(Succeed())
Eventually(
func() (bool, error) {
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
if openStackCluster.Status.Bastion == nil {
return false, errors.New("bastion does not exist in status")
}
bastionServerName := openStackCluster.Status.Bastion.Name
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName, Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackBastionFlavorAlt)})
Expect(err).NotTo(HaveOccurred())
if len(bastionServer) == 1 {
return true, nil
}
return false, errors.New("new bastion server does not exist")
}, 2*time.Minute, 10*time.Second,
).Should(BeTrue())
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
Expect(openStackCluster.Spec.Bastion).To(Equal(openStackClusterWithNewBastionFlavor.Spec.Bastion))
Expect(openStackCluster.Status.Bastion).NotTo(BeNil())
Expect(openStackCluster.Status.Bastion.State).To(Equal("ACTIVE"))
})
})

Expand Down

0 comments on commit 00efecd

Please sign in to comment.