Bug 9981

Summary: Make Autobuilder workers get hostname dynamically
Product: [Infrastructure] AutoBuilder Reporter: Michael Halstead <mhalstead>
Component: autobuilderAssignee: Aaron Chan <aaron.chun.yew.chan>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: Medium CC: aaron.chun.yew.chan, benjamin.esquivel, infras.ab.watcher, Infras.watcher, joshuagloe, monserratx.sedeno.bustos, pidge, richard.purdie, sgw, stephano
Version: unspecified   
Target Milestone: Future   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Michael Halstead 2016-07-19 18:34:29 UTC
Right now we put the autobuilder's hostname in several files. It would be helpful is the hostname could be grabbed from the system if it isn't configured. For example, this would allow us to use the same buildbot.tac across an entire cluster instead of customizing for each worker.

Examples of "hardcoded" hostnames can be found in:

config/autobuilder.conf
yocto-worker/buildbot.tac
Comment 1 Joshua Lock 2017-11-22 01:52:56 UTC
For yocto-worker/buildbot.tac we should be able towrite Python to get the hostname and use it. Untested, but I think something like this should work:

import socket
workername = socket.gethostname()
Comment 2 Aaron Chan 2018-07-31 02:03:22 UTC
Since the upgrade to buildbot-worker 1.1.1 and beyond, there are many features 
added into buildbot-worker. 
Hence would like to revisit this on why we are trying to get the hostname from the workers and where we might use this info.

we could add in a possible patch on the following:

import socket
workername = socket.gethostname()

or use

import netifaces where we can access the network interfaces on each worker.

hence today the way I get this information is running a custom startup script
as part of buildbot-worker-update

$ buildbot-worker-update <path worker created> <owner name> <owner email>
$ buildbot-worker-update ~/yocto-worker "Michael Halstead" "michael@yoctoproject.org"

This will update the worker info on its Kernel version, Hostname info, etc into
yocto-worker/info/host
Comment 3 Aaron Chan 2018-10-22 08:27:40 UTC
Patches describe to autoset the buildbot worker with the system hostname.
This helps to reduce the need to supply worker name during create-worker on all other worker cluster on the same network.
Therefore the command is simplify as:

buildbot-worker create-worker --umask=0o22 <path> <server>:<port> <password>

Signed-off-by: Aaron Chan <aaron.chun.yew.chan@intel.com>
---
 worker/buildbot_worker/scripts/runner.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/worker/buildbot_worker/scripts/runner.py b/worker/buildbot_worker/scripts/runner.py
index 06d369331..827dca470 100644
--- a/worker/buildbot_worker/scripts/runner.py
+++ b/worker/buildbot_worker/scripts/runner.py
@@ -24,6 +24,7 @@ import os
 import re
 import sys
 import textwrap
+import socket
 
 from twisted.python import log
 from twisted.python import reflect
@@ -176,12 +177,12 @@ class CreateWorkerOptions(MakerBase):
             "[options] <basedir> <master> <name> <passwd>"
 
     def parseArgs(self, *args):
-        if len(args) != 4:
+        if len(args) != 3:
             raise usage.UsageError("incorrect number of arguments")
-        basedir, master, name, passwd = args
+        basedir, master, passwd = args
         self['basedir'] = basedir
         self['host'], self['port'] = self.validateMasterArgument(master)
-        self['name'] = name
+        self['name'] = socket.gethostname()
         self['passwd'] = passwd
 
     def postOptions(self):
--
2.11.0
Comment 4 Aaron Chan 2018-10-22 08:34:14 UTC
The patch has been send to Buildbot maintainer Pierre Tardy for review at 
https://github.com/tardyp/buildbot

On worker end, we run,
$ buildbot-worker create-worker <path> <server>:<port> <password>

With this patch buildbot-worker will create the worker directory and buildbot.tac without the need to supply worker name, instead worker name is set
based on system hostname where worker is created.

This ticket will be set to resolved.
Comment 5 Michael Halstead 2018-11-09 16:03:34 UTC
That is a fine solution. This was filed when we were using autobuilder1 and the problems it would have solved are no longer and issue.