Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving UT coverage #73

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f4447c8
added test case for ParseLuns
mbasha-dell Dec 4, 2024
274718c
added test for GetPowerPathDevices
mbasha-dell Dec 5, 2024
ba80e23
Merge branch 'main' of https://github.com/dell/gobrick into pub/ut-co…
samihan-dell Jan 2, 2025
cfe4014
test: Increased UT code coverage to 86.2% for pkg/scsi
samihan-dell Jan 2, 2025
452559b
test: Increased UT code coverage
samihan-dell Jan 3, 2025
6d71250
test: Increased coverage of gobrick package to 50.6%
samihan-dell Jan 6, 2025
830abd5
test: Increased coverage of gobrick package to 50.6%
samihan-dell Jan 6, 2025
5aad100
test: Added few UTs
samihan-dell Jan 6, 2025
ce65e45
test: Updated few UTs
samihan-dell Jan 7, 2025
d491e69
increased the pkg/gobrick code coverage to 54.5%
niranjan-n1 Jan 7, 2025
bf45de5
fixed lint issue
niranjan-n1 Jan 7, 2025
09a7ed8
test: Added few test in nvme.go file
samihan-dell Jan 8, 2025
49b4c36
test: Fixed tests now rdm.go UTs are passing
samihan-dell Jan 9, 2025
ba9b3b6
test: increased UT coverage by almost 3%
samihan-dell Jan 9, 2025
54d0d6b
test: Refactored nvme.go UTs
samihan-dell Jan 9, 2025
365ba71
test: Added UTs for nvme ConnectVolume increased coverage by almost 10%
samihan-dell Jan 9, 2025
b14d40c
test: Added commented testcase but its failing
samihan-dell Jan 9, 2025
ded17f6
test: Increased UT coverage to 71.1% Added UTs for nvme.go file
samihan-dell Jan 10, 2025
c3e80d8
test: Fixed failing UTs for tryNVMeConnect in nvme.go
samihan-dell Jan 10, 2025
26fc05b
Merge branch 'main' into pub/ut-coverage
niranjan-n1 Jan 15, 2025
9cf0e33
test: Added UT for tryEnableManualISCSISessionMGMT
samihan-dell Jan 20, 2025
ab5ba30
test: Upadted UTs for connectPowerpathDevice
samihan-dell Jan 20, 2025
38f0342
test: Added few test in iscsi_test.go file
samihan-dell Jan 21, 2025
893968b
test: added unit test in nvme_test.go
samihan-dell Jan 21, 2025
49efb14
fix: fixing linting issue
samihan-dell Jan 22, 2025
0074df8
test: Added Unt test for nvme.go
samihan-dell Jan 22, 2025
8977fdf
test: Added Unt test for nvme.go
samihan-dell Jan 23, 2025
df1070f
test: Added mocks for NVMe struct
samihan-dell Jan 24, 2025
446e7c1
test: Added Unit test for nvme.go
samihan-dell Jan 24, 2025
52625bb
test: Added Unit test for ConnectVolume in nvme.go
samihan-dell Jan 28, 2025
76ca3c0
test: Added Unit test for tryNVMeConnect in nvme.go
samihan-dell Jan 28, 2025
4196c23
test: Added Unit test for tryNVMeConnect in nvme.go
samihan-dell Jan 28, 2025
dfce855
test: Added Unit test for nvme.go
samihan-dell Jan 29, 2025
67d7305
refactor: Removed commented Unit test
samihan-dell Jan 29, 2025
e462081
refactor: Removed commented Unit test
samihan-dell Jan 29, 2025
2aba8a6
test: Added Unit test for nvme.go
samihan-dell Jan 29, 2025
ece37f0
test: Increased test coverage to 80.2%
samihan-dell Jan 29, 2025
8151204
fix: Fixing linting issues
samihan-dell Jan 29, 2025
a3b0476
Merge branch 'main' of https://github.com/dell/gobrick into pub/ut-co…
samihan-dell Jan 29, 2025
18d4f84
test: increased UT coverage of pkg/powerpath package from 88% to 91.5%
samihan-dell Feb 6, 2025
e5846e6
test: increased UT coverage of pkg/utils package from 0% to 100%
samihan-dell Feb 6, 2025
eecdc28
test: increased UT coverage of pkg/scsi package from 86.2% to 96.6%
samihan-dell Feb 7, 2025
13c3c0f
test: Covered 100% lines from base.go file in gobrick package
samihan-dell Feb 25, 2025
d178c87
test: Updated testcase for cleanNVMeDevices
samihan-dell Feb 25, 2025
8a5eda6
test: added unit tests for cleanNVMeDevices function in base.go
samihan-dell Feb 25, 2025
382f23a
test: added unit tests for cleanDevices function in base.go
samihan-dell Feb 27, 2025
75bd0bc
test: added unit tests for getNVMEDMWWN function in base.go
samihan-dell Feb 27, 2025
5228a8f
added test cases in fc.go
chaganti-rajitha Feb 28, 2025
38a67a8
fixed linting issues in fc.go
chaganti-rajitha Feb 28, 2025
b872c7f
commented failing test case in fc.go
chaganti-rajitha Feb 28, 2025
5928bfb
removed go build tag from sync_tools_test.go file
samihan-dell Feb 28, 2025
e9c3f81
Merge branch 'pub/ut-coverage' of https://github.com/dell/gobrick int…
samihan-dell Feb 28, 2025
e0b58dd
added back build tags
chaganti-rajitha Feb 28, 2025
2524777
test: Increased test coverage of gobrick package to 85.3%
samihan-dell Feb 28, 2025
18602d7
Merge branch 'pub/ut-coverage' of https://github.com/dell/gobrick int…
samihan-dell Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 409 additions & 0 deletions base_test.go

