From 5d7b18f6d8b0da6511e2caa240b27711189dac0c Mon Sep 17 00:00:00 2001 From: Jifeng Yang Date: Fri, 18 Nov 2016 17:15:19 -0500 Subject: [PATCH] Change "status" from id to name in server update Restful API --- traffic_ops/app/lib/API/Server2.pm | 7 +++++++ traffic_ops/app/t/api/1.2/server_create.t | 2 ++ 2 files changed, 9 insertions(+) diff --git a/traffic_ops/app/lib/API/Server2.pm b/traffic_ops/app/lib/API/Server2.pm index b13fba580a..11cbcf7324 100644 --- a/traffic_ops/app/lib/API/Server2.pm +++ b/traffic_ops/app/lib/API/Server2.pm @@ -110,6 +110,13 @@ sub check_server_params { return ( \%params, "'type' $json->{'type'} not found!" ); } + if ( defined( $json->{'status'} ) ) { + eval { $params{'status'} = &admin_status_id( $self, $json->{'status'} ); }; + if ( $@ || ( !defined( $params{'status'} ) ) ) { + return ( \%params, "'status' $json->{'status'} not found!" ); + } + } + eval { $params{'profile'} = &profile_id( $self, $json->{'profile'} ); }; if ( $@ || ( !defined( $params{'profile'} ) ) ) { # $@ holds Perl errors return ( \%params, "'profile' $json->{'profile'} not found!" ); diff --git a/traffic_ops/app/t/api/1.2/server_create.t b/traffic_ops/app/t/api/1.2/server_create.t index 80178f8c04..c6c3c050ab 100644 --- a/traffic_ops/app/t/api/1.2/server_create.t +++ b/traffic_ops/app/t/api/1.2/server_create.t @@ -106,6 +106,7 @@ ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'applicat "interfaceMtu" => "1500", "physLocation" => "Denver", "type" => "EDGE", + "status" => "OFFLINE", "profile" => "EDGE1" }) ->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content}; } ) ->json_is( "/response/hostName" => "tc1_ats3") @@ -118,6 +119,7 @@ ok $t->put_ok('/api/1.2/servers/' . $svr_id . '/update' => {Accept => 'applicat ->json_is( "/response/interfaceMtu" => "1500") ->json_is( "/response/physLocation" => "Denver") ->json_is( "/response/type" => "EDGE") + ->json_is( "/response/status" => "OFFLINE") ->json_is( "/response/profile" => "EDGE1") , 'Does the server details return?';