aboutsummaryrefslogtreecommitdiff
path: root/bbot/agent.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bbot/agent.cxx')
-rw-r--r--bbot/agent.cxx114
1 files changed, 73 insertions, 41 deletions
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<machine_header_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/<name>/get/*
+ // PUT requests to .../build/<name>/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<result_manifest> (rf, "result");
+ }
+ else
{
// <name>-<toolchain>-<xxx>
//
@@ -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/<name>/get/*
- // PUT requests to .../build/<name>/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<result_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<task_manifest> (f, "task")
- : parse_manifest<task_manifest> (cin, "stdin", "task"));
-
- url = controllers[0];
+ auto t (parse_manifest<task_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;