juju_machine_agent_name can return an invalid machine name.

Bug #1996637 reported by Pedro Castillo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Fix Released
Medium
Caner Derici

Bug Description

The `juju_machine_agent_name` from the juju-introspect scripts can return an invalid machine name. The script will match any directory under `/var/lib/juju/agents` whose name starts with `machine`, which is generally only the `machine-N` directory, but in some edge cases it will grab other directories and concatenate the values into an invalid machine tag.

Here is the bash function which grabs the machine name:
```
juju_machine_agent_name () {
  local machine=$(find /var/lib/juju/agents -type d -name 'machine*' -printf %f)
  echo $machine
}
```

Here is an edge case where the script grabs an invalid machine name:
```
ubuntu@juju-7cfc1d-18-lxd-10:/var/lib/juju/agents$ juju_machine_agent_name
machinelearningmachine-18-lxd-10
```

Here is the same `find` command but echoing the full path of the directories it matched:
```
ubuntu@juju-7cfc1d-18-lxd-10:/var/lib/juju/agents$ find /var/lib/juju/agents -type d -name 'machine*'
/var/lib/juju/agents/unit-gnocchi-3/.venv/lib/python3.6/site-packages/botocore/data/machinelearning
/var/lib/juju/agents/machine-18-lxd-10
```

This was found on an LXD container on an environment running juju-agent version 2.9.18.

I believe that modifying the `juju_machine_agent_name` to replace the `find` command with `ls /var/lib/juju/agents | grep '^machine-' would be a good fix. Otherwise, adding a `-maxdepth 1` to the `find` command would also fix the issue.

Tags: bitesize
Revision history for this message
John A Meinel (jameinel) wrote :

This should be a very simple fix, and I agree that we shouldn't be recursing into any sub directories.

Changed in juju:
importance: Undecided → Medium
milestone: none → 2.9.38
status: New → Triaged
tags: added: bitesize
Caner Derici (cderici)
Changed in juju:
assignee: nobody → Caner Derici (cderici)
Revision history for this message
Caner Derici (cderici) wrote :
Caner Derici (cderici)
Changed in juju:
status: Triaged → Fix Committed
Changed in juju:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.