summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2020-02-16 11:27:40 +0000
committerintrigeri <intrigeri@boum.org>2020-02-16 12:02:54 +0000
commit46ad3c627b16c54342bf6a380116a4c223e1450e (patch)
tree271a148a330478cc9ffad19d27bbc0a2a7d035e7
parent8b71d196767b19e71ef6d25309a7a8f5faa68bd9 (diff)
jenkins-slave.service: only enable a node if we marked it as temporarily offline (#10601)
The enable_node() method toggles offline status iff. the master thinks the node is currently offline, which can be the case: - either because the agent was not started yet (this is always true at this stage) *and* the master already understood that the agent that was running before the reboot got disconnected: that's racy so let's not rely on this, contrary to what the previous implementation did before this commit; - or because we marked the node as temporarily offline ourselves (before rebooting, in test_Tails_*). Let's eliminate at least one part of the race condition, by: - only fiddling with temporarilyOffline state when we really need to, i.e. when we explicitly put the node temporarily offline ourselves; this makes us stop rely on the exact timing of when the Jenkins master registers the fact an older agent got disconnected; - waiting for the Jenkins master to have registered this state change, before we start the agent; I'm not sure this is really needed, but I'm under the impression that the master processes requests to put a node back online in a non-blocking manner, which would race against the startup of the agent, and I'm not willing to bet on the opposite. I'm not sure this will be sufficient to fully fix this race condition.
-rw-r--r--templates/jenkins/jenkins-slave.service.erb4
1 files changed, 2 insertions, 2 deletions
diff --git a/templates/jenkins/jenkins-slave.service.erb b/templates/jenkins/jenkins-slave.service.erb
index f901871..9a231f6 100644
--- a/templates/jenkins/jenkins-slave.service.erb
+++ b/templates/jenkins/jenkins-slave.service.erb
@@ -4,8 +4,8 @@ Description=Jenkins slave node
[Service]
Type=simple
ExecStartPre=/usr/local/share/jenkins-slave-download <%= @master_url %>
-ExecStartPre=/bin/sh -c \
- '/usr/bin/python3 -c "import jenkins; jenkins.Jenkins(\\"<%= @master_url %>\\").enable_node(\\"<%= @domain == 'lizard' ? @hostname : @fqdn %>\\")"'
+ExecStartPre=/usr/bin/python3 -c 'import jenkins; server = jenkins.Jenkins("<%= @master_url %>"); node = "<%= @domain == "lizard" ? @hostname : @fqdn %>"; server.enable_node(node) if server.get_node_info(node)["temporarilyOffline"] else True'
+ExecStartPre=/usr/bin/python3 -c 'while __import__("jenkins").Jenkins("<%= @master_url %>").get_node_info("<%= @domain == "lizard" ? @hostname : @fqdn %>")["temporarilyOffline"]: __import__("time").sleep(1)'
ExecStart=/usr/bin/java -jar /run/jenkins/slave.jar -jnlpUrl <%= @master_url %>/computer/<%= @node_name %>/slave-agent.jnlp
User=jenkins
LimitNOFILE=8192