예제 #1
0
func fakeDNS(port int) (*Resolver, error) {
	res := New("", records.Config{
		Masters:    []string{"144.76.157.37:5050"},
		TTL:        60,
		Port:       port,
		Domain:     "mesos",
		Resolvers:  records.GetLocalDNS(),
		Listener:   "127.0.0.1",
		SOARname:   "root.ns1.mesos.",
		SOAMname:   "ns1.mesos.",
		HTTPPort:   8123,
		ExternalOn: true,
	})

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		return res, err
	}

	var sj records.StateJSON
	err = json.Unmarshal(b, &sj)
	if err != nil {
		return res, err
	}

	masters := []string{"144.76.157.37:5050"}
	spec := labels.ForRFC952()
	res.rs = &records.RecordGenerator{}
	res.rs.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, spec)

	return res, nil
}
예제 #2
0
// Finds the master and inserts DNS state
func (rg *RecordGenerator) ParseState(leader string, c Config) error {

	// find master -- return if error
	sj, err := rg.findMaster(leader, c.Masters)
	if err != nil {
		logging.Error.Println("no master")
		return err
	}
	if sj.Leader == "" {
		logging.Error.Println("Unexpected error")
		err = errors.New("empty master")
		return err
	}

	hostSpec := labels.ForRFC1123()
	if c.EnforceRFC952 {
		hostSpec = labels.ForRFC952()
	}

	return rg.InsertState(sj, c.Domain, c.SOARname, c.Listener, c.Masters, hostSpec)
}
예제 #3
0
func TestSanitizedSlaveAddress(t *testing.T) {
	spec := labels.ForRFC952()
	x := sanitizedSlaveAddress("1.2.3.4", spec)
	if x != "1.2.3.4" {
		t.Fatalf("unexpected slave address %q", x)
	}

	x = sanitizedSlaveAddress("localhost", spec)
	if x != "127.0.0.1" {
		t.Fatalf("unexpected slave address %q", x)
	}

	x = sanitizedSlaveAddress("unbelievable.domain.acme", spec)
	if x != "unbelievable.domain.acme" {
		t.Fatalf("unexpected slave address %q", x)
	}

	x = sanitizedSlaveAddress("unbelievable<>.domain!@#...acme", spec)
	if x != "unbelievable.domain.acme" {
		t.Fatalf("unexpected slave address %q", x)
	}
}
예제 #4
0
// ensure we are parsing what we think we are
func TestInsertState(t *testing.T) {
	var sj StateJSON

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		t.Fatal("missing test data")
	}

	err = json.Unmarshal(b, &sj)
	if err != nil {
		t.Fatal(err)
	}
	sj.Leader = "[email protected]:5050"

	masters := []string{"144.76.157.37:5050"}
	spec := labels.ForRFC952()
	rg := &RecordGenerator{}
	rg.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, spec)

	// ensure we are only collecting running tasks
	_, ok := rg.SRVs["_poseidon._tcp.marathon.mesos."]
	if ok {
		t.Error("should not find this not-running task - SRV record")
	}

	rrs, ok := rg.As["liquor-store.marathon.mesos."]
	if !ok {
		t.Error("should find this running task - A record")
	}
	if got, want := rrs, []string{"1.2.3.11", "1.2.3.12"}; !reflect.DeepEqual(got, want) {
		t.Errorf("should return the slave ips 1.2.3.11, 1.2.3.12 for the task, but got %v", rrs)
	}

	rrs, ok = rg.As["_container.liquor-store.marathon.mesos."]
	if !ok {
		t.Error("should find the container ip")
	}
	if got, want := rrs, []string{"10.3.0.1", "10.3.0.2"}; !reflect.DeepEqual(got, want) {
		t.Errorf("should return the container IPs 10.3.0.1, 10.3.0.2 for the task, but got %v", rrs)
	}

	_, ok = rg.As["poseidon.marathon.mesos."]
	if ok {
		t.Error("should not find this not-running task - A record")
	}

	_, ok = rg.As["_container.poseidon.marathon.mesos."]
	if ok {
		t.Error("should not find a container IP")
	}

	_, ok = rg.As["master.mesos."]
	if !ok {
		t.Error("should find a running master - A record")
	}

	_, ok = rg.As["master0.mesos."]
	if !ok {
		t.Error("should find a running master0 - A record")
	}

	_, ok = rg.As["leader.mesos."]
	if !ok {
		t.Error("should find a leading master - A record")
	}

	_, ok = rg.SRVs["_leader._tcp.mesos."]
	if !ok {
		t.Error("should find a leading master - SRV record")
	}

	// test for 10 SRV names
	if got, want := len(rg.SRVs), 10; got != want {
		t.Errorf("not enough SRVs, got %d, expected %d", got, want)
	}

	// test for 5 A names
	if got, want := len(rg.As), 16; got != want {
		t.Errorf("not enough As, got %d, expected %d", got, want)
	}

	// ensure we translate the framework name as well
	_, ok = rg.As["some-box.chronoswithaspaceandmixe.mesos."]
	if !ok {
		t.Error("should find this task w/a space in the framework name - A record")
	}

	// ensure we find this SRV
	rrs = rg.SRVs["_liquor-store._tcp.marathon.mesos."]
	// ensure there are 3 RRDATA answers for this SRV name
	if len(rrs) != 3 {
		t.Error("not enough SRV records")
	}

	// ensure we don't find this as a SRV record
	rrs = rg.SRVs["_liquor-store.marathon.mesos."]
	if len(rrs) != 0 {
		t.Error("not a proper SRV record")
	}

}
예제 #5
0
// ensure we are parsing what we think we are
func TestInsertState(t *testing.T) {

	var sj StateJSON

	b, err := ioutil.ReadFile("../factories/fake.json")
	if err != nil {
		t.Error("missing test data")
	}

	err = json.Unmarshal(b, &sj)
	if err != nil {
		t.Error(err)
	}
	sj.Leader = "[email protected]:5050"

	masters := []string{"144.76.157.37:5050"}
	spec := labels.ForRFC952()
	rg := &RecordGenerator{}
	rg.InsertState(sj, "mesos", "mesos-dns.mesos.", "127.0.0.1", masters, spec)

	// ensure we are only collecting running tasks
	_, ok := rg.SRVs["_poseidon._tcp.marathon.mesos."]
	if ok {
		t.Error("should not find this not-running task - SRV record")
	}

	_, ok = rg.As["liquor-store.marathon.mesos."]
	if !ok {
		t.Error("should find this running task - A record")
	}

	_, ok = rg.As["poseidon.marathon.mesos."]
	if ok {
		t.Error("should not find this not-running task - A record")
	}

	_, ok = rg.As["master.mesos."]
	if !ok {
		t.Error("should find a running master - A record")
	}

	_, ok = rg.As["master0.mesos."]
	if !ok {
		t.Error("should find a running master0 - A record")
	}

	_, ok = rg.As["leader.mesos."]
	if !ok {
		t.Error("should find a leading master - A record")
	}

	_, ok = rg.SRVs["_leader._tcp.mesos."]
	if !ok {
		t.Error("should find a leading master - SRV record")
	}

	// test for 10 SRV names
	if len(rg.SRVs) != 10 {
		t.Error("not enough SRVs")
	}

	// test for 5 A names
	if len(rg.As) != 13 {
		t.Error("not enough As")
	}

	// ensure we translate the framework name as well
	_, ok = rg.As["some-box.chronoswithaspaceandmixe.mesos."]
	if !ok {
		t.Error("should find this task w/a space in the framework name - A record")
	}

	// ensure we find this SRV
	rrs := rg.SRVs["_liquor-store._tcp.marathon.mesos."]
	// ensure there are 3 RRDATA answers for this SRV name
	if len(rrs) != 3 {
		t.Error("not enough SRV records")
	}

	// ensure we don't find this as a SRV record
	rrs = rg.SRVs["_liquor-store.marathon.mesos."]
	if len(rrs) != 0 {
		t.Error("not a proper SRV record")
	}

}