Skip to content

Commit

Permalink
feat(v2 upgrade): support engine live upgrade
Browse files Browse the repository at this point in the history
Longhorn 9104

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Nov 19, 2024
1 parent f654d45 commit fe16578
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 3 additions & 5 deletions pkg/spdk/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (e *Engine) checkInitiatorAndTargetCreationRequirements(podIP, initiatorIP,
targetCreationRequired = true
}
} else {
err = fmt.Errorf("invalid initiator and target address for engine %s creation", e.Name)
err = fmt.Errorf("invalid initiator and target addresses for engine %s creation with initiator address %v and target address %v", e.Name, initiatorIP, targetIP)
}

Check warning on line 130 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L128-L130

Added lines #L128 - L130 were not covered by tests
} else if podIP == initiatorIP {
e.log.Info("Creating an initiator instance")
Expand All @@ -135,16 +135,15 @@ func (e *Engine) checkInitiatorAndTargetCreationRequirements(podIP, initiatorIP,
e.log.Info("Creating a target instance")
targetCreationRequired = true
} else {
err = fmt.Errorf("invalid initiator and target address for engine %s creation", e.Name)
err = fmt.Errorf("invalid initiator and target addresses for engine %s creation with initiator address %v and target address %v", e.Name, initiatorIP, targetIP)
}

return initiatorCreationRequired, targetCreationRequired, err
}

func (e *Engine) Create(spdkClient *spdkclient.Client, replicaAddressMap map[string]string, portCount int32, superiorPortAllocator *commonbitmap.Bitmap, initiatorAddress, targetAddress string, upgradeRequired, salvageRequested bool) (ret *spdkrpc.Engine, err error) {
func (e *Engine) Create(spdkClient *spdkclient.Client, replicaAddressMap map[string]string, portCount int32, superiorPortAllocator *commonbitmap.Bitmap, initiatorAddress, targetAddress string, salvageRequested bool) (ret *spdkrpc.Engine, err error) {

Check warning on line 144 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L144

Added line #L144 was not covered by tests
logrus.WithFields(logrus.Fields{
"portCount": portCount,
"upgradeRequired": upgradeRequired,
"replicaAddressMap": replicaAddressMap,
"initiatorAddress": initiatorAddress,
"targetAddress": targetAddress,
Expand Down Expand Up @@ -306,7 +305,6 @@ func (e *Engine) Create(spdkClient *spdkclient.Client, replicaAddressMap map[str
log := e.log.WithFields(logrus.Fields{
"initiatorCreationRequired": initiatorCreationRequired,
"targetCreationRequired": targetCreationRequired,
"upgradeRequired": upgradeRequired,
"initiatorAddress": initiatorAddress,
"targetAddress": targetAddress,
})
Expand Down
20 changes: 11 additions & 9 deletions pkg/spdk/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {
expectedError: nil,
},
{
name: "Create local target instance only",
name: "Create local target instance on the node with initiator instance",
podIP: "192.168.1.1",
initiatorIP: "192.168.1.1",
targetIP: "192.168.1.1",
Expand All @@ -58,7 +58,7 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {
expectedError: nil,
},
{
name: "Create remote target instance only",
name: "Create local target instance on the node without initiator instance",
podIP: "192.168.1.2",
initiatorIP: "192.168.1.1",
targetIP: "192.168.1.2",
Expand All @@ -70,7 +70,7 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {
expectedError: nil,
},
{
name: "Invalid initiator and target address",
name: "Invalid initiator and target addresses",
podIP: "192.168.1.1",
initiatorIP: "192.168.1.2",
targetIP: "192.168.1.3",
Expand All @@ -79,7 +79,7 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {
standbyTargetPort: 0,
expectedInitiatorCreationRequired: false,
expectedTargetCreationRequired: false,
expectedError: fmt.Errorf("invalid initiator and target address for engine %s creation", "test-engine"),
expectedError: fmt.Errorf("invalid initiator and target addresses for engine test-engine creation with initiator address 192.168.1.2 and target address 192.168.1.3"),
},
{
name: "Standby target instance is already created",
Expand All @@ -94,9 +94,8 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {
expectedError: nil,
},
}

for testName, testCase := range testCases {
c.Logf("testing TestCheckInitiatorAndTargetCreationRequirements.%v", testName)
c.Logf("testing checkInitiatorAndTargetCreationRequirements.%v", testName)

engine := &Engine{
Port: testCase.port,
Expand All @@ -108,8 +107,11 @@ func (s *TestSuite) TestCheckInitiatorAndTargetCreationRequirements(c *C) {

initiatorCreationRequired, targetCreationRequired, err := engine.checkInitiatorAndTargetCreationRequirements(testCase.podIP, testCase.initiatorIP, testCase.targetIP)

c.Assert(initiatorCreationRequired, Equals, testCase.expectedInitiatorCreationRequired)
c.Assert(targetCreationRequired, Equals, testCase.expectedTargetCreationRequired)
c.Assert(err, DeepEquals, testCase.expectedError)
c.Assert(initiatorCreationRequired, Equals, testCase.expectedInitiatorCreationRequired,
Commentf("Test case '%s': unexpected initiator creation requirement", testCase.name))
c.Assert(targetCreationRequired, Equals, testCase.expectedTargetCreationRequired,
Commentf("Test case '%s': unexpected target creation requirement", testCase.name))
c.Assert(err, DeepEquals, testCase.expectedError,
Commentf("Test case '%s': unexpected error result", testCase.name))
}
}
2 changes: 1 addition & 1 deletion pkg/spdk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func (s *Server) EngineCreate(ctx context.Context, req *spdkrpc.EngineCreateRequ
spdkClient := s.spdkClient
s.Unlock()

return e.Create(spdkClient, req.ReplicaAddressMap, req.PortCount, s.portAllocator, req.InitiatorAddress, req.TargetAddress, req.UpgradeRequired, req.SalvageRequested)
return e.Create(spdkClient, req.ReplicaAddressMap, req.PortCount, s.portAllocator, req.InitiatorAddress, req.TargetAddress, req.SalvageRequested)

Check warning on line 879 in pkg/spdk/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/server.go#L879

Added line #L879 was not covered by tests
}

func localTargetExists(e *Engine) bool {
Expand Down

0 comments on commit fe16578

Please sign in to comment.