Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
UB-1977 exclude the warning messages in multipath output (#303)
Browse files Browse the repository at this point in the history
UB-1977 exclude the warning messages in multipath output

Signed-off-by: 27149chen <[email protected]>
  • Loading branch information
27149chen authored Apr 7, 2019
1 parent 3f22f0e commit b758e1f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
2 changes: 2 additions & 0 deletions remote/mounter/block_device_utils/mpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (b *blockDeviceUtils) mpathDevFullPath(dev string) string {
func (b *blockDeviceUtils) DiscoverBySgInq(mpathOutput string, volumeWwn string) (string, error) {
defer b.logger.Trace(logs.DEBUG)()

mpathOutput = utils.ExcludeNoTargetPortGroupMessagesFromMultipathOutput(mpathOutput, b.logger)

scanner := bufio.NewScanner(strings.NewReader(mpathOutput))
// regex to find all dm-X line from IBM vendor.
// Note: searching "IBM" in the line also focus the search on IBM devices only and also eliminate the need to run sg_inq on faulty devices.
Expand Down
27 changes: 27 additions & 0 deletions utils/mpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package utils

import (
"bufio"
"fmt"
"regexp"
"strings"

"github.com/IBM/ubiquity/utils/logs"
)

const multipathCmd = "multipath"
const MultipathTimeout = 10 * 1000
const WarningNoTargetPortGroup = "couldn't get target port group"

/*
GetMultipathOutputAndDeviceMapperAndDevice analysises the output of command "multipath -ll",
Expand Down Expand Up @@ -85,3 +89,26 @@ func GetMultipathOutputAndDeviceMapperAndDevice(volumeWwn string, exec Executor)
}
return outputBytes, devMapper, deviceNames, nil
}

func excludeWarningMessageLines(inputData string, warningPattern *regexp.Regexp, logger logs.Logger) string {
scanner := bufio.NewScanner(strings.NewReader(inputData))
res := ""
for scanner.Scan() {
line := scanner.Text()
if warningPattern.MatchString(line) {
logger.Debug(fmt.Sprintf(`Found warning message line "%s", exclude it.`, line))
continue
}
if res == "" {
res = line
} else {
res = res + "\n" + line
}
}
return res
}

func ExcludeNoTargetPortGroupMessagesFromMultipathOutput(mpathOutput string, logger logs.Logger) string {
regex, _ := regexp.Compile(WarningNoTargetPortGroup)
return excludeWarningMessageLines(mpathOutput, regex, logger)
}
56 changes: 52 additions & 4 deletions utils/mpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/IBM/ubiquity/fakes"
"github.com/IBM/ubiquity/utils"
"github.com/IBM/ubiquity/utils/logs"
)

const (
Expand All @@ -18,7 +19,7 @@ const (
fakeProfile = "gold"
)

var fakeWwn = "6005076306ffd69d0000000000001004"
var fakeWwn = "6005076306FFD69d0000000000001004"

var fakeMultipathOutput = `
mpathg (36005076306ffd69d0000000000001004) dm-14 IBM ,2107900
Expand All @@ -35,7 +36,7 @@ size=2.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
` + "`- 29:0:7:0 sdd 8:48 active ready running\n"

var fakeMultipathOutputWithMultiplePathGroups = `
mpathc (6005076306ffd69d0000000000001004) dm-4 IBM ,2145
mpathc (36005076306ffd69d0000000000001004) dm-4 IBM ,2145
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=50 status=active
| '- 43:0:0:3 sda 8:112 active ready running
Expand All @@ -50,7 +51,7 @@ size=1.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`

var fakeMultipathOutputWithDifferentSpaces = `
mpathj (6005076306ffd69d0000000000001004) dm-27 IBM ,2107900
mpathj (36005076306ffd69d0000000000001004) dm-27 IBM ,2107900
size=1.0G features='0' hwhandler='0' wp=rw
'-+- policy='service-time 0' prio=1 status=active
|- 33:0:12:1 sdcp 69:208 active ready running
Expand All @@ -61,7 +62,37 @@ size=1.0G features='0' hwhandler='0' wp=rw
'- 34:0:9:1 sdcq 69:224 active ready running
`

var _ = Describe("scbe_mounter_test", func() {
var fakeMultipathOutputWithWarnings = `
Apr 04 16:38:06 | sde: couldn't get target port group
Apr 04 16:38:06 | sdd: couldn't get target port group
mpathj (36005076306ffd69d0000000000001004) dm-17 IBM ,2145
size=1.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=0 status=enabled
| '- 39:0:0:1 sde 8:64 failed faulty running
'-+- policy='service-time 0' prio=0 status=enabled
'- 40:0:0:1 sdd 8:48 failed faulty running
mpathi (3600507680c8701159800000000001af3) dm-14 IBM ,2145
size=20G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=50 status=active
| '- 40:0:0:0 sdb 8:16 active ready running
'-+- policy='service-time 0' prio=10 status=enabled
'- 39:0:0:0 sdc 8:32 active ready running
`

var fakeMultipathOutputWithWarningsExcluded = `mpathj (36005076306ffd69d0000000000001004) dm-17 IBM ,2145
size=1.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=0 status=enabled
| '- 39:0:0:1 sde 8:64 failed faulty running
'-+- policy='service-time 0' prio=0 status=enabled
'- 40:0:0:1 sdd 8:48 failed faulty running
mpathi (3600507680c8701159800000000001af3) dm-14 IBM ,2145
size=20G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=50 status=active
| '- 40:0:0:0 sdb 8:16 active ready running
'-+- policy='service-time 0' prio=10 status=enabled
'- 39:0:0:0 sdc 8:32 active ready running`

var _ = Describe("multipath_utils_test", func() {
var (
fakeExec *fakes.FakeExecutor
)
Expand Down Expand Up @@ -95,5 +126,22 @@ var _ = Describe("scbe_mounter_test", func() {
Expect(devMapper).To(Equal("mpathj"))
Expect(devNames).To(Equal([]string{"sdcp", "sdcn", "sdco", "sdcr", "sdcs", "sdcq"}))
})

It("should get device names from multipath output with warning header", func() {
fakeExec.ExecuteWithTimeoutReturns([]byte(fakeMultipathOutputWithWarnings), nil)
_, devMapper, devNames, err := utils.GetMultipathOutputAndDeviceMapperAndDevice(fakeWwn, fakeExec)
Ω(err).ShouldNot(HaveOccurred())
Expect(devMapper).To(Equal("mpathj"))
Expect(devNames).To(Equal([]string{"sde", "sdd"}))
})
})

Context("ExcludeNoTargetPortGroupMessagesFromMultipathOutput", func() {

It("should exclude the warning messages from multipath output", func() {
logger := logs.GetLogger()
out := utils.ExcludeNoTargetPortGroupMessagesFromMultipathOutput(fakeMultipathOutputWithWarnings, logger)
Expect(out).To(Equal(fakeMultipathOutputWithWarningsExcluded))
})
})
})

0 comments on commit b758e1f

Please sign in to comment.