Exemple #1
0
func (*environSuite) TestSetConfigUpdatesConfig(c *gc.C) {
	origAttrs := coretesting.Attrs{
		"server-name":  "http://maas2.testing.invalid",
		"maas-oauth":   "a:b:c",
		"admin-secret": "secret",
	}
	cfg := getSimpleTestConfig(c, origAttrs)
	env, err := maas.NewEnviron(cfg)
	c.Check(err, gc.IsNil)
	c.Check(env.Config().Name(), gc.Equals, "testenv")

	anotherServer := "http://maas.testing.invalid"
	anotherOauth := "c:d:e"
	anotherSecret := "secret2"
	newAttrs := coretesting.Attrs{
		"server-name":  anotherServer,
		"maas-oauth":   anotherOauth,
		"admin-secret": anotherSecret,
	}
	cfg2 := getSimpleTestConfig(c, newAttrs)
	errSetConfig := env.SetConfig(cfg2)
	c.Check(errSetConfig, gc.IsNil)
	c.Check(env.Config().Name(), gc.Equals, "testenv")
	authClient, _ := gomaasapi.NewAuthenticatedClient(anotherServer, anotherOauth, maas.APIVersion)
	maasClient := gomaasapi.NewMAAS(*authClient)
	MAASServer := maas.GetMAASClient(env)
	c.Check(MAASServer, gc.DeepEquals, maasClient)
}
Exemple #2
0
// SetConfig is specified in the Environ interface.
func (env *maasEnviron) SetConfig(cfg *config.Config) error {
	env.ecfgMutex.Lock()
	defer env.ecfgMutex.Unlock()

	// The new config has already been validated by itself, but now we
	// validate the transition from the old config to the new.
	var oldCfg *config.Config
	if env.ecfgUnlocked != nil {
		oldCfg = env.ecfgUnlocked.Config
	}
	cfg, err := env.Provider().Validate(cfg, oldCfg)
	if err != nil {
		return err
	}

	ecfg, err := providerInstance.newConfig(cfg)
	if err != nil {
		return err
	}

	env.ecfgUnlocked = ecfg

	authClient, err := gomaasapi.NewAuthenticatedClient(ecfg.MAASServer(), ecfg.MAASOAuth(), apiVersion)
	if err != nil {
		return err
	}
	env.maasClientUnlocked = gomaasapi.NewMAAS(*authClient)

	return nil
}
func TestNodeDo(t *testing.T) {
	authClient, err := gomaasapi.NewAuthenticatedClient("http://example.com/", "a:b:c", "1.0")
	if err != nil {
		t.Fail()
	}
	if err := nodeDo(gomaasapi.NewMAAS(*authClient), "system_id", "node_action", url.Values{}); err == nil {
		t.Fail()
	}
}
func TestGetAllNodes(t *testing.T) {
	authClient, err := gomaasapi.NewAuthenticatedClient("http://example.com/", "a:b:c", "1.0")
	if err != nil {
		t.Fail()
	}
	if _, err := getAllNodes(gomaasapi.NewMAAS(*authClient)); err == nil {
		t.Fail()
	}
}
func TestMaasReleaseNode(t *testing.T) {
	authClient, err := gomaasapi.NewAuthenticatedClient("http://example.com/", "a:b:c", "1.0")
	if err != nil {
		t.Fail()
	}
	if err := maasReleaseNode(gomaasapi.NewMAAS(*authClient), "system_id"); err == nil {
		t.Fail()
	}
}
func TestMaasAllocateNodes(t *testing.T) {
	authClient, err := gomaasapi.NewAuthenticatedClient("http://example.com/", "a:b:c", "1.0")
	if err != nil {
		t.Fail()
	}
	if _, err := maasAllocateNodes(gomaasapi.NewMAAS(*authClient), url.Values{}); err == nil {
		t.Fail()
	}
}
func (c *Config) Client() (interface{}, error) {
	log.Println("[DEBUG] [Config.Client] Configuring the MAAS API client")
	authClient, err := gomaasapi.NewAuthenticatedClient(c.APIURL, c.APIKey, c.APIver)
	if err != nil {
		log.Printf("[ERROR] [Config.Client] Unable to authenticate against the MAAS Server (%s)", c.APIURL)
		return nil, err
	}
	c.MAASObject = gomaasapi.NewMAAS(*authClient)
	return c, nil
}
func (*EnvironSuite) TestSetConfigUpdatesConfig(c *C) {
	name := "test env"
	cfg := getTestConfig(name, "http://maas2.testing.invalid", "a:b:c", "secret")
	env, err := NewEnviron(cfg)
	c.Check(err, IsNil)
	c.Check(env.name, Equals, "test env")

	anotherServer := "http://maas.testing.invalid"
	anotherOauth := "c:d:e"
	anotherSecret := "secret2"
	cfg2 := getTestConfig(name, anotherServer, anotherOauth, anotherSecret)
	errSetConfig := env.SetConfig(cfg2)
	c.Check(errSetConfig, IsNil)
	c.Check(env.name, Equals, name)
	authClient, _ := gomaasapi.NewAuthenticatedClient(anotherServer, anotherOauth, apiVersion)
	maas := gomaasapi.NewMAAS(*authClient)
	MAASServer := env.maasClientUnlocked
	c.Check(MAASServer, DeepEquals, maas)
}