This is an automated email from the ASF dual-hosted git repository.
mitchell852 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 3995be2 added missing API tests for snapshot endpoints (#5002)
3995be2 is described below
commit 3995be21c45e8a9fa4d056fcfa5943312451dafc
Author: mattjackson220 <[email protected]>
AuthorDate: Fri Sep 18 16:22:47 2020 -0600
added missing API tests for snapshot endpoints (#5002)
* added missing API tests for snapshot endpoints
* updated snapshot docs to include note about monitoring endpoint
* fixed v1 monitoring test
---
docs/source/api/v1/snapshot_name.rst | 1 +
docs/source/api/v2/snapshot.rst | 1 +
docs/source/api/v3/snapshot.rst | 1 +
traffic_ops/testing/api/v1/crconfig_test.go | 63 +++++++++++++++++++++++++++
traffic_ops/testing/api/v1/monitoring_test.go | 50 +++++++++++++++++++++
traffic_ops/testing/api/v2/crconfig_test.go | 17 ++++++++
traffic_ops/testing/api/v3/crconfig_test.go | 17 ++++++++
traffic_ops/v1-client/crconfig.go | 33 ++++++++++++++
traffic_ops/v2-client/crconfig.go | 15 +++++++
traffic_ops/v3-client/crconfig.go | 15 +++++++
10 files changed, 213 insertions(+)
diff --git a/docs/source/api/v1/snapshot_name.rst
b/docs/source/api/v1/snapshot_name.rst
index f02230f..2795c72 100644
--- a/docs/source/api/v1/snapshot_name.rst
+++ b/docs/source/api/v1/snapshot_name.rst
@@ -24,6 +24,7 @@
``PUT``
=======
Performs a CDN :term:`Snapshot`. Effectively, this propagates the new
*configuration* of the CDN to its *operating state*, which replaces the output
of the :ref:`to-api-v1-cdns-name-snapshot` endpoint with the output of the
:ref:`to-api-v1-cdns-name-snapshot-new` endpoint.
+This also changes the output of the
:ref:`to-api-v1-cdns-name-configs-monitoring` endpoint since that endpoint
returns the latest monitoring information from the *operating state*.
.. Note:: Snapshotting the CDN also deletes all HTTPS certificates for every
:term:`Delivery Service` which has been deleted since the last :term:`Snapshot`.
diff --git a/docs/source/api/v2/snapshot.rst b/docs/source/api/v2/snapshot.rst
index 0d0299d..d626e35 100644
--- a/docs/source/api/v2/snapshot.rst
+++ b/docs/source/api/v2/snapshot.rst
@@ -22,6 +22,7 @@
``PUT``
=======
Performs a CDN :term:`Snapshot`. Effectively, this propagates the new
*configuration* of the CDN to its *operating state*, which replaces the output
of the :ref:`to-api-cdns-name-snapshot` endpoint with the output of the
:ref:`to-api-cdns-name-snapshot-new` endpoint.
+This also changes the output of the
:ref:`to-api-v2-cdns-name-configs-monitoring` endpoint since that endpoint
returns the latest monitoring information from the *operating state*.
.. Note:: Snapshotting the CDN also deletes all HTTPS certificates for every
:term:`Delivery Service` which has been deleted since the last :term:`Snapshot`.
diff --git a/docs/source/api/v3/snapshot.rst b/docs/source/api/v3/snapshot.rst
index 7d28a32..f2643eb 100644
--- a/docs/source/api/v3/snapshot.rst
+++ b/docs/source/api/v3/snapshot.rst
@@ -22,6 +22,7 @@
``PUT``
=======
Performs a CDN :term:`Snapshot`. Effectively, this propagates the new
*configuration* of the CDN to its *operating state*, which replaces the output
of the :ref:`to-api-cdns-name-snapshot` endpoint with the output of the
:ref:`to-api-cdns-name-snapshot-new` endpoint.
+This also changes the output of the :ref:`to-api-cdns-name-configs-monitoring`
endpoint since that endpoint returns the latest monitoring information from the
*operating state*.
.. Note:: Snapshotting the CDN also deletes all HTTPS certificates for every
:term:`Delivery Service` which has been deleted since the last :term:`Snapshot`.
diff --git a/traffic_ops/testing/api/v1/crconfig_test.go
b/traffic_ops/testing/api/v1/crconfig_test.go
index d01fa16..e02a0c8 100644
--- a/traffic_ops/testing/api/v1/crconfig_test.go
+++ b/traffic_ops/testing/api/v1/crconfig_test.go
@@ -26,6 +26,10 @@ import (
func TestCRConfig(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles,
Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers,
DeliveryServices}, func() {
UpdateTestCRConfigSnapshot(t)
+ SnapshotTestCDNbyName(t)
+ SnapshotTestCDNbyInvalidName(t)
+ SnapshotTestCDNbyID(t)
+ SnapshotTestCDNbyInvalidID(t)
})
}
@@ -133,4 +137,63 @@ func UpdateTestCRConfigSnapshot(t *testing.T) {
if err != nil {
t.Fatalf("cannot DELETE Parameter by name: %v - %v", err,
delResp)
}
+
+ crcBtsNew, _, err := TOSession.GetCRConfigNew(cdn)
+ if err != nil {
+ t.Errorf("GetCRConfig err expected nil, actual %+v", err)
+ }
+ crcNew := tc.CRConfig{}
+ if err := json.Unmarshal(crcBtsNew, &crcNew); err != nil {
+ t.Errorf("GetCRConfig bytes expected: valid tc.CRConfig, actual
JSON unmarshal err: %+v", err)
+ }
+
+ if len(crcNew.DeliveryServices) != len(crc.DeliveryServices) {
+ t.Errorf("/new endpoint returned a different snapshot.
DeliveryServices length expected %v, was %v", len(crc.DeliveryServices),
len(crcNew.DeliveryServices))
+ }
+
+ if *crcNew.Stats.TMHost != "" {
+ t.Errorf("update to snapshot not captured in /new endpoint")
+ }
+}
+
+func SnapshotTestCDNbyName(t *testing.T) {
+
+ firstCDN := testData.CDNs[0]
+ _, err := TOSession.SnapshotCRConfig(firstCDN.Name)
+ if err != nil {
+ t.Errorf("failed to snapshot CDN by name: %v", err)
+ }
+}
+
+func SnapshotTestCDNbyInvalidName(t *testing.T) {
+
+ invalidCDNName := "cdn-invalid"
+ _, err := TOSession.SnapshotCRConfig(invalidCDNName)
+ if err == nil {
+ t.Errorf("snapshot occurred on invalid cdn name: %v - %v",
invalidCDNName, err)
+ }
+}
+
+func SnapshotTestCDNbyID(t *testing.T) {
+
+ firstCDN := testData.CDNs[0]
+ // Retrieve the CDN by name so we can get the id for the snapshot
+ resp, _, err := TOSession.GetCDNByName(firstCDN.Name)
+ if err != nil {
+ t.Errorf("cannot GET CDN by name: '%s', %v", firstCDN.Name, err)
+ }
+ remoteCDN := resp[0]
+ alert, _, err := TOSession.SnapshotCRConfigByID(remoteCDN.ID)
+ if err != nil {
+ t.Errorf("failed to snapshot CDN by id: %v - %v", err, alert)
+ }
+}
+
+func SnapshotTestCDNbyInvalidID(t *testing.T) {
+
+ invalidCDNID := 999999
+ alert, _, err := TOSession.SnapshotCRConfigByID(invalidCDNID)
+ if err == nil {
+ t.Errorf("snapshot occurred on invalid cdn id: %v - %v - %v",
invalidCDNID, err, alert)
+ }
}
diff --git a/traffic_ops/testing/api/v1/monitoring_test.go
b/traffic_ops/testing/api/v1/monitoring_test.go
new file mode 100644
index 0000000..d7e7474
--- /dev/null
+++ b/traffic_ops/testing/api/v1/monitoring_test.go
@@ -0,0 +1,50 @@
+/*
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package v1
+
+import (
+ "testing"
+
+ "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+func TestMonitoring(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles,
Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers,
DeliveryServices}, func() {
+ AllCDNsCanSnapshot(t)
+ })
+}
+
+func AllCDNsCanSnapshot(t *testing.T) {
+ serversByHost := make(map[string]tc.ServerV1)
+
+ for _, server := range testData.Servers {
+ serversByHost[server.HostName] = server
+ }
+
+ for _, cdn := range testData.CDNs {
+ _, err := TOSession.SnapshotCRConfig(cdn.Name)
+ if err != nil {
+ t.Error(err)
+ continue
+ }
+
+ tmConfig, _, err :=
TOSession.GetTrafficMonitorConfigMap(cdn.Name)
+ if err != nil && tmConfig != nil {
+ t.Error(err)
+ continue
+ }
+ }
+}
diff --git a/traffic_ops/testing/api/v2/crconfig_test.go
b/traffic_ops/testing/api/v2/crconfig_test.go
index cce4404..c5d2c57 100644
--- a/traffic_ops/testing/api/v2/crconfig_test.go
+++ b/traffic_ops/testing/api/v2/crconfig_test.go
@@ -137,6 +137,23 @@ func UpdateTestCRConfigSnapshot(t *testing.T) {
if err != nil {
t.Fatalf("cannot DELETE Parameter by name: %v - %v", err,
delResp)
}
+
+ crcBtsNew, _, err := TOSession.GetCRConfigNew(cdn)
+ if err != nil {
+ t.Errorf("GetCRConfig err expected nil, actual %+v", err)
+ }
+ crcNew := tc.CRConfig{}
+ if err := json.Unmarshal(crcBtsNew, &crcNew); err != nil {
+ t.Errorf("GetCRConfig bytes expected: valid tc.CRConfig, actual
JSON unmarshal err: %+v", err)
+ }
+
+ if len(crcNew.DeliveryServices) != len(crc.DeliveryServices) {
+ t.Errorf("/new endpoint returned a different snapshot.
DeliveryServices length expected %v, was %v", len(crc.DeliveryServices),
len(crcNew.DeliveryServices))
+ }
+
+ if *crcNew.Stats.TMHost != "" {
+ t.Errorf("update to snapshot not captured in /new endpoint")
+ }
}
func SnapshotTestCDNbyName(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/crconfig_test.go
b/traffic_ops/testing/api/v3/crconfig_test.go
index 5a88c33..3786d52 100644
--- a/traffic_ops/testing/api/v3/crconfig_test.go
+++ b/traffic_ops/testing/api/v3/crconfig_test.go
@@ -138,6 +138,23 @@ func UpdateTestCRConfigSnapshot(t *testing.T) {
if err != nil {
t.Fatalf("cannot DELETE Parameter by name: %v - %v", err,
delResp)
}
+
+ crcBtsNew, _, err := TOSession.GetCRConfigNew(cdn)
+ if err != nil {
+ t.Errorf("GetCRConfig err expected nil, actual %+v", err)
+ }
+ crcNew := tc.CRConfig{}
+ if err := json.Unmarshal(crcBtsNew, &crcNew); err != nil {
+ t.Errorf("GetCRConfig bytes expected: valid tc.CRConfig, actual
JSON unmarshal err: %+v", err)
+ }
+
+ if len(crcNew.DeliveryServices) != len(crc.DeliveryServices) {
+ t.Errorf("/new endpoint returned a different snapshot.
DeliveryServices length expected %v, was %v", len(crc.DeliveryServices),
len(crcNew.DeliveryServices))
+ }
+
+ if *crcNew.Stats.TMHost != "" {
+ t.Errorf("update to snapshot not captured in /new endpoint")
+ }
}
func SnapshotTestCDNbyName(t *testing.T) {
diff --git a/traffic_ops/v1-client/crconfig.go
b/traffic_ops/v1-client/crconfig.go
index e13611e..de42396 100644
--- a/traffic_ops/v1-client/crconfig.go
+++ b/traffic_ops/v1-client/crconfig.go
@@ -17,7 +17,10 @@ package client
import (
"encoding/json"
+ "fmt"
"net/http"
+
+ "github.com/apache/trafficcontrol/lib/go-tc"
)
type OuterResponse struct {
@@ -39,9 +42,39 @@ func (to *Session) GetCRConfig(cdn string) ([]byte, ReqInf,
error) {
return []byte(resp.Response), reqInf, nil
}
+// GetCRConfigNew returns the raw JSON bytes of the CRConfig from Traffic Ops,
and whether the bytes were from the client's internal cache.
+func (to *Session) GetCRConfigNew(cdn string) ([]byte, ReqInf, error) {
+ uri := apiBase + `/cdns/` + cdn + `/snapshot/new`
+ bts, reqInf, err := to.getBytesWithTTL(uri, tmPollingInterval)
+ if err != nil {
+ return nil, reqInf, err
+ }
+
+ resp := OuterResponse{}
+ if err := json.Unmarshal(bts, &resp); err != nil {
+ return nil, reqInf, err
+ }
+ return []byte(resp.Response), reqInf, nil
+}
+
+// SnapshotCRConfig snapshots a CDN by name.
func (to *Session) SnapshotCRConfig(cdn string) (ReqInf, error) {
uri := apiBase + `/snapshot/` + cdn
_, remoteAddr, err := to.request(http.MethodPut, uri, nil)
reqInf := ReqInf{RemoteAddr: remoteAddr, CacheHitStatus:
CacheHitStatusMiss}
return reqInf, err
}
+
+// SnapshotCDNByID snapshots a CDN by ID.
+func (to *Session) SnapshotCRConfigByID(id int) (tc.Alerts, ReqInf, error) {
+ url := fmt.Sprintf(apiBase+`/cdns/%d/snapshot`, id)
+ resp, remoteAddr, err := to.request(http.MethodPut, url, nil)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr:
remoteAddr}
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ defer resp.Body.Close()
+ var alerts tc.Alerts
+ err = json.NewDecoder(resp.Body).Decode(&alerts)
+ return alerts, reqInf, nil
+}
diff --git a/traffic_ops/v2-client/crconfig.go
b/traffic_ops/v2-client/crconfig.go
index 8260507..a8414ad 100644
--- a/traffic_ops/v2-client/crconfig.go
+++ b/traffic_ops/v2-client/crconfig.go
@@ -46,6 +46,21 @@ func (to *Session) GetCRConfig(cdn string) ([]byte, ReqInf,
error) {
return []byte(resp.Response), reqInf, nil
}
+// GetCRConfigNew returns the raw JSON bytes of the latest CRConfig from
Traffic Ops, and whether the bytes were from the client's internal cache.
+func (to *Session) GetCRConfigNew(cdn string) ([]byte, ReqInf, error) {
+ uri := apiBase + `/cdns/` + cdn + `/snapshot/new`
+ bts, reqInf, err := to.getBytesWithTTL(uri, tmPollingInterval)
+ if err != nil {
+ return nil, reqInf, err
+ }
+
+ resp := OuterResponse{}
+ if err := json.Unmarshal(bts, &resp); err != nil {
+ return nil, reqInf, err
+ }
+ return []byte(resp.Response), reqInf, nil
+}
+
// SnapshotCRConfig snapshots a CDN by name.
func (to *Session) SnapshotCRConfig(cdn string) (ReqInf, error) {
uri := fmt.Sprintf("%s?cdn=%s", API_SNAPSHOT, url.QueryEscape(cdn))
diff --git a/traffic_ops/v3-client/crconfig.go
b/traffic_ops/v3-client/crconfig.go
index e02eb05..11fe56b 100644
--- a/traffic_ops/v3-client/crconfig.go
+++ b/traffic_ops/v3-client/crconfig.go
@@ -46,6 +46,21 @@ func (to *Session) GetCRConfig(cdn string) ([]byte, ReqInf,
error) {
return []byte(resp.Response), reqInf, nil
}
+// GetCRConfigNew returns the raw JSON bytes of the latest CRConfig from
Traffic Ops, and whether the bytes were from the client's internal cache.
+func (to *Session) GetCRConfigNew(cdn string) ([]byte, ReqInf, error) {
+ uri := apiBase + `/cdns/` + cdn + `/snapshot/new`
+ bts, reqInf, err := to.getBytesWithTTL(uri, tmPollingInterval)
+ if err != nil {
+ return nil, reqInf, err
+ }
+
+ resp := OuterResponse{}
+ if err := json.Unmarshal(bts, &resp); err != nil {
+ return nil, reqInf, err
+ }
+ return []byte(resp.Response), reqInf, nil
+}
+
// SnapshotCRConfig snapshots a CDN by name.
func (to *Session) SnapshotCRConfig(cdn string) (ReqInf, error) {
uri := fmt.Sprintf("%s?cdn=%s", API_SNAPSHOT, url.QueryEscape(cdn))