You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2017/01/17 18:52:38 UTC
[1/2] incubator-trafficcontrol git commit: checks for ip and ip6 /
profile uniqueness on server create / update
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master 811c6ad2a -> 068dac649
checks for ip and ip6 / profile uniqueness on server create / update
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2b28d560
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2b28d560
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2b28d560
Branch: refs/heads/master
Commit: 2b28d560ff3e2e64592f791639234d63f47d6763
Parents: 811c6ad
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Fri Jan 6 14:25:41 2017 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Tue Jan 17 11:52:21 2017 -0700
----------------------------------------------------------------------
.../development/traffic_ops_api/v12/server.rst | 8 +-
traffic_ops/app/lib/API/Server.pm | 40 ++++-
traffic_ops/app/t/api/1.2/server.t | 148 ++++++++++++++++---
3 files changed, 165 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2b28d560/docs/source/development/traffic_ops_api/v12/server.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/server.rst b/docs/source/development/traffic_ops_api/v12/server.rst
index 2a08586..d49fc75 100644
--- a/docs/source/development/traffic_ops_api/v12/server.rst
+++ b/docs/source/development/traffic_ops_api/v12/server.rst
@@ -889,7 +889,7 @@ Server
+----------------+----------+------------------------------------------------+
| interfaceName | yes | |
+----------------+----------+------------------------------------------------+
- | ipAddress | yes | |
+ | ipAddress | yes | Must be unique per server profile. |
+----------------+----------+------------------------------------------------+
| ipNetmask | yes | |
+----------------+----------+------------------------------------------------+
@@ -913,7 +913,7 @@ Server
+----------------+----------+------------------------------------------------+
| xmppPasswd | no | |
+----------------+----------+------------------------------------------------+
- | ip6Address | no | |
+ | ip6Address | no | Must be unique per server profile. |
+----------------+----------+------------------------------------------------+
| ip6Gateway | no | |
+----------------+----------+------------------------------------------------+
@@ -1095,7 +1095,7 @@ Server
+----------------+----------+------------------------------------------------+
| interfaceName | yes | |
+----------------+----------+------------------------------------------------+
- | ipAddress | yes | |
+ | ipAddress | yes | Must be unique per server profile. |
+----------------+----------+------------------------------------------------+
| ipNetmask | yes | |
+----------------+----------+------------------------------------------------+
@@ -1119,7 +1119,7 @@ Server
+----------------+----------+------------------------------------------------+
| xmppPasswd | no | |
+----------------+----------+------------------------------------------------+
- | ip6Address | no | |
+ | ip6Address | no | Must be unique per server profile. |
+----------------+----------+------------------------------------------------+
| ip6Gateway | no | |
+----------------+----------+------------------------------------------------+
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2b28d560/traffic_ops/app/lib/API/Server.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Server.pm b/traffic_ops/app/lib/API/Server.pm
index 26addee..0888d7d 100644
--- a/traffic_ops/app/lib/API/Server.pm
+++ b/traffic_ops/app/lib/API/Server.pm
@@ -190,7 +190,7 @@ sub update {
return $self->forbidden();
}
- my ( $is_valid, $result ) = $self->is_server_valid($params);
+ my ( $is_valid, $result ) = $self->is_server_valid($params, $id);
if ( !$is_valid ) {
return $self->alert($result);
@@ -850,7 +850,7 @@ sub get_servers_by_cdn {
return ( $forbidden, $servers );
}
- my $servers = $self->db->resultset('Server')->search( { cdn_id => $cdn_id } );
+ $servers = $self->db->resultset('Server')->search( { cdn_id => $cdn_id } );
return ( $forbidden, $servers );
}
@@ -880,18 +880,48 @@ sub get_servers_by_cachegroup {
return ( $forbidden, $servers );
}
- my $servers = $self->db->resultset('Server')->search( { cachegroup => $cg_id } );
+ $servers = $self->db->resultset('Server')->search( { cachegroup => $cg_id } );
return ( $forbidden, $servers );
}
sub is_server_valid {
- my $self = shift;
- my $params = shift;
+ my $self = shift;
+ my $params = shift;
+ my $id = shift;
if ( !$self->is_valid_server_type( $params->{typeId} ) ) {
return ( 0, "Invalid server type" );
}
+ my $ip_used_for_profile;
+ if ($id) {
+ $ip_used_for_profile = $self->db->resultset('Server')
+ ->search( { -and => [ 'ip_address' => $params->{ipAddress} , 'profile' => $params->{profileId}, 'id' => { '!=' => $id } ] })->single();
+ } else {
+ $ip_used_for_profile = $self->db->resultset('Server')
+ ->search( { -and => [ 'ip_address' => $params->{ipAddress} , 'profile' => $params->{profileId} ] })->single();
+ }
+
+ if ($ip_used_for_profile) {
+ return ( 0, "IP Address already in use for that profile" );
+ }
+
+ my $ip6_used_for_profile;
+ if (defined($params->{ip6Address}) && $params->{ip6Address} ne "") {
+ if ($id) {
+ $ip6_used_for_profile = $self->db->resultset('Server')
+ ->search( { -and => [ 'ip6_address' => $params->{ip6Address} , 'profile' => $params->{profileId}, 'id' => { '!=' => $id } ] })->single();
+ } else {
+ $ip6_used_for_profile = $self->db->resultset('Server')
+ ->search( { -and => [ 'ip6_address' => $params->{ip6Address} , 'profile' => $params->{profileId} ] })->single();
+ }
+
+ }
+
+ if ($ip6_used_for_profile) {
+ return ( 0, "IP6 Address already in use for that profile" );
+ }
+
my $rules = {
fields => [
qw/cachegroupId cdnId domainName hostName httpsPort iloIpAddress iloIpNetmask iloIpGateway iloUsername iloPassword interfaceMtu interfaceName ip6Address ip6Gateway ipAddress ipNetmask ipGateway mgmtIpAddress mgmtIpNetmask mgmtIpGateway offlineReason physLocationId profileId rack routerHostName routerPortName statusId tcpPort typeId updPending/
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2b28d560/traffic_ops/app/t/api/1.2/server.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/server.t b/traffic_ops/app/t/api/1.2/server.t
index 3cc0040..2ae3f72 100644
--- a/traffic_ops/app/t/api/1.2/server.t
+++ b/traffic_ops/app/t/api/1.2/server.t
@@ -37,18 +37,6 @@ my $t = Test::Mojo->new('TrafficOps');
Test::TestHelper->unload_core_data($schema);
Test::TestHelper->load_core_data($schema);
-sub get_svr_id {
- my $host_name = shift;
- my $q = "select id from server where host_name = \'$host_name\'";
- my $get_svr = $dbh->prepare($q);
- $get_svr->execute();
- my $p = $get_svr->fetchall_arrayref( {} );
- $get_svr->finish();
- my $id = $p->[0]->{id};
- return $id;
-}
-
-
ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302)
->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?';
@@ -84,15 +72,12 @@ ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} =
->json_is( "/response/secondaryParentCachegroup" => "")
, 'Does the cache group details return?';
-
ok $t->get_ok('/api/1.2/servers?type=MID')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
->json_is( "/response/0/hostName", "atlanta-mid-01" )
->json_is( "/response/0/domainName", "ga.atlanta.kabletown.net" )
->json_is( "/response/0/type", "MID" )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
-
ok $t->get_ok('/api/1.2/servers?cdn=100')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
->json_is( "/response/0/hostName", "atlanta-edge-01" )
->json_is( "/response/0/domainName", "ga.atlanta.kabletown.net" )
@@ -112,8 +97,6 @@ ok $t->get_ok('/api/1.2/servers?type=MID&status=ONLINE')->status_is(200)->or( su
->json_is( "/response/0/status", "ONLINE" )
->or( sub { diag $t->tx->res->content->asset->{content}; } );
-
-
ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} => json => {
"name" => "edge_atl_group1",
"shortName" => "eag1",
@@ -130,8 +113,6 @@ ok $t->post_ok('/api/1.2/cachegroups/create' => {Accept => 'application/json'} =
->json_is( "/response/secondaryParentCachegroup" => "")
, 'Does the cache group details return?';
-
-
ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
"hostName" => "server1",
"domainName" => "example-domain.com",
@@ -148,7 +129,6 @@ ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => js
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Is a server created when all required fields are provided?';
-
ok $t->post_ok('/api/1.2/servers/create' => {Accept => 'application/json'} => json => {
"hostName" => "server2",
"domainName" => "example-domain.com",
@@ -338,7 +318,6 @@ ok $t->post_ok('/api/1.2/deliveryservices/test-ds4/servers' => {Accept => 'appli
->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
, 'Assign the server to the delivery service?';
-
ok $t->get_ok('/api/1.2/servers?type=MID&status=ONLINE')->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
->json_is( "/response/0/type", "MID" )
->json_is( "/response/0/status", "ONLINE" )
@@ -431,8 +410,133 @@ ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'applicat
"physLocation" => "HotAtlanta" })
->status_is(404)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 100,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.78",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.78",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server creation succeed?';
+
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 100,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.78",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.78",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server creation fail because ipAddress is already used by the profile?';
+
+my $server_id =&get_svr_id('my-server-host');
+ok $t->put_ok('/api/1.2/servers/' . $server_id => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 200,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.78",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.78",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server update succeed because ipAddress is already used by the profile but...by this server?';
+
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host-ip6",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 100,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.79",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.79",
+ "ip6Address" => "2001:853:fe0f:27::2/64",
+ "ip6Gateway" => "2001:853:fe0f:27::1",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server creation succeed?';
+
+ok $t->post_ok('/api/1.2/servers' => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host-ip6",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 100,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.80",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.80",
+ "ip6Address" => "2001:853:fe0f:27::2/64",
+ "ip6Gateway" => "2001:853:fe0f:27::1",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server creation fail because ip6Address is already used by the profile?';
+
+my $server_id =&get_svr_id('my-server-host-ip6');
+ok $t->put_ok('/api/1.2/servers/' . $server_id => {Accept => 'application/json'} => json => {
+ "hostName" => "my-server-host-ip6",
+ "domainName" => "example-domain.com",
+ "cachegroupId" => 200,
+ "cdnId" => 100,
+ "ipAddress" => "10.74.27.80",
+ "interfaceName" => "bond0",
+ "ipNetmask" => "255.255.255.252",
+ "ipGateway" => "10.74.27.80",
+ "ip6Address" => "2001:853:fe0f:27::2/64",
+ "ip6Gateway" => "2001:853:fe0f:27::1",
+ "interfaceMtu" => 1500,
+ "physLocationId" => 100,
+ "typeId" => 1,
+ "statusId" => 1,
+ "updPending" => \0,
+ "profileId" => 100 })
+ ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } )
+ , 'Does the server update succeed because ip6Address is already used by the profile but...by this server?';
+
ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
$dbh->disconnect();
done_testing();
-
+sub get_svr_id {
+ my $host_name = shift;
+ my $q = "select id from server where host_name = \'$host_name\'";
+ my $get_svr = $dbh->prepare($q);
+ $get_svr->execute();
+ my $p = $get_svr->fetchall_arrayref( {} );
+ $get_svr->finish();
+ my $id = $p->[0]->{id};
+ return $id;
+}
[2/2] incubator-trafficcontrol git commit: This closes #165.
Posted by da...@apache.org.
This closes #165.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/068dac64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/068dac64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/068dac64
Branch: refs/heads/master
Commit: 068dac6491fc6cb30473dd12760c89bf61c5b99e
Parents: 2b28d56
Author: Dan Kirkwood <da...@gmail.com>
Authored: Tue Jan 17 11:52:29 2017 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Tue Jan 17 11:52:29 2017 -0700
----------------------------------------------------------------------
----------------------------------------------------------------------