lxc / python3-lxc

Python 3.x binding for liblxc
https://linuxcontainers.org/lxc
GNU Lesser General Public License v2.1
57 stars 38 forks source link

Incorrect behavior with create() after destroy() #16

Closed ach5948 closed 3 years ago

ach5948 commented 7 years ago

Required information

Issue description

After instantiating, creating, and destroying a linux container, calling create without re-instantiating returns false rather than recreating the container

Steps to reproduce

  1. test = lxc.Container("test")
  2. test.create(template="debian")
  3. test.destroy()
  4. test.create(template="debian")

the second call simply returns false

anirudh-goyal commented 4 years ago

Hello, could me and my classmates work on this issue please?

Was originally planning to work on issue https://github.com/lxc/python3-lxc/issues/15 but it turns out someone already opened a PR for it.

anirudh-goyal commented 3 years ago

Hey @stgraber, just wanted to check in again if it would be okay for me to work on this issue? Thanks!

stgraber commented 3 years ago

Absolutely!

stgraber commented 3 years ago

Assigned it to you now!

anirudh-goyal commented 3 years ago

Thanks for assigning it @stgraber!

I've been a little lost trying to think of the solution.

However, when I go to python3-lxc and run python3 setup.py build, I get an error saying that lxc.c:27:10: fatal error: 'lxc/lxccontainer.h' file not found

Could you please give me some direction here? Or do you think this issue is more involved than we think it is and would require a lot of context?

stgraber commented 3 years ago

Ok, so the issue here is that create() creates a rootfs for a container while destroy() deletes the container itself including its path. It's that step which is preventing it be re-created as the object still has its old config, causing it to prevent a new create() run.

To fix this in python3-lxc, I think we need to changes:

As this is not going to be touching the C part of this, you can just install python3-lxc on an Ubuntu system and then use this in a python3 shell to reproduce the issue:

import lxc
test = lxc.Container("test")
test.destroy()
test.create("busybox")
test.destroy()
test.create("busybox")

This should output True every time when this issue is fixed.

You can directly mess with the python3 binding live by editing /usr/lib/python3/dist-packages/lxc/__init__.py on such a system.

anirudh-goyal commented 3 years ago

Thanks a lot for the explanation, that makes sense. I was able to set things up on an Ubuntu system and edit the binding as you suggested for testing it.

I'm a little confused by one thing though. Even before I made any changes, all my create() calls are returning False. Do you know what might be the issue here?

Going off of the Steps to Reproduce in the issue description, this is what I'm getting:

test = lxc.Container("test") -> test.create(template="debian") False test.destroy() False test.create(template="debian") False

I did, however, open a PR #23 that does the changes you suggested.

stgraber commented 3 years ago

Yeah, test with busybox not debian, we don't ship the debian template by default.