From efa53d6ad8797310b10d299408c2e3fa33978e27 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Apr 2017 08:02:53 +0200 Subject: Add --fake-machine and machine-less agent/worker test --- bbot/agent | 2 - bbot/agent.cli | 7 ++++ bbot/agent.cxx | 114 +++++++++++++++++++++++++++++++++++-------------------- bbot/utility | 2 + bbot/utility.txx | 5 +++ bbot/worker.cli | 5 +++ bbot/worker.cxx | 23 ++++++++++- 7 files changed, 113 insertions(+), 45 deletions(-) (limited to 'bbot') diff --git a/bbot/agent b/bbot/agent index 14d2995..1271a87 100644 --- a/bbot/agent +++ b/bbot/agent @@ -22,8 +22,6 @@ namespace bbot extern size_t tc_num; // Toolchain number. extern string tc_id; // Toolchain id. - extern strings controllers; // Controller URLs. - extern string hname; // Our host name. extern uid_t uid; // Our effective user id. extern string uname; // Our effective user name. diff --git a/bbot/agent.cli b/bbot/agent.cli index c67535e..b71db4e 100644 --- a/bbot/agent.cli +++ b/bbot/agent.cli @@ -149,6 +149,13 @@ namespace bbot "Fake the package building process by creating the aborted build result." } + path --fake-machine + { + "", + "Fake the machine enumeration process by reading the machine header + manifest from (or \cb{stdin} if is '\cb{-}')." + } + path --fake-request { "", diff --git a/bbot/agent.cxx b/bbot/agent.cxx index 8847e62..60d59e6 100644 --- a/bbot/agent.cxx +++ b/bbot/agent.cxx @@ -45,8 +45,6 @@ namespace bbot size_t tc_num; string tc_id; - strings controllers; - string hname; uid_t uid; string uname; @@ -257,6 +255,24 @@ try bootstrapped_machine_manifests rm; dir_paths rd; + if (ops.fake_machine_specified ()) + { + auto mh ( + parse_manifest ( + ops.fake_machine (), "machine header")); + + rm.push_back ( + bootstrapped_machine_manifest { + machine_manifest {mh.id, mh.name, mh.summary, machine_type::kvm}, + toolchain_manifest {tc_id}, + bootstrap_manifest {} + }); + + rd.push_back (dir_path (ops.machines ()) /= mh.name); // For diagnostics. + + return make_pair (move (rm), move (rd)); + } + // The first level are machine volumes. // for (const dir_entry& ve: dir_iterator (machines)) @@ -517,6 +533,7 @@ static result_manifest perform_task (const dir_path& md, const bootstrapped_machine_manifest& mm, const task_manifest& tm) +try { tracer trace ("perform_task"); @@ -542,7 +559,36 @@ perform_task (const dir_path& md, // // 5. Clean up (force the machine down and delete the snapshot). // - try + + // TFTP server mapping (server chroot is --tftp): + // + // GET requests to .../build//get/* + // PUT requests to .../build//put/* + // + auto_rmdir arm ((dir_path (ops.tftp ()) /= "build") /= tc_name); + + dir_path gd (dir_path (arm.path ()) /= "get"); + dir_path pd (dir_path (arm.path ()) /= "put"); + + try_mkdir_p (gd); + try_mkdir_p (pd); + + path tf (gd / "manifest"); // Task manifest file. + path rf (pd / "manifest"); // Result manifest file. + + serialize_manifest (tm, tf, "task"); + + if (ops.fake_machine_specified ()) + { + // Simply wait for the file to appear. + // + for (size_t i (0); !file_exists (rf); sleep (1)) + if (i++ % 10 == 0) + l3 ([&]{trace << "waiting for result manifest";}); + + r = parse_manifest (rf, "result"); + } + else { // -- // @@ -553,24 +599,8 @@ perform_task (const dir_path& md, string br ("br1"); // Using private bridge for now. - // Start the TFTP server (server chroot is --tftp). Map: - // - // GET requests to .../build//get/* - // PUT requests to .../build//put/* + // Start the TFTP server. // - auto_rmdir arm ((dir_path (ops.tftp ()) /= "build") /= tc_name); - - dir_path gd (dir_path (arm.path ()) /= "get"); - dir_path pd (dir_path (arm.path ()) /= "put"); - - try_mkdir_p (gd); - try_mkdir_p (pd); - - path tf (gd / "manifest"); // Task manifest file. - path rf (pd / "manifest"); // Result manifest file. - - serialize_manifest (tm, tf, "task"); - tftp_server tftpd ("Gr ^/?(.+)$ /build/" + tc_name + "/get/\\1\n" + "Pr ^/?(.+)$ /build/" + tc_name + "/put/\\1\n"); @@ -640,16 +670,6 @@ perform_task (const dir_path& md, // r = parse_manifest (rf, "result"); - // Update package name/version if the returned value as "unknown". - // - if (r.version == bpkg::version ("0")) - { - assert (r.status == result_status::abnormal); - - r.name = tm.name; - r.version = tm.version; - } - // If the build terminated abnormally, suspent the machine for // investigation (note that here we don't wait or return). // @@ -664,13 +684,23 @@ perform_task (const dir_path& md, run_btrfs (trace, "subvolume", "delete", xp); } - catch (const system_error& e) + + // Update package name/version if the returned value as "unknown". + // + if (r.version == bpkg::version ("0")) { - fail << "build error: " << e; + assert (r.status == result_status::abnormal); + + r.name = tm.name; + r.version = tm.version; } return r; } +catch (const system_error& e) +{ + fail << "build error: " << e << endf; +} extern "C" void handle_signal (int sig) @@ -748,10 +778,15 @@ try tc_num = ops.toolchain_num (); tc_id = ops.toolchain_id (); - if (argc < 2) + + // Controller URLs. + // + if (argc < 2 && !ops.fake_request_specified ()) fail << "controller url expected" << info << "run " << argv[0] << " --help for details"; + strings controllers; + for (int i (1); i != argc; ++i) controllers.push_back (argv[i]); @@ -830,18 +865,15 @@ try if (ops.fake_request_specified ()) { - const path& f (ops.fake_request ()); - task_manifest t (f.string () != "-" - ? parse_manifest (f, "task") - : parse_manifest (cin, "stdin", "task")); - - url = controllers[0]; + auto t (parse_manifest (ops.fake_request (), "task")); tr = task_response_manifest { "fake-session", // Dummy session. string (), // Empty challange. url, // Empty result URL. move (t)}; + + url = "http://example.org"; } else { @@ -893,9 +925,9 @@ try // verify it is one of those we sent). // size_t i (0); - for (const bootstrapped_machine_manifest& m: ms) + for (const machine_header_manifest& m: tq.machines) { - if (m.machine.name == tr.task->machine) + if (m.name == tr.task->machine) break; ++i; diff --git a/bbot/utility b/bbot/utility index 59f6e09..f154a9e 100644 --- a/bbot/utility +++ b/bbot/utility @@ -141,6 +141,8 @@ namespace bbot // Manifest parsing and serialization. // + // For parsing, if path is '-', then read from stdin. + // template T parse_manifest (const path&, const char* what, bool ignore_unknown = true); diff --git a/bbot/utility.txx b/bbot/utility.txx index edd674b..4ee4c6f 100644 --- a/bbot/utility.txx +++ b/bbot/utility.txx @@ -2,6 +2,8 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : TBC; see accompanying LICENSE file +#include // cin + #include #include @@ -148,6 +150,9 @@ namespace bbot try { + if (f.string () == "-") + return parse_manifest (std::cin, "stdin", what, ignore_unknown); + if (!file_exists (f)) fail << what << " manifest file " << f << " does not exist"; diff --git a/bbot/worker.cli b/bbot/worker.cli index fd88521..61d3f4c 100644 --- a/bbot/worker.cli +++ b/bbot/worker.cli @@ -39,6 +39,11 @@ namespace bbot { "\h|OPTIONS|" + // + // NOTE: when adding new options, consider whether they should be + // propagated from startup to build. + // + bool --help {"Print usage information and exit."} bool --version {"Print version and exit."} diff --git a/bbot/worker.cxx b/bbot/worker.cxx index 0212d26..a2e53b2 100644 --- a/bbot/worker.cxx +++ b/bbot/worker.cxx @@ -182,7 +182,9 @@ build (size_t argc, const char* argv[]) for (const variable& v: tm.config) cfg.push_back (v.unquoted ()); - dir_path dir ("build"); + // Use target (if present) or machine as configuration directory name. + // + dir_path dir (tm.target ? tm.target->string () : tm.machine); r.status |= run_bpkg (trace, r.log, "create", @@ -380,10 +382,27 @@ startup () // Run it. // + strings os; + + if (ops.systemd_daemon ()) + os.push_back ("--systemd-daemon"); + + if (ops.verbose_specified ()) + { + os.push_back ("--verbose"); + os.push_back (to_string (ops.verbose ())); + } + + if (ops.tftp_host_specified ()) + { + os.push_back ("--tftp-host"); + os.push_back (ops.tftp_host ()); + } + // Note that we use the effective (absolute) path instead of recall since // we may have changed the CWD. // - run (trace, pp, tg, argv0.effect_string ()); + run (trace, pp, tg, argv0.effect_string (), os); } catch (const failed&) { -- cgit v1.1