Skip to content

Commit cc7b5fc

Browse files
CON-2295: Merge of multipath.conf is not comprehensive (#169)
Signed-off-by: Adarsh Pratik <[email protected]>
1 parent 4df04fb commit cc7b5fc

File tree

12 files changed

+1538
-730
lines changed

12 files changed

+1538
-730
lines changed

linux/os.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ package linux
1919
import (
2020
"errors"
2121
"fmt"
22-
log "github.com/hpe-storage/common-host-libs/logger"
23-
"github.com/hpe-storage/common-host-libs/util"
2422
"os"
2523
"regexp"
2624
"strconv"
2725
"strings"
2826
"sync"
27+
28+
log "github.com/hpe-storage/common-host-libs/logger"
29+
"github.com/hpe-storage/common-host-libs/util"
2930
)
3031

3132
const (
@@ -96,6 +97,42 @@ func GetOsInfo() (*OsInfo, error) {
9697
return osInfo, nil
9798
}
9899

100+
func GetDistro() (string, error) {
101+
osInfoLock.Lock()
102+
defer osInfoLock.Unlock()
103+
var out, distro string
104+
if f, err := os.Stat(osReleaseFile); err == nil && !f.IsDir() && f.Size() != 0 {
105+
// get only PRETTY_NAME field of os-release
106+
var lines []string
107+
lines, err = util.FileGetStrings(osReleaseFile)
108+
for _, line := range lines {
109+
if strings.Contains(line, "PRETTY_NAME") {
110+
// remove quotes and key
111+
out = strings.Replace(strings.Replace(line, "\"", "", -1), "PRETTY_NAME=", "", -1)
112+
break
113+
}
114+
}
115+
116+
if out != "" {
117+
if strings.Contains(out, "Ubuntu") {
118+
distro = "Ubuntu"
119+
} else if strings.Contains(out, "Red Hat") {
120+
distro = "Red Hat"
121+
} else if strings.Contains(out, "Centos") {
122+
distro = "Centos"
123+
} else if strings.Contains(out, "SUSE") {
124+
distro = "SUSE"
125+
} else {
126+
log.Info("Cannot determine Distro")
127+
return "", errors.New("Undefined DistroType")
128+
}
129+
return distro, nil
130+
}
131+
}
132+
return "", errors.New("Unable to determine DistroType")
133+
134+
}
135+
99136
// GetKernelVersion returns OS kernel version
100137
func (o *OsInfo) GetKernelVersion() string {
101138
return strings.TrimSpace(o.kernelVersion)

mpathconfig/configresource.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import (
66
"container/list"
77
"errors"
88
"fmt"
9-
log "github.com/hpe-storage/common-host-libs/logger"
10-
"github.com/hpe-storage/common-host-libs/util"
119
"os"
1210
"path"
1311
"regexp"
1412
"strconv"
1513
"strings"
1614
"sync"
1715
"time"
16+
17+
log "github.com/hpe-storage/common-host-libs/logger"
18+
"github.com/hpe-storage/common-host-libs/util"
1819
)
1920

2021
const (
@@ -239,25 +240,21 @@ func addOption(section *Section, option string) {
239240

240241
//checks for the section
241242
func isSection(line string) (bool, error) {
242-
line = strings.TrimSpace(line)
243-
prefixes := []string{"defaults", "blacklist", "blacklist_exceptions", "devices", "device", "multipaths", "multipath"}
244-
for _, prefix := range prefixes {
245-
r, err := regexp.Compile("^"+prefix+"\\s*[{]*$")
246-
if err != nil {
247-
return false, err
248-
}
249-
250-
if(r.MatchString(line)) {
251-
return true, nil
252-
}
253-
}
254-
255-
return false, nil
256-
}
257-
258-
243+
line = strings.TrimSpace(line)
244+
prefixes := []string{"defaults", "blacklist", "blacklist_exceptions", "devices", "device", "multipaths", "multipath"}
245+
for _, prefix := range prefixes {
246+
r, err := regexp.Compile("^" + prefix + "\\s*[{]*$")
247+
if err != nil {
248+
return false, err
249+
}
259250

251+
if r.MatchString(line) {
252+
return true, nil
253+
}
254+
}
260255

256+
return false, nil
257+
}
261258

262259
// ParseConfig reads and parses give config file into sections
263260
func ParseConfig(filePath string) (config *Configuration, err error) {
@@ -349,9 +346,9 @@ func SaveConfig(config *Configuration, filePath string) (err error) {
349346
return err
350347
}
351348

352-
// GetNimbleSection gets nimble device section in /etc/multipath.conf
353-
func (config *Configuration) GetNimbleSection() (section *Section, err error) {
354-
log.Trace("GetNimbleSection called")
349+
// GetDeviceSection gets device section in /etc/multipath.conf
350+
func (config *Configuration) GetDeviceSection(deviceType string) (section *Section, err error) {
351+
log.Trace("GetDeviceSection called for device: ", deviceType)
355352
config.mutex.RLock()
356353
defer config.mutex.RUnlock()
357354

@@ -363,7 +360,7 @@ func (config *Configuration) GetNimbleSection() (section *Section, err error) {
363360
if s.GetChildren().Len() != 0 {
364361
for e := s.GetChildren().Front(); e != nil; e = e.Next() {
365362
childSection := e.Value.(*Section)
366-
if childSection.GetName() == "device" && strings.Contains(childSection.properties["vendor"], "Nimble") {
363+
if childSection.GetName() == "device" && strings.Contains(childSection.properties["vendor"], deviceType) {
367364
return childSection, nil
368365
}
369366
}

mpathconfig/configresource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestParseDeviceSection(t *testing.T) {
1414
)
1515
} else {
1616
// config found
17-
section, err := config.GetNimbleSection()
17+
section, err := config.GetDeviceSection()
1818
if err != nil {
1919
t.Error(
2020
"Parsing nimble device section failed ", err,

0 commit comments

Comments
 (0)