示例#1
0
func TestSetMinionConfig(t *testing.T) {
	t.Parallel()
	s := server{db.New()}

	cfg := pb.MinionConfig{
		Role:           pb.MinionConfig_MASTER,
		PrivateIP:      "priv",
		Spec:           "spec",
		Provider:       "provider",
		Size:           "size",
		Region:         "region",
		EtcdMembers:    []string{"etcd1", "etcd2"},
		AuthorizedKeys: []string{"key1", "key2"},
	}
	expMinion := db.Minion{
		Self:           true,
		Spec:           "spec",
		Role:           db.Master,
		PrivateIP:      "priv",
		Provider:       "provider",
		Size:           "size",
		Region:         "region",
		AuthorizedKeys: "key1\nkey2",
	}
	_, err := s.SetMinionConfig(nil, &cfg)
	assert.NoError(t, err)
	checkMinionEquals(t, s.Conn, expMinion)
	checkEtcdEquals(t, s.Conn, db.Etcd{
		EtcdIPs: []string{"etcd1", "etcd2"},
	})

	// Update a field.
	cfg.Spec = "new"
	expMinion.Spec = "new"
	cfg.EtcdMembers = []string{"etcd3"}
	_, err = s.SetMinionConfig(nil, &cfg)
	assert.NoError(t, err)
	checkMinionEquals(t, s.Conn, expMinion)
	checkEtcdEquals(t, s.Conn, db.Etcd{
		EtcdIPs: []string{"etcd3"},
	})
}
示例#2
0
func (s server) GetMinionConfig(cts context.Context,
	_ *pb.Request) (*pb.MinionConfig, error) {

	var cfg pb.MinionConfig

	if m, err := s.MinionSelf(); err == nil {
		cfg.Role = db.RoleToPB(m.Role)
		cfg.PrivateIP = m.PrivateIP
		cfg.Spec = m.Spec
		cfg.Provider = m.Provider
		cfg.Size = m.Size
		cfg.Region = m.Region
	} else {
		cfg.Role = db.RoleToPB(db.None)
	}

	return &cfg, nil
}