From 8d164b234947b41bfbf9d0e488b5bf15f3737f17 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Wed, 20 Apr 2022 11:48:32 -0600 Subject: [PATCH] test: improve reliability of mon failover test The mon failover test was failing if the cluster reconcile was being triggered in the middle of the failover and if the ordering of the mons happened to attempt to start the mons that were not failed over. The other mons couldn't be updated due to the upgrade checks, so the test would timeout waiting for the mons that would never update in time. Signed-off-by: Travis Nielsen (cherry picked from commit f7cefbbbde0ad3602f73c7a085662b8ad222d762) --- tests/integration/ceph_smoke_test.go | 59 ++++++++++++---------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/tests/integration/ceph_smoke_test.go b/tests/integration/ceph_smoke_test.go index 5907b8191..30cf692b8 100644 --- a/tests/integration/ceph_smoke_test.go +++ b/tests/integration/ceph_smoke_test.go @@ -143,52 +143,45 @@ func (s *SmokeSuite) TestMonFailover() { require.NoError(s.T(), err) require.Equal(s.T(), 3, len(deployments)) + // Scale down a mon so the operator won't trigger a reconcile monToKill := deployments[0].Name - logger.Infof("Killing mon %s", monToKill) - propagation := metav1.DeletePropagationForeground - delOptions := &metav1.DeleteOptions{PropagationPolicy: &propagation} - err = s.k8sh.Clientset.AppsV1().Deployments(s.settings.Namespace).Delete(ctx, monToKill, *delOptions) - require.NoError(s.T(), err) + logger.Infof("Scaling down mon %s", monToKill) + scale, err := s.k8sh.Clientset.AppsV1().Deployments(s.settings.Namespace).GetScale(ctx, monToKill, metav1.GetOptions{}) + assert.NoError(s.T(), err) + scale.Spec.Replicas = 0 + _, err = s.k8sh.Clientset.AppsV1().Deployments(s.settings.Namespace).UpdateScale(ctx, monToKill, scale, metav1.UpdateOptions{}) + assert.NoError(s.T(), err) // Wait for the health check to start a new monitor - originalMonDeleted := false for i := 0; i < 30; i++ { deployments, err := s.getNonCanaryMonDeployments() require.NoError(s.T(), err) - // Make sure the old mon is not still alive - foundOldMon := false - for _, mon := range deployments { + var currentMons []string + var originalMonDeployment *appsv1.Deployment + for i, mon := range deployments { + currentMons = append(currentMons, mon.Name) if mon.Name == monToKill { - foundOldMon = true + originalMonDeployment = &deployments[i] } } + logger.Infof("mon deployments: %v", currentMons) - // Check if we have three monitors - if foundOldMon { - if originalMonDeleted { - // Depending on the state of the orchestration, the operator might trigger - // re-creation of the deleted mon. In this case, consider the test successful - // rather than wait for the failover which will never occur. - logger.Infof("Original mon created again, no need to wait for mon failover") - return - } - logger.Infof("Waiting for old monitor to stop") - } else { - logger.Infof("Waiting for a new monitor to start") - originalMonDeleted = true - if len(deployments) == 3 { - var newMons []string - for _, mon := range deployments { - newMons = append(newMons, mon.Name) - } - logger.Infof("Found a new monitor! monitors=%v", newMons) - return - } - - assert.Equal(s.T(), 2, len(deployments)) + // Check if the original mon was scaled up again + // Depending on the state of the orchestration, the operator might trigger + // re-creation of the deleted mon. In this case, consider the test successful + // rather than wait for the failover which will never occur. + if originalMonDeployment != nil && *originalMonDeployment.Spec.Replicas > 0 { + logger.Infof("Original mon created again, no need to wait for mon failover") + return } + if len(deployments) == 3 && originalMonDeployment == nil { + logger.Infof("Found a new monitor!") + return + } + + logger.Infof("Waiting for a new monitor to start and previous one to be deleted") time.Sleep(5 * time.Second) }