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

zrhoffman 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 b0cb1e0  Legacy Server Defaults Monitor to True (#5771)
b0cb1e0 is described below

commit b0cb1e036ead1ee856f741c0f2a3ea4d2c9651a4
Author: mattjackson220 <[email protected]>
AuthorDate: Wed Apr 21 13:00:08 2021 -0600

    Legacy Server Defaults Monitor to True (#5771)
    
    * Legacy Server Defaults Monitor to True
    
    * updated changelog
    
    * fixed test
---
 CHANGELOG.md              |  1 +
 lib/go-tc/servers.go      | 12 ++++++++++--
 lib/go-tc/servers_test.go |  6 +++---
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0024019..1bf4f6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5695](https://github.com/apache/trafficcontrol/issues/5695) - Ensure 
vitals are calculated only against monitored interfaces
 - [#5724](https://github.com/apache/trafficcontrol/issues/5724) - Set XMPPID 
to hostname if the server had none, don't error on server update when XMPPID is 
empty
 - [#5744](https://github.com/apache/trafficcontrol/issues/5744) - Sort TM 
Delivery Service States page by DS name
+- Fixed server creation through legacy API versions to default `monitor` to 
`true`.
 
 ### Changed
 - Updated the Traffic Ops Python client to 3.0
diff --git a/lib/go-tc/servers.go b/lib/go-tc/servers.go
index 79d7cd7..a7ebd2b 100644
--- a/lib/go-tc/servers.go
+++ b/lib/go-tc/servers.go
@@ -185,8 +185,8 @@ type LegacyInterfaceDetails struct {
 }
 
 // ToInterfaces converts a LegacyInterfaceDetails to a slice of
-// ServerInterfaceInfo structures. No interfaces will be marked for monitoring,
-// and it will generate service addresses according to the passed indicators
+// ServerInterfaceInfo structures. Only one interface is expected and will be 
marked for monitoring.
+// It will generate service addresses according to the passed indicators
 // for each address family.
 func (lid *LegacyInterfaceDetails) ToInterfaces(ipv4IsService, ipv6IsService 
bool) ([]ServerInterfaceInfo, error) {
        var iface ServerInterfaceInfo
@@ -201,6 +201,10 @@ func (lid *LegacyInterfaceDetails) 
ToInterfaces(ipv4IsService, ipv6IsService boo
        }
        iface.Name = *lid.InterfaceName
 
+       // default to true since there should only be one interface from legacy 
API versions
+       // if Monitor is false on all interfaces, then TM will see the server 
as unhealthy
+       iface.Monitor = true
+
        var ips []ServerIPAddress
        if lid.IPAddress != nil && *lid.IPAddress != "" {
                if lid.IPGateway != nil && *lid.IPGateway == "" {
@@ -268,6 +272,10 @@ func (lid *LegacyInterfaceDetails) 
ToInterfacesV4(ipv4IsService, ipv6IsService b
        }
        iface.Name = *lid.InterfaceName
 
+       // default to true since there should only be one interface from legacy 
API versions
+       // if Monitor is false on all interfaces, then TM will see the server 
as unhealthy
+       iface.Monitor = true
+
        var ips []ServerIPAddress
        if lid.IPAddress != nil && *lid.IPAddress != "" {
                if lid.IPGateway != nil && *lid.IPGateway == "" {
diff --git a/lib/go-tc/servers_test.go b/lib/go-tc/servers_test.go
index 2d53f93..cb17e52 100644
--- a/lib/go-tc/servers_test.go
+++ b/lib/go-tc/servers_test.go
@@ -54,7 +54,7 @@ func ExampleLegacyInterfaceDetails_ToInterfaces() {
                        fmt.Printf("\taddr=%s, gateway=%s, service 
address=%t\n", ip.Address, *ip.Gateway, ip.ServiceAddress)
                }
        }
-       // Output: name=test, monitor=false
+       // Output: name=test, monitor=true
        //      addr=1.2.3.4/30, gateway=4.3.2.1, service address=true
        //      addr=::14/64, gateway=::15, service address=false
        //
@@ -1124,8 +1124,8 @@ func TestServerNullableV2_Upgrade(t *testing.T) {
                        t.Errorf("Incorrect Interface MTU after upgrade; want: 
%d, got: %d", *nullable.InterfaceMtu, *inf.MTU)
                }
 
-               if inf.Monitor {
-                       t.Error("Incorrect Interface Monitor after upgrade; 
want: false, got: true")
+               if !inf.Monitor {
+                       t.Error("Incorrect Interface Monitor after upgrade; 
want: true, got: false")
                }
 
                if inf.MaxBandwidth != nil {

Reply via email to