This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit d1b3487551ead61e1ee1153da0d89d1029f86baf
Author: Robert O Butts <[email protected]>
AuthorDate: Mon Apr 5 14:07:31 2021 -0600

    Fix ORT adding remap lines for DSes not on Mids (#5713)
    
    Bug was ORT Mid remap gen not using the new lib/go-tc DSType
    UsesMidCache func, but having old code checking live and natnl,
    which ended up with HTTP_NO_CACHE generating remap lines on Mids.
    
    This could particularly cause issues because the hdr_rw_mid_ file
    generation did use ds.Type.UsesMidCache, potentially resulting
    in a remap line with a file that didn't exist, causing ATS to fail
    to load.
    
    This could be mitigated by creating a locatin Param for the file,
    to force it to be created.
    
    Note this did not affect Topologies, which use their own criteria
    for both header rewrite file and remap line generation.
    
    (cherry picked from commit 4b85e933f0ff402f4813ddbe8efd9b13e19743d3)
---
 lib/go-atscfg/remapdotconfig.go      |   3 +-
 lib/go-atscfg/remapdotconfig_test.go | 143 +++++++++++++++++++++++++++++++++++
 2 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/lib/go-atscfg/remapdotconfig.go b/lib/go-atscfg/remapdotconfig.go
index e5ca856..3ad3af1 100644
--- a/lib/go-atscfg/remapdotconfig.go
+++ b/lib/go-atscfg/remapdotconfig.go
@@ -137,7 +137,8 @@ func getServerConfigRemapDotConfigForMid(
                                continue
                        }
                }
-               if ds.Type.IsLive() && !ds.Type.IsNational() && !hasTopology {
+
+               if !ds.Type.UsesMidCache() && (!hasTopology || *ds.Topology == 
"") {
                        continue // Live local delivery services skip mids 
(except Topologies ignore DS types)
                }
 
diff --git a/lib/go-atscfg/remapdotconfig_test.go 
b/lib/go-atscfg/remapdotconfig_test.go
index 8b1c60c..e054ad5 100644
--- a/lib/go-atscfg/remapdotconfig_test.go
+++ b/lib/go-atscfg/remapdotconfig_test.go
@@ -8267,3 +8267,146 @@ func makeTestRemapServer() *Server {
        server.Type = "MID"
        return server
 }
+
+func TestMakeRemapDotConfigMidNoNoCacheRemapLine(t *testing.T) {
+       hdr := "myHeaderComment"
+
+       server := makeTestRemapServer()
+       server.Type = "MID"
+
+       ds := DeliveryService{}
+       ds.ID = util.IntPtr(48)
+       dsType := tc.DSType("HTTP_NO_CACHE")
+       ds.Type = &dsType
+       ds.OrgServerFQDN = util.StrPtr("origin.example.test")
+       ds.RangeRequestHandling = 
util.IntPtr(tc.RangeRequestHandlingCacheRangeRequest)
+       ds.RemapText = util.StrPtr("@plugin=tslua.so 
@pparam=my-range-manipulator.lua")
+       ds.SigningAlgorithm = util.StrPtr("foo")
+       ds.XMLID = util.StrPtr("mydsname")
+       ds.QStringIgnore = 
util.IntPtr(int(tc.QueryStringIgnoreIgnoreInCacheKeyAndPassUp))
+       ds.RegexRemap = util.StrPtr("")
+       ds.FQPacingRate = util.IntPtr(314159)
+       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.ProfileName = util.StrPtr("dsprofile")
+       ds.Protocol = util.IntPtr(int(tc.DSProtocolHTTPToHTTPS))
+       ds.AnonymousBlockingEnabled = util.BoolPtr(false)
+       ds.Active = util.BoolPtr(true)
+
+       // non-nil default values should not trigger header rewrite plugin 
directive
+       ds.EdgeHeaderRewrite = util.StrPtr("")
+       ds.MidHeaderRewrite = util.StrPtr("mid-header-rewrite")
+       ds.ServiceCategory = util.StrPtr("")
+       ds.MaxOriginConnections = util.IntPtr(0)
+
+       dses := []DeliveryService{ds}
+
+       dss := []tc.DeliveryServiceServer{
+               tc.DeliveryServiceServer{
+                       Server:          util.IntPtr(*server.ID),
+                       DeliveryService: util.IntPtr(*ds.ID),
+               },
+       }
+
+       dsRegexes := []tc.DeliveryServiceRegexes{
+               tc.DeliveryServiceRegexes{
+                       DSName: *ds.XMLID,
+                       Regexes: []tc.DeliveryServiceRegex{
+                               tc.DeliveryServiceRegex{
+                                       Type:      
string(tc.DSMatchTypeHostRegex),
+                                       SetNumber: 0,
+                                       Pattern:   `.*\.mypattern\..*`,
+                               },
+                       },
+               },
+       }
+
+       serverParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "trafficserver",
+                       ConfigFile: "package",
+                       Value:      "7",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "serverpkgval",
+                       ConfigFile: "package",
+                       Value:      "serverpkgval __HOSTNAME__ foo",
+                       Profiles:   []byte(*server.Profile),
+               },
+               tc.Parameter{
+                       Name:       "dscp_remap_no",
+                       ConfigFile: "package",
+                       Value:      "notused",
+                       Profiles:   []byte(*server.Profile),
+               },
+       }
+
+       cacheKeyParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "shouldnotexist",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "shouldnotexisteither",
+                       Profiles:   []byte(`["not-dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "not_location",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "notinconfig",
+                       Profiles:   []byte(`["global"]`),
+               },
+               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{}{}
+
+       cfg, err := MakeRemapDotConfig(server, dses, dss, dsRegexes, 
serverParams, cdn, cacheKeyParams, topologies, cgs, serverCapabilities, 
dsRequiredCapabilities, hdr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       txt = strings.TrimSpace(txt)
+
+       testComment(t, txt, hdr)
+
+       txtLines := strings.Split(txt, "\n")
+
+       if len(txtLines) != 1 {
+               t.Fatalf("expected 0 remaps from HTTP_NO_CACHE DS on Mid, 
actual: '%v' count %v", txt, len(txtLines))
+       }
+
+       remapLine := txtLines[0]
+
+       if strings.Contains(remapLine, "hdr_rw_mid_mydsname.config") {
+               t.Errorf("expected remap line for HTTP_NO_CACHE to not exist on 
Mid server, regardless of Mid Header Rewrite, actual '%v'", txt)
+       }
+}

Reply via email to