// Validate implements environs.EnvironProvider.Validate. func (provider environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) { // Check for valid changes for the base config values. if err := config.Validate(cfg, old); err != nil { return nil, err } validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults) if err != nil { return nil, err } localConfig := newEnvironConfig(cfg, validated) // Before potentially creating directories, make sure that the // root directory has not changed. if old != nil { oldLocalConfig, err := provider.newConfig(old) if err != nil { return nil, fmt.Errorf("old config is not a valid local config: %v", old) } if localConfig.rootDir() != oldLocalConfig.rootDir() { return nil, fmt.Errorf("cannot change root-dir from %q to %q", oldLocalConfig.rootDir(), localConfig.rootDir()) } if localConfig.storagePort() != oldLocalConfig.storagePort() { return nil, fmt.Errorf("cannot change storage-port from %v to %v", oldLocalConfig.storagePort(), localConfig.storagePort()) } if localConfig.sharedStoragePort() != oldLocalConfig.sharedStoragePort() { return nil, fmt.Errorf("cannot change shared-storage-port from %v to %v", oldLocalConfig.sharedStoragePort(), localConfig.sharedStoragePort()) } } dir := utils.NormalizePath(localConfig.rootDir()) if dir == "." { dir = config.JujuHomePath(cfg.Name()) localConfig.attrs["root-dir"] = dir } // Apply the coerced unknown values back into the config. return cfg.Apply(localConfig.attrs) }
func (*fileSuite) TestNormalizePath(c *gc.C) { for _, test := range []struct { path string expected string }{{ path: "/var/lib/juju", expected: "/var/lib/juju", }, { path: "~/foo", expected: "/home/test-user/foo", }, { path: "~/foo//../bar", expected: "/home/test-user/bar", }, { path: "~bob/foo", expected: "~bob/foo", }} { c.Assert(utils.NormalizePath(test.path), gc.Equals, test.expected) } }