diff --git a/pkg/baremetal/manager.go b/pkg/baremetal/manager.go index 5790c46a0d..b4570d4adf 100644 --- a/pkg/baremetal/manager.go +++ b/pkg/baremetal/manager.go @@ -2458,6 +2458,7 @@ func (s *SBaremetalServer) DoDiskConfig(term *ssh.Client) error { for tried := 0; !tool.IsAllDisksReady() && tried < maxTries; tried++ { time.Sleep(5 * time.Second) tool.RetrieveDiskInfo() + log.Warningf("disktool not ready string: %s", tool.DebugString()) } if !tool.IsAllDisksReady() { diff --git a/pkg/baremetal/utils/disktool/disktool.go b/pkg/baremetal/utils/disktool/disktool.go index 9c3b7d24a5..1daae03fbf 100644 --- a/pkg/baremetal/utils/disktool/disktool.go +++ b/pkg/baremetal/utils/disktool/disktool.go @@ -288,7 +288,7 @@ func (ps *DiskPartitions) String() string { func (ps *DiskPartitions) DebugString() string { partitionsStr := []string{} for _, p := range ps.partitions { - partitionsStr = append(partitionsStr, fmt.Sprintf("%#v", *p)) + partitionsStr = append(partitionsStr, fmt.Sprintf("{%#v}", *p)) } return fmt.Sprintf("driver: %s, dev: %s, sectors: %d, partitions: %#v", ps.driver, ps.dev, ps.sectors, partitionsStr) } @@ -599,7 +599,7 @@ func (tool *PartitionTool) DebugString() string { return ret } for driver, disks := range tool.diskTable { - s := fmt.Sprintf("%s: %v", driver, disksString(disks)) + s := fmt.Sprintf("(%s: %v)", driver, disksString(disks)) ret = append(ret, s) } return strings.Join(ret, "\n") diff --git a/pkg/baremetal/utils/raid/sas2iru/sas2iru.go b/pkg/baremetal/utils/raid/sas2iru/sas2iru.go index 13c51a4d58..e228980b7b 100644 --- a/pkg/baremetal/utils/raid/sas2iru/sas2iru.go +++ b/pkg/baremetal/utils/raid/sas2iru/sas2iru.go @@ -38,7 +38,7 @@ type Mpt2SASRaidPhyDev struct { } func newMpt2SASRaidPhyDev(adapter int) *Mpt2SASRaidPhyDev { - b := raid.NewRaidBasePhyDev(baremetal.DISK_DRIVER_MARVELRAID) + b := raid.NewRaidBasePhyDev(baremetal.DISK_DRIVER_MPT2SAS) b.Adapter = adapter return &Mpt2SASRaidPhyDev{ RaidBasePhyDev: b, @@ -116,6 +116,7 @@ func (dev *Mpt2SASRaidPhyDev) isComplete() bool { func (dev *Mpt2SASRaidPhyDev) ToBaremetalStorage(idx int) *baremetal.BaremetalStorage { s := dev.RaidBasePhyDev.ToBaremetalStorage(idx) + s.Index = int64(idx) s.Slot = dev.slot s.Enclosure = dev.enclosure s.Block = int64(dev.block) @@ -296,7 +297,9 @@ func (adapter *Mpt2SASRaidAdaptor) BuildRaid10(devs []*baremetal.BaremetalStorag } func (adapter *Mpt2SASRaidAdaptor) BuildNoneRaid(devs []*baremetal.BaremetalStorage) error { - return fmt.Errorf("Not impl") + // TODO: not impl + // return fmt.Errorf("Not impl") + return nil } func (adapter *Mpt2SASRaidAdaptor) RemoveLogicVolumes() error { @@ -338,11 +341,25 @@ func (r *Mpt2SASRaid) ParsePhyDevs() error { return r.parseAdapters(ret) } +func getLineAdapterIndex(line string) int { + dat := regexp.MustCompile(`\s+`).Split(strings.TrimSpace(line), -1) + if len(dat) == 0 { + return -1 + } + if regexp.MustCompile(`\d+`).MatchString(dat[0]) { + if !regexp.MustCompile(`^\d+`).MatchString(dat[0]) { + return -1 + } + idx, _ := strconv.Atoi(dat[0]) + return idx + } + return -1 +} + func (r *Mpt2SASRaid) parseAdapters(lines []string) error { for _, line := range lines { - dat := regexp.MustCompile(`\s+`).Split(strings.TrimSpace(line), -1) - if regexp.MustCompile(`\d+`).MatchString(dat[0]) { - idx, _ := strconv.Atoi(dat[0]) + idx := getLineAdapterIndex(line) + if idx >= 0 { adapter := newMpt2SASRaidAdaptor(idx, r) r.adapters = append(r.adapters, adapter) } diff --git a/pkg/baremetal/utils/raid/sas2iru/sas2iru_test.go b/pkg/baremetal/utils/raid/sas2iru/sas2iru_test.go new file mode 100644 index 0000000000..eed9b958de --- /dev/null +++ b/pkg/baremetal/utils/raid/sas2iru/sas2iru_test.go @@ -0,0 +1,40 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sas2iru + +import "testing" + +func Test_getLineAdapterIndex(t *testing.T) { + tests := []struct { + line string + want int + }{ + { + line: "0 SAS3008 100h 97h 00h:5eh:00h:00h 1000h 0097h", + want: 0, + }, + { + line: "SAS3IRCU: Utility Completed Successfully.", + want: -1, + }, + } + for _, tt := range tests { + t.Run(tt.line, func(t *testing.T) { + if got := getLineAdapterIndex(tt.line); got != tt.want { + t.Errorf("getLineAdapterIndex() = %v, want %v", got, tt.want) + } + }) + } +}