Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions pkg/dock/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,9 @@ func (pdd *provisionDockDiscoverer) Discover() error {
if err != nil {
return fmt.Errorf("can not read pools in db")
}
dbPolsMap := make(map[string]map[string]*model.StoragePoolSpec)
for _, dck := range pdd.dcks {
dbPolsMap[dck.Id] = make(map[string]*model.StoragePoolSpec)
}
dbPolsMap := make(map[string]*model.StoragePoolSpec)
for _, polInDb := range polsInDb {
if dbPolsMap[polInDb.DockId] != nil {
polInDb.Status = unavailableStatus
dbPolsMap[polInDb.DockId][polInDb.Id] = polInDb
}
dbPolsMap[polInDb.Id] = polInDb
}
for _, dck := range pdd.dcks {
// Call function of StorageDrivers configured by storage drivers.
Expand All @@ -173,7 +167,7 @@ func (pdd *provisionDockDiscoverer) Discover() error {
pols, err = d.ListPools()
for _, pol := range pols {
log.Infof("Backend %s discovered pool %s", dck.DriverName, pol.Name)
delete(dbPolsMap[dck.Id], pol.Id)
delete(dbPolsMap, pol.Id)
pol.DockId = dck.Id
pol.Status = availableStatus
}
Expand All @@ -199,7 +193,7 @@ func (pdd *provisionDockDiscoverer) Discover() error {
pol.Id = pools[0].Id
}

delete(dbPolsMap[dck.Id], pol.Id)
delete(dbPolsMap, pol.Id)
pol.DockId = dck.Id
pol.ReplicationType = replicationType
pol.ReplicationDriverName = replicationDriverName
Expand All @@ -216,11 +210,13 @@ func (pdd *provisionDockDiscoverer) Discover() error {
}

pdd.pols = append(pdd.pols, pols...)
for _, pol := range dbPolsMap[dck.Id] {
pdd.pols = append(pdd.pols, pol)
}

}
// The rest of pools in db should be unavailable pools
for _, pol := range dbPolsMap {
pol.Status = unavailableStatus
pdd.pols = append(pdd.pols, pol)
}
if len(pdd.pols) == 0 {
return fmt.Errorf("there is no pool can be found")
}
Expand Down
26 changes: 21 additions & 5 deletions pkg/dock/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ func TestInit(t *testing.T) {
func TestDiscover(t *testing.T) {
var fdd = NewFakeDockDiscoverer()
var expected []*model.StoragePoolSpec
var dbPols []*model.StoragePoolSpec

for i := range SampleDocks {
fdd.dcks = append(fdd.dcks, &SampleDocks[i])
}
for i := range SamplePools {
fdd.pols = append(fdd.pols, &SamplePools[i])
dbPols = append(dbPols, &SamplePools[i])
expected = append(expected, &SamplePools[i])
}
// Add unavailable pool
for i := range UnavailablePools {
dbPols = append(dbPols, &UnavailablePools[i])
expected = append(expected, &UnavailablePools[i])
}
m1 := map[string][]string{
"Name": {SamplePools[0].Name},
"DockId": {""},
Expand All @@ -101,10 +107,10 @@ func TestDiscover(t *testing.T) {
}

mockClient := new(dbtest.Client)
mockClient.On("ListPools", c.NewAdminContext()).Return(fdd.pols, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m1).Return(expected, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m2).Return(expected, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m3).Return(expected, nil)
mockClient.On("ListPools", c.NewAdminContext()).Return(dbPols, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m1).Return([]*model.StoragePoolSpec{&SamplePools[0]}, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m2).Return([]*model.StoragePoolSpec{&SamplePools[1]}, nil)
mockClient.On("ListPoolsWithFilter", c.NewAdminContext(), m3).Return([]*model.StoragePoolSpec{&SamplePools[2]}, nil)
fdd.c = mockClient

if err := fdd.Discover(); err != nil {
Expand All @@ -116,6 +122,16 @@ func TestDiscover(t *testing.T) {
if !reflect.DeepEqual(fdd.pols, expected) {
t.Errorf("Expected %+v, got %+v\n", expected, fdd.pols)
}
for i := 0; i < len(SamplePools); i++ {
if fdd.pols[i].Status != "available" {
t.Errorf("Expected available, got %s, pool name is %s\n", fdd.pols[i].Status, fdd.pols[i].Name)
}
}
for i := len(SamplePools); i < len(SamplePools)+len(UnavailablePools); i++ {
if fdd.pols[i].Status != "unavailable" {
t.Errorf("Expected unavailable, got %s, pool name is %s\n", fdd.pols[i].Status, fdd.pols[i].Name)
}
}
}

func TestReport(t *testing.T) {
Expand Down
35 changes: 35 additions & 0 deletions testutils/collection/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,41 @@ var (
},
}

UnavailablePools = []model.StoragePoolSpec{
{
BaseModel: &model.BaseModel{
Id: "084bf71e-a102-11e7-88a8-e31fe6d52249",
},
Name: "unavailable pool",
Description: "This is the first sample storage pool for testing",
StorageType: "block",
TotalCapacity: int64(100),
FreeCapacity: int64(90),
DockId: "b7602e18-771e-11e7-8f38-dbd6d291f4e0",
AvailabilityZone: "default",
MultiAttach: true,
Extras: model.StoragePoolExtraSpec{
DataStorage: model.DataStorageLoS{
ProvisioningPolicy: "Thin",
Compression: true,
Deduplication: false,
},
IOConnectivity: model.IOConnectivityLoS{
AccessProtocol: "rbd",
MaxIOPS: 8000000,
MaxBWS: 700,
MinIOPS: 1000000,
MinBWS: 100,
Latency: 100,
},
Advanced: map[string]interface{}{
"diskType": "SSD",
"latency": "3ms",
},
},
},
}

SampleAvailabilityZones = []string{"default"}

SampleFileShares = []model.FileShareSpec{
Expand Down