Large diffs are not rendered by default.

89 changes: 71 additions & 18 deletions fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ type FCConnectorParams struct {
MaxParallelOperations int
}

// External function variables
var (
traceFuncCallFunc = tracer.TraceFuncCall

getPowerPathDevicesFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, devices []string) (string, error) {
return fc.powerpath.GetPowerPathDevices
}

waitUdevSymlinkFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, device, wwn string) error {
return fc.scsi.WaitUdevSymlink
}
)

// NewFCConnector create new FCConnector
func NewFCConnector(params FCConnectorParams) *FCConnector {
mp := multipath.NewMultipath(params.Chroot)
Expand Down Expand Up @@ -239,15 +252,43 @@ func (fc *FCConnector) validateFCVolumeInfo(ctx context.Context, info FCVolumeIn
return nil
}

// External function variables
var (
waitForDeviceWWNFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, hbas []FCHBA, info FCVolumeInfo) (string, error) {
return fc.waitForDeviceWWN
}
getDevicesByWWNFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, wwn string) ([]string, error) {
return fc.scsi.GetDevicesByWWN
}
isPowerpathDaemonRunningFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context) bool {
return fc.powerpath.IsDaemonRunning
}
waitPowerpathDeviceFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, wwn string, devices []string) (string, error) {
return fc.waitPowerpathDevice
}
isMultipathDaemonRunningFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context) bool {
return fc.multipath.IsDaemonRunning
}
waitSingleDeviceFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, wwn string, devices []string) (string, error) {
return fc.waitSingleDevice
}
waitMultipathDeviceFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, wwn string, devices []string) (string, error) {
return fc.waitMultipathDevice
}
checkDeviceIsValidFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, devicePath string) bool {
return fc.scsi.CheckDeviceIsValid
}
)

func (fc *FCConnector) connectDevice(
ctx context.Context, hbas []FCHBA, info FCVolumeInfo,
) (Device, error) {
defer tracer.TraceFuncCall(ctx, "FCConnector.connectDevice")()
wwn, err := fc.waitForDeviceWWN(ctx, hbas, info)
defer traceFuncCallFunc(ctx, "FCConnector.connectDevice")()
wwn, err := waitForDeviceWWNFunc(ctx, fc)(ctx, hbas, info)
if err != nil {
return Device{}, err
}
devices, err := fc.scsi.GetDevicesByWWN(ctx, wwn)
devices, err := getDevicesByWWNFunc(ctx, fc)(ctx, wwn)
if err != nil || len(devices) == 0 {
msg := "failed to get devices by WWN: " + wwn
logger.Error(ctx, msg)
Expand All @@ -256,28 +297,28 @@ func (fc *FCConnector) connectDevice(

var device string
var isMP bool
if fc.powerpath.IsDaemonRunning(ctx) {
device, err = fc.waitPowerpathDevice(ctx, wwn, devices)
if isPowerpathDaemonRunningFunc(ctx, fc)(ctx) {
device, err = waitPowerpathDeviceFunc(ctx, fc)(ctx, wwn, devices)
if err != nil {
msg := "failed to find powerpath device"
logger.Error(ctx, msg)
return Device{}, errors.New(msg)
}
} else if !fc.multipath.IsDaemonRunning(ctx) {
device, err = fc.waitSingleDevice(ctx, wwn, devices)
} else if !isMultipathDaemonRunningFunc(ctx, fc)(ctx) {
device, err = waitSingleDeviceFunc(ctx, fc)(ctx, wwn, devices)
if err != nil {
return Device{}, err
}
} else {
isMP = true
device, err = fc.waitMultipathDevice(ctx, wwn, devices)
device, err = waitMultipathDeviceFunc(ctx, fc)(ctx, wwn, devices)
if err != nil {
msg := "failed to find multipath device"
logger.Error(ctx, msg)
return Device{}, errors.New(msg)
}
}
if !fc.scsi.CheckDeviceIsValid(ctx, path.Join("/dev/", device)) {
if !checkDeviceIsValidFunc(ctx, fc)(ctx, path.Join("/dev/", device)) {
msg := "multipath device was found but failed to read data from it"
logger.Error(ctx, msg)
return Device{}, errors.New(msg)
Expand All @@ -297,7 +338,7 @@ func (fc *FCConnector) waitSingleDevice(ctx context.Context, wwn string, devices
default:
}
for _, d := range devices {
if err := fc.scsi.WaitUdevSymlink(ctx, d, wwn); err == nil {
if err := waitUdevSymlinkFunc(ctx, fc)(ctx, d, wwn); err == nil {
return d, nil
}
}
Expand All @@ -308,18 +349,30 @@ func (fc *FCConnector) waitSingleDevice(ctx context.Context, wwn string, devices
return "", errors.New(msg)
}

var (
addWWIDFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, wwn string) error {
return fc.multipath.AddWWID
}
addPathFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, devPath string) error {
return fc.multipath.AddPath
}
getDMDeviceByChildrenFunc = func(_ context.Context, fc *FCConnector) func(ctx context.Context, devices []string) (string, error) {
return fc.scsi.GetDMDeviceByChildren
}
)

func (fc *FCConnector) waitMultipathDevice(
ctx context.Context, wwn string, devices []string,
) (string, error) {
defer tracer.TraceFuncCall(ctx, "FCConnector.waitMultipathDevice")()
err := fc.multipath.AddWWID(ctx, wwn)
defer traceFuncCallFunc(ctx, "FCConnector.waitMultipathDevice")()
err := addWWIDFunc(ctx, fc)(ctx, wwn)
if err != nil {
return "", err
}

for _, d := range devices {
devPath := path.Join("/dev/", d)
if err := fc.multipath.AddPath(ctx, devPath); err != nil {
if err := addPathFunc(ctx, fc)(ctx, devPath); err != nil {
logger.Info(ctx, err.Error())
}
}
Expand All @@ -331,9 +384,9 @@ func (fc *FCConnector) waitMultipathDevice(
return "", errors.New("waitMultipathDevice canceled")
default:
}
resp, err := fc.scsi.GetDMDeviceByChildren(ctx, devices)
resp, err := getDMDeviceByChildrenFunc(ctx, fc)(ctx, devices)
if err == nil {
if err := fc.scsi.WaitUdevSymlink(ctx, resp, wwn); err == nil {
if err := waitUdevSymlinkFunc(ctx, fc)(ctx, resp, wwn); err == nil {
mpath = resp
break
}
Expand All @@ -352,17 +405,17 @@ func (fc *FCConnector) waitMultipathDevice(
func (fc *FCConnector) waitPowerpathDevice(
ctx context.Context, wwn string, devices []string,
) (string, error) {
defer tracer.TraceFuncCall(ctx, "FCConnector.waitPowerpathDevice")()
defer traceFuncCallFunc(ctx, "FCConnector.waitPowerpathDevice")()
var ppath string
for i := 0; i < int(fc.waitDeviceRegisterTimeout.Seconds()); i++ {
select {
case <-ctx.Done():
return "", errors.New("PowerpathDevice canceled")
default:
}
resp, err := fc.powerpath.GetPowerPathDevices(ctx, devices)
resp, err := getPowerPathDevicesFunc(ctx, fc)(ctx, devices)
if err == nil {
if err := fc.scsi.WaitUdevSymlink(ctx, resp, wwn); err == nil {
if err := waitUdevSymlinkFunc(ctx, fc)(ctx, resp, wwn); err == nil {
ppath = resp
break
}
Expand Down
Loading
Loading