Esempio n. 1
0
func (s *storageService) initStorageDriver(ctx types.Context) error {
	driverName := s.config.GetString("driver")
	if driverName == "" {
		driverName = s.config.GetString("libstorage.driver")
		if driverName == "" {
			driverName = s.config.GetString("libstorage.storage.driver")
			if driverName == "" {
				return goof.WithField(
					"service", s.name, "error getting driver name")
			}
		}
	}

	ctx.WithField("driverName", driverName).Debug("got driver name")
	driver, err := registry.NewStorageDriver(driverName)
	if err != nil {
		return err
	}

	ctx = ctx.WithValue(context.DriverKey, driver)

	if err := driver.Init(ctx, s.config); err != nil {
		return err
	}

	s.driver = driver
	return nil
}
Esempio n. 2
0
// Check if InstanceID metadata is properly returned by executor
// and InstanceID.ID is filled out by InstanceInspect
func TestInstanceID(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	// create storage driver
	sd, err := registry.NewStorageDriver(ebs.Name)
	if err != nil {
		t.Fatal(err)
	}

	// initialize storage driver
	ctx := context.Background()
	if err := sd.Init(ctx, registry.NewConfig()); err != nil {
		t.Fatal(err)
	}
	// Get Instance ID metadata from executor
	iid, err := ebsUtils.InstanceID(ctx)
	assert.NoError(t, err)
	if err != nil {
		t.Fatal(err)
	}

	// Fill in Instance ID's ID field with InstanceInspect
	ctx = ctx.WithValue(context.InstanceIDKey, iid)
	i, err := sd.InstanceInspect(ctx, utils.NewStore())
	if err != nil {
		t.Fatal(err)
	}

	iid = i.InstanceID

	// test resulting InstanceID
	apitests.Run(
		t, ebs.Name, nil,
		(&apitests.InstanceIDTest{
			Driver:   ebs.Name,
			Expected: iid,
		}).Test)

}
Esempio n. 3
0
func TestInstanceID(t *testing.T) { //PASSES lowercase hidden for testing other stuff
	if skipTests() {
		t.SkipNow()
	}

	sd, err := registry.NewStorageDriver(rackspace.Name)
	if err != nil {
		t.Fatal(err)
	}

	ctx := context.Background()
	configR := registry.NewConfig()
	if err := configR.ReadConfig(bytes.NewReader(configYAML)); err != nil {
		panic(err)
	}
	if err := sd.Init(ctx, configR); err != nil {
		t.Fatal(err)
	}
	iid, err := rackspacex.InstanceID(configR)
	if err != nil {
		t.Fatal(err)
	}

	ctx = ctx.WithValue(context.InstanceIDKey, iid)
	i, err := sd.InstanceInspect(ctx, utils.NewStore())
	if err != nil {
		t.Fatal(err)
	}

	iid = i.InstanceID

	apitests.Run(
		t, rackspace.Name, configYAML,
		(&apitests.InstanceIDTest{
			Driver:   rackspace.Name,
			Expected: iid,
		}).Test)
}
Esempio n. 4
0
func TestInstanceID(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	sd, err := registry.NewStorageDriver(efs.Name)
	if err != nil {
		t.Fatal(err)
	}

	ctx := context.Background()
	if err := sd.Init(ctx, registry.NewConfig()); err != nil {
		t.Fatal(err)
	}

	iid, err := efsx.InstanceID()
	assert.NoError(t, err)
	if err != nil {
		t.Error("failed TestInstanceID")
		t.FailNow()
	}
	assert.NotEqual(t, iid, "")

	ctx = ctx.WithValue(context.InstanceIDKey, iid)
	i, err := sd.InstanceInspect(ctx, utils.NewStore())
	if err != nil {
		t.Fatal(err)
	}

	iid = i.InstanceID

	apitests.Run(
		t, efs.Name, configYAML,
		(&apitests.InstanceIDTest{
			Driver:   efs.Name,
			Expected: iid,
		}).Test)
}
Esempio n. 5
0
// New returns a new libStorage client.
func New(goCtx gocontext.Context, config gofig.Config) (types.Client, error) {

	if config == nil {
		var err error
		if config, err = apicnfg.NewConfig(); err != nil {
			return nil, err
		}
	}

	config = config.Scope(types.ConfigClient)
	types.BackCompat(config)

	var (
		c   *client
		err error
	)

	c = &client{ctx: context.New(goCtx), config: config}
	c.ctx = c.ctx.WithValue(context.ClientKey, c)

	logFields := log.Fields{}
	logConfig, err := utils.ParseLoggingConfig(
		config, logFields, "libstorage.client")
	if err != nil {
		return nil, err
	}

	// always update the server context's log level
	context.SetLogLevel(c.ctx, logConfig.Level)
	c.ctx.WithFields(logFields).Info("configured logging")

	if config.IsSet(types.ConfigService) {
		c.ctx = c.ctx.WithValue(
			context.ServiceKey, config.GetString(types.ConfigService))
	}

	storDriverName := config.GetString(types.ConfigStorageDriver)
	if storDriverName == "" {
		c.ctx.Warn("no storage driver found")
	} else {
		if c.sd, err = registry.NewStorageDriver(storDriverName); err != nil {
			return nil, err
		}
		if err = c.sd.Init(c.ctx, config); err != nil {
			return nil, err
		}
		if papi, ok := c.sd.(types.ProvidesAPIClient); ok {
			c.api = papi.API()
		}
		if pxli, pxliOk := c.sd.(types.ProvidesStorageExecutorCLI); pxliOk {
			c.xli = pxli.XCLI()
		}
		c.ctx.Info("storage driver initialized")
	}

	// if the API or XLI are nil, then the storage driver is not the libStorage
	// storage driver, and we should jump avoid any more initialization
	if c.api == nil || c.xli == nil {
		c.ctx.Info("created libStorage client")
		return c, nil
	}

	osDriverName := config.GetString(types.ConfigOSDriver)
	if osDriverName == "" {
		c.ctx.Warn("no os driver found")
	} else {
		if c.od, err = registry.NewOSDriver(osDriverName); err != nil {
			return nil, err
		}
		if err = c.od.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("os driver initialized")
	}

	intDriverName := config.GetString(types.ConfigIntegrationDriver)
	if intDriverName == "" {
		c.ctx.Warn("no integration driver found")
	} else {
		if c.id, err = registry.NewIntegrationDriver(
			intDriverName); err != nil {
			return nil, err
		}
		if err := c.id.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("integration driver initialized")
	}

	c.ctx.Info("created libStorage client")
	return c, nil
}