Skip to content

Commit

Permalink
CON-2295: Merge of multipath.conf is not comprehensive (#169)
Browse files Browse the repository at this point in the history
Signed-off-by: Adarsh Pratik <[email protected]>
  • Loading branch information
adarshpratikhpe authored Mar 29, 2022
1 parent 4df04fb commit cc7b5fc
Show file tree
Hide file tree
Showing 12 changed files with 1,538 additions and 730 deletions.
41 changes: 39 additions & 2 deletions linux/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package linux
import (
"errors"
"fmt"
log "github.com/hpe-storage/common-host-libs/logger"
"github.com/hpe-storage/common-host-libs/util"
"os"
"regexp"
"strconv"
"strings"
"sync"

log "github.com/hpe-storage/common-host-libs/logger"
"github.com/hpe-storage/common-host-libs/util"
)

const (
Expand Down Expand Up @@ -96,6 +97,42 @@ func GetOsInfo() (*OsInfo, error) {
return osInfo, nil
}

func GetDistro() (string, error) {
osInfoLock.Lock()
defer osInfoLock.Unlock()
var out, distro string
if f, err := os.Stat(osReleaseFile); err == nil && !f.IsDir() && f.Size() != 0 {
// get only PRETTY_NAME field of os-release
var lines []string
lines, err = util.FileGetStrings(osReleaseFile)
for _, line := range lines {
if strings.Contains(line, "PRETTY_NAME") {
// remove quotes and key
out = strings.Replace(strings.Replace(line, "\"", "", -1), "PRETTY_NAME=", "", -1)
break
}
}

if out != "" {
if strings.Contains(out, "Ubuntu") {
distro = "Ubuntu"
} else if strings.Contains(out, "Red Hat") {
distro = "Red Hat"
} else if strings.Contains(out, "Centos") {
distro = "Centos"
} else if strings.Contains(out, "SUSE") {
distro = "SUSE"
} else {
log.Info("Cannot determine Distro")
return "", errors.New("Undefined DistroType")
}
return distro, nil
}
}
return "", errors.New("Unable to determine DistroType")

}

// GetKernelVersion returns OS kernel version
func (o *OsInfo) GetKernelVersion() string {
return strings.TrimSpace(o.kernelVersion)
Expand Down
43 changes: 20 additions & 23 deletions mpathconfig/configresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"container/list"
"errors"
"fmt"
log "github.com/hpe-storage/common-host-libs/logger"
"github.com/hpe-storage/common-host-libs/util"
"os"
"path"
"regexp"
"strconv"
"strings"
"sync"
"time"

log "github.com/hpe-storage/common-host-libs/logger"
"github.com/hpe-storage/common-host-libs/util"
)

const (
Expand Down Expand Up @@ -239,25 +240,21 @@ func addOption(section *Section, option string) {

//checks for the section
func isSection(line string) (bool, error) {
line = strings.TrimSpace(line)
prefixes := []string{"defaults", "blacklist", "blacklist_exceptions", "devices", "device", "multipaths", "multipath"}
for _, prefix := range prefixes {
r, err := regexp.Compile("^"+prefix+"\\s*[{]*$")
if err != nil {
return false, err
}

if(r.MatchString(line)) {
return true, nil
}
}

return false, nil
}


line = strings.TrimSpace(line)
prefixes := []string{"defaults", "blacklist", "blacklist_exceptions", "devices", "device", "multipaths", "multipath"}
for _, prefix := range prefixes {
r, err := regexp.Compile("^" + prefix + "\\s*[{]*$")
if err != nil {
return false, err
}

if r.MatchString(line) {
return true, nil
}
}

return false, nil
}

// ParseConfig reads and parses give config file into sections
func ParseConfig(filePath string) (config *Configuration, err error) {
Expand Down Expand Up @@ -349,9 +346,9 @@ func SaveConfig(config *Configuration, filePath string) (err error) {
return err
}

// GetNimbleSection gets nimble device section in /etc/multipath.conf
func (config *Configuration) GetNimbleSection() (section *Section, err error) {
log.Trace("GetNimbleSection called")
// GetDeviceSection gets device section in /etc/multipath.conf
func (config *Configuration) GetDeviceSection(deviceType string) (section *Section, err error) {
log.Trace("GetDeviceSection called for device: ", deviceType)
config.mutex.RLock()
defer config.mutex.RUnlock()

Expand All @@ -363,7 +360,7 @@ func (config *Configuration) GetNimbleSection() (section *Section, err error) {
if s.GetChildren().Len() != 0 {
for e := s.GetChildren().Front(); e != nil; e = e.Next() {
childSection := e.Value.(*Section)
if childSection.GetName() == "device" && strings.Contains(childSection.properties["vendor"], "Nimble") {
if childSection.GetName() == "device" && strings.Contains(childSection.properties["vendor"], deviceType) {
return childSection, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion mpathconfig/configresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestParseDeviceSection(t *testing.T) {
)
} else {
// config found
section, err := config.GetNimbleSection()
section, err := config.GetDeviceSection()
if err != nil {
t.Error(
"Parsing nimble device section failed ", err,
Expand Down
Loading

0 comments on commit cc7b5fc

Please sign in to comment.