print lxc-start-ephemeral container name in a machine-readable way

Bug #1197754 reported by Robie Basak
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
autopkgtest (Ubuntu)
Fix Committed
Low
Paride Legovini
lxc (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

A script cannot call lxc-start-ephemeral and get a named container in a reliable, race-free way.

Having the caller specify a name directly is racy, since the name could have been taken in between checking that it doesn't exist already and calling lxc-start-ephemeral.

Allowing lxc-start-ephemeral allows it to take care of the mkdir (and retries) to generate an LXC container name in a race free manner, but this needs -d to return the name in a machine-readable way, so that we can create ephemeral LXC containers from scripts.

Please add a machine-readable mechanism to "lxc-start-ephemeral -d" and then we can modify adt-virt-lxc to use it.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Re: [Bug 1197754] [NEW] "lxc-start-ephemeral -d" is racy

Quoting Robie Basak (<email address hidden>):
> Public bug reported:
>
> A script cannot call lxc-start-ephemeral and get a named container in a
> reliable, race-free way.
>
> Having the caller specify a name directly is racy, since the name could
> have been taken in between checking that it doesn't exist already and
> calling lxc-start-ephemeral.

Practically speaking, have you actually created the container name with
mktemp (i.e. mktemp -u -t lxc-XXXXXX | sed 's@/tmp/@@') and gotten name
clashes?

> Allowing lxc-start-ephemeral allows it to take care of the mkdir (and
> retries) to generate an LXC container name in a race free manner, but
> this needs -d to return the name in a machine-readable way, so that we
> can create ephemeral LXC containers from scripts.
>
> Please add a machine-readable mechanism to "lxc-start-ephemeral -d" and
> then we can modify adt-virt-lxc to use it.

That does sound like a good idea - we could add a '--terse' suboption to
-d to only print '$name $ip'

Revision history for this message
Robie Basak (racb) wrote :

On Fri, Jul 05, 2013 at 12:01:08PM -0000, Serge Hallyn wrote:
> Practically speaking, have you actually created the container name with
> mktemp (i.e. mktemp -u -t lxc-XXXXXX | sed 's@/tmp/@@') and gotten name
> clashes?

No, but eyebrows were raised on my approach of generating a random name
on code review, so that's why I filed this bug.

> > Please add a machine-readable mechanism to "lxc-start-ephemeral -d" and
> > then we can modify adt-virt-lxc to use it.
>
> That does sound like a good idea - we could add a '--terse' suboption to
> -d to only print '$name $ip'

That'd be great.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

 summary: lxc-start-ephemeral - provide terse -d output option
 status: Triaged
 importance: medium

Changed in lxc (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
Martin Pitt (pitti)
Changed in autopkgtest (Ubuntu):
importance: Medium → Low
Martin Pitt (pitti)
summary: - "lxc-start-ephemeral -d" is racy
+ print lxc-start-ephemeral container name in a machine-readable way
Revision history for this message
Stéphane Graber (stgraber) wrote :

stgraber@dakara:~/data/code/lxc/lxc$ lxc-start-ephemeral -o blah -d | grep "lxc-console" | awk '{print $NF}'
blah-psrfp_3s

Not the prettiest thing ever, but definitively doable with current lxc-start-ephemeral.
I won't be spending more time on lxc-start-ephemeral though as we'll have the new lxc-copy there soon that will take-over most if not all of it (lxc-start-ephemeral will likely be gone in 2.0).

So marking this fix-released as the above does work.

Changed in lxc (Ubuntu):
status: Triaged → Fix Released
Martin Pitt (pitti)
summary: - print lxc-start-ephemeral container name in a machine-readable way
+ print lxc-copy -e container name in a machine-readable way
summary: - print lxc-copy -e container name in a machine-readable way
+ print lxc-start-ephemeral container name in a machine-readable way
Revision history for this message
Paride Legovini (paride) wrote :

With 0b4c5056925e7358374874c8bf4767290157e903 (in autopkgtest 5.33) lxc-start-ephemeral is not called anymore.

Changed in autopkgtest (Ubuntu):
assignee: nobody → Paride Legovini (paride)
status: Triaged → Fix Committed
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.