Skip to content

Commit

Permalink
unit test: fix newInstanceManager
Browse files Browse the repository at this point in the history
The TestCleanupRedundantInstanceManagers test fails due to a hard-coded and incorrect instance manager image.
This issue surfaces after the introduction of the feature in commit 7b3521b.

Longhorn 8658

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and mergify[bot] committed May 29, 2024
1 parent 98ea8ce commit ad74200
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,18 @@ func newInstanceManager(
instanceEngines map[string]longhorn.InstanceProcess,
instanceReplicas map[string]longhorn.InstanceProcess,
dataEngine longhorn.DataEngineType,
instanceManagerImage string,
isDeleting bool) *longhorn.InstanceManager {

im := &longhorn.InstanceManager{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: TestNamespace,
UID: uuid.NewUUID(),
Labels: types.GetInstanceManagerLabels(nodeID, TestInstanceManagerImage, longhorn.InstanceManagerTypeAllInOne, dataEngine),
Labels: types.GetInstanceManagerLabels(nodeID, instanceManagerImage, longhorn.InstanceManagerTypeAllInOne, dataEngine),
},
Spec: longhorn.InstanceManagerSpec{
Image: TestInstanceManagerImage,
Image: instanceManagerImage,
NodeID: nodeID,
Type: longhorn.InstanceManagerTypeAllInOne,
DataEngine: dataEngine,
Expand Down
17 changes: 17 additions & 0 deletions controller/instance_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, "", "", "", "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateStopped),
Expand All @@ -153,6 +154,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, "", "", TestNode1, "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateRunning),
Expand All @@ -178,6 +180,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, "", "", TestNode1, "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateRunning),
Expand All @@ -203,6 +206,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, "", TestInstanceManagerName, TestNode1, "", 0, false, longhorn.InstanceStateStarting, longhorn.InstanceStateRunning),
Expand All @@ -228,6 +232,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, "", "", TestNode1, "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateRunning),
Expand All @@ -253,6 +258,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, TestEngineImage, TestInstanceManagerName, TestNode1, TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateRunning),
Expand All @@ -278,6 +284,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, TestEngineImage, TestInstanceManagerName, "", TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateStopped),
Expand All @@ -303,6 +310,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, TestEngineImage, TestInstanceManagerName, "", TestIP1, TestPort1, false, longhorn.InstanceStateRunning, longhorn.InstanceStateStopped),
Expand All @@ -328,6 +336,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, TestEngineImage, TestInstanceManagerName, "", TestIP1, TestPort1, false, longhorn.InstanceStateRunning, longhorn.InstanceStateStopped),
Expand All @@ -353,6 +362,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, "", TestInstanceManagerName, "", "", 0, false, longhorn.InstanceStateStopping, longhorn.InstanceStateStopped),
Expand All @@ -368,6 +378,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, "", TestInstanceManagerName, "", "", 0, false, longhorn.InstanceStateStopping, longhorn.InstanceStateStopped),
Expand All @@ -383,6 +394,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, TestEngineImage, TestInstanceManagerName, "", TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateStopped),
Expand All @@ -399,6 +411,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, "", "", "", "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateStopping),
Expand All @@ -424,6 +437,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
true,
),
newEngine(NonExistingInstance, TestEngineImage, TestInstanceManagerName, TestNode1, TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateRunning),
Expand All @@ -439,6 +453,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
true,
),
newEngine(NonExistingInstance, "", "", "", "", 0, false, longhorn.InstanceStateStopped, longhorn.InstanceStateStopped),
Expand All @@ -454,6 +469,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(NonExistingInstance, TestEngineImage, TestInstanceManagerName, TestNode1, TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateRunning),
Expand All @@ -479,6 +495,7 @@ func (s *TestSuite) TestReconcileInstanceState(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
newEngine(ExistingInstance, TestEngineImage, TestInstanceManagerName, TestNode1, TestIP1, TestPort1, true, longhorn.InstanceStateRunning, longhorn.InstanceStateRunning),
Expand Down
1 change: 1 addition & 0 deletions controller/instance_manager_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func (s *TestSuite) TestSyncInstanceManager(c *C) {
tc.currentOwnerID, tc.nodeID, currentIP,
tc.currentEngines, tc.currentReplicas,
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
)
err = imIndexer.Add(im)
Expand Down
5 changes: 5 additions & 0 deletions controller/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
)
)
Expand Down Expand Up @@ -1008,6 +1009,7 @@ func (s *NodeControllerSuite) TestCreateDefaultInstanceManager(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
},
Expand Down Expand Up @@ -1070,6 +1072,7 @@ func (s *NodeControllerSuite) TestCleanupRedundantInstanceManagers(c *C) {
},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestExtraInstanceManagerImage,
false,
)
extraInstanceManager.Spec.Image = TestExtraInstanceManagerImage
Expand Down Expand Up @@ -1148,6 +1151,7 @@ func (s *NodeControllerSuite) TestCleanupRedundantInstanceManagers(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
"extra-instance-manager-name": extraInstanceManager,
Expand Down Expand Up @@ -1243,6 +1247,7 @@ func (s *NodeControllerSuite) TestCleanupAllInstanceManagers(c *C) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
},
Expand Down
2 changes: 2 additions & 0 deletions controller/volume_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ func (s *TestSuite) runTestCases(c *C, testCases map[string]*VolumeTestCase) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
metav1.CreateOptions{},
Expand All @@ -1334,6 +1335,7 @@ func (s *TestSuite) runTestCases(c *C, testCases map[string]*VolumeTestCase) {
map[string]longhorn.InstanceProcess{},
map[string]longhorn.InstanceProcess{},
longhorn.DataEngineTypeV1,
TestInstanceManagerImage,
false,
),
metav1.CreateOptions{},
Expand Down

0 comments on commit ad74200

Please sign in to comment.