diff --git a/.docs/about/release-notes.md b/.docs/about/release-notes.md index 37ea47bdc..afb7c3298 100644 --- a/.docs/about/release-notes.md +++ b/.docs/about/release-notes.md @@ -208,8 +208,8 @@ users. The commands are now categorized into logical groups: Global Flags: -c, --config="/Users/akutz/.rexray/config.yaml": The REX-Ray configuration file -?, --help[=false]: Help for rexray - -h, --host="tcp://:7979": The REX-Ray service address - -l, --logLevel="info": The log level (panic, fatal, error, warn, info, debug) + -h, --rexrayHost="tcp://:7979": The REX-Ray service address + -l, --rexrayLogLevel="info": The log level (panic, fatal, error, warn, info, debug) -v, --verbose[=false]: Print verbose help information Use "rexray [command] --help" for more information about a command. diff --git a/.docs/index.md b/.docs/index.md index ef859ba39..81568b01f 100644 --- a/.docs/index.md +++ b/.docs/index.md @@ -12,8 +12,8 @@ list storage for a guest hosted on Amazon Web Services (AWS) with `REX-Ray`: ```bash $ export REXRAY_STORAGEDRIVERS=ec2 -$ export AWS_ACCESS_KEY=access_key -$ export AWS_SECRET_KEY=secret_key +$ export AWS_ACCESSKEY=access_key +$ export AWS_SECRETKEY=secret_key $ rexray volume get - providername: ec2 diff --git a/.docs/user-guide/config.md b/.docs/user-guide/config.md index e085cb17c..81f2ee875 100644 --- a/.docs/user-guide/config.md +++ b/.docs/user-guide/config.md @@ -70,11 +70,37 @@ This is an example configuration with the default configuration for the general options as described in the following section: ```yaml -logLevel: warn -osDrivers: -- linux -volumeDrivers: -- docker +rexray: + logLevel: warn + osDrivers: + - linux + volumeDrivers: + - docker +``` + +## Configuration Files +There are two `REX-Ray` configuration files - global and user: + +* `/etc/rexray/config.yml` +* `$HOME/.rexray/config.yml` + +Please note that while the user configuration file is located inside the user's +home directory, this is the directory of the user that starts `REX-Ray`. And +if `REX-Ray` is being started as a service, then `sudo` is likely being used, +which means that `$HOME/.rexray/config.yml` won't point to *your* home +directory, but rather `/root/.rexray/config.yml`. + +This is an example configuration with the default configuration for the general +options as described in the following section: + +```yaml +rexray: + logLevel: warn + osDrivers: + - linux + storageDrivers: + volumeDrivers: + - docker ``` ## Configuration Properties @@ -88,58 +114,27 @@ These are the global configuration properties with their default values as represented in a a YAML configuration file: ```yaml -logLevel: warn -osDrivers: -- linux -storageDrivers: -volumeDrivers: -- docker +rexray: + logLevel: warn + osDrivers: + - linux + storageDrivers: + volumeDrivers: + - docker ``` -The property `logLevel` is a string and the properties `osDrivers`, -`storageDrivers`, and `volumeDrivers` are all arrays of strings. These values -can also be set via environment variables or the command line, but to do so -requires knowing the names of the environment variables or CLI flags to use. -Luckily those are very easy to figure out just by knowing the property names. - -### Top-Level Properties -For any configuration file property there is really only one exception to -consider when deriving the name of the property's equivalent environment -variable or CLI flag: is the property a top-level property? The top-level -properties are: - - * `logLevel` - * `osDrivers` - * `storageDrivers` - * `volumeDrivers` - -For any top-level property the name of its equivalent environment variable is -the name of the property, in all caps, prefixed with `REXRAY_`. Additionally, -the name of the property's CLI flag is equivalent to the property name, as is. -The following table illustrates the transformations: - -Property Name | Environment Variable | CLI Flag ---------------|----------------------|------------- -`logLevel` | `REXRAY_LOGLEVEL` | `--logLevel` -`osDrivers` | `REXRAY_OSDRIVERS` | `--osDrivers` -`storageDrivers` | `REXRAY_STORAGEDRIVERS` | `--storageDrivers` -`volumeDrivers` | `REXRAY_VOLUMEDRIVERS` | `--volumeDrivers` - -### All Other Properties -The other properties that might appear in the `REX-Ray` configuration file all -fall under some type of heading. For example, a possible configuration of the -Amazon Web Services (AWS) Elastic Compute Cloud (EC2) storage driver might look -like this: +The property `rexray.logLevel` is a string and the properties +`rexray.osDrivers`, `rexray.storageDrivers`, and `rexray.volumeDrivers` are all +arrays of strings. These values can also be set via environment variables or the +command line, but to do so requires knowing the names of the environment +variables or CLI flags to use. Luckily those are very easy to figure out just +by knowing the property names. -```yaml -aws: - accessKey: MyAccessKey - secretKey: MySecretKey - region: USNW -``` +All properties that might appear in the `REX-Ray` configuration file +fall under some type of heading. For example, take the default configuration +above. -For any property that's nested, the rule for environment variables is as -follows: +The rule for environment variables is as follows: * Each nested level becomes a part of the environment variable name followed by an underscore `_` except for the terminating part. @@ -155,6 +150,23 @@ Nested properties follow these rules for CLI flags: The following table illustrates the transformations: +Property Name | Environment Variable | CLI Flag +--------------|----------------------|------------- +`rexray.logLevel` | `REXRAY_LOGLEVEL` | `--rexrayLogLevel` +`rexray.osDrivers` | `REXRAY_OSDRIVERS` | `--rexrayOsDrivers` +`rexray.storageDrivers` | `REXRAY_STORAGEDRIVERS` | `--rexrayStorageDrivers` +`rexray.volumeDrivers` | `REXRAY_VOLUMEDRIVERS` | `--rexrayVolumeDrivers` + +Another example is a possible configuration of the Amazon Web Services (AWS) +Elastic Compute Cloud (EC2) storage driver: + +```yaml +aws: + accessKey: MyAccessKey + secretKey: MySecretKey + region: USNW +``` + Property Name | Environment Variable | CLI Flag --------------|----------------------|------------- `aws.accessKey` | `AWS_ACCESSKEY` | `--awsAccessKey` @@ -163,9 +175,9 @@ Property Name | Environment Variable | CLI Flag ### String Arrays Please note that properties that are represented as arrays in a configuration -file, such as the `osDrivers`, `storageDrivers`, and `volumeDrivers` above, are -not arrays, but multi-valued strings where a space acts as a delimiter. This is -because the Viper project +file, such as the `rexray.osDrivers`, `rexray.storageDrivers`, and +`rexray.volumeDrivers` above, are not arrays, but multi-valued strings where a +space acts as a delimiter. This is because the Viper project [does not bind](https://github.com/spf13/viper/issues/112) Go StringSlices (string arrays) correctly to [PFlags](https://github.com/spf13/pflag). @@ -173,14 +185,15 @@ For example, this is how one would specify the storage drivers `ec2` and `xtremio` in a configuration file: ```yaml -storageDrivers: +rexray: + storageDrivers: - ec2 - xtremio ``` However, to specify the same values in an environment variable, `REXRAY_STORAGEDRIVERS="ec2 xtremio"`, and as a CLI flag, -`--storageDrivers="ec2 xtremio"`. +`--rexrayStorageDrivers="ec2 xtremio"`. ## Logging The `REX-Ray` log level determines the level of verbosity emitted by the @@ -194,13 +207,6 @@ as well: `info` | Log errors, warnings, and workflow messages `debug` | Log everything -The log level can be set by environment variable, a configuration file, or via -the command line: - -Environment Variable | Config File Property | CLI Flag(s) ----------------------|----------------------|------------- -`REXRAY_LOGLEVEL` | `logLevel` | `--logLevel`, `-l` - For example, the following two commands may look slightly different, but they are functionally the same, both printing a list of volumes using the `debug` log level: @@ -215,57 +221,20 @@ rexray volume get -l debug env REXRAY_LOGLEVEL=debug rexray volume get ``` -## OS Drivers +### OS Drivers Operating system (OS) drivers enable `REX-Ray` to manage storage on -the underlying OS. - -### OS Driver Types -Currently the following OS drivers are supported: +the underlying OS. Currently the following OS drivers are supported: Driver | Driver Name --------|------------ Linux | linux -### Automatic OS Drivers The OS driver `linux` is automatically activated when `REX-Ray` is running on the Linux OS. -### Activating OS Drivers -While all drivers are automatically registered, they are not all automatically -activated. OS drivers can be activated by by environment variable, a -configuration file, or via the command line: - -Environment Variable | Config File Property | CLI Flag(s) ----------------------|----------------------|------------- -`REXRAY_OSDRIVERS` | `osDrivers` | `--osDrivers` - -The environment variable and CLI flag both expect a space-delimited list of -OS driver names such as: - -```bash -env REXRAY_OSDRIVERS=linux rexray volume get -``` - -or - -```bash -rexray volume get --osDrivers=linux -``` - -However, when specifying the `osDrivers` option in a configuration file, since -the option is multi-valued, it would look like the following: - -```yaml -osDrivers: -- linux -``` - -## Storage Drivers +### Storage Drivers Storage drivers enable `REX-Ray` to communicate with direct-attached or remote -storage systems. - -### Storage Driver Types -Currently the following storage drivers are supported: +storage systems. Currently the following storage drivers are supported: Driver | Driver Name --------|------------ @@ -275,80 +244,15 @@ Rackspace | rackspace ScaleIO | scaleio XtremIO | xtremio -### Automatic Storage Drivers -No storage drivers are automatically activated. - -### Activating Storage Drivers -While all drivers are automatically registered, not all are automatically -activated. Storage drivers can be activated by by environment variable, a -configuration file, or via the command line: - -Environment Variable | Config File Property | CLI Flag(s) ----------------------|----------------------|------------- -`REXRAY_STORAGEDRIVERS` | `storageDrivers` | `--storageDrivers` - -The environment variable and CLI flag both expect a space-delimited list of -storage driver names such as: +The `rexray.storageDrivers` property can be used to activate storage drivers.. -```bash -env REXRAY_STORAGEDRIVERS="ec2 xtremio" rexray volume get -``` - -or - -```bash -rexray volume get --osDrivers="ec2 xtremio" -``` - -However, when specifying the `storageDrivers` option in a configuration file, -since the option is multi-valued, it would look like the following: - -```yaml -storageDrivers: -- ec2 -- xtremio -``` - -## Volume Drivers +### Volume Drivers Volume drivers enable `REX-Ray` to manage volumes for consumers of the storage, -such as `Docker` or `Mesos`. - -### Volume Driver Types -Currently the following volume drivers are supported: +such as `Docker` or `Mesos`. Currently the following volume drivers are +supported: Driver | Driver Name --------|------------ Docker | docker -### Automatic Volume Drivers The volume driver `docker` is automatically activated. - -### Activating Volume Drivers -While all drivers are automatically registered, they are not all automatically -activated. Volume drivers can be activated by by environment variable, a -configuration file, or via the command line: - -Environment Variable | Config File Property | CLI Flag(s) ----------------------|----------------------|------------- -`REXRAY_VOLUMEDRIVERS` | `volumeDrivers` | `--volumeDrivers` - -The environment variable and CLI flag both expect a space-delimited list of -volume driver names such as: - -```bash -env REXRAY_VOLUMEDRIVERS=docker rexray volume get -``` - -or - -```bash -rexray volume get --volumeDrivers=docker -``` - -However, when specifying the `volumeDrivers` option in a configuration file, -since the option is multi-valued, it would look like the following: - -```yaml -volumeDrivers: -- docker -``` diff --git a/core/config/config.go b/core/config/config.go deleted file mode 100644 index a885704dc..000000000 --- a/core/config/config.go +++ /dev/null @@ -1,383 +0,0 @@ -package config - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - "regexp" - "strings" - - log "github.com/Sirupsen/logrus" - flag "github.com/spf13/pflag" - "github.com/spf13/viper" - - "github.com/emccode/rexray/core/errors" - "github.com/emccode/rexray/util" -) - -var ( - envVarRx *regexp.Regexp - bracketRx *regexp.Regexp - registrations []*Registration -) - -func init() { - envVarRx = regexp.MustCompile(`^\s*([^#=]+)=(.+)$`) - bracketRx = regexp.MustCompile(`^\[(.*)\]$`) - loadEtcEnvironment() - Register(globalRegistration()) - Register(driverRegistration()) -} - -// Config contains the configuration information -type Config struct { - FlagSets map[string]*flag.FlagSet `json:"-"` - v *viper.Viper -} - -// Register registers a new configuration with the config package. -func Register(r *Registration) { - registrations = append(registrations, r) -} - -// New initializes a new instance of a Config struct -func New() *Config { - return NewConfig(true, true, "config", "yml") -} - -// NewConfig initialies a new instance of a Config object with the specified -// options. -func NewConfig( - loadGlobalConfig, loadUserConfig bool, - configName, configType string) *Config { - - log.Debug("initializing configuration") - - c := &Config{ - v: viper.New(), - FlagSets: map[string]*flag.FlagSet{}, - } - c.v.SetTypeByDefaultValue(false) - c.v.SetConfigName(configName) - c.v.SetConfigType(configType) - - c.processRegistrations() - - cfgFile := fmt.Sprintf("%s.%s", configName, configType) - etcRexRayFile := util.EtcFilePath(cfgFile) - usrRexRayFile := fmt.Sprintf("%s/.rexray/%s", util.HomeDir(), cfgFile) - - if loadGlobalConfig && util.FileExists(etcRexRayFile) { - log.WithField("path", etcRexRayFile).Debug("loading global config file") - if err := c.ReadConfigFile(etcRexRayFile); err != nil { - log.WithFields(log.Fields{ - "path": etcRexRayFile, - "error": err}).Error( - "error reading global config file") - } - } - - if loadUserConfig && util.FileExists(usrRexRayFile) { - log.WithField("path", usrRexRayFile).Debug("loading user config file") - if err := c.ReadConfigFile(usrRexRayFile); err != nil { - log.WithFields(log.Fields{ - "path": usrRexRayFile, - "error": err}).Error( - "error reading user config file") - } - } - - return c -} - -func (c *Config) processRegistrations() { - for _, r := range registrations { - - fs := &flag.FlagSet{} - - for _, k := range r.keys { - - evn := k.envVarName - - if !strings.Contains(k.keyName, ".") { - evn = fmt.Sprintf("REXRAY_%s", k.envVarName) - } - - log.WithFields(log.Fields{ - "keyName": k.keyName, - "keyType": k.keyType, - "flagName": k.flagName, - "envVar": evn, - "defaultValue": k.defVal, - "usage": k.desc, - }).Debug("adding flag") - - // bind the environment variable - c.v.BindEnv(k.keyName, evn) - - if k.short == "" { - switch k.keyType { - case String: - fs.String(k.flagName, k.defVal.(string), k.desc) - case Int: - fs.Int(k.flagName, k.defVal.(int), k.desc) - case Bool: - fs.Bool(k.flagName, k.defVal.(bool), k.desc) - } - } else { - switch k.keyType { - case String: - fs.StringP(k.flagName, k.short, k.defVal.(string), k.desc) - case Int: - fs.IntP(k.flagName, k.short, k.defVal.(int), k.desc) - case Bool: - fs.BoolP(k.flagName, k.short, k.defVal.(bool), k.desc) - } - } - - c.v.BindPFlag(k.keyName, fs.Lookup(k.flagName)) - } - - c.FlagSets[r.name+" Flags"] = fs - - // read the config - if r.yaml != "" { - c.ReadConfig(bytes.NewReader([]byte(r.yaml))) - } - } -} - -// Copy creates a copy of this Config instance -func (c *Config) Copy() (*Config, error) { - newC := New() - m := map[string]interface{}{} - c.v.Unmarshal(&m) - for k, v := range m { - newC.v.Set(k, v) - } - return newC, nil -} - -// FromJSON initializes a new Config instance from a JSON string -func FromJSON(from string) (*Config, error) { - c := New() - m := map[string]interface{}{} - if err := json.Unmarshal([]byte(from), &m); err != nil { - return nil, err - } - for k, v := range m { - c.v.Set(k, v) - } - return c, nil -} - -// ToJSON exports this Config instance to a JSON string -func (c *Config) ToJSON() (string, error) { - buf, _ := json.MarshalIndent(c, "", " ") - return string(buf), nil -} - -// ToJSONCompact exports this Config instance to a compact JSON string -func (c *Config) ToJSONCompact() (string, error) { - buf, _ := json.Marshal(c) - return string(buf), nil -} - -// MarshalJSON implements the encoding/json.Marshaller interface. It allows -// this type to provide its own marshalling routine. -func (c *Config) MarshalJSON() ([]byte, error) { - return json.Marshal(c.allSettings()) -} - -// ReadConfig reads a configuration stream into the current config instance -func (c *Config) ReadConfig(in io.Reader) error { - - if in == nil { - return errors.New("config reader is nil") - } - - c.v.ReadConfigNoNil(in) - - return nil -} - -// ReadConfigFile reads a configuration files into the current config instance -func (c *Config) ReadConfigFile(filePath string) error { - buf, err := ioutil.ReadFile(filePath) - if err != nil { - return err - } - return c.ReadConfig(bytes.NewBuffer(buf)) -} - -// EnvVars returns an array of the initialized configuration keys as key=value -// strings where the key is configuration key's environment variable key and -// the value is the current value for that key. -func (c *Config) EnvVars() []string { - keyVals := c.allSettings() - envVars := make(map[string]string) - c.flattenEnvVars("", keyVals, envVars) - var evArr []string - for k, v := range envVars { - kk := k - if !strings.Contains(k, "_") { - kk = "REXRAY_" + k - } - evArr = append(evArr, fmt.Sprintf("%s=%v", kk, v)) - } - return evArr -} - -// flattenEnvVars returns a map of configuration keys coming from a config -// which may have been nested. -func (c *Config) flattenEnvVars( - prefix string, keys map[string]interface{}, envVars map[string]string) { - - for k, v := range keys { - - var kk string - if prefix == "" { - kk = k - } else { - kk = fmt.Sprintf("%s.%s", prefix, k) - } - ek := strings.ToUpper(strings.Replace(kk, ".", "_", -1)) - - log.WithFields(log.Fields{ - "key": kk, - "value": v, - }).Debug("flattening env vars") - - switch vt := v.(type) { - case string: - envVars[ek] = vt - case []interface{}: - var vArr []string - for _, iv := range vt { - vArr = append(vArr, iv.(string)) - } - envVars[ek] = strings.Join(vArr, " ") - case map[string]interface{}: - c.flattenEnvVars(kk, vt, envVars) - case bool: - envVars[ek] = fmt.Sprintf("%v", vt) - case int, int32, int64: - envVars[ek] = fmt.Sprintf("%v", vt) - } - } - return -} - -func (c *Config) allSettings() map[string]interface{} { - as := map[string]interface{}{} - ms := map[string]map[string]interface{}{} - - for k, v := range c.v.AllSettings() { - switch tv := v.(type) { - case nil: - continue - case map[string]interface{}: - ms[k] = tv - default: - as[k] = tv - } - } - - for msk, msv := range ms { - flat := map[string]interface{}{} - flattenMapKeys(msk, msv, flat) - for fk, fv := range flat { - if asv, ok := as[fk]; ok && asv == fv { - delete(as, fk) - } - } - as[msk] = msv - } - - return as -} - -func flattenMapKeys( - prefix string, m map[string]interface{}, flat map[string]interface{}) { - for k, v := range m { - kk := fmt.Sprintf("%s.%s", prefix, k) - switch vt := v.(type) { - case map[string]interface{}: - flattenMapKeys(kk, vt, flat) - default: - flat[strings.ToLower(kk)] = v - } - } -} - -// GetString returns the value associated with the key as a string -func (c *Config) GetString(k string) string { - return c.v.GetString(k) -} - -// GetBool returns the value associated with the key as a bool -func (c *Config) GetBool(k string) bool { - return c.v.GetBool(k) -} - -// GetStringSlice returns the value associated with the key as a string slice -func (c *Config) GetStringSlice(k string) []string { - return c.v.GetStringSlice(k) -} - -// GetInt returns the value associated with the key as an int -func (c *Config) GetInt(k string) int { - return c.v.GetInt(k) -} - -// Get returns the value associated with the key -func (c *Config) Get(k string) interface{} { - return c.v.Get(k) -} - -// Set sets an override value -func (c *Config) Set(k string, v interface{}) { - c.v.Set(k, v) -} - -func loadEtcEnvironment() { - lr := util.LineReader("/etc/environment") - if lr == nil { - return - } - for l := range lr { - m := envVarRx.FindStringSubmatch(l) - if m == nil || len(m) < 3 || os.Getenv(m[1]) != "" { - continue - } - os.Setenv(m[1], m[2]) - } -} - -func globalRegistration() *Registration { - r := NewRegistration("Global") - r.Yaml(`host: tcp://:7979 -logLevel: warn -`) - r.Key(String, "h", "tcp://:7979", "The REX-Ray host", "host") - r.Key(String, - "l", "warn", "The log level (error, warn, info, debug)", "logLevel") - return r -} - -func driverRegistration() *Registration { - r := NewRegistration("Driver") - r.Yaml(`osDrivers: -- linux -volumeDrivers: -- docker -`) - r.Key(String, "", "linux", "The OS drivers to consider", "osDrivers") - r.Key(String, "", "", "The storage drivers to consider", "storageDrivers") - r.Key(String, - "", "docker", "The volume drivers to consider", "volumeDrivers") - return r -} diff --git a/core/config/config_registration.go b/core/config/config_registration.go deleted file mode 100644 index 492c6b3c2..000000000 --- a/core/config/config_registration.go +++ /dev/null @@ -1,120 +0,0 @@ -package config - -import ( - "bytes" - "strings" - "unicode" - - "github.com/emccode/rexray/core/errors" -) - -// Registration is used to register configuration information with the config -// package. -type Registration struct { - name string - yaml string - keys []*regKey -} - -// KeyType is a config registration key type. -type KeyType int - -const ( - // String is a key with a string value - String KeyType = iota - - // Int is a key with an integer value - Int - - // Bool is a key with a boolean value - Bool -) - -type regKey struct { - keyType KeyType - defVal interface{} - short string - desc string - keyName string - flagName string - envVarName string -} - -// NewRegistration creates a new registration with the given name. -func NewRegistration(name string) *Registration { - return &Registration{ - name: name, - keys: []*regKey{}, - } -} - -// Yaml sets the registration's default yaml configuration. -func (r *Registration) Yaml(y string) { - r.yaml = y -} - -// Key adds a key to the registration. -// -// The first vararg argument is the yaml name of the key, using a '.' as -// the nested separator. If the second two arguments are omitted they will be -// generated from the first argument. The second argument is the explicit name -// of the flag bound to this key. The third argument is the explicit name of -// the environment variable bound to thie key. -func (r *Registration) Key( - keyType KeyType, - short string, - defVal interface{}, - description string, - keys ...string) { - - if keys == nil { - panic(errors.New("keys is nil")) - } - - lk := len(keys) - - if lk == 0 { - panic(errors.New("len(keys) == 0")) - } - - kn := keys[0] - - rk := ®Key{ - keyType: keyType, - short: short, - desc: description, - defVal: defVal, - keyName: keys[0], - } - - if lk < 2 { - kp := strings.Split(kn, ".") - for x, s := range kp { - if x == 0 { - var buff []byte - b := bytes.NewBuffer(buff) - for y, r := range s { - if y == 0 { - b.WriteRune(unicode.ToLower(r)) - } else { - b.WriteRune(r) - } - } - kp[x] = b.String() - } else { - kp[x] = strings.Title(s) - } - } - rk.flagName = strings.Join(kp, "") - } - - if lk < 3 { - kp := strings.Split(kn, ".") - for x, s := range kp { - kp[x] = strings.ToUpper(s) - } - rk.envVarName = strings.Join(kp, "_") - } - - r.keys = append(r.keys, rk) -} diff --git a/core/config/config_test.go b/core/config/config_test.go deleted file mode 100644 index 968c6a0f9..000000000 --- a/core/config/config_test.go +++ /dev/null @@ -1,627 +0,0 @@ -package config - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "reflect" - "strings" - "testing" - - //log "github.com/Sirupsen/logrus" - - "github.com/emccode/rexray/util" -) - -var ( - tmpPrefixDirs []string - usrRexRayFile string -) - -func TestMain(m *testing.M) { - //log.SetLevel(log.DebugLevel) - usrRexRayDir := fmt.Sprintf("%s/.rexray", util.HomeDir()) - os.MkdirAll(usrRexRayDir, 0755) - usrRexRayFile = fmt.Sprintf("%s/%s.%s", usrRexRayDir, "config", "yml") - usrRexRayFileBak := fmt.Sprintf("%s.bak", usrRexRayFile) - - os.Remove(usrRexRayFileBak) - os.Rename(usrRexRayFile, usrRexRayFileBak) - - exitCode := m.Run() - for _, d := range tmpPrefixDirs { - os.RemoveAll(d) - } - - os.Remove(usrRexRayFile) - os.Rename(usrRexRayFileBak, usrRexRayFile) - os.Exit(exitCode) -} - -func newPrefixDir(testName string, t *testing.T) string { - tmpDir, err := ioutil.TempDir( - "", fmt.Sprintf("rexray-core-config_test-%s", testName)) - if err != nil { - t.Fatal(err) - } - - util.Prefix(tmpDir) - os.MkdirAll(tmpDir, 0755) - tmpPrefixDirs = append(tmpPrefixDirs, tmpDir) - return tmpDir -} - -func TestAssertConfigDefaults(t *testing.T) { - newPrefixDir("TestAssertConfigDefaults", t) - wipeEnv() - c := New() - - osDrivers := c.GetStringSlice("osDrivers") - volDrivers := c.GetStringSlice("volumeDrivers") - - assertString(t, c, "host", "tcp://:7979") - assertString(t, c, "logLevel", "warn") - - if len(osDrivers) != 1 || osDrivers[0] != "linux" { - t.Fatalf("osDrivers != []string{\"linux\"}, == %v", osDrivers) - } - - if len(volDrivers) != 1 || volDrivers[0] != "docker" { - t.Fatalf("volumeDrivers != []string{\"docker\"}, == %v", volDrivers) - } -} - -func TestAssertTestRegistration(t *testing.T) { - newPrefixDir("TestAssertTestRegistration", t) - wipeEnv() - Register(testRegistration()) - c := New() - - userName := c.GetString("mockProvider.username") - password := c.GetString("mockProvider.password") - useCerts := c.GetBool("mockProvider.useCerts") - minVolSize := c.GetInt("mockProvider.Docker.minVolSize") - - if userName != "admin" { - t.Fatalf("mockProvider.userName != admin, == %s", userName) - } - - if password != "" { - t.Fatalf("mockProvider.password != '', == %s", password) - } - - if !useCerts { - t.Fatalf("mockProvider.useCerts != true, == %v", useCerts) - } - - if minVolSize != 16 { - t.Fatalf("minVolSize != 16, == %d", minVolSize) - } -} - -func TestBaselineJSON(t *testing.T) { - newPrefixDir("TestBaselineJSON", t) - wipeEnv() - Register(testRegistration()) - c := New() - - var err error - var cJSON string - if cJSON, err = c.ToJSON(); err != nil { - t.Fatal(err) - } - - cMap := map[string]interface{}{} - ccMap := map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - if err := json.Unmarshal( - []byte(jsonConfigBaseline), &ccMap); err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cMap, ccMap) { - t.Fail() - } - - if reflect.DeepEqual(map[string]interface{}{}, ccMap) { - t.Fail() - } - - if reflect.DeepEqual(cMap, map[string]interface{}{}) { - t.Fail() - } -} - -func TestToJSON(t *testing.T) { - newPrefixDir("TestToJSON", t) - wipeEnv() - Register(testRegistration()) - c := New() - - if err := c.ReadConfig(bytes.NewReader(yamlConfig1)); err != nil { - t.Fatal(err) - } - - var err error - var cJSON string - if cJSON, err = c.ToJSON(); err != nil { - t.Fatal(err) - } - - t.Log(cJSON) - t.Log(jsonConfigWithYamlConfig1) - - cMap := map[string]interface{}{} - ccMap := map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - if err := json.Unmarshal( - []byte(jsonConfigWithYamlConfig1), &ccMap); err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cMap, ccMap) { - t.Fatal("json not equal pre minVolSize change") - } - - mvs := c.GetInt("mockprovider.docker.minvolsize") - if mvs != 32 { - t.Fatal("mvs != 32") - } - - c.Set("mockprovider.docker.minvolsize", 128) - mvs = c.GetInt("mockprovider.docker.minvolsize") - if mvs != 128 { - t.Fatal("mvs != 128") - } - - if cJSON, err = c.ToJSON(); err != nil { - t.Fatal(err) - } - - cMap = map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - - if reflect.DeepEqual(cMap, ccMap) { - t.Fatal("json equal post minVolSize change") - } -} - -func TestToJSONCompact(t *testing.T) { - newPrefixDir("TestToJSONCompact", t) - wipeEnv() - Register(testRegistration()) - c := New() - - if err := c.ReadConfig(bytes.NewReader(yamlConfig1)); err != nil { - t.Fatal(err) - } - - var err error - var cJSON string - if cJSON, err = c.ToJSONCompact(); err != nil { - t.Fatal(err) - } - - cMap := map[string]interface{}{} - ccMap := map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - if err := json.Unmarshal( - []byte(jsonConfigWithYamlConfig1), &ccMap); err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cMap, ccMap) { - t.Fail() - } - - mvs := c.GetInt("mockprovider.docker.minvolsize") - if mvs != 32 { - t.Fatal("mvs != 32") - } - - c.Set("mockprovider.docker.minvolsize", 128) - mvs = c.GetInt("mockprovider.docker.minvolsize") - if mvs != 128 { - t.Fatal("mvs != 128") - } - - if cJSON, err = c.ToJSONCompact(); err != nil { - t.Fatal(err) - } - - cMap = map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - - if reflect.DeepEqual(cMap, ccMap) { - t.Fail() - } -} - -func TestFromJSON(t *testing.T) { - newPrefixDir("TestFromJSON", t) - wipeEnv() - Register(testRegistration()) - - c := New() - - if err := c.ReadConfig(bytes.NewReader(yamlConfig1)); err != nil { - t.Fatal(err) - } - - var err error - var cJSON string - if cJSON, err = c.ToJSON(); err != nil { - t.Fatal(err) - } - - var cfj *Config - var cfJSON string - if cfj, err = FromJSON(jsonConfigWithYamlConfig1); err != nil { - t.Fatal(err) - } - if cfJSON, err = cfj.ToJSON(); err != nil { - t.Fatal(err) - } - - cMap := map[string]interface{}{} - cfjMap := map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - if err := json.Unmarshal([]byte(cfJSON), &cfjMap); err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cMap, cfjMap) { - t.Fail() - } -} - -func TestFromJSONWithErrors(t *testing.T) { - _, err := FromJSON("///*") - if err == nil { - t.Fatal("expected unmarshalling error") - } -} - -func TestEnvVars(t *testing.T) { - newPrefixDir("TestEnvVars", t) - wipeEnv() - Register(testRegistration()) - c := New() - - if err := c.ReadConfig(bytes.NewReader(yamlConfig1)); err != nil { - t.Fatal(err) - } - - fev := c.EnvVars() - - for _, v := range fev { - t.Log(v) - } - - assertEnvVar("REXRAY_HOST=tcp://:7979", fev, t) - assertEnvVar("REXRAY_LOGLEVEL=error", fev, t) - assertEnvVar("REXRAY_STORAGEDRIVERS=ec2 xtremio", fev, t) - assertEnvVar("REXRAY_OSDRIVERS=linux", fev, t) - assertEnvVar("REXRAY_VOLUMEDRIVERS=docker", fev, t) - assertEnvVar("MOCKPROVIDER_USERNAME=admin", fev, t) - assertEnvVar("MOCKPROVIDER_USECERTS=true", fev, t) - assertEnvVar("MOCKPROVIDER_DOCKER_MINVOLSIZE=32", fev, t) -} - -func assertEnvVar(s string, evs []string, t *testing.T) { - if !util.StringInSlice(s, evs) { - t.Fatal(s) - } -} - -func TestCopy(t *testing.T) { - newPrefixDir("TestCopy", t) - wipeEnv() - Register(testRegistration()) - - etcRexRayCfg := util.EtcFilePath("config.yml") - t.Logf("etcRexRayCfg=%s", etcRexRayCfg) - util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg) - - c := New() - - assertString(t, c, "logLevel", "error") - assertStorageDrivers(t, c) - assertOsDrivers1(t, c) - - cc, _ := c.Copy() - - assertString(t, cc, "logLevel", "error") - assertStorageDrivers(t, cc) - assertOsDrivers1(t, cc) - - cJSON, _ := c.ToJSON() - ccJSON, _ := cc.ToJSON() - - cMap := map[string]interface{}{} - ccMap := map[string]interface{}{} - - if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil { - t.Fatal(err) - } - if err := json.Unmarshal([]byte(ccJSON), &ccMap); err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cMap, ccMap) { - t.Fail() - } -} - -func TestNewWithUserConfigFile(t *testing.T) { - util.WriteStringToFile(string(yamlConfig1), usrRexRayFile) - defer os.RemoveAll(usrRexRayFile) - - c := New() - - assertString(t, c, "logLevel", "error") - assertStorageDrivers(t, c) - assertOsDrivers1(t, c) - - if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil { - t.Fatal(err) - } - - assertString(t, c, "logLevel", "debug") - assertStorageDrivers(t, c) - assertOsDrivers2(t, c) -} - -func TestNewWithUserConfigFileWithErrors(t *testing.T) { - util.WriteStringToFile(string(yamlConfig1), usrRexRayFile) - defer os.RemoveAll(usrRexRayFile) - - os.Chmod(usrRexRayFile, 0000) - New() -} - -func TestNewWithGlobalConfigFile(t *testing.T) { - newPrefixDir("TestNewWithGlobalConfigFile", t) - - etcRexRayCfg := util.EtcFilePath("config.yml") - t.Logf("etcRexRayCfg=%s", etcRexRayCfg) - util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg) - - c := New() - - assertString(t, c, "logLevel", "error") - assertStorageDrivers(t, c) - assertOsDrivers1(t, c) - - if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil { - t.Fatal(err) - } - - assertString(t, c, "logLevel", "debug") - assertStorageDrivers(t, c) - assertOsDrivers2(t, c) -} - -func TestNewWithGlobalConfigFileWithErrors(t *testing.T) { - newPrefixDir("TestNewWithGlobalConfigFileWithErrors", t) - - etcRexRayCfg := util.EtcFilePath("config.yml") - t.Logf("etcRexRayCfg=%s", etcRexRayCfg) - util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg) - - os.Chmod(etcRexRayCfg, 0000) - New() -} - -func TestReadConfigFile(t *testing.T) { - var err error - var tmp *os.File - if tmp, err = ioutil.TempFile("", "TestReadConfigFile"); err != nil { - t.Fatal(err) - } - defer os.Remove(tmp.Name()) - - if _, err := tmp.Write(yamlConfig1); err != nil { - t.Fatal(err) - } - tmp.Close() - - os.Chmod(tmp.Name(), 0000) - - c := New() - if err := c.ReadConfigFile(tmp.Name()); err == nil { - t.Fatal("expected error reading config file") - } -} - -func TestReadConfig(t *testing.T) { - c := NewConfig(false, false, "config", "yml") - if err := c.ReadConfig(bytes.NewReader(yamlConfig1)); err != nil { - t.Fatal(err) - } - - assertString(t, c, "logLevel", "error") - assertStorageDrivers(t, c) - assertOsDrivers1(t, c) - - if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil { - t.Fatal(err) - } - - assertString(t, c, "logLevel", "debug") - assertStorageDrivers(t, c) - assertOsDrivers2(t, c) -} - -func TestReadNilConfig(t *testing.T) { - if err := New().ReadConfig(nil); err == nil { - t.Fatal("expected nil config error") - } -} - -func wipeEnv() { - evs := os.Environ() - for _, v := range evs { - k := strings.Split(v, "=")[0] - os.Setenv(k, "") - } -} - -func printConfig(c *Config, t *testing.T) { - for k, v := range c.v.AllSettings() { - t.Logf("%s=%v\n", k, v) - } -} - -func testRegistration() *Registration { - r := NewRegistration("Mock Provider") - r.Yaml(`mockProvider: - userName: admin - useCerts: true - docker: - MinVolSize: 16 -`) - r.Key(String, "", "admin", "", "mockProvider.userName") - r.Key(String, "", "", "", "mockProvider.password") - r.Key(Bool, "", false, "", "mockProvider.useCerts") - r.Key(Int, "", 16, "", "mockProvider.docker.minVolSize") - r.Key(Bool, "i", true, "", "mockProvider.insecure") - r.Key(Int, "m", 256, "", "mockProvider.docker.maxVolSize") - return r -} - -func assertString(t *testing.T, c *Config, key, expected string) { - v := c.GetString(key) - if v != expected { - t.Fatalf("%s != %s; == %v", key, expected, v) - } -} - -func assertStorageDrivers(t *testing.T, c *Config) { - sd := c.GetStringSlice("storageDrivers") - if sd == nil { - t.Fatalf("storageDrivers == nil") - } - - if len(sd) != 2 { - t.Fatalf("len(storageDrivers) != 2; == %d", len(sd)) - } - - if sd[0] != "ec2" { - t.Fatalf("sd[0] != ec2; == %v", sd[0]) - } - - if sd[1] != "xtremio" { - t.Fatalf("sd[1] != xtremio; == %v", sd[1]) - } -} - -func assertOsDrivers1(t *testing.T, c *Config) { - od := c.GetStringSlice("osDrivers") - if od == nil { - t.Fatalf("osDrivers == nil") - } - if len(od) != 1 { - t.Fatalf("len(osDrivers) != 1; == %d", len(od)) - } - if od[0] != "linux" { - t.Fatalf("od[0] != linux; == %v", od[0]) - } -} - -func assertOsDrivers2(t *testing.T, c *Config) { - od := c.GetStringSlice("osDrivers") - if od == nil { - t.Fatalf("osDrivers == nil") - } - if len(od) != 2 { - t.Fatalf("len(osDrivers) != 2; == %d", len(od)) - } - if od[0] != "darwin" { - t.Fatalf("od[0] != darwin; == %v", od[0]) - } - if od[1] != "linux" { - t.Fatalf("od[1] != linux; == %v", od[1]) - } -} - -var yamlConfig1 = []byte(`logLevel: error -storageDrivers: -- ec2 -- xtremio -osDrivers: -- linux -mockProvider: - userName: admin - useCerts: true - docker: - MinVolSize: 32 -`) - -var yamlConfig2 = []byte(`logLevel: debug -osDrivers: -- darwin -- linux -`) - -var jsonConfigBaseline = `{ - "host": "tcp://:7979", - "loglevel": "warn", - "mockprovider": { - "docker": { - "MinVolSize": 16 - }, - "useCerts": true, - "userName": "admin" - }, - "osdrivers": [ - "linux" - ], - "volumedrivers": [ - "docker" - ] -} -` - -var jsonConfigWithYamlConfig1 = `{ - "host": "tcp://:7979", - "loglevel": "error", - "mockprovider": { - "docker": { - "MinVolSize": 32 - }, - "useCerts": true, - "userName": "admin" - }, - "osdrivers": [ - "linux" - ], - "storagedrivers": [ - "ec2", - "xtremio" - ], - "volumedrivers": [ - "docker" - ] -} -` diff --git a/core/core.go b/core/core.go index c77f3a900..e1f4f1e9c 100644 --- a/core/core.go +++ b/core/core.go @@ -1,5 +1,45 @@ package core +import ( + "github.com/akutz/gofig" +) + func init() { initDrivers() + gofig.Register(globalRegistration()) + gofig.Register(driverRegistration()) +} + +func globalRegistration() *gofig.Registration { + r := gofig.NewRegistration("Global") + r.Yaml(` +rexray: + host: tcp://:7979 + logLevel: warn +`) + r.Key(gofig.String, "h", "tcp://:7979", + "The REX-Ray host", "rexray.host") + r.Key(gofig.String, "l", "warn", + "The log level (error, warn, info, debug)", "rexray.logLevel") + return r +} + +func driverRegistration() *gofig.Registration { + r := gofig.NewRegistration("Driver") + r.Yaml(` +rexray: + osDrivers: + - linux + storageDrivers: + - libstorage + volumeDrivers: + - docker +`) + r.Key(gofig.String, "", "linux", + "The OS drivers to consider", "rexray.osDrivers") + r.Key(gofig.String, "", "", + "The storage drivers to consider", "rexray.storageDrivers") + r.Key(gofig.String, "", "docker", + "The volume drivers to consider", "rexray.volumeDrivers") + return r } diff --git a/core/rexray.go b/core/rexray.go index 847473736..118f82e48 100644 --- a/core/rexray.go +++ b/core/rexray.go @@ -3,13 +3,13 @@ package core import ( log "github.com/Sirupsen/logrus" - "github.com/emccode/rexray/core/config" + "github.com/akutz/gofig" "github.com/emccode/rexray/util" ) // RexRay is the library's entrance type and storage management platform. type RexRay struct { - Config *config.Config + Config gofig.Config OS OSDriverManager Volume VolumeDriverManager Storage StorageDriverManager @@ -18,10 +18,10 @@ type RexRay struct { // New creates a new REX-Ray instance and configures it with the // provided configuration instance. -func New(conf *config.Config) *RexRay { +func New(conf gofig.Config) *RexRay { if conf == nil { - conf = config.New() + conf = gofig.New() } r := &RexRay{ @@ -44,13 +44,13 @@ func (r *RexRay) InitDrivers() error { vd := map[string]VolumeDriver{} sd := map[string]StorageDriver{} - log.Info(r.Config.Get("osDrivers")) - log.Info(r.Config.Get("volumeDrivers")) - log.Info(r.Config.Get("storageDrivers")) + 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("osDrivers") - volDrivers := r.Config.GetStringSlice("volumeDrivers") - storDrivers := r.Config.GetStringSlice("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, diff --git a/daemon/module/admin/admin.go b/daemon/module/admin/admin.go index 29f0d9dfe..7ac5e3f5d 100644 --- a/daemon/module/admin/admin.go +++ b/daemon/module/admin/admin.go @@ -11,7 +11,7 @@ import ( "strconv" "time" - "github.com/emccode/rexray/core/config" + "github.com/akutz/gofig" "github.com/emccode/rexray/daemon/module" "github.com/emccode/rexray/util" "github.com/gorilla/handlers" @@ -169,7 +169,7 @@ func moduleInstPostHandler(w http.ResponseWriter, req *http.Request) { "config": cfgJSON, }).Debug("received module instance post request") - cfg, cfgErr := config.FromJSON(cfgJSON) + cfg, cfgErr := gofig.FromJSON(cfgJSON) if cfgErr != nil { w.Write(getJSONError("Error unmarshalling config json", nil)) log.Printf("Error unmarshalling config json\n") diff --git a/daemon/module/docker/remotevolumedriver/remvoldriver.go b/daemon/module/docker/remotevolumedriver/remvoldriver.go index 72db8635f..20df4f007 100644 --- a/daemon/module/docker/remotevolumedriver/remvoldriver.go +++ b/daemon/module/docker/remotevolumedriver/remvoldriver.go @@ -13,8 +13,8 @@ import ( "github.com/emccode/rexray/daemon/module" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/emccode/rexray/util" ) @@ -50,7 +50,7 @@ func init() { mc := &module.Config{ Address: modAddress, - Config: config.New(), + Config: gofig.New(), } module.RegisterModule(modName, true, newModule, []*module.Config{mc}) diff --git a/daemon/module/docker/volumedriver/voldriver.go b/daemon/module/docker/volumedriver/voldriver.go index 4895647b8..a1b397a70 100644 --- a/daemon/module/docker/volumedriver/voldriver.go +++ b/daemon/module/docker/volumedriver/voldriver.go @@ -14,8 +14,8 @@ import ( log "github.com/Sirupsen/logrus" "github.com/emccode/rexray/daemon/module" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/emccode/rexray/util" ) @@ -48,7 +48,7 @@ func init() { mc := &module.Config{ Address: modAddress, - Config: config.New(), + Config: gofig.New(), } module.RegisterModule(modName, true, newMod, []*module.Config{mc}) diff --git a/daemon/module/module.go b/daemon/module/module.go index 73f1f7743..2cfff1078 100644 --- a/daemon/module/module.go +++ b/daemon/module/module.go @@ -8,7 +8,7 @@ import ( log "github.com/Sirupsen/logrus" - "github.com/emccode/rexray/core/config" + "github.com/akutz/gofig" "github.com/emccode/rexray/core/errors" ) @@ -60,8 +60,8 @@ func GetModOptVal(opts map[string]string, key string) string { // Config is a struct used to configure a module. type Config struct { - Address string `json:"address"` - Config *config.Config `json:"config,omitempty"` + Address string `json:"address"` + Config gofig.Config `json:"config,omitempty"` } // Type is a struct that describes a module type diff --git a/drivers/mock/mock.go b/drivers/mock/mock.go index f3af3df3f..f06b11e91 100644 --- a/drivers/mock/mock.go +++ b/drivers/mock/mock.go @@ -5,8 +5,9 @@ import ( "strconv" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" + "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" ) const ( @@ -53,7 +54,7 @@ func RegisterMockDrivers() { core.RegisterDriver(MockOSDriverName, newOSDriver) core.RegisterDriver(MockVolDriverName, newVolDriver) core.RegisterDriver(MockStorDriverName, newStorDriver) - config.Register(mockRegistration()) + gofig.Register(mockRegistration()) } // RegisterBadMockDrivers registers the bad mock drivers. @@ -64,17 +65,17 @@ func RegisterBadMockDrivers() { core.RegisterDriver(BadMockStorDriverName, newBadStorDriver) } -func mockRegistration() *config.Registration { - r := config.NewRegistration("Mock Provider") +func mockRegistration() *gofig.Registration { + r := gofig.NewRegistration("Mock Provider") r.Yaml(`mockProvider: userName: admin useCerts: true docker: minVolSize: 16 `) - r.Key(config.String, "", "admin", "", "mockProvider.userName") - r.Key(config.String, "", "", "", "mockProvider.password") - r.Key(config.Bool, "", false, "", "mockProvider.useCerts") - r.Key(config.Int, "", 16, "", "mockProvider.docker.minVolSize") + r.Key(gofig.String, "", "admin", "", "mockProvider.userName") + r.Key(gofig.String, "", "", "", "mockProvider.password") + r.Key(gofig.Bool, "", false, "", "mockProvider.useCerts") + r.Key(gofig.Int, "", 16, "", "mockProvider.docker.minVolSize") return r } diff --git a/drivers/storage/ec2/ec2.go b/drivers/storage/ec2/ec2.go index 497842568..97df88232 100644 --- a/drivers/storage/ec2/ec2.go +++ b/drivers/storage/ec2/ec2.go @@ -11,9 +11,9 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/goamz/goamz/aws" "github.com/goamz/goamz/ec2" @@ -48,7 +48,7 @@ func eff(fields errors.Fields) map[string]interface{} { func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) } func newDriver() core.Driver { @@ -835,10 +835,10 @@ func (d *driver) CopySnapshot(runAsync bool, return snapshot[0], nil } -func configRegistration() *config.Registration { - r := config.NewRegistration("Amazon EC2") - r.Key(config.String, "", "", "", "aws.accessKey") - r.Key(config.String, "", "", "", "aws.secretKey") - r.Key(config.String, "", "", "", "aws.region") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("Amazon EC2") + r.Key(gofig.String, "", "", "", "aws.accessKey") + r.Key(gofig.String, "", "", "", "aws.secretKey") + r.Key(gofig.String, "", "", "", "aws.region") return r } diff --git a/drivers/storage/openstack/openstack.go b/drivers/storage/openstack/openstack.go index cc014ee75..23189c535 100644 --- a/drivers/storage/openstack/openstack.go +++ b/drivers/storage/openstack/openstack.go @@ -12,9 +12,9 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/rackspace/gophercloud" @@ -60,7 +60,7 @@ func eff(fields errors.Fields) map[string]interface{} { func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) } func newDriver() core.Driver { @@ -140,13 +140,13 @@ func (d *driver) newCmd(name string, args ...string) *exec.Cmd { return newCmd(d.r.Config, name, args...) } -func newCmd(c *config.Config, name string, args ...string) *exec.Cmd { +func newCmd(c gofig.Config, name string, args ...string) *exec.Cmd { cmd := exec.Command(name, args...) cmd.Env = c.EnvVars() return cmd } -func getInstanceID(c *config.Config) (string, error) { +func getInstanceID(c gofig.Config) (string, error) { cmd := newCmd(c, "/usr/sbin/dmidecode") cmdOut, err := cmd.Output() @@ -250,7 +250,7 @@ func (d *driver) getBlockDevices( } -func getInstanceRegion(cfg *config.Config) (string, error) { +func getInstanceRegion(cfg gofig.Config) (string, error) { cmd := newCmd( cfg, "/usr/bin/xenstore-read", "vm-data/provider_data/region") @@ -983,17 +983,17 @@ func (d *driver) availabilityZoneName() string { return d.r.Config.GetString("openstack.availabilityZoneName") } -func configRegistration() *config.Registration { - r := config.NewRegistration("Openstack") - r.Key(config.String, "", "", "", "openstack.authURL") - r.Key(config.String, "", "", "", "openstack.userID") - r.Key(config.String, "", "", "", "openstack.userName") - r.Key(config.String, "", "", "", "openstack.password") - r.Key(config.String, "", "", "", "openstack.tenantID") - r.Key(config.String, "", "", "", "openstack.tenantName") - r.Key(config.String, "", "", "", "openstack.domainID") - r.Key(config.String, "", "", "", "openstack.domainName") - r.Key(config.String, "", "", "", "openstack.regionName") - r.Key(config.String, "", "", "", "openstack.availabilityZoneName") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("Openstack") + r.Key(gofig.String, "", "", "", "openstack.authURL") + r.Key(gofig.String, "", "", "", "openstack.userID") + r.Key(gofig.String, "", "", "", "openstack.userName") + r.Key(gofig.String, "", "", "", "openstack.password") + r.Key(gofig.String, "", "", "", "openstack.tenantID") + r.Key(gofig.String, "", "", "", "openstack.tenantName") + r.Key(gofig.String, "", "", "", "openstack.domainID") + r.Key(gofig.String, "", "", "", "openstack.domainName") + r.Key(gofig.String, "", "", "", "openstack.regionName") + r.Key(gofig.String, "", "", "", "openstack.availabilityZoneName") return r } diff --git a/drivers/storage/rackspace/rackspace.go b/drivers/storage/rackspace/rackspace.go index 56cd505d9..fb0b10643 100644 --- a/drivers/storage/rackspace/rackspace.go +++ b/drivers/storage/rackspace/rackspace.go @@ -10,9 +10,9 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/rackspace/gophercloud" @@ -57,7 +57,7 @@ func eff(fields errors.Fields) map[string]interface{} { func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) } func newDriver() core.Driver { @@ -126,13 +126,13 @@ func (d *driver) newCmd(name string, args ...string) *exec.Cmd { return newCmd(d.r.Config, name, args...) } -func newCmd(c *config.Config, name string, args ...string) *exec.Cmd { +func newCmd(c gofig.Config, name string, args ...string) *exec.Cmd { cmd := exec.Command(name, args...) cmd.Env = c.EnvVars() return cmd } -func getInstanceID(c *config.Config) (string, error) { +func getInstanceID(c gofig.Config) (string, error) { cmd := newCmd(c, "/usr/bin/xenstore-read", "name") cmdOut, err := cmd.Output() @@ -244,7 +244,7 @@ func (d *driver) getBlockDevices( } -func getInstanceRegion(cfg *config.Config) (string, error) { +func getInstanceRegion(cfg gofig.Config) (string, error) { cmd := newCmd( cfg, "/usr/bin/xenstore-read", "vm-data/provider_data/region") @@ -938,15 +938,15 @@ func (d *driver) domainName() string { return d.r.Config.GetString("rackspace.domainName") } -func configRegistration() *config.Registration { - r := config.NewRegistration("Rackspace") - r.Key(config.String, "", "", "", "rackspace.authURL") - r.Key(config.String, "", "", "", "rackspace.userID") - r.Key(config.String, "", "", "", "rackspace.userName") - r.Key(config.String, "", "", "", "rackspace.password") - r.Key(config.String, "", "", "", "rackspace.tenantID") - r.Key(config.String, "", "", "", "rackspace.tenantName") - r.Key(config.String, "", "", "", "rackspace.domainID") - r.Key(config.String, "", "", "", "rackspace.domainName") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("Rackspace") + r.Key(gofig.String, "", "", "", "rackspace.authURL") + r.Key(gofig.String, "", "", "", "rackspace.userID") + r.Key(gofig.String, "", "", "", "rackspace.userName") + r.Key(gofig.String, "", "", "", "rackspace.password") + r.Key(gofig.String, "", "", "", "rackspace.tenantID") + r.Key(gofig.String, "", "", "", "rackspace.tenantName") + r.Key(gofig.String, "", "", "", "rackspace.domainID") + r.Key(gofig.String, "", "", "", "rackspace.domainName") return r } diff --git a/drivers/storage/scaleio/scaleio.go b/drivers/storage/scaleio/scaleio.go index 7c34633fd..25f22faa3 100644 --- a/drivers/storage/scaleio/scaleio.go +++ b/drivers/storage/scaleio/scaleio.go @@ -6,12 +6,12 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" "github.com/emccode/goscaleio" types "github.com/emccode/goscaleio/types/v1" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" ) @@ -47,7 +47,7 @@ func eff(fields errors.Fields) map[string]interface{} { func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) } func newDriver() core.Driver { @@ -678,19 +678,19 @@ func (d *driver) storagePoolName() string { return d.r.Config.GetString("scaleio.storagePoolName") } -func configRegistration() *config.Registration { - r := config.NewRegistration("ScaleIO") - r.Key(config.String, "", "", "", "scaleio.endpoint") - r.Key(config.Bool, "", false, "", "scaleio.insecure") - r.Key(config.Bool, "", false, "", "scaleio.useCerts") - r.Key(config.String, "", "", "", "scaleio.userID") - r.Key(config.String, "", "", "", "scaleio.userName") - r.Key(config.String, "", "", "", "scaleio.password") - r.Key(config.String, "", "", "", "scaleio.systemID") - r.Key(config.String, "", "", "", "scaleio.systemName") - r.Key(config.String, "", "", "", "scaleio.protectionDomainID") - r.Key(config.String, "", "", "", "scaleio.protectionDomainName") - r.Key(config.String, "", "", "", "scaleio.storagePoolID") - r.Key(config.String, "", "", "", "scaleio.storagePoolName") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("ScaleIO") + r.Key(gofig.String, "", "", "", "scaleio.endpoint") + r.Key(gofig.Bool, "", false, "", "scaleio.insecure") + r.Key(gofig.Bool, "", false, "", "scaleio.useCerts") + r.Key(gofig.String, "", "", "", "scaleio.userID") + r.Key(gofig.String, "", "", "", "scaleio.userName") + r.Key(gofig.String, "", "", "", "scaleio.password") + r.Key(gofig.String, "", "", "", "scaleio.systemID") + r.Key(gofig.String, "", "", "", "scaleio.systemName") + r.Key(gofig.String, "", "", "", "scaleio.protectionDomainID") + r.Key(gofig.String, "", "", "", "scaleio.protectionDomainName") + r.Key(gofig.String, "", "", "", "scaleio.storagePoolID") + r.Key(gofig.String, "", "", "", "scaleio.storagePoolName") return r } diff --git a/drivers/storage/xtremio/xtremio.go b/drivers/storage/xtremio/xtremio.go index 13a24fb6b..ad91764b2 100644 --- a/drivers/storage/xtremio/xtremio.go +++ b/drivers/storage/xtremio/xtremio.go @@ -14,10 +14,10 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" xtio "github.com/emccode/goxtremio" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" ) @@ -53,7 +53,7 @@ func eff(fields errors.Fields) map[string]interface{} { func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) } func newDriver() core.Driver { @@ -849,14 +849,14 @@ func (d *driver) remoteManagement() bool { return d.r.Config.GetBool("xtremio.remoteManagement") } -func configRegistration() *config.Registration { - r := config.NewRegistration("XtremIO") - r.Key(config.String, "", "", "", "xtremio.endpoint") - r.Key(config.Bool, "", false, "", "xtremio.insecure") - r.Key(config.String, "", "", "", "xtremio.userName") - r.Key(config.String, "", "", "", "xtremio.password") - r.Key(config.Bool, "", false, "", "xtremio.deviceMapper") - r.Key(config.Bool, "", false, "", "xtremio.multipath") - r.Key(config.Bool, "", false, "", "xtremio.remoteManagement") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("XtremIO") + r.Key(gofig.String, "", "", "", "xtremio.endpoint") + r.Key(gofig.Bool, "", false, "", "xtremio.insecure") + r.Key(gofig.String, "", "", "", "xtremio.userName") + r.Key(gofig.String, "", "", "", "xtremio.password") + r.Key(gofig.Bool, "", false, "", "xtremio.deviceMapper") + r.Key(gofig.Bool, "", false, "", "xtremio.multipath") + r.Key(gofig.Bool, "", false, "", "xtremio.remoteManagement") return r } diff --git a/drivers/volume/docker/volume.go b/drivers/volume/docker/volume.go index 90cdd51db..cd57b1d39 100644 --- a/drivers/volume/docker/volume.go +++ b/drivers/volume/docker/volume.go @@ -7,9 +7,9 @@ import ( "strings" log "github.com/Sirupsen/logrus" + "github.com/akutz/gofig" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/emccode/rexray/util" ) @@ -29,7 +29,7 @@ var ( func init() { core.RegisterDriver(providerName, newDriver) - config.Register(configRegistration()) + gofig.Register(configRegistration()) mountDirectoryPath = util.LibFilePath("volumes") os.MkdirAll(mountDirectoryPath, 0755) } @@ -674,11 +674,11 @@ func (d *driver) NetworkName(volumeName, instanceID string) (string, error) { return volumes[0].NetworkName, nil } -func configRegistration() *config.Registration { - r := config.NewRegistration("Docker") - r.Key(config.String, "", "", "", "docker.volumeType") - r.Key(config.Int, "", 0, "", "docker.iops") - r.Key(config.Int, "", 0, "", "docker.size") - r.Key(config.String, "", "", "", "docker.availabilityZone") +func configRegistration() *gofig.Registration { + r := gofig.NewRegistration("Docker") + r.Key(gofig.String, "", "", "", "docker.volumeType") + r.Key(gofig.Int, "", 0, "", "docker.iops") + r.Key(gofig.Int, "", 0, "", "docker.size") + r.Key(gofig.String, "", "", "", "docker.availabilityZone") return r } diff --git a/glide.yaml b/glide.yaml index 41329e05f..8cce91e51 100644 --- a/glide.yaml +++ b/glide.yaml @@ -27,6 +27,9 @@ import: - package: github.com/akutz/golf ref: v0.1.1 vcs: git + - package: github.com/akutz/gofig + ref: master + vcs: git - package: github.com/go-yaml/yaml ref: b4a9f8c4b84c6c4256d669c649837f1441e4b050 repo: https://github.com/akutz/yaml.git diff --git a/rexray.go b/rexray.go index 42abb2e6f..54b6a9547 100644 --- a/rexray.go +++ b/rexray.go @@ -6,8 +6,8 @@ // REX-Ray: // // [0]akutz@pax:~$ export REXRAY_STORAGEDRIVERS=ec2 -// [0]akutz@pax:~$ export AWS_ACCESS_KEY=access_key -// [0]akutz@pax:~$ export AWS_SECRET_KEY=secret_key +// [0]akutz@pax:~$ export AWS_ACCESSKEY=access_key +// [0]akutz@pax:~$ export AWS_SECRETKEY=secret_key // [0]akutz@pax:~$ rexray volume get // // - providername: ec2 @@ -32,8 +32,8 @@ // // r := rexray.NewWithEnv(map[string]string{ // "REXRAY_STORAGEDRIVERS": "ec2", -// "AWS_ACCESS_KEY": "access_key", -// "AWS_SECRET_KEY": "secret_key"}) +// "AWS_ACCESSKEY": "access_key", +// "AWS_SECRETKEY": "secret_key"}) // // r.InitDrivers() // @@ -45,8 +45,9 @@ import ( "io" "os" + "github.com/akutz/gofig" + "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" // This blank import loads the drivers package _ "github.com/emccode/rexray/drivers" @@ -66,7 +67,7 @@ func NewWithEnv(env map[string]string) (*core.RexRay, error) { // NewWithConfigFile creates a new REX-Ray instance and configures it with a // custom configuration file. func NewWithConfigFile(path string) (*core.RexRay, error) { - c := config.New() + c := gofig.New() if err := c.ReadConfigFile(path); err != nil { return nil, err } @@ -76,7 +77,7 @@ func NewWithConfigFile(path string) (*core.RexRay, error) { // NewWithConfigReader creates a new REX-Ray instance and configures it with a // custom configuration stream. func NewWithConfigReader(in io.Reader) (*core.RexRay, error) { - c := config.New() + c := gofig.New() if err := c.ReadConfig(in); err != nil { return nil, err } @@ -87,5 +88,5 @@ func NewWithConfigReader(in io.Reader) (*core.RexRay, error) { // configuration workflow: environment variables followed by global and user // configuration files. func New() (*core.RexRay, error) { - return core.New(config.New()), nil + return core.New(gofig.New()), nil } diff --git a/rexray/cli/cli.go b/rexray/cli/cli.go index af76dbdc0..118df4850 100644 --- a/rexray/cli/cli.go +++ b/rexray/cli/cli.go @@ -254,7 +254,7 @@ func (c *CLI) updateLogLevel() { log.SetLevel(log.DebugLevel) } - log.WithField("logLevel", c.logLevel()).Debug("updated log level") + log.WithField("rexrayLogLevel", c.logLevel()).Debug("updated log level") } func (c *CLI) preRun(cmd *cobra.Command, args []string) { @@ -401,9 +401,9 @@ func (c *CLI) isModuleCmd(cmd *cobra.Command) bool { } func (c *CLI) logLevel() string { - return c.r.Config.GetString("logLevel") + return c.r.Config.GetString("rexray.logLevel") } func (c *CLI) host() string { - return c.r.Config.GetString("host") + return c.r.Config.GetString("rexray.host") } diff --git a/rexray/cli/cmds_other.go b/rexray/cli/cmds_other.go index 20874aead..b04951283 100644 --- a/rexray/cli/cmds_other.go +++ b/rexray/cli/cmds_other.go @@ -66,7 +66,7 @@ func (c *CLI) initOtherFlags() { "verbose", "v", false, "Print verbose help information") // add the flag sets - for _, fs := range c.r.Config.FlagSets { + for _, fs := range c.r.Config.FlagSets() { c.c.PersistentFlags().AddFlagSet(fs) } diff --git a/rexray/cli/service.go b/rexray/cli/service.go index fab49f027..12b9dfe3d 100644 --- a/rexray/cli/service.go +++ b/rexray/cli/service.go @@ -172,10 +172,10 @@ func (c *CLI) tryToStartDaemon() { cmdArgs := []string{ "start", fmt.Sprintf("--client=%s", client), - fmt.Sprintf("--logLevel=%v", c.logLevel())} + fmt.Sprintf("--rexrayLogLevel=%v", c.logLevel())} if c.host() != "" { - cmdArgs = append(cmdArgs, fmt.Sprintf("--host=%s", c.host())) + cmdArgs = append(cmdArgs, fmt.Sprintf("--rexrayHost=%s", c.host())) } cmd := exec.Command(thisAbsPath, cmdArgs...) diff --git a/rexray/cli/usage.go b/rexray/cli/usage.go index 22c652703..8f8335e4a 100644 --- a/rexray/cli/usage.go +++ b/rexray/cli/usage.go @@ -84,7 +84,7 @@ func (c *CLI) globalFlags(cmd *cobra.Command) *flag.FlagSet { } func (c *CLI) driverFlags() *flag.FlagSet { - return c.r.Config.FlagSets["Driver Flags"] + return c.r.Config.FlagSets()["Driver Flags"] } func (c *CLI) sansAdditionalFlags(flags *flag.FlagSet) *flag.FlagSet { @@ -121,7 +121,7 @@ func (c *CLI) additionalFlags() *flag.FlagSet { func (c *CLI) additionalFlagSets() map[string]*flag.FlagSet { afs := map[string]*flag.FlagSet{} - for fsn, fs := range c.r.Config.FlagSets { + for fsn, fs := range c.r.Config.FlagSets() { if fsn == "Global Flags" || fsn == "Driver Flags" { continue } diff --git a/test/bad_mock_drivers_test.go b/test/bad_mock_drivers_test.go index 0837d647f..80add8b9b 100644 --- a/test/bad_mock_drivers_test.go +++ b/test/bad_mock_drivers_test.go @@ -10,9 +10,9 @@ import ( func TestNewWithBadOSDriver(t *testing.T) { r := core.New(nil) - r.Config.Set("osDrivers", []string{mock.BadMockOSDriverName}) - r.Config.Set("volumeDrivers", []string{mock.MockVolDriverName}) - r.Config.Set("storageDrivers", []string{mock.MockStorDriverName}) + r.Config.Set("rexray.osDrivers", []string{mock.BadMockOSDriverName}) + r.Config.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + r.Config.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) if err := r.InitDrivers(); err != errors.ErrNoOSDrivers { t.Fatal(err) } @@ -20,9 +20,9 @@ func TestNewWithBadOSDriver(t *testing.T) { func TestNewWithBadVolumeDriver(t *testing.T) { r := core.New(nil) - r.Config.Set("osDrivers", []string{mock.MockOSDriverName}) - r.Config.Set("volumeDrivers", []string{mock.BadMockVolDriverName}) - r.Config.Set("storageDrivers", []string{mock.MockStorDriverName}) + r.Config.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + r.Config.Set("rexray.volumeDrivers", []string{mock.BadMockVolDriverName}) + r.Config.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) if err := r.InitDrivers(); err != errors.ErrNoVolumeDrivers { t.Fatal(err) } @@ -30,9 +30,9 @@ func TestNewWithBadVolumeDriver(t *testing.T) { func TestNewWithBadStorageDriver(t *testing.T) { r := core.New(nil) - r.Config.Set("osDrivers", []string{mock.MockOSDriverName}) - r.Config.Set("volumeDrivers", []string{mock.MockVolDriverName}) - r.Config.Set("storageDrivers", []string{mock.BadMockStorDriverName}) + r.Config.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + r.Config.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + r.Config.Set("rexray.storageDrivers", []string{mock.BadMockStorDriverName}) if err := r.InitDrivers(); err != errors.ErrNoStorageDrivers { t.Fatal(err) } diff --git a/test/test_test.go b/test/test_test.go index 17d202e08..c8df2b64b 100644 --- a/test/test_test.go +++ b/test/test_test.go @@ -7,9 +7,10 @@ import ( "strings" "testing" + "github.com/akutz/gofig" + "github.com/emccode/rexray" "github.com/emccode/rexray/core" - "github.com/emccode/rexray/core/config" "github.com/emccode/rexray/core/errors" "github.com/emccode/rexray/drivers/mock" "github.com/emccode/rexray/util" @@ -22,10 +23,10 @@ func TestMain(m *testing.M) { } func getRexRay() (*core.RexRay, error) { - c := config.New() - c.Set("osDrivers", []string{mock.MockOSDriverName}) - c.Set("volumeDrivers", []string{mock.MockVolDriverName}) - c.Set("storageDrivers", []string{mock.MockStorDriverName}) + c := gofig.New() + c.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + c.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + c.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) r := core.New(c) if err := r.InitDrivers(); err != nil { @@ -36,10 +37,10 @@ func getRexRay() (*core.RexRay, error) { } func getRexRayNoDrivers() (*core.RexRay, error) { - c := config.New() - c.Set("osDrivers", []string{""}) - c.Set("volumeDrivers", []string{""}) - c.Set("storageDrivers", []string{""}) + c := gofig.New() + c.Set("rexray.osDrivers", []string{""}) + c.Set("rexray.volumeDrivers", []string{""}) + c.Set("rexray.storageDrivers", []string{""}) r := core.New(c) r.InitDrivers() return r, nil @@ -56,9 +57,9 @@ func TestNewWithConfig(t *testing.T) { func TestNewWithNilConfig(t *testing.T) { r := core.New(nil) - r.Config.Set("osDrivers", []string{mock.MockOSDriverName}) - r.Config.Set("volumeDrivers", []string{mock.MockVolDriverName}) - r.Config.Set("storageDrivers", []string{mock.MockStorDriverName}) + r.Config.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + r.Config.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + r.Config.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) if err := r.InitDrivers(); err != nil { t.Fatal(err) @@ -85,10 +86,10 @@ func TestNew(t *testing.T) { } func TestNewNoOSDrivers(t *testing.T) { - c := config.New() - c.Set("osDrivers", []string{}) - c.Set("volumeDrivers", []string{mock.MockVolDriverName}) - c.Set("storageDrivers", []string{mock.MockStorDriverName}) + c := gofig.New() + c.Set("rexray.osDrivers", []string{}) + c.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + c.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) r := core.New(c) if err := r.InitDrivers(); err != errors.ErrNoOSDrivers { t.Fatal(err) @@ -96,10 +97,10 @@ func TestNewNoOSDrivers(t *testing.T) { } func TestNewNoVolumeDrivers(t *testing.T) { - c := config.New() - c.Set("osDrivers", []string{mock.MockOSDriverName}) - c.Set("volumeDrivers", []string{}) - c.Set("storageDrivers", []string{mock.MockStorDriverName}) + c := gofig.New() + c.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + c.Set("rexray.volumeDrivers", []string{}) + c.Set("rexray.storageDrivers", []string{mock.MockStorDriverName}) r := core.New(c) if err := r.InitDrivers(); err != errors.ErrNoVolumeDrivers { t.Fatal(err) @@ -107,10 +108,10 @@ func TestNewNoVolumeDrivers(t *testing.T) { } func TestNewNoStorageDrivers(t *testing.T) { - c := config.New() - c.Set("osDrivers", []string{mock.MockOSDriverName}) - c.Set("volumeDrivers", []string{mock.MockVolDriverName}) - c.Set("storageDrivers", []string{}) + c := gofig.New() + c.Set("rexray.osDrivers", []string{mock.MockOSDriverName}) + c.Set("rexray.volumeDrivers", []string{mock.MockVolDriverName}) + c.Set("rexray.storageDrivers", []string{}) r := core.New(c) if err := r.InitDrivers(); err != errors.ErrNoStorageDrivers { t.Fatal(err) @@ -277,11 +278,13 @@ func assertDriverNames(t *testing.T, r *core.RexRay) { } } -var yamlConfig1 = []byte(`logLevel: error -osDrivers: -- mockOSDriver -volumeDrivers: -- mockVolumeDriver -storageDrivers: -- mockStorageDriver +var yamlConfig1 = []byte(` +rexray: + logLevel: error + osDrivers: + - mockOSDriver + volumeDrivers: + - mockVolumeDriver + storageDrivers: + - mockStorageDriver `)