Repository: incubator-trafficcontrol Updated Branches: refs/heads/2.1.x 0cc0d5c2d -> 1d4e2a4d5
deletes applicable staticdnsentries and jobs when a ds is deleted - cherry pick of b7b293718c0ca8174dba5759c01301208d5c6a78 Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/4e8cd6b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/4e8cd6b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/4e8cd6b1 Branch: refs/heads/2.1.x Commit: 4e8cd6b186def21d5559e295f9e475d9eb6433ec Parents: 0cc0d5c Author: Jeremy Mitchell <mitchell...@gmail.com> Authored: Wed Aug 16 14:32:14 2017 -0600 Committer: hbeatty <hbea...@users.noreply.github.com> Committed: Mon Aug 21 13:36:53 2017 -0400 ---------------------------------------------------------------------- .../20170816000000_staticdnsentry_ds_fk.sql | 36 ++++++++++ .../20170816000001_job_deliveryservice_fk.sql | 36 ++++++++++ traffic_ops/app/t/api/1.2/deliveryservice.t | 75 ++++++++++---------- 3 files changed, 111 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4e8cd6b1/traffic_ops/app/db/migrations/20170816000000_staticdnsentry_ds_fk.sql ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/migrations/20170816000000_staticdnsentry_ds_fk.sql b/traffic_ops/app/db/migrations/20170816000000_staticdnsentry_ds_fk.sql new file mode 100644 index 0000000..5c3bd51 --- /dev/null +++ b/traffic_ops/app/db/migrations/20170816000000_staticdnsentry_ds_fk.sql @@ -0,0 +1,36 @@ +/* + + 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. +*/ + + +-- +goose Up +-- SQL in section 'Up' is executed when this migration is applied +ALTER TABLE staticdnsentry +DROP CONSTRAINT fk_staticdnsentry_ds, +ADD CONSTRAINT fk_staticdnsentry_ds + FOREIGN KEY (deliveryservice) + REFERENCES deliveryservice (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +-- +goose Down +-- SQL section 'Down' is executed when this migration is rolled back +ALTER TABLE staticdnsentry +DROP CONSTRAINT fk_staticdnsentry_ds, +ADD CONSTRAINT fk_staticdnsentry_ds + FOREIGN KEY (deliveryservice) + REFERENCES deliveryservice (id) + ON DELETE NO_ACTION + ON UPDATE NO_ACTION; + http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4e8cd6b1/traffic_ops/app/db/migrations/20170816000001_job_deliveryservice_fk.sql ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/migrations/20170816000001_job_deliveryservice_fk.sql b/traffic_ops/app/db/migrations/20170816000001_job_deliveryservice_fk.sql new file mode 100644 index 0000000..1a08211 --- /dev/null +++ b/traffic_ops/app/db/migrations/20170816000001_job_deliveryservice_fk.sql @@ -0,0 +1,36 @@ +/* + + 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. +*/ + + +-- +goose Up +-- SQL in section 'Up' is executed when this migration is applied +ALTER TABLE job +DROP CONSTRAINT fk_job_deliveryservice1, +ADD CONSTRAINT fk_job_deliveryservice1 + FOREIGN KEY (job_deliveryservice) + REFERENCES deliveryservice (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +-- +goose Down +-- SQL section 'Down' is executed when this migration is rolled back +ALTER TABLE job +DROP CONSTRAINT fk_job_deliveryservice1, +ADD CONSTRAINT fk_job_deliveryservice1 + FOREIGN KEY (job_deliveryservice) + REFERENCES deliveryservice (id) + ON DELETE NO_ACTION + ON UPDATE NO_ACTION; + http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4e8cd6b1/traffic_ops/app/t/api/1.2/deliveryservice.t ---------------------------------------------------------------------- diff --git a/traffic_ops/app/t/api/1.2/deliveryservice.t b/traffic_ops/app/t/api/1.2/deliveryservice.t index d99fa36..2ff5e0f 100644 --- a/traffic_ops/app/t/api/1.2/deliveryservice.t +++ b/traffic_ops/app/t/api/1.2/deliveryservice.t @@ -179,46 +179,49 @@ ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id => {Accept => 'application/j ok $t->delete_ok('/api/1.2/deliveryservices/' . $ds_id)->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id => {Accept => 'application/json'} => json => { - "active" => \1, - "cdnId" => 100, - "displayName" => "ds_displayname_11", - "dscp" => 1, - "geoLimit" => 1, - "geoProvider" => 1, - "initialDispersion" => 2, - "ipv6RoutingEnabled" => 1, - "logsEnabled" => 1, - "missLat" => 45, - "missLong" => 45, - "multiSiteOrigin" => 0, - "orgServerFqdn" => "http://10.75.168.91", - "protocol" => 2, - "qstringIgnore" => 1, - "rangeRequestHandling" => 1, - "regionalGeoBlocking" => 1, - "signed" => 1, - "typeId" => 7, - "xmlId" => "ds_1", -})->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); - -ok $t->post_ok( - '/api/1.2/deliveryservices/test-ds1/servers' => { Accept => 'application/json' } => json => { - "serverNames" => [ "atlanta-edge-01", "atlanta-edge-02" ] - } - )->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/response/xmlId" => "test-ds1" ) - ->json_is( "/response/serverNames/0" => "atlanta-edge-01" )->json_is( "/response/serverNames/1" => "atlanta-edge-02" ), - 'Does the assigned servers return?'; + ok $t->put_ok('/api/1.2/deliveryservices/' . $ds_id => {Accept => 'application/json'} => json => { + "active" => \1, + "cdnId" => 100, + "displayName" => "ds_displayname_11", + "dscp" => 1, + "geoLimit" => 1, + "geoProvider" => 1, + "initialDispersion" => 2, + "ipv6RoutingEnabled" => 1, + "logsEnabled" => 1, + "missLat" => 45, + "missLong" => 45, + "multiSiteOrigin" => 0, + "orgServerFqdn" => "http://10.75.168.91", + "protocol" => 2, + "qstringIgnore" => 1, + "rangeRequestHandling" => 1, + "regionalGeoBlocking" => 1, + "signed" => 1, + "typeId" => 7, + "xmlId" => "ds_1", + })->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + + ok $t->post_ok( + '/api/1.2/deliveryservices/test-ds1/servers' => { Accept => 'application/json' } => json => { + "serverNames" => [ "atlanta-edge-01", "atlanta-edge-02" ] + } + )->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )->json_is( "/response/xmlId" => "test-ds1" ) + ->json_is( "/response/serverNames/0" => "atlanta-edge-01" )->json_is( "/response/serverNames/1" => "atlanta-edge-02" ), + 'Does the assigned servers return?'; + + ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } ) + ->json_is( "/response/0/xmlId", "steering-ds1" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 1 ) + ->json_is( "/response/1/xmlId", "steering-ds2" ); -ok $t->get_ok("/api/1.2/deliveryservices")->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content} } ) - ->json_is( "/response/0/xmlId", "steering-ds1" )->json_is( "/response/0/logsEnabled", 0 )->json_is( "/response/0/ipv6RoutingEnabled", 1 ) - ->json_is( "/response/1/xmlId", "steering-ds2" ); + ok $t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(defined($tenant_id) ? 3 : 2); -$t->get_ok('/api/1.2/deliveryservices?logsEnabled=true')->status_is(200)->$count_response(defined($tenant_id) ? 3 : 2); + ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->put_ok('/api/1.2/snapshot/cdn1')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + # try deleting a deliveryservice that has a job and a staticdnsentry + ok $t->delete_ok('/api/1.2/deliveryservices/100')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ); -ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } ); + ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } ); }