cephfs: add function ParseDefaultConfigEnv to set ceph config from env

Similar to the rados function of the same name, ParseDefaultConfigEnv
uses the environment to configure the cephfs mount.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-06-11 14:46:25 -04:00 committed by John Mulligan
parent c34501fc6a
commit 7dea1f728f
2 changed files with 33 additions and 0 deletions

View File

@ -92,6 +92,19 @@ func (mount *MountInfo) ParseConfigArgv(argv []string) error {
return getError(ret) return getError(ret)
} }
// ParseDefaultConfigEnv configures the mount from the default Ceph
// environment variable CEPH_ARGS.
//
// Implements:
// int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *var);
func (mount *MountInfo) ParseDefaultConfigEnv() error {
if err := mount.validate(); err != nil {
return err
}
ret := C.ceph_conf_parse_env(mount.mount, nil)
return getError(ret)
}
// SetConfigOption sets the value of the configuration option identified by // SetConfigOption sets the value of the configuration option identified by
// the given name. // the given name.
// //

View File

@ -299,6 +299,26 @@ func TestParseConfigArgv(t *testing.T) {
assert.Error(t, err) assert.Error(t, err)
} }
func TestParseDefaultConfigEnv(t *testing.T) {
mount, err := CreateMount()
require.NoError(t, err)
require.NotNil(t, mount)
defer func() { assert.NoError(t, mount.Release()) }()
origVal, err := mount.GetConfigOption("log_file")
assert.NoError(t, err)
err = os.Setenv("CEPH_ARGS", "--log_file /dev/null")
assert.NoError(t, err)
err = mount.ParseDefaultConfigEnv()
assert.NoError(t, err)
currVal, err := mount.GetConfigOption("log_file")
assert.NoError(t, err)
assert.Equal(t, "/dev/null", currVal)
assert.NotEqual(t, "/dev/null", origVal)
}
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
mount, err := CreateMount() mount, err := CreateMount()
assert.NoError(t, err) assert.NoError(t, err)