Esempio n. 1
0
func (s *configSuite) TestClientConfigNonLocal(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)
	ecfg = ecfg.Apply(c, map[string]interface{}{
		"remote-url":  "10.0.0.1",
		"client-cert": "<a valid x.509 cert>",
		"client-key":  "<a valid x.509 key>",
		"server-cert": "<a valid x.509 server cert>",
	})

	clientCfg, err := ecfg.ClientConfig()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(clientCfg, jc.DeepEquals, lxdclient.Config{
		Namespace: cfg.Name(),
		Remote: lxdclient.Remote{
			Name:     "juju-remote",
			Host:     "10.0.0.1",
			Protocol: lxdclient.LXDProtocol,
			Cert: &lxdclient.Cert{
				Name:    fmt.Sprintf("juju cert for env %q", s.config.Name()),
				CertPEM: []byte("<a valid x.509 cert>"),
				KeyPEM:  []byte("<a valid x.509 key>"),
			},
			ServerPEMCert: "<a valid x.509 server cert>",
		},
	})
}
Esempio n. 2
0
func (s *configSuite) TestUpdateForClientConfigNonLocal(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)
	ecfg = ecfg.Apply(c, map[string]interface{}{
		"remote-url":  "10.0.0.1",
		"client-cert": "<a valid x.509 cert>",
		"client-key":  "<a valid x.509 key>",
	})

	before, extras := ecfg.Values(c)
	c.Assert(extras, gc.HasLen, 0)

	clientCfg, err := ecfg.ClientConfig()
	c.Assert(err, jc.ErrorIsNil)
	updated, err := ecfg.UpdateForClientConfig(clientCfg)
	c.Assert(err, jc.ErrorIsNil)

	after, extras := updated.Values(c)
	c.Assert(extras, gc.HasLen, 0)

	c.Check(before, jc.DeepEquals, lxd.ConfigValues{
		Namespace:  cfg.Name(),
		RemoteURL:  "10.0.0.1",
		ClientCert: "<a valid x.509 cert>",
		ClientKey:  "<a valid x.509 key>",
	})
	c.Check(after, jc.DeepEquals, lxd.ConfigValues{
		Namespace:  cfg.Name(),
		RemoteURL:  "10.0.0.1",
		ClientCert: "<a valid x.509 cert>",
		ClientKey:  "<a valid x.509 key>",
	})
}
Esempio n. 3
0
func (s *configSuite) TestDefaults(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)

	values, extras := ecfg.Values(c)
	c.Assert(extras, gc.HasLen, 0)

	c.Check(values, jc.DeepEquals, lxd.ConfigValues{})
}
Esempio n. 4
0
func (s *configSuite) TestDefaults(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)

	values, extras := ecfg.Values(c)
	c.Assert(extras, gc.HasLen, 0)

	c.Check(values, jc.DeepEquals, lxd.ConfigValues{
		Namespace:  cfg.Name(),
		RemoteURL:  "",
		ClientCert: "",
		ClientKey:  "",
	})
}
Esempio n. 5
0
func (s *configSuite) TestUpdateForClientConfigLocal(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)

	clientCfg, err := ecfg.ClientConfig()
	c.Assert(err, jc.ErrorIsNil)
	updated, err := ecfg.UpdateForClientConfig(clientCfg)
	c.Assert(err, jc.ErrorIsNil)

	values, extras := updated.Values(c)
	c.Assert(extras, gc.HasLen, 0)

	c.Check(values, jc.DeepEquals, lxd.ConfigValues{
		Namespace:  cfg.Name(),
		RemoteURL:  "",
		ClientCert: "",
		ClientKey:  "",
	})
}
Esempio n. 6
0
func (s *configSuite) TestClientConfigLocal(c *gc.C) {
	cfg := lxd.NewBaseConfig(c)
	ecfg := lxd.NewConfig(cfg)
	values, _ := ecfg.Values(c)
	c.Assert(values.RemoteURL, gc.Equals, "")

	clientCfg, err := ecfg.ClientConfig()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(clientCfg, jc.DeepEquals, lxdclient.Config{
		Namespace: cfg.Name(),
		Dirname:   lxdlib.ConfigPath("juju-testenv"),
		Remote: lxdclient.Remote{
			Name: "juju-remote",
			Host: "",
			Cert: nil,
		},
	})
}