Working with the beaker command line

A graphical User interface has the potential ability to guide users on their journey from n00b13 to power user. If a user has never used a system before, the graphical user interface can provide a visual orientation to the system that is intuitive and inviting.

Once a user starts to depend on a system and use it regularly, they often want to automate tasks performed in that system.

I am reminded of these principals as I start making use of my company’s beaker server. I need short term access to machines of various architectures develop and test our Yocto based coding efforts.

We have an internal build of beaker that requires a Kerberos ticket. Thus, before I do anything with beaker, I have to:

kinit ayoung@REDHAT.COM

The reason I have to put in the user principal is because, with my FreeIPA works, I tend to point at multiple KDCs for different domains. For most people, the kinit command alone would be sufficient. Either way, I end up with a ticket-granting-ticket (TGT.)

Once I have a TGT, I can list my jobs.

bkr job-list  -o ayoung 
["J:5170756", "J:5149484", "J:5093612", "J:5078388", "J:5072955"]

A regular beaker user will collect a lot of jobs over time. To see if any are not completed:

bkr job-list  -o ayoung  --unfinished 

I have one. How did I get it? By submitting a clone of an old job. I started by going to the web UI and pulling up my sets of jobs:

If I select any one of them

I can select clone. This gives a page with the xml output from the previous invocation;

<job retention_tag="scratch">
  <whiteboard>Reserve Workflow provision of distro RHEL-8.4.0-20210304.2 on any lab system for 356400 seconds</whiteboard>
  <recipeSet priority="Normal">
    <recipe whiteboard="" role="RECIPE_MEMBERS" ks_meta="" kernel_options="" kernel_options_post="">
      <autopick random="false"/>
      <watchdog panic="ignore"/>
          <distro_family op="=" value="RedHatEnterpriseLinux8"/>
          <distro_variant op="=" value="BaseOS"/>
          <distro_name op="=" value="RHEL-8.4.0-20210304.2"/>
          <distro_arch op="=" value="aarch64"/>
        <labcontroller op="=" value=""/>
        <system_type op="=" value="Machine"/>
      <task name="/distribution/check-install" role="STANDALONE"/>
      <task name="/distribution/reservesys" role="STANDALONE">
          <param name="RESERVETIME" value="356400"/>

If I save that to a file I can re-invoke it from the command line:

bkr job-submit  ansible4yocto/playbooks/files/beaker-aarch64-rhel.xml

Now I want to query my set of jobs, but only show ones that are not finished.

bkr job-list  -o ayoung  --unfinished 

To inspect this job, I can pull the ID out using jq.

 bkr job-list  -o ayoung  --unfinished | jq -r  ".[]"

To see the details of it, I can use the bkr job-results command, but it comes back as a lot of XML. I can use xmllint to make it more legible.

bkr job-results J:5170756 | xmllint --format - | head -2
<?xml version="1.0"?>
<job id="5170756" owner="" result="Pass" status="Running" retention_tag="scratch">

And use xpath to pull out a subsection. To see the whiteboard;

bkr job-results J:5170756 | xmllint --format - | xpath -e /job/whiteboard
Found 1 nodes in stdin:
-- NODE --
<whiteboard>Reserve Workflow provision of distro RHEL-8.4.0-20210304.2 on any lab system for 356400 seconds</whiteboard>

How about to figure out if the machine has been allocated and provisioned?

(I am going to use a touch of sed to make the results more readable)

$ bkr job-results J:5170756 | xpath -e /job/recipeSet/recipe/task/results/result | sed 's!>!>\n!g'
Found 3 nodes in stdin:
-- NODE --
-- NODE --
<result path="/distribution/check-install" start_time="2021-03-09 13:49:35" score="426" result="Pass" id="574797323">
<log href="" name="dmesg.log" />
<log href="" name="avc.log" />
-- NODE --
<result path="/distribution/check-install/Sysinfo" start_time="2021-03-09 13:49:35" score="None" result="Pass" id="574797325">
<log href="" name="avc.log" />
<log href="" name="resultoutputfile.log" />
<result path="/distribution/reservesys" start_time="2021-03-09 13:50:35" score="0" result="Pass" id="574797547">
<log href="" name="avc.log" />
<log href="" name="resultoutputfile.log" />

We can see the status of the reservesys and check-install tasks. What is the name of the system that I have been allocated?

$ bkr job-results J:5170756 | xpath -e /job/recipeSet/recipe/roles/role
Found 1 nodes in stdin:
-- NODE --
<role value="RECIPE_MEMBERS"><system value=""></system></role>

If I want to use this in some other script:

bkr job-results J:5170756 | xpath -q -e string\(/job/recipeSet/recipe/roles/role/system/@value\)

1 thought on “Working with the beaker command line

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.