func TestRexRayDriverNames(t *testing.T) { var err error var r *core.RexRay if r, err = getRexRay(); err != nil { panic(err) } allDriverNames := []string{ strings.ToLower(mock.MockOSDriverName), strings.ToLower(mock.MockVolDriverName), strings.ToLower(mock.MockStorDriverName), strings.ToLower(mock.BadMockOSDriverName), strings.ToLower(mock.BadMockVolDriverName), strings.ToLower(mock.BadMockStorDriverName), "linux", "docker", "ec2", "gce", "isilon", "openstack", "rackspace", "scaleio", "virtualbox", "vmax", "xtremio", } var regDriverNames []string for dn := range r.DriverNames() { regDriverNames = append(regDriverNames, strings.ToLower(dn)) } for _, n := range allDriverNames { if !gotil.StringInSlice(n, regDriverNames) { t.Fail() } } for _, n := range regDriverNames { if !gotil.StringInSlice(n, allDriverNames) { t.Fail() } } }
func assertEnvVar(s string, evs []string, t *testing.T) { if !gotil.StringInSlice(s, evs) { t.Fatal(s) } }
// InitDrivers initializes the drivers for the REX-Ray platform. func (r *RexRay) InitDrivers() error { od := map[string]OSDriver{} vd := map[string]VolumeDriver{} sd := map[string]StorageDriver{} log.Info(r.Config.Get("rexray.osDrivers")) log.Info(r.Config.Get("rexray.volumeDrivers")) log.Info(r.Config.Get("rexray.storageDrivers")) osDrivers := r.Config.GetStringSlice("rexray.osDrivers") volDrivers := r.Config.GetStringSlice("rexray.volumeDrivers") storDrivers := r.Config.GetStringSlice("rexray.storageDrivers") log.WithFields(log.Fields{ "osDrivers": osDrivers, "volumeDrivers": volDrivers, "storageDrivers": storDrivers, }).Debug("core get drivers") for n, d := range r.drivers { switch td := d.(type) { case OSDriver: if gotil.StringInSlice(n, osDrivers) { if err := d.Init(r); err != nil { log.WithFields(log.Fields{ "driverName": n, "error": err}).Debug("error initializing driver") continue } od[n] = td } case VolumeDriver: if gotil.StringInSlice(n, volDrivers) { if err := d.Init(r); err != nil { log.WithFields(log.Fields{ "driverName": n, "error": err}).Debug("error initializing driver") continue } vd[n] = td } case StorageDriver: if gotil.StringInSlice(n, storDrivers) { if err := d.Init(r); err != nil { log.WithFields(log.Fields{ "driverName": n, "error": err}).Debug("error initializing driver") continue } sd[n] = td } } } r.OS = &odm{ rexray: r, drivers: od, } r.Volume = &vdm{ rexray: r, drivers: vd, } r.Storage = &sdm{ rexray: r, drivers: sd, } if err := r.OS.Init(r); err != nil { return err } if err := r.Volume.Init(r); err != nil { return err } if err := r.Storage.Init(r); err != nil { return err } return nil }