This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 356
Support queueing updates by type and profile #6014
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6599ab7
wip
srijeet0406 8ed303c
Adding tests
srijeet0406 2eacda7
fix documentation
srijeet0406 7572fc2
fix documentation
srijeet0406 ba102ea
fix imports, add go docs
srijeet0406 4758bb2
use pre existing route, instead of creating a new one
srijeet0406 5e01d12
code review fixes
srijeet0406 c3102d3
code review changes
srijeet0406 8a45539
move UI button to right
srijeet0406 aaa4fcd
Merge branch 'master' into CDN-13414
srijeet0406 7a276b6
do not throw an error if no servers matched the criteria
srijeet0406 9d1859f
Merge branch 'CDN-13414' of https://github.com/srijeet0406/trafficcon…
srijeet0406 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
traffic_ops/testing/api/v4/cdn_queue_updates_by_type_profile_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| package v4 | ||
|
|
||
| /* | ||
|
|
||
| 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. | ||
| */ | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| client "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
| ) | ||
|
|
||
| func TestCDNQueueUpdateByProfileAndType(t *testing.T) { | ||
| WithObjs(t, []TCObj{Types, CDNs, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers}, func() { | ||
| QueueUpdatesByType(t) | ||
| QueueUpdatesByProfile(t) | ||
| }) | ||
| } | ||
|
|
||
| func QueueUpdatesByType(t *testing.T) { | ||
| allServersResp, _, err := TOSession.GetServers(client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get all servers: %v", err) | ||
| } | ||
|
|
||
| // Clear updates on all servers to begin with | ||
| for _, s := range allServersResp.Response { | ||
| if s.ID != nil { | ||
| _, _, err = TOSession.SetServerQueueUpdate(*s.ID, false, client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Errorf("couldn't clear updates on server with ID: %d, err: %v", *s.ID, err.Error()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| allServersResp, _, err = TOSession.GetServers(client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get all servers: %v", err) | ||
| } | ||
| queryOpts := client.NewRequestOptions() | ||
| if len(testData.Servers) < 1 { | ||
| t.Fatalf("no servers to run the tests on...quitting.") | ||
| } | ||
| server := testData.Servers[0] | ||
| opts := client.NewRequestOptions() | ||
| if server.CDNName == nil { | ||
| t.Fatalf("server doesn't have a CDN name...quitting") | ||
| } | ||
| opts.QueryParameters.Set("name", *server.CDNName) | ||
|
|
||
| // Get the first server's CDN ID | ||
| cdns, _, err := TOSession.GetCDNs(opts) | ||
| if err != nil { | ||
| t.Fatalf("error while getting CDNs: %v", err) | ||
| } | ||
| if len(cdns.Response) < 1 { | ||
| t.Fatalf("expected 1 CDN in response, got %d", len(cdns.Response)) | ||
| } | ||
| opts.QueryParameters.Del("name") | ||
| queryOpts.QueryParameters.Set("type", server.Type) | ||
| // Queue updates by type (and CDN) | ||
| _, _, err = TOSession.QueueUpdatesForCDN(cdns.Response[0].ID, true, queryOpts) | ||
| if err != nil { | ||
| t.Errorf("couldn't queue updates by type (and CDN): %v", err) | ||
| } | ||
|
|
||
| // Get all the servers for the same CDN and type as that of the first server | ||
| opts.QueryParameters.Set("cdn", strconv.Itoa(cdns.Response[0].ID)) | ||
| opts.QueryParameters.Set("type", server.Type) | ||
| serverIDMap := make(map[int]bool, 0) | ||
| resp, _, err := TOSession.GetServers(opts) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get servers by cdn and type: %v", err) | ||
| } | ||
| if len(resp.Response) < 1 { | ||
| t.Fatalf("expected atleast one server in response, got %d", len(resp.Response)) | ||
| } | ||
| for _, s := range resp.Response { | ||
| if s.UpdPending == nil || !*s.UpdPending { | ||
| t.Errorf("expected updates to be queued on all the servers filtered by type and CDN, but %s didn't queue updates", *s.HostName) | ||
| } | ||
| if s.ID != nil { | ||
| serverIDMap[*s.ID] = true | ||
| } | ||
| } | ||
|
|
||
| // Make sure that the servers that are not filtered by the above criteria do not have updates queued | ||
| allServersResp, _, err = TOSession.GetServers(client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get all servers: %v", err) | ||
| } | ||
| for _, s := range allServersResp.Response { | ||
| if s.ID != nil { | ||
| if _, ok := serverIDMap[*s.ID]; !ok { | ||
| if s.UpdPending != nil && *s.UpdPending { | ||
| t.Errorf("did not expect server with ID: %d to have queued updates", *s.ID) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| _, _, err = TOSession.QueueUpdatesForCDN(cdns.Response[0].ID, false, queryOpts) | ||
| if err != nil { | ||
| t.Errorf("couldn't queue updates by type (and CDN): %v", err) | ||
| } | ||
| } | ||
|
|
||
| func QueueUpdatesByProfile(t *testing.T) { | ||
| allServersResp, _, err := TOSession.GetServers(client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get all servers: %v", err) | ||
| } | ||
|
|
||
| // Clear updates on all servers to begin with | ||
| for _, s := range allServersResp.Response { | ||
| if s.ID != nil { | ||
| _, _, err = TOSession.SetServerQueueUpdate(*s.ID, false, client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Errorf("couldn't clear updates on server with ID: %d, err: %v", *s.ID, err.Error()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| queryOpts := client.NewRequestOptions() | ||
| if len(testData.Servers) < 1 { | ||
| t.Fatalf("no servers to run the tests on...quitting.") | ||
| } | ||
| server := testData.Servers[0] | ||
| opts := client.NewRequestOptions() | ||
| if server.CDNName == nil || server.Profile == nil { | ||
| t.Fatalf("server doesn't have a CDN name or a profile name...quitting") | ||
| } | ||
|
|
||
| //Get the first server's CDN ID | ||
| opts.QueryParameters.Set("name", strings.TrimSpace(*server.CDNName)) | ||
|
|
||
| cdns, _, err := TOSession.GetCDNs(opts) | ||
| if err != nil { | ||
| t.Fatalf("error while getting CDNs: %v", err) | ||
| } | ||
| if len(cdns.Response) < 1 { | ||
| t.Fatalf("expected 1 CDN in response, got %d", len(cdns.Response)) | ||
| } | ||
| opts.QueryParameters.Del("name") | ||
|
|
||
| // Get the first server's Profile ID | ||
| opts.QueryParameters.Set("name", *server.Profile) | ||
| profiles, _, err := TOSession.GetProfiles(opts) | ||
| if err != nil { | ||
| t.Fatalf("error while getting profiles: %v", err) | ||
| } | ||
| if len(profiles.Response) < 1 { | ||
| t.Fatalf("expected 1 profile in response, got %d", len(profiles.Response)) | ||
| } | ||
| opts.QueryParameters.Del("name") | ||
| queryOpts.QueryParameters.Set("profile", profiles.Response[0].Name) | ||
| // Queue updates by profile (and CDN) | ||
| _, _, err = TOSession.QueueUpdatesForCDN(cdns.Response[0].ID, true, queryOpts) | ||
| if err != nil { | ||
| t.Errorf("couldn't queue updates by profile (and CDN): %v", err) | ||
| } | ||
|
|
||
| // Get all the servers for the same CDN and profile as that of the first server | ||
| opts.QueryParameters.Set("cdn", strconv.Itoa(cdns.Response[0].ID)) | ||
| opts.QueryParameters.Set("profileId", strconv.Itoa(profiles.Response[0].ID)) | ||
| serverIDMap := make(map[int]bool, 0) | ||
| resp, _, err := TOSession.GetServers(opts) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get servers by cdn and profile: %v", err) | ||
| } | ||
| if len(resp.Response) < 1 { | ||
| t.Fatalf("expected atleast one server in response, got %d", len(resp.Response)) | ||
| } | ||
| for _, s := range resp.Response { | ||
| if s.UpdPending == nil || !*s.UpdPending { | ||
| t.Errorf("expected updates to be queued on all the servers filtered by profile and CDN, but %s didn't queue updates", *s.HostName) | ||
| } | ||
| if s.ID != nil { | ||
| serverIDMap[*s.ID] = true | ||
| } | ||
| } | ||
|
|
||
| // Make sure that the servers that are not filtered by the above criteria do not have updates queued | ||
| allServersResp, _, err = TOSession.GetServers(client.NewRequestOptions()) | ||
| if err != nil { | ||
| t.Fatalf("couldn't get all servers: %v", err) | ||
| } | ||
| for _, s := range allServersResp.Response { | ||
| if s.ID != nil { | ||
| if _, ok := serverIDMap[*s.ID]; !ok { | ||
| if s.UpdPending != nil && *s.UpdPending { | ||
| t.Errorf("did not expect server with ID: %d to have queued updates", *s.ID) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| _, _, err = TOSession.QueueUpdatesForCDN(cdns.Response[0].ID, false, queryOpts) | ||
| if err != nil { | ||
| t.Errorf("couldn't queue updates by type (and CDN): %v", err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.