From 0f1f5d97abe645236b5d2bb4b0f3ed3656b837ee Mon Sep 17 00:00:00 2001 From: Daniel Spangenberg Date: Thu, 8 Nov 2018 16:03:51 +0100 Subject: [PATCH] Validate machine status in e2e --- pkg/cloud/aws/actuators/machine/utils.go | 5 +-- test/machines/machines_test.go | 19 ++++------ test/machines/utils.go | 46 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 test/machines/utils.go diff --git a/pkg/cloud/aws/actuators/machine/utils.go b/pkg/cloud/aws/actuators/machine/utils.go index 7a3921c0aa..ea47e466a9 100644 --- a/pkg/cloud/aws/actuators/machine/utils.go +++ b/pkg/cloud/aws/actuators/machine/utils.go @@ -193,10 +193,7 @@ func ProviderConfigFromMachine(machine *clusterv1.Machine) (*providerconfigv1.AW // ProviderStatusFromMachine gets the machine provider status from the specified machine. func ProviderStatusFromMachine(codec codec, m *clusterv1.Machine) (*providerconfigv1.AWSMachineProviderStatus, error) { status := &providerconfigv1.AWSMachineProviderStatus{} - var err error - if m.Status.ProviderStatus != nil { - err = codec.DecodeProviderStatus(m.Status.ProviderStatus, status) - } + err := codec.DecodeProviderStatus(m.Status.ProviderStatus, status) return status, err } diff --git a/test/machines/machines_test.go b/test/machines/machines_test.go index 14adcdc736..f776d12d92 100644 --- a/test/machines/machines_test.go +++ b/test/machines/machines_test.go @@ -23,6 +23,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + machineutils "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine" awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client" ) @@ -36,19 +37,6 @@ func TestCart(t *testing.T) { RunSpecs(t, "Machine Suite") } -func createSecretAndWait(f *framework.Framework, secret *apiv1.Secret) { - _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Create(secret) - Expect(err).NotTo(HaveOccurred()) - - err = wait.Poll(framework.PollInterval, framework.PoolTimeout, func() (bool, error) { - if _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{}); err != nil { - return false, nil - } - return true, nil - }) - Expect(err).NotTo(HaveOccurred()) -} - var _ = framework.SigKubeDescribe("Machines", func() { var testNamespace *apiv1.Namespace f, err := framework.NewFramework() @@ -204,6 +192,11 @@ var _ = framework.SigKubeDescribe("Machines", func() { })) }) + By("Checking machine status", func() { + condition := getMachineCondition(f, testMachine) + Expect(condition.Reason).To(Equal(machineutils.MachineCreationSucceeded)) + }) + f.DeleteMachineAndWait(testMachine, acw) }) diff --git a/test/machines/utils.go b/test/machines/utils.go new file mode 100644 index 0000000000..ccfa7fabf0 --- /dev/null +++ b/test/machines/utils.go @@ -0,0 +1,46 @@ +package machines + +import ( + . "github.com/onsi/gomega" + apiv1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" + + "github.com/openshift/cluster-api-actuator-pkg/pkg/e2e/framework" + + providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1" + machineutils "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine" +) + +func createSecretAndWait(f *framework.Framework, secret *apiv1.Secret) { + _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Create(secret) + Expect(err).NotTo(HaveOccurred()) + + err = wait.Poll(framework.PollInterval, framework.PoolTimeout, func() (bool, error) { + if _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{}); err != nil { + return false, nil + } + return true, nil + }) + Expect(err).NotTo(HaveOccurred()) +} + +func getMachineProviderStatus(f *framework.Framework, machine *clusterv1alpha1.Machine) *providerconfigv1.AWSMachineProviderStatus { + machine, err := f.CAPIClient.ClusterV1alpha1().Machines(machine.Namespace).Get(machine.Name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + + codec, err := providerconfigv1.NewCodec() + Expect(err).NotTo(HaveOccurred()) + + machineProviderStatus, err := machineutils.ProviderStatusFromMachine(codec, machine) + Expect(err).NotTo(HaveOccurred()) + + return machineProviderStatus +} + +func getMachineCondition(f *framework.Framework, machine *clusterv1alpha1.Machine) providerconfigv1.AWSMachineProviderCondition { + conditions := getMachineProviderStatus(f, machine).Conditions + Expect(len(conditions)).To(Equal(1), "ambiguous conditions: %#v", conditions) + return conditions[0] +}