From cc745958b146d882574288d316cbf695d35dff96 Mon Sep 17 00:00:00 2001 From: Gergely Fejer Date: Mon, 13 Apr 2020 18:07:51 -0500 Subject: [PATCH] Updated firmware/commit to return a firmware object. Removed broken stretch-backport version of cmake. --- captived/.docker/Dockerfile | 4 +--- captived/CMakeLists.txt | 2 +- captived/integration-tests/firmware_Test.py | 10 ++++++++++ captived/src/main.cpp | 2 +- captived/src/rest/firmware_commit.cpp | 10 ++++++---- captived/src/rest/firmware_commit.hpp | 5 ++++- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/captived/.docker/Dockerfile b/captived/.docker/Dockerfile index dae2737..9b174be 100644 --- a/captived/.docker/Dockerfile +++ b/captived/.docker/Dockerfile @@ -11,13 +11,11 @@ RUN apt-get update && \ git \ gcc g++ \ make \ + cmake \ libevent-dev libjansson-dev \ python3 python3-dev python3-pip \ python3-setuptools python3-wheel \ python3-venv && \ - apt-get install -y --no-install-recommends \ - -t stretch-backports \ - cmake && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ rm -rf /var/cache/apt/{pkgcache,srcpkgcache}.bin diff --git a/captived/CMakeLists.txt b/captived/CMakeLists.txt index 5508970..e369c53 100644 --- a/captived/CMakeLists.txt +++ b/captived/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) project(captived - VERSION "0.2.5" + VERSION "0.2.6" ) include(GNUInstallDirs) diff --git a/captived/integration-tests/firmware_Test.py b/captived/integration-tests/firmware_Test.py index 60ad18c..0105471 100755 --- a/captived/integration-tests/firmware_Test.py +++ b/captived/integration-tests/firmware_Test.py @@ -228,8 +228,18 @@ def test_30_commit_firmware(self): commit_url = URL + '/firmware/commit' put_json = 'garbage data' resp = requests.put(commit_url, headers=HEADERS, json=put_json) + jresp = resp.json() + print ("\nResponse from commit:") + print (json.dumps(jresp, indent=4)) self.assertEqual(resp.status_code, 200) + # Verify that commit sent back a firmware object. + self.assertIn('running_version', jresp) + self.assertEqual(self.version_from_artifact_file(), jresp['running_version']) + + self.assertIn('update_state', jresp) + self.assertEqual('normal', jresp['update_state']) + # get the firmware and check it resp = requests.get(firmware_url) diff --git a/captived/src/main.cpp b/captived/src/main.cpp index d1d44d4..beb30e1 100644 --- a/captived/src/main.cpp +++ b/captived/src/main.cpp @@ -97,7 +97,7 @@ main(int argc, char* argv[]) { firmware.add("update_state", firmware_state); rest::firmware_commit commit( - URI_FIRMWARE_COMMIT, sys, fw_mgr, COMMAND_MENDER_COMMIT); + URI_FIRMWARE_COMMIT, sys, fw_mgr, COMMAND_MENDER_COMMIT, firmware); rest::model model_number(URI_MODEL, sys, FILE_FIRMWARE_VERSION); diff --git a/captived/src/rest/firmware_commit.cpp b/captived/src/rest/firmware_commit.cpp index a4f8287..7ed9aa9 100644 --- a/captived/src/rest/firmware_commit.cpp +++ b/captived/src/rest/firmware_commit.cpp @@ -7,11 +7,13 @@ namespace rest { firmware_commit::firmware_commit(std::string path, system& system, firmware_manager& fw_mgr, - std::string commit_exe) + std::string commit_exe, + firmware& fw) : resource(path), system_(system), fw_mgr_(fw_mgr), - commit_exe_(commit_exe) {} + commit_exe_(commit_exe), + fw_(fw) {} int firmware_commit::execute() { @@ -37,8 +39,8 @@ firmware_commit::put(req_type body) { int result = execute(); if (0 == result) { - auto msg = "Firmware was committed"; - return ok(json::string(msg)); + auto empty_req = req_type(); + return fw_.get(empty_req); } else { std::stringstream ss; ss << "Failed to firmware_commit with error code: " << result; diff --git a/captived/src/rest/firmware_commit.hpp b/captived/src/rest/firmware_commit.hpp index 1302903..48bcd0b 100644 --- a/captived/src/rest/firmware_commit.hpp +++ b/captived/src/rest/firmware_commit.hpp @@ -2,6 +2,7 @@ #include +#include "firmware.hpp" #include "firmware_manager.hpp" #include "rest/resource.hpp" #include "system.hpp" @@ -14,7 +15,8 @@ class firmware_commit : public resource { firmware_commit(std::string path, system& system, firmware_manager& fw_mgr, - std::string commit_exe); + std::string commit_exe, + firmware& fw); resp_type put(req_type body) override; @@ -29,6 +31,7 @@ class firmware_commit : public resource { system& system_; std::string commit_exe_; firmware_manager& fw_mgr_; + firmware& fw_; }; } // namespace rest