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

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 6953823  Fix t3c parent.config gen for EDGE/MID+ Types (#5908)
6953823 is described below

commit 695382320bda4c90751982c838092871d5e7be5c
Author: Robert O Butts <[email protected]>
AuthorDate: Thu Jun 3 11:51:45 2021 -0600

    Fix t3c parent.config gen for EDGE/MID+ Types (#5908)
---
 CHANGELOG.md                          |   1 +
 lib/go-atscfg/parentdotconfig.go      |   2 +-
 lib/go-atscfg/parentdotconfig_test.go | 143 ++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9375dd4..5aa213d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -63,6 +63,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5548](https://github.com/apache/trafficcontrol/issues/5548) - Don't return 
a `403 Forbidden` when the user tries to get servers of a non-existent DS using 
`GET /servers?dsId={{nonexistent DS ID}}`
 - [#5732](https://github.com/apache/trafficcontrol/issues/5732) - TO API POST 
/cdns/dnsseckeys/generate times out with large numbers of delivery services
 - Fixed server creation through legacy API versions to default `monitor` to 
`true`.
+- Fixed t3c to generate topology parents correctly for parents with the Type 
MID+ or EDGE+ versus just the literal. Naming cache types to not be exactly 
'EDGE' or 'MID' is still discouraged and not guaranteed to work, but it's 
unfortunately somewhat common, so this fixes it in one particular case.
 - Fixed t3c to create config files and directories as ats.ats
 
 ### Changed
diff --git a/lib/go-atscfg/parentdotconfig.go b/lib/go-atscfg/parentdotconfig.go
index b35e67f..1a161ff 100644
--- a/lib/go-atscfg/parentdotconfig.go
+++ b/lib/go-atscfg/parentdotconfig.go
@@ -1055,7 +1055,7 @@ func getTopologyParents(
                        continue
                }
 
-               if tc.CacheType(sv.Type) != tc.CacheTypeEdge && 
tc.CacheType(sv.Type) != tc.CacheTypeMid && sv.Type != tc.OriginTypeName {
+               if !strings.HasPrefix(sv.Type, tc.EdgeTypePrefix) && 
!strings.HasPrefix(sv.Type, tc.MidTypePrefix) && sv.Type != tc.OriginTypeName {
                        continue // only consider edges, mids, and origins in 
the CacheGroup.
                }
                if _, dsHasOrigin := dsOrigins[ServerID(*sv.ID)]; sv.Type == 
tc.OriginTypeName && !dsHasOrigin {
diff --git a/lib/go-atscfg/parentdotconfig_test.go 
b/lib/go-atscfg/parentdotconfig_test.go
index 16ed85e..7e6718d 100644
--- a/lib/go-atscfg/parentdotconfig_test.go
+++ b/lib/go-atscfg/parentdotconfig_test.go
@@ -1873,6 +1873,149 @@ func TestMakeParentDotConfigTopologiesParams(t 
*testing.T) {
        }
 }
 
+func TestMakeParentDotConfigTopologiesNonStandardServerTypes(t *testing.T) {
+       hdr := ParentConfigOpts{AddComments: false, HdrComment: 
"myHeaderComment"}
+
+       ds0 := makeParentDS()
+       ds0Type := tc.DSTypeHTTP
+       ds0.Type = &ds0Type
+       ds0.QStringIgnore = 
util.IntPtr(int(tc.QStringIgnoreUseInCacheKeyAndPassUp))
+       ds0.OrgServerFQDN = util.StrPtr("http://ds0.example.net";)
+
+       ds1 := makeParentDS()
+       ds1.ID = util.IntPtr(43)
+       ds1Type := tc.DSTypeDNS
+       ds1.Type = &ds1Type
+       ds1.QStringIgnore = util.IntPtr(int(tc.QStringIgnoreDrop))
+       ds1.OrgServerFQDN = util.StrPtr("http://ds1.example.net";)
+       ds1.Topology = util.StrPtr("t0")
+
+       dses := []DeliveryService{*ds0, *ds1}
+
+       parentConfigParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       ParentConfigParamQStringHandling,
+                       ConfigFile: "parent.config",
+                       Value:      "myQStringHandlingParam",
+                       Profiles:   []byte(`["serverprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       ParentConfigParamAlgorithm,
+                       ConfigFile: "parent.config",
+                       Value:      tc.AlgorithmConsistentHash,
+                       Profiles:   []byte(`["serverprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       ParentConfigParamQString,
+                       ConfigFile: "parent.config",
+                       Value:      "myQstringParam",
+                       Profiles:   []byte(`["serverprofile"]`),
+               },
+       }
+
+       serverParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "trafficserver",
+                       ConfigFile: "package",
+                       Value:      "7",
+                       Profiles:   []byte(`["global"]`),
+               },
+       }
+
+       server := makeTestParentServer()
+       server.Cachegroup = util.StrPtr("edgeCG")
+       server.CachegroupID = util.IntPtr(400)
+
+       mid0 := makeTestParentServer()
+       mid0.Cachegroup = util.StrPtr("midCG")
+       mid0.CachegroupID = util.IntPtr(500)
+       mid0.HostName = util.StrPtr("mymid")
+       mid0.ID = util.IntPtr(45)
+       setIP(mid0, "192.168.2.2")
+       mid0.Type = "MIDSOMETHING-RANDOM"
+
+       mid1 := makeTestParentServer()
+       mid1.Cachegroup = util.StrPtr("midCG")
+       mid1.CachegroupID = util.IntPtr(500)
+       mid1.HostName = util.StrPtr("mymid1")
+       mid1.ID = util.IntPtr(46)
+       mid1.Type = "MID_SOMETHING_ELSE"
+       setIP(mid1, "192.168.2.3")
+
+       servers := []Server{*server, *mid0, *mid1}
+
+       topologies := []tc.Topology{
+               tc.Topology{
+                       Name: "t0",
+                       Nodes: []tc.TopologyNode{
+                               tc.TopologyNode{
+                                       Cachegroup: "edgeCG",
+                                       Parents:    []int{1},
+                               },
+                               tc.TopologyNode{
+                                       Cachegroup: "midCG",
+                               },
+                       },
+               },
+       }
+
+       serverCapabilities := map[int]map[ServerCapability]struct{}{}
+       dsRequiredCapabilities := map[int]map[ServerCapability]struct{}{}
+
+       eCG := &tc.CacheGroupNullable{}
+       eCG.Name = server.Cachegroup
+       eCG.ID = server.CachegroupID
+       eCG.ParentName = mid0.Cachegroup
+       eCG.ParentCachegroupID = mid0.CachegroupID
+       eCGType := tc.CacheGroupEdgeTypeName
+       eCG.Type = &eCGType
+
+       mCG := &tc.CacheGroupNullable{}
+       mCG.Name = mid0.Cachegroup
+       mCG.ID = mid0.CachegroupID
+       mCGType := tc.CacheGroupMidTypeName
+       mCG.Type = &mCGType
+
+       cgs := []tc.CacheGroupNullable{*eCG, *mCG}
+
+       dss := []DeliveryServiceServer{
+               DeliveryServiceServer{
+                       Server:          *server.ID,
+                       DeliveryService: *ds0.ID,
+               },
+               DeliveryServiceServer{
+                       Server:          *server.ID,
+                       DeliveryService: *ds1.ID,
+               },
+       }
+       cdn := &tc.CDN{
+               DomainName: "cdndomain.example",
+               Name:       "my-cdn-name",
+       }
+
+       cfg, err := MakeParentDotConfig(dses, server, servers, topologies, 
serverParams, parentConfigParams, serverCapabilities, dsRequiredCapabilities, 
cgs, dss, cdn, hdr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       testComment(t, txt, hdr.HdrComment)
+
+       if !strings.Contains(txt, "dest_domain=ds0.example.net") {
+               t.Errorf("expected parent 'dest_domain=ds0.example.net', 
actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "dest_domain=ds1.example.net") {
+               t.Errorf("expected parent 'dest_domain=ds1.example.net', 
actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "qstring=myQStringHandlingParam") {
+               t.Errorf("expected qstring from param 
'qstring=myQStringHandlingParam', actual: '%v'", txt)
+       }
+       if strings.Contains(txt, "# topology") {
+               // ATS doesn't support inline comments in parent.config
+               t.Errorf("expected: no inline '# topology' comment, actual: 
'%v'", txt)
+       }
+}
+
 func TestMakeParentDotConfigSecondaryMode(t *testing.T) {
 
        hdr := ParentConfigOpts{AddComments: false, HdrComment: 
"myHeaderComment"}

Reply via email to