Skip to content

Commit

Permalink
Merge branch 'dev' into fix/umountflow_ignore_already_unmounted_or_cl…
Browse files Browse the repository at this point in the history
…eanned_mp
  • Loading branch information
tzurE committed Dec 6, 2017
2 parents 03d61d6 + e076dc0 commit c5de9bd
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 4 deletions.
139 changes: 137 additions & 2 deletions fakes/fake_block_device_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions remote/mounter/block_device_utils/block_device_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
. "github.com/onsi/gomega"
"io/ioutil"
"testing"
"strings"
)

var _ = Describe("block_device_utils_test", func() {
Expand Down Expand Up @@ -158,6 +159,91 @@ var _ = Describe("block_device_utils_test", func() {
Expect(err).To(HaveOccurred())
})
})
Context( ".DiscoverBySgInq", func(){
It("should return mpathhe", func() {
mpathOutput := `mpathhe (36001738cfc9035eb0000000000cea5f6) dm-3 IBM ,2810XIV
size=19G features='1 queue_if_no_path' hwhandler='0' wp=rw
-+- policy='service-time 0' prio=1 status=active
|- 33:0:0:1 sdb 8:16 active ready running
- 34:0:0:1 sdc 8:32 active ready running`
volWwn := "0x6001738cfc9035eb0000000000cea5f6"
expectedWwn := strings.TrimPrefix(volWwn, "0x")
inq_result := fmt.Sprintf(`VPD INQUIRY: Device Identification page
Designation descriptor number 1, descriptor length: 20
designator_type: NAA, code_set: Binary
associated with the addressed logical unit
NAA 6, IEEE Company_id: 0x1738
Vendor Specific Identifier: 0xcfc9035eb
Vendor Specific Identifier Extension: 0xcea5f6
[%s]`, volWwn)
fakeExec.ExecuteReturns([]byte(fmt.Sprintf("%s", inq_result)), nil)
dev, err := bdUtils.DiscoverBySgInq(mpathOutput, expectedWwn)
Expect(dev).To(Equal("mpathhe"))
Expect(err).ToNot(HaveOccurred())
Expect(fakeExec.ExecuteCallCount()).To(Equal(1))
cmd, _ := fakeExec.ExecuteArgsForCall(0)
Expect(cmd).To(Equal("sg_inq"))
})
It("should return wwn command fails", func() {
mpathOutput := `mpathhe (36001738cfc9035eb0000000000cea5f6) dm-3 IBM ,2810XIV
size=19G features='1 queue_if_no_path' hwhandler='0' wp=rw
-+- policy='service-time 0' prio=1 status=active
|- 33:0:0:1 sdb 8:16 active ready running
- 34:0:0:1 sdc 8:32 active ready running`
wwn := "wwn"
fakeExec.ExecuteReturns([]byte{}, cmdErr)
_, err := bdUtils.DiscoverBySgInq(mpathOutput, wwn)
Expect(err).To(HaveOccurred())
})
})
Context( ".GetWwnByScsiInq", func(){
It("GetWwnByScsiInq fails if sg_inq command fails", func() {
dev := "dev"
fakeExec.ExecuteReturns([]byte{}, cmdErr)
_, err := bdUtils.GetWwnByScsiInq(dev)
Expect(err).To(HaveOccurred())
})
It("should return wwn for mpath device", func() {
dev := "dev"
expecedWwn := "0x6001738cfc9035eb0000000000AAAAAA"
result := fmt.Sprintf(`VPD INQUIRY: Device Identification page
Designation descriptor number 1, descriptor length: 20
designator_type: NAA, code_set: Binary
associated with the addressed logical unit
NAA 6, IEEE Company_id: 0x1738
Vendor Specific Identifier: 0xcfc9035eb
Vendor Specific Identifier Extension: 0xcea5f6
[%s]`, expecedWwn)
fakeExec.ExecuteReturns([]byte(fmt.Sprintf("%s", result)), nil)
wwn, err := bdUtils.GetWwnByScsiInq(dev)
Expect(err).ToNot(HaveOccurred())
Expect(wwn).To(Equal(strings.TrimPrefix(expecedWwn, "0x")))
Expect(fakeExec.ExecuteCallCount()).To(Equal(1))
cmd, args := fakeExec.ExecuteArgsForCall(0)
Expect(cmd).To(Equal("sg_inq"))
Expect(args).To(Equal([]string{"-p", "0x83", dev}))
})
It("should not find wwn for device", func() {
dev := "dev"
expecedWwn := "6001738cfc9035eb0000000000AAAAAA"
result := fmt.Sprintf(`VPD INQUIRY: Device Identification page
Designation descriptor number 1, descriptor length: 20
designator_type: NAA, code_set: Binary
associated with the addressed logical unit
NAA 6, IEEE Company_id: 0x1738
Vendor Specific Identifier: 0xcfc9035eb
Vendor Specific Identifier Extension: 0xcea5f6
[%s]`, expecedWwn)
fakeExec.ExecuteReturns([]byte(fmt.Sprintf("%s", result)), nil)
_, err := bdUtils.GetWwnByScsiInq(dev)
Expect(err).To(HaveOccurred())
Expect(fakeExec.ExecuteCallCount()).To(Equal(1))
cmd, args := fakeExec.ExecuteArgsForCall(0)
Expect(cmd).To(Equal("sg_inq"))
Expect(args).To(Equal([]string{"-p", "0x83", dev}))
})
})

Context(".Cleanup", func() {
It("Cleanup calls dmsetup and multipath", func() {
mpath := "mpath"
Expand Down
10 changes: 10 additions & 0 deletions remote/mounter/block_device_utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ type unsupportedProtocolError struct {
func (e *unsupportedProtocolError) Error() string {
return fmt.Sprintf("Protocol [%v] is not supported", e.protocol)
}

type noRegexWwnMatchInScsiInqError struct {
dev string
line string
}

func (e *noRegexWwnMatchInScsiInqError) Error() string {
return fmt.Sprintf("Could not find wwn pattern in sg_inq of mpath devive: [%s] in line Vendor Specific " +
"Identifier Extension: [%s]", e.dev, e.line)
}

0 comments on commit c5de9bd

Please sign in to comment.