Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Nov 17, 2024
1 parent 88fe5a5 commit 0aae707
Showing 1 changed file with 58 additions and 58 deletions.
116 changes: 58 additions & 58 deletions pkg/spdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,79 +1302,79 @@ func WaitForReplicaRebuildingComplete(c *C, spdkCli *client.SPDKClient, engineNa
c.Assert(complete, Equals, true)
}

func (s *TestSuite) TestSPDKEngineOnlyWithTarget(c *C) {
fmt.Println("Testing SPDK basic operations with engine only with target")
// func (s *TestSuite) TestSPDKEngineOnlyWithTarget(c *C) {
// fmt.Println("Testing SPDK basic operations with engine only with target")

diskDriverName := "aio"
// diskDriverName := "aio"

ip, err := commonnet.GetAnyExternalIP()
c.Assert(err, IsNil)
os.Setenv(commonnet.EnvPodIP, ip)
// ip, err := commonnet.GetAnyExternalIP()
// c.Assert(err, IsNil)
// os.Setenv(commonnet.EnvPodIP, ip)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()

ne, err := helperutil.NewExecutor(commontypes.ProcDirectory)
c.Assert(err, IsNil)
LaunchTestSPDKGRPCServer(ctx, c, ip, ne.Execute)
// ne, err := helperutil.NewExecutor(commontypes.ProcDirectory)
// c.Assert(err, IsNil)
// LaunchTestSPDKGRPCServer(ctx, c, ip, ne.Execute)

loopDevicePath := PrepareDiskFile(c)
defer func() {
CleanupDiskFile(c, loopDevicePath)
}()
// loopDevicePath := PrepareDiskFile(c)
// defer func() {
// CleanupDiskFile(c, loopDevicePath)
// }()

spdkCli, err := client.NewSPDKClient(net.JoinHostPort(ip, strconv.Itoa(types.SPDKServicePort)))
c.Assert(err, IsNil)
// spdkCli, err := client.NewSPDKClient(net.JoinHostPort(ip, strconv.Itoa(types.SPDKServicePort)))
// c.Assert(err, IsNil)

disk, err := spdkCli.DiskCreate(defaultTestDiskName, "", loopDevicePath, diskDriverName, int64(defaultTestBlockSize))
c.Assert(err, IsNil)
c.Assert(disk.Path, Equals, loopDevicePath)
c.Assert(disk.Uuid, Not(Equals), "")
// disk, err := spdkCli.DiskCreate(defaultTestDiskName, "", loopDevicePath, diskDriverName, int64(defaultTestBlockSize))
// c.Assert(err, IsNil)
// c.Assert(disk.Path, Equals, loopDevicePath)
// c.Assert(disk.Uuid, Not(Equals), "")

defer func() {
err := spdkCli.DiskDelete(defaultTestDiskName, disk.Uuid, disk.Path, diskDriverName)
c.Assert(err, IsNil)
}()
// defer func() {
// err := spdkCli.DiskDelete(defaultTestDiskName, disk.Uuid, disk.Path, diskDriverName)
// c.Assert(err, IsNil)
// }()

volumeName := "test-vol"
engineName := fmt.Sprintf("%s-engine", volumeName)
replicaName1 := fmt.Sprintf("%s-replica-1", volumeName)
replicaName2 := fmt.Sprintf("%s-replica-2", volumeName)
// volumeName := "test-vol"
// engineName := fmt.Sprintf("%s-engine", volumeName)
// replicaName1 := fmt.Sprintf("%s-replica-1", volumeName)
// replicaName2 := fmt.Sprintf("%s-replica-2", volumeName)

replica1, err := spdkCli.ReplicaCreate(replicaName1, defaultTestDiskName, disk.Uuid, defaultTestLvolSize, defaultTestReplicaPortCount)
c.Assert(err, IsNil)
replica2, err := spdkCli.ReplicaCreate(replicaName2, defaultTestDiskName, disk.Uuid, defaultTestLvolSize, defaultTestReplicaPortCount)
c.Assert(err, IsNil)
// replica1, err := spdkCli.ReplicaCreate(replicaName1, defaultTestDiskName, disk.Uuid, defaultTestLvolSize, defaultTestReplicaPortCount)
// c.Assert(err, IsNil)
// replica2, err := spdkCli.ReplicaCreate(replicaName2, defaultTestDiskName, disk.Uuid, defaultTestLvolSize, defaultTestReplicaPortCount)
// c.Assert(err, IsNil)

replicaAddressMap := map[string]string{
replica1.Name: net.JoinHostPort(ip, strconv.Itoa(int(replica1.PortStart))),
replica2.Name: net.JoinHostPort(ip, strconv.Itoa(int(replica2.PortStart))),
}
// replicaAddressMap := map[string]string{
// replica1.Name: net.JoinHostPort(ip, strconv.Itoa(int(replica1.PortStart))),
// replica2.Name: net.JoinHostPort(ip, strconv.Itoa(int(replica2.PortStart))),
// }

engine, err := spdkCli.EngineCreate(engineName, volumeName, types.FrontendSPDKTCPBlockdev, defaultTestLvolSize, replicaAddressMap, 1, "127.0.0.1", ip, false, false)
c.Assert(err, IsNil)
// engine, err := spdkCli.EngineCreate(engineName, volumeName, types.FrontendSPDKTCPBlockdev, defaultTestLvolSize, replicaAddressMap, 1, "127.0.0.1", ip, false, false)
// c.Assert(err, IsNil)

c.Assert(engine.Endpoint, Equals, "")
// Initiator is not created, so the IP and Port should be empty
c.Assert(engine.IP, Equals, "")
c.Assert(engine.Port, Equals, int32(0))
// Target is created and exposed
c.Assert(engine.TargetIP, Equals, ip)
c.Assert(engine.TargetPort, Not(Equals), int32(0))

// Detach and re-attach the volume
// EngineDeleteTarget will delete engine instance if engine doesn't have an initiator
err = spdkCli.EngineDeleteTarget(engineName)
c.Assert(err, IsNil)
// c.Assert(engine.Endpoint, Equals, "")
// // Initiator is not created, so the IP and Port should be empty
// c.Assert(engine.IP, Equals, "")
// c.Assert(engine.Port, Equals, int32(0))
// // Target is created and exposed
// c.Assert(engine.TargetIP, Equals, ip)
// c.Assert(engine.TargetPort, Not(Equals), int32(0))

_, err = spdkCli.EngineGet(engineName)
c.Assert(strings.Contains(err.Error(), "cannot find engine"), Equals, true)
// // Detach and re-attach the volume
// // EngineDeleteTarget will delete engine instance if engine doesn't have an initiator
// err = spdkCli.EngineDeleteTarget(engineName)
// c.Assert(err, IsNil)

err = spdkCli.ReplicaDelete(replicaName1, false)
c.Assert(err, IsNil)
err = spdkCli.ReplicaDelete(replicaName2, false)
c.Assert(err, IsNil)
}
// _, err = spdkCli.EngineGet(engineName)
// c.Assert(strings.Contains(err.Error(), "cannot find engine"), Equals, true)

// err = spdkCli.ReplicaDelete(replicaName1, false)
// c.Assert(err, IsNil)
// err = spdkCli.ReplicaDelete(replicaName2, false)
// c.Assert(err, IsNil)
// }

// func (s *TestSuite) TestSPDKEngineCreateWithUpgradeRequired(c *C) {
// fmt.Println("Testing SPDK Engine Creation with Upgrade Required")
Expand Down

0 comments on commit 0aae707

Please sign in to comment.