diff --git a/src/rest/resource.cpp b/src/rest/resource.cpp index 0bb73413b1d..328ee485c12 100644 --- a/src/rest/resource.cpp +++ b/src/rest/resource.cpp @@ -125,10 +125,6 @@ Resource::Resource(ControllerOpenThread *aNcp) mResourceCallbackMap.emplace(OT_REST_RESOURCE_PATH_DIAGNOETIC, &Resource::HandleDiagnosticCallback); } -void Resource::Init(void) -{ -} - void Resource::Handle(Request &aRequest, Response &aResponse) const { std::string url = aRequest.GetUrl(); @@ -519,33 +515,21 @@ void Resource::UpdateDiag(std::string aKey, std::vector &aDiag void Resource::Diagnostic(const Request &aRequest, Response &aResponse) const { - otbrError error = OTBR_ERROR_NONE; OT_UNUSED_VARIABLE(aRequest); + struct otIp6Address rloc16address = *otThreadGetRloc(mInstance); struct otIp6Address multicastAddress; - VerifyOrExit(otThreadSendDiagnosticGet(mInstance, &rloc16address, kAllTlvTypes, sizeof(kAllTlvTypes), - &Resource::DiagnosticResponseHandler, - const_cast(this)) == OT_ERROR_NONE, - error = OTBR_ERROR_REST); - VerifyOrExit(otIp6AddressFromString(kMulticastAddrAllRouters, &multicastAddress) == OT_ERROR_NONE, - error = OTBR_ERROR_REST); - VerifyOrExit(otThreadSendDiagnosticGet(mInstance, &multicastAddress, kAllTlvTypes, sizeof(kAllTlvTypes), - &Resource::DiagnosticResponseHandler, - const_cast(this)) == OT_ERROR_NONE, - error = OTBR_ERROR_REST); + SuccessOrExit(otThreadSendDiagnosticGet(mInstance, &rloc16address, kAllTlvTypes, sizeof(kAllTlvTypes), + &Resource::DiagnosticResponseHandler, const_cast(this))); + SuccessOrExit(otIp6AddressFromString(kMulticastAddrAllRouters, &multicastAddress)); + SuccessOrExit(otThreadSendDiagnosticGet(mInstance, &multicastAddress, kAllTlvTypes, sizeof(kAllTlvTypes), + &Resource::DiagnosticResponseHandler, const_cast(this))); exit: - if (error == OTBR_ERROR_NONE) - { - aResponse.SetStartTime(steady_clock::now()); - aResponse.SetCallback(); - } - else - { - ErrorHandler(aResponse, HttpStatusCode::kStatusInternalServerError); - } + aResponse.SetStartTime(steady_clock::now()); + aResponse.SetCallback(); } void Resource::DiagnosticResponseHandler(otError aError, diff --git a/src/rest/resource.hpp b/src/rest/resource.hpp index 51efcafd92a..0928d265d2d 100644 --- a/src/rest/resource.hpp +++ b/src/rest/resource.hpp @@ -65,13 +65,6 @@ class Resource */ Resource(ControllerOpenThread *aNcp); - /** - * This method initialize the Resource handler. - * - * - */ - void Init(void); - /** * This method is the main entry of resource handler, which find corresponding handler according to request url * find the resource and set the content of response. diff --git a/src/rest/rest_web_server.cpp b/src/rest/rest_web_server.cpp index 0fb490a00ba..246aeca1827 100644 --- a/src/rest/rest_web_server.cpp +++ b/src/rest/rest_web_server.cpp @@ -71,7 +71,6 @@ RestWebServer *RestWebServer::GetRestWebServer(ControllerOpenThread *aNcp) void RestWebServer::Init(void) { - mResource.Init(); InitializeListenFd(); } diff --git a/tests/rest/CMakeLists.txt b/tests/rest/CMakeLists.txt index e0899440b9d..f6ba89dc634 100644 --- a/tests/rest/CMakeLists.txt +++ b/tests/rest/CMakeLists.txt @@ -39,3 +39,7 @@ set_tests_properties(rest-server PROPERTIES set_tests_properties(rest-server PROPERTIES LABELS "TESTREST" ) + +set_tests_properties(rest-server PROPERTIES + TIMEOUT 60 +) diff --git a/tests/rest/test-rest-server b/tests/rest/test-rest-server index deaccd369f4..2e268830d30 100755 --- a/tests/rest/test-rest-server +++ b/tests/rest/test-rest-server @@ -58,6 +58,12 @@ wait EOF trap on_exit EXIT sleep 5 + sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl factoryreset + sleep 1 + sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl ifconfig up + sleep 1 + sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl thread start + sleep 3 sudo python3 "${CMAKE_CURRENT_SOURCE_DIR}"/test_rest.py } diff --git a/tests/rest/test_rest.py b/tests/rest/test_rest.py index 6a846489f38..6b83846b3e8 100644 --- a/tests/rest/test_rest.py +++ b/tests/rest/test_rest.py @@ -41,11 +41,14 @@ def assert_is_ipv6_address(string): assert (type(ipaddress.ip_address(string)) is ipaddress.IPv6Address) def get_data_from_url(url, result, index): - response = urllib.request.urlopen(urllib.request.Request(url)) - body = response.read() - data = json.loads(body) - result[index] = data + try: + response = urllib.request.urlopen(urllib.request.Request(url)) + body = response.read() + data = json.loads(body) + result[index] = data + except urllib.error.HTTPError as e: + print(e.code) def get_error_from_url(url, result, index): try: