You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/07/11 01:19:53 UTC
[trafficcontrol] 06/13: successfully tested the Create and Update
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
commit 96e4a81e6bf00771ef61849510fe7a4a9f6472aa
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 30 15:36:47 2018 -0600
successfully tested the Create and Update
---
lib/go-tc/v13/staticdnsentries.go | 46 ++-
.../testing/api/v13/staticdnsentries_test.go | 47 ++-
traffic_ops/testing/api/v13/tc-fixtures.json | 315 +++++++++++----------
traffic_ops/traffic_ops_golang/routes.go | 7 +-
.../staticdnsentry/staticdnsentry.go | 7 +-
5 files changed, 239 insertions(+), 183 deletions(-)
diff --git a/lib/go-tc/v13/staticdnsentries.go b/lib/go-tc/v13/staticdnsentries.go
index 14941f4..cfb1ef8 100644
--- a/lib/go-tc/v13/staticdnsentries.go
+++ b/lib/go-tc/v13/staticdnsentries.go
@@ -34,15 +34,23 @@ type StaticDNSEntry struct {
// required: true
Address string `json:"address" db:"address"`
- // The Cachegroup associated
+ // The Cachegroup Name associated
//
- CacheGroup string `json:"cachegroup" db:"cachegroup"`
+ CacheGroupName string `json:"cachegroup"`
+
+ // The Cachegroup ID associated
+ //
+ CacheGroupID int `json:"cachegroupId" db:"cachegroup_id"`
// The DeliveryService associated
//
- // required: true
DeliveryService string `json:"deliveryservice" db:"dsname"`
+ // The DeliveryService associated
+ //
+ // required: true
+ DeliveryServiceID int `json:"deliveryserviceId" db:"deliveryservice_id"`
+
// The host of the static dns entry
//
// required: true
@@ -64,9 +72,13 @@ type StaticDNSEntry struct {
// The type of the static DNS entry
//
- // required: true
// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
- Type string `json:"type" db:"type"`
+ Type string `json:"type"`
+
+ // The type id of the static DNS entry
+ //
+ // required: true
+ TypeID int `json:"typeId" db:"type_id"`
}
// StatisDNSEntryNullable ...
@@ -77,15 +89,23 @@ type StaticDNSEntryNullable struct {
// required: true
Address *string `json:"address" db:"address"`
- // The Cachegroup associated
+ // The Cachegroup Name associated
//
- CacheGroup *string `json:"cachegroup" db:"cachegroup"`
+ CacheGroupName *string `json:"cachegroup" db:"cachegroup"`
- // The DeliveryService associated
+ // The Cachegroup ID associated
+ //
+ CacheGroupID *int `json:"cachegroupId" db:"cachegroup_id"`
+
+ // The DeliveryService Name associated
//
- // required: true
DeliveryService *string `json:"deliveryservice" db:"dsname"`
+ // DeliveryService ID of the StaticDNSEntry
+ //
+ // required: true
+ DeliveryServiceID *int `json:"deliveryserviceId" db:"deliveryservice_id"`
+
// The host of the static dns entry
//
// required: true
@@ -107,7 +127,11 @@ type StaticDNSEntryNullable struct {
// The type of the static DNS entry
//
- // required: true
// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
- Type *string `json:"type" db:"type"`
+ Type *string `json:"type"`
+
+ // The type id of the static DNS entry
+ //
+ // required: true
+ TypeID int `json:"typeId" db:"type_id"`
}
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index 3e88032..1cbe9ed 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -56,14 +56,31 @@ func TestStaticDNSEntries(t *testing.T) {
func CreateTestStaticDNSEntries(t *testing.T) {
for _, staticDNSEntry := range testData.StaticDNSEntries {
- // GET EDGE type
+
+ // GET StaticDNSEntry type
respTypes, _, err := TOSession.GetTypeByName(staticDNSEntry.Type)
- fmt.Printf("respTypes ---> %v\n", respTypes)
if err != nil {
t.Errorf("cannot GET Type by name: %v\n", err)
}
respType := respTypes[0]
- staticDNSEntry.Type = respType.Name
+ staticDNSEntry.TypeID = respType.ID
+
+ // GET DeliveryService to associate
+ respDSes, _, err := TOSession.GetDeliveryServiceByXMLID(staticDNSEntry.DeliveryService)
+ if err != nil {
+ t.Errorf("cannot GET DeliveryService by XMLID: %v\n", err)
+ }
+ respDS := respDSes[0]
+ staticDNSEntry.DeliveryServiceID = respDS.ID
+
+ // GET Cachegroup to associate
+ respGroups, _, err := TOSession.GetCacheGroupByName(staticDNSEntry.CacheGroupName)
+ if err != nil {
+ t.Errorf("cannot GET CacheGroup by Name: %v\n", err)
+ }
+ respGroup := respGroups[0]
+ staticDNSEntry.CacheGroupID = respGroup.ID
+
resp, _, err := TOSession.CreateStaticDNSEntry(staticDNSEntry)
log.Debugln("Response: ", resp)
if err != nil {
@@ -75,25 +92,27 @@ func CreateTestStaticDNSEntries(t *testing.T) {
func UpdateTestStaticDNSEntries(t *testing.T) {
- firstStaticDNSEntrie := testData.StaticDNSEntries[0]
- // Retrieve the StaticDNSEntrie by name so we can get the id for the Update
- resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntrie.Host)
+ firstStaticDNSEntry := testData.StaticDNSEntries[0]
+ // Retrieve the StaticDNSEntries by name so we can get the id for the Update
+ resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntry.Host)
if err != nil {
- t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntrie.Host, err)
+ t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
}
remoteStaticDNSEntry := resp[0]
+ fmt.Printf("remoteStaticDNSEntry ---> %v\n", remoteStaticDNSEntry)
+ fmt.Printf("remoteStaticDNSEntry.ID ---> %v\n", remoteStaticDNSEntry.ID)
expectedAddress := "address99"
remoteStaticDNSEntry.Address = expectedAddress
var alert tc.Alerts
alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
if err != nil {
- t.Errorf("cannot UPDATE StaticDNSEntrie by id: %v - %v\n", err, alert)
+ t.Errorf("cannot UPDATE StaticDNSEntries by id: %v - %v\n", err, alert)
}
- // Retrieve the StaticDNSEntrie to check StaticDNSEntrie name got updated
+ // Retrieve the StaticDNSEntries to check StaticDNSEntries name got updated
resp, _, err = TOSession.GetStaticDNSEntryByID(remoteStaticDNSEntry.ID)
if err != nil {
- t.Errorf("cannot GET StaticDNSEntries by name: '$%s', %v\n", firstStaticDNSEntrie.Host, err)
+ t.Errorf("cannot GET StaticDNSEntries by name: '$%s', %v\n", firstStaticDNSEntry.Host, err)
}
respStaticDNSEntry := resp[0]
if respStaticDNSEntry.Address != expectedAddress {
@@ -115,17 +134,17 @@ func GetTestStaticDNSEntries(t *testing.T) {
func DeleteTestStaticDNSEntries(t *testing.T) {
for _, staticDNSEntry := range testData.StaticDNSEntries {
- // Retrieve the StaticDNSEntrie by name so we can get the id for the Update
+ // Retrieve the StaticDNSEntries by name so we can get the id for the Update
resp, _, err := TOSession.GetStaticDNSEntriesByHost(staticDNSEntry.Host)
if err != nil {
t.Errorf("cannot GET StaticDNSEntries by name: %v - %v\n", staticDNSEntry.Host, err)
}
if len(resp) > 0 {
- respStaticDNSEntrie := resp[0]
+ respStaticDNSEntry := resp[0]
- _, _, err := TOSession.DeleteStaticDNSEntryByID(respStaticDNSEntrie.ID)
+ _, _, err := TOSession.DeleteStaticDNSEntryByID(respStaticDNSEntry.ID)
if err != nil {
- t.Errorf("cannot DELETE StaticDNSEntrie by name: '%s' %v\n", respStaticDNSEntrie.Host, err)
+ t.Errorf("cannot DELETE StaticDNSEntrie by name: '%s' %v\n", respStaticDNSEntry.Host, err)
}
// Retrieve the StaticDNSEntrie to see if it got deleted
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index d0799d0..3381924 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -174,137 +174,137 @@
],
"deliveryServices": [
{
- "active": true,
- "cacheurl": "cacheUrl1",
- "ccrDnsTtl": 3600,
- "cdnName": "cdn1",
- "checkPath": "",
- "deepCachingType": "NEVER",
- "displayName": "ds1DisplayName",
- "dnsBypassCname": null,
- "dnsBypassIp": "",
- "dnsBypassIp6": "",
- "dnsBypassTtl": 30,
- "dscp": 40,
- "edgeHeaderRewrite": "edgeHeader1",
- "exampleURLs": [
- "http://ccr.ds1.example.net",
- "https://ccr.ds1.example.net"
- ],
- "fqPacingRate": 0,
- "geoLimit": 0,
- "geoLimitCountries": "",
- "geoLimitRedirectURL": null,
- "geoProvider": 0,
- "globalMaxMbps": 0,
- "globalMaxTps": 0,
- "httpBypassFqdn": "",
- "infoUrl": "TBD",
- "initialDispersion": 1,
- "ipv6RoutingEnabled": true,
- "lastUpdated": "2018-04-06 16:48:51+00",
- "logsEnabled": false,
- "longDesc": "d s 1",
- "longDesc1": "ds1",
- "longDesc2": "ds1",
- "matchList": [
- {
- "pattern": ".*\\.ds1\\..*",
- "setNumber": 0,
- "type": "HOST_REGEXP"
- }
- ],
- "maxDnsAnswers": 0,
- "midHeaderRewrite": "midHeader1",
- "missLat": 41.881944,
- "missLong": -87.627778,
- "multiSiteOrigin": false,
- "orgServerFqdn": "http://origin.example.net",
- "originShield": null,
- "profileDescription": null,
- "profileId": null,
- "profileName": null,
- "protocol": 2,
- "qstringIgnore": 1,
- "rangeRequestHandling": 0,
- "regexRemap": "rr1",
- "regionalGeoBlocking": false,
- "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/remapPlugin1.lua",
- "routingName": "ccr-ds1",
- "signed": false,
- "signingAlgorithm": "url_sig",
- "sslKeyVersion": 2,
- "tenant": "tenant1",
- "tenantName": "tenant1",
- "type": "HTTP_LIVE",
- "xmlId": "ds1",
- "anonymousBlockingEnabled": true
- },
- {
- "active": true,
- "cacheurl": "cacheUrl2",
- "ccrDnsTtl": 3600,
- "cdnName": "cdn1",
- "checkPath": "",
- "deepCachingType": "NEVER",
- "displayName": "d s 1",
- "dnsBypassCname": null,
- "dnsBypassIp": "",
- "dnsBypassIp6": "",
- "dnsBypassTtl": 30,
- "dscp": 40,
- "edgeHeaderRewrite": "edgeRewrite2",
- "exampleURLs": [
- "http://ccr.ds2.example.net",
- "https://ccr.ds2x.example.net"
- ],
- "fqPacingRate": 0,
- "geoLimit": 0,
- "geoLimitCountries": "",
- "geoLimitRedirectURL": null,
- "geoProvider": 0,
- "globalMaxMbps": 0,
- "globalMaxTps": 0,
- "httpBypassFqdn": "",
- "infoUrl": "TBD",
- "initialDispersion": 1,
- "ipv6RoutingEnabled": true,
- "lastUpdated": "2018-04-06 16:48:51+00",
- "logsEnabled": false,
- "longDesc": "d s 1",
- "longDesc1": "ds2",
- "longDesc2": "ds2",
- "matchList": [
- {
- "pattern": ".*\\.ds2\\..*",
- "setNumber": 0,
- "type": "HOST_REGEXP"
- }
- ],
- "maxDnsAnswers": 0,
- "midHeaderRewrite": "midRewrite2",
- "missLat": 41.881944,
- "missLong": -87.627778,
- "multiSiteOrigin": false,
- "orgServerFqdn": "http://origin.ds2.example.net",
- "originShield": null,
- "profileDescription": null,
- "profileName": null,
- "protocol": 2,
- "qstringIgnore": 1,
- "rangeRequestHandling": 0,
- "regexRemap": "regexRemap2",
- "regionalGeoBlocking": false,
- "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/ds2plugin.lua",
- "routingName": "ccr-ds2",
- "signed": false,
- "signingAlgorithm": "url_sig",
- "sslKeyVersion": 2,
- "tenant": "tenant2",
- "tenantName": "tenant2",
- "type": "HTTP_LIVE",
- "xmlId": "ds2",
- "anonymousBlockingEnabled": true
+ "active": true,
+ "cacheurl": "cacheUrl1",
+ "ccrDnsTtl": 3600,
+ "cdnName": "cdn1",
+ "checkPath": "",
+ "deepCachingType": "NEVER",
+ "displayName": "ds1DisplayName",
+ "dnsBypassCname": null,
+ "dnsBypassIp": "",
+ "dnsBypassIp6": "",
+ "dnsBypassTtl": 30,
+ "dscp": 40,
+ "edgeHeaderRewrite": "edgeHeader1",
+ "exampleURLs": [
+ "http://ccr.ds1.example.net",
+ "https://ccr.ds1.example.net"
+ ],
+ "fqPacingRate": 0,
+ "geoLimit": 0,
+ "geoLimitCountries": "",
+ "geoLimitRedirectURL": null,
+ "geoProvider": 0,
+ "globalMaxMbps": 0,
+ "globalMaxTps": 0,
+ "httpBypassFqdn": "",
+ "infoUrl": "TBD",
+ "initialDispersion": 1,
+ "ipv6RoutingEnabled": true,
+ "lastUpdated": "2018-04-06 16:48:51+00",
+ "logsEnabled": false,
+ "longDesc": "d s 1",
+ "longDesc1": "ds1",
+ "longDesc2": "ds1",
+ "matchList": [
+ {
+ "pattern": ".*\\.ds1\\..*",
+ "setNumber": 0,
+ "type": "HOST_REGEXP"
+ }
+ ],
+ "maxDnsAnswers": 0,
+ "midHeaderRewrite": "midHeader1",
+ "missLat": 41.881944,
+ "missLong": -87.627778,
+ "multiSiteOrigin": false,
+ "orgServerFqdn": "http://origin.example.net",
+ "originShield": null,
+ "profileDescription": null,
+ "profileId": null,
+ "profileName": null,
+ "protocol": 2,
+ "qstringIgnore": 1,
+ "rangeRequestHandling": 0,
+ "regexRemap": "rr1",
+ "regionalGeoBlocking": false,
+ "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/remapPlugin1.lua",
+ "routingName": "ccr-ds1",
+ "signed": false,
+ "signingAlgorithm": "url_sig",
+ "sslKeyVersion": 2,
+ "tenant": "tenant1",
+ "tenantName": "tenant1",
+ "type": "HTTP_LIVE",
+ "xmlId": "ds1",
+ "anonymousBlockingEnabled": true
+ },
+ {
+ "active": true,
+ "cacheurl": "cacheUrl2",
+ "ccrDnsTtl": 3600,
+ "cdnName": "cdn1",
+ "checkPath": "",
+ "deepCachingType": "NEVER",
+ "displayName": "d s 1",
+ "dnsBypassCname": null,
+ "dnsBypassIp": "",
+ "dnsBypassIp6": "",
+ "dnsBypassTtl": 30,
+ "dscp": 40,
+ "edgeHeaderRewrite": "edgeRewrite2",
+ "exampleURLs": [
+ "http://ccr.ds2.example.net",
+ "https://ccr.ds2x.example.net"
+ ],
+ "fqPacingRate": 0,
+ "geoLimit": 0,
+ "geoLimitCountries": "",
+ "geoLimitRedirectURL": null,
+ "geoProvider": 0,
+ "globalMaxMbps": 0,
+ "globalMaxTps": 0,
+ "httpBypassFqdn": "",
+ "infoUrl": "TBD",
+ "initialDispersion": 1,
+ "ipv6RoutingEnabled": true,
+ "lastUpdated": "2018-04-06 16:48:51+00",
+ "logsEnabled": false,
+ "longDesc": "d s 1",
+ "longDesc1": "ds2",
+ "longDesc2": "ds2",
+ "matchList": [
+ {
+ "pattern": ".*\\.ds2\\..*",
+ "setNumber": 0,
+ "type": "HOST_REGEXP"
+ }
+ ],
+ "maxDnsAnswers": 0,
+ "midHeaderRewrite": "midRewrite2",
+ "missLat": 41.881944,
+ "missLong": -87.627778,
+ "multiSiteOrigin": false,
+ "orgServerFqdn": "http://origin.ds2.example.net",
+ "originShield": null,
+ "profileDescription": null,
+ "profileName": null,
+ "protocol": 2,
+ "qstringIgnore": 1,
+ "rangeRequestHandling": 0,
+ "regexRemap": "regexRemap2",
+ "regionalGeoBlocking": false,
+ "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/ds2plugin.lua",
+ "routingName": "ccr-ds2",
+ "signed": false,
+ "signingAlgorithm": "url_sig",
+ "sslKeyVersion": 2,
+ "tenant": "tenant2",
+ "tenantName": "tenant2",
+ "type": "HTTP_LIVE",
+ "xmlId": "ds2",
+ "anonymousBlockingEnabled": true
}
],
"divisions": [
@@ -616,16 +616,24 @@
],
"roles": [
{
- "name":"new_admin",
- "description":"super-user 2",
- "privLevel":30,
- "capabilities":["all-read","all-write", "cdn-read"]
- },
- {
- "name":"bad_admin",
- "description":"super-user 3",
- "privLevel":30,
- "capabilities":["all-read","all-write","invalid-capability"]
+ "name": "new_admin",
+ "description": "super-user 2",
+ "privLevel": 30,
+ "capabilities": [
+ "all-read",
+ "all-write",
+ "cdn-read"
+ ]
+ },
+ {
+ "name": "bad_admin",
+ "description": "super-user 3",
+ "privLevel": 30,
+ "capabilities": [
+ "all-read",
+ "all-write",
+ "invalid-capability"
+ ]
}
],
"servers": [
@@ -1016,25 +1024,28 @@
],
"staticdnsentries": [
{
- "host": "host1",
"address": "address1",
- "dsname": "ds1",
- "typename": "AAAA_RECORD",
- "ttl": 10
+ "cachegroup": "cachegroup1",
+ "deliveryservice": "test-ds1",
+ "host": "host1",
+ "type": "AAAA_RECORD",
+ "ttl": 10
},
{
- "host": "host2",
"address": "address2",
- "dsname": "ds2",
- "typename": "A_RECORD",
- "ttl": 10
+ "cachegroup": "cachegroup2",
+ "deliveryservice": "test-ds1",
+ "host": "host2",
+ "type": "A_RECORD",
+ "ttl": 10
},
{
"host": "host3",
- "dsName": "ds3",
+ "deliveryservice": "test-ds1",
+ "cachegroup": "cachegroup2",
"address": "127.0.0.1",
- "typename": "CNAME_RECORD",
- "ttl": 10
+ "type": "CNAME_RECORD",
+ "ttl": 10
}
],
"statuses": [
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 252851d..d976577 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -318,9 +318,10 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
//StaticDNSEntries
{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadOnlyHandler(staticdnsentry.GetReaderSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
{1.3, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
- {1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
- {1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
- {1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
+ {1.3, http.MethodGet, `staticdnsentries/{id}$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.3, http.MethodPut, `staticdnsentries/{id}$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+ {1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+ {1.3, http.MethodDelete, `staticdnsentries/{id}$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
//ProfileParameters
{1.1, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 988b3ab..0c2ac98 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -157,10 +157,10 @@ host,
type,
ttl) VALUES (
:address,
-:deliveryservice,
-:cachegroup,
+:deliveryservice_id,
+:cachegroup_id,
:host,
-:type,
+:type_id,
:ttl) RETURNING id,last_updated`
return query
}
@@ -292,6 +292,7 @@ func selectQuery() string {
return `SELECT
ds.xml_id as dsname,
sde.host,
+sde.id as id,
sde.ttl,
sde.address,
tp.name as type,