You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "traeak (via GitHub)" <gi...@apache.org> on 2023/02/01 20:58:49 UTC

[GitHub] [trafficcontrol] traeak commented on a diff in pull request #7323: t3c add support for anycast on http routed delivery services

traeak commented on code in PR #7323:
URL: https://github.com/apache/trafficcontrol/pull/7323#discussion_r1093721734


##########
lib/go-atscfg/remapdotconfig_test.go:
##########
@@ -72,12 +91,203 @@ func pluginsFromTokens(tokens []string, prefix string) []string {
 	return plugins
 }
 
+func TestAnyCastRemapDotConfig(t *testing.T) {
+	hdr := "myHeaderComment"
+	mappings := map[string]bool{
+		"http://dnsroutingname.mypattern1": false,
+		"http://myregexpattern1":           false,
+		"http://server.mypattern0":         false,
+		"https://server.mypattern0":        false,
+		"http://mcastserver1.mypattern0":   false,
+		"https://mcastserver1.mypattern0":  false,
+		"http://mcastserver2.mypattern0":   false,
+		"https://mcastserver2.mypattern0":  false,
+		"http://myregexpattern0":           false,
+		"https://myregexpattern0":          false,
+	}
+	server := makeTestRemapServer()
+	server.Type = "EDGE"
+	server.Interfaces = []tc.ServerInterfaceInfoV40{}
+	setIPInfo(server, "lo", "192.168.2.6", "fdf8:f53b:82e4::53")
+	servers := makeTestAnyCastServers()
+	for _, anyCsstServer := range getAnyCastPartners(server, servers) {
+		if len(anyCsstServer) != 2 {
+			t.Errorf("expected 2 edges in anycast group, actual '%v'", len(anyCsstServer))
+		}
+	}
+
+	ds := DeliveryService{}
+	ds.ID = util.IntPtr(48)
+	dsType := tc.DSType("HTTP")
+	ds.Type = &dsType
+	ds.OrgServerFQDN = util.StrPtr("origin.example.test")
+	ds.MidHeaderRewrite = util.StrPtr("mymidrewrite")
+	ds.RangeRequestHandling = util.IntPtr(0)
+	ds.RemapText = nil
+	ds.EdgeHeaderRewrite = util.StrPtr("myedgeheaderrewrite")
+	ds.SigningAlgorithm = nil
+	ds.XMLID = util.StrPtr("mydsname")
+	ds.QStringIgnore = util.IntPtr(0)
+	ds.RegexRemap = util.StrPtr("myregexremap")
+	ds.FQPacingRate = util.IntPtr(0)
+	ds.DSCP = util.IntPtr(0)
+	ds.RoutingName = util.StrPtr("myroutingname")
+	ds.MultiSiteOrigin = util.BoolPtr(false)
+	ds.OriginShield = util.StrPtr("myoriginshield")
+	ds.ProfileID = util.IntPtr(49)
+	ds.Protocol = util.IntPtr(int(tc.DSProtocolHTTPAndHTTPS))
+	ds.AnonymousBlockingEnabled = util.BoolPtr(false)
+	ds.Active = util.BoolPtr(true)
+
+	ds1 := DeliveryService{}
+	ds1.ID = util.IntPtr(49)
+	dsType1 := tc.DSType("DNS")
+	ds1.Type = &dsType1
+	ds1.OrgServerFQDN = util.StrPtr("origin.example.test")
+	ds1.RangeRequestHandling = util.IntPtr(0)
+	ds1.RemapText = nil
+	ds1.SigningAlgorithm = nil
+	ds1.XMLID = util.StrPtr("mydsname1")
+	ds1.QStringIgnore = util.IntPtr(0)
+	ds1.RegexRemap = util.StrPtr("")
+	ds1.FQPacingRate = util.IntPtr(0)
+	ds1.DSCP = util.IntPtr(0)
+	ds1.RoutingName = util.StrPtr("dnsroutingname")
+	ds1.MultiSiteOrigin = util.BoolPtr(false)
+	ds1.OriginShield = util.StrPtr("myoriginshield")
+	ds1.ProfileID = util.IntPtr(49)
+	ds1.ProfileName = util.StrPtr("dsprofile")
+	ds1.Protocol = util.IntPtr(int(tc.DSProtocolHTTP))
+	ds1.AnonymousBlockingEnabled = util.BoolPtr(false)
+	ds1.Active = util.BoolPtr(true)
+
+	dses := []DeliveryService{ds, ds1}
+
+	dss := []DeliveryServiceServer{
+		DeliveryServiceServer{
+			Server:          *server.ID,
+			DeliveryService: *ds.ID,
+		},
+		DeliveryServiceServer{
+			Server:          *server.ID,
+			DeliveryService: *ds1.ID,
+		},
+	}
+	for _, srv := range servers {
+		for _, ds := range dses {
+			dssrv := DeliveryServiceServer{
+				Server:          *srv.ID,
+				DeliveryService: *ds.ID,
+			}
+			dss = append(dss, dssrv)
+		}
+	}
+	dsRegexes := []tc.DeliveryServiceRegexes{}
+	for i, ds := range dses {
+		pattern := fmt.Sprintf(`.*\.mypattern%d\..*`, i)
+		customRex := fmt.Sprintf("myregexpattern%d", i)
+		dsr := tc.DeliveryServiceRegexes{
+			DSName: *ds.XMLID,
+			Regexes: []tc.DeliveryServiceRegex{
+				tc.DeliveryServiceRegex{
+					Type:      string(tc.DSMatchTypeHostRegex),
+					SetNumber: 0,
+					Pattern:   pattern,
+				},
+				tc.DeliveryServiceRegex{
+					Type:      string(tc.DSMatchTypeHostRegex),
+					SetNumber: 1,
+					Pattern:   customRex,
+				},
+			},
+		}
+		dsRegexes = append(dsRegexes, dsr)
+	}
+	serverParams := []tc.Parameter{
+		tc.Parameter{
+			Name:       "trafficserver",
+			ConfigFile: "package",
+			Value:      "9",
+			Profiles:   []byte(`["global"]`),
+		},
+	}
+	remapConfigParams := []tc.Parameter{
+		tc.Parameter{
+			Name:       "cachekey.pparam",
+			ConfigFile: "remap.config",
+			Value:      "--cachekeykey=cachekeyval",
+			Profiles:   []byte(`["dsprofile"]`),
+		},
+		tc.Parameter{
+			Name:       "not_location",
+			ConfigFile: "cachekey.config",
+			Value:      "notinconfig",
+			Profiles:   []byte(`["global"]`),
+		},
+	}
+	cdn := &tc.CDN{
+		DomainName: "cdndomain.example",
+		Name:       "my-cdn-name",
+	}
+	topologies := []tc.Topology{}
+	cgs := []tc.CacheGroupNullable{}
+	serverCapabilities := map[int]map[ServerCapability]struct{}{}
+	dsRequiredCapabilities := map[int]map[ServerCapability]struct{}{}
+	configDir := `/opt/trafficserver/etc/trafficserver`
+
+	cfg, err := MakeRemapDotConfig(server, servers, dses, dss, dsRegexes, serverParams, cdn, remapConfigParams, topologies, cgs, serverCapabilities, dsRequiredCapabilities, configDir, &RemapDotConfigOpts{HdrComment: hdr})
+	if err != nil {
+		t.Fatal(err)
+	}
+	txt := cfg.Text
+
+	//t.Logf("text: %v", txt)
+
+	txt = strings.TrimSpace(txt)
+
+	testComment(t, txt, hdr)
+
+	txtLines := strings.Split(txt, "\n")
+	for _, line := range txtLines[2:] {
+		switch {
+		case strings.Contains(line, "http://dnsroutingname.mypattern1"):
+			mappings["http://dnsroutingname.mypattern1"] = true
+		case strings.Contains(line, "http://myregexpattern1"):
+			mappings["http://myregexpattern1"] = true
+		case strings.Contains(line, "http://server.mypattern0"):
+			mappings["http://server.mypattern0"] = true
+		case strings.Contains(line, "https://server.mypattern0"):
+			mappings["https://server.mypattern0"] = true
+		case strings.Contains(line, "http://mcastserver1.mypattern0"):
+			mappings["http://mcastserver1.mypattern0"] = true
+		case strings.Contains(line, "https://mcastserver1.mypattern0"):
+			mappings["https://mcastserver1.mypattern0"] = true
+		case strings.Contains(line, "http://mcastserver2.mypattern0"):
+			mappings["http://mcastserver2.mypattern0"] = true
+		case strings.Contains(line, "https://mcastserver2.mypattern0"):
+			mappings["https://mcastserver2.mypattern0"] = true
+		case strings.Contains(line, "http://myregexpattern0"):
+			mappings["http://myregexpattern0"] = true
+		case strings.Contains(line, "https://myregexpattern0"):
+			mappings["https://myregexpattern0"] = true
+		default:
+			t.Fatalf("unexpected remap line '%v'", line)
+		}
+	}
+	for key, val := range mappings {
+		if !val {
+			t.Fatalf("expected to find remap rule for '%v'", key)
+		}
+	}
+}

Review Comment:
   Forgot blank line before next function definition.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org