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

python: set_config_item("lxc.cgroup.*") generates duplicate lines in config file #14

Open amezin opened 7 years ago

amezin commented 7 years ago

With Python bindings:

    container.set_config_item('lxc.cgroup.memory.limit_in_bytes', mem_limit)
    container.set_config_item('lxc.cgroup.memory.memsw.limit_in_bytes', memsw_limit)

generates following lines in container config:

lxc.cgroup.memory.limit_in_bytes = 3G
lxc.cgroup.memory.memsw.limit_in_bytes = 
lxc.cgroup.memory.memsw.limit_in_bytes = 4G

And if there are other set_config_items before 'lxc.cgroup.memory.limit_in_bytes':

lxc.cgroup.memory.limit_in_bytes = 
lxc.cgroup.memory.limit_in_bytes = 3G
lxc.cgroup.memory.memsw.limit_in_bytes = 
lxc.cgroup.memory.memsw.limit_in_bytes = 4G

Happens on current stable-2.0 branch, haven't tested master branch yet

brauner commented 7 years ago

Afaik, this is expected behavior. Config lines override each other in the order they are specified in.

brauner commented 7 years ago

Closing as this is expected behavior.

amezin commented 7 years ago

Yes, it works correctly, but why should single set_config_item generate two lines in config file, one of which is useless garbage?

brauner commented 7 years ago

Oh wait, maybe I misunderstood you. Are you saying that one single call to:

container.set_config_item('lxc.cgroup.memory.memsw.limit_in_bytes', memsw_limit)

will set two lines in the container's config file?

amezin commented 7 years ago

One single call to

container.set_config_item('lxc.cgroup.memory.memsw.limit_in_bytes', memsw_limit)

(+ container.save_config() of course) will produce this:

...
lxc.cgroup.memory.memsw.limit_in_bytes = 
lxc.cgroup.memory.memsw.limit_in_bytes = 4G
...

even if there were no "lxc.cgroup.memory.memsw.limit_in_bytes" lines in the config file before the call

brauner commented 7 years ago

Right, sorry I misunderstood. :)

sobczyk commented 7 years ago

This fails starting a container on ubuntu 16.04 (lxc 2.0.8-0ubuntu1~16.04.2) when I override some settings from python Failed to parse config: lxc.rootfs.backend =

brauner commented 7 years ago

Once we release the new config file parser this should be fixed.

dankegel commented 7 years ago

This just bit me, and it breaks lxc-ls. I'm using 2.0.8-0ubuntu1~16.04.2

When did this sneak in? It's a bit of a dumpster fire, now I can't query any of my 20 containers.

brauner commented 7 years ago

@dankegel, what exactly?

dankegel commented 7 years ago

I'm not quite sure what's going on, but I have about ten ubuntu 16.04 systems each running several containers (in a configuration roughly unchanged since 2012).

On machines with 2.0.7-0ubuntu1~16.04.2, I see duplicate empty lxc.hook.pre-mount lines before the real one, but that doesn't seem to bother lxc-ls.

On machines with 2.0.8-0ubuntu1~16.04.2, I also see duplicate empty lxc.ephemeral lines before the real ones, and lxc-ls complains lxc-ls: parse.c: lxc_file_for_each_line: 57 Failed to parse config: lxc.ephemeral = If I remove the empty duplicate, lxc-ls works again.

I have no idea what creates those lines, my script "just" calls lxc-start.

I suppose I can just modify my script to remove the bogus line after creating each new ephemeral container... so it's only a dumpster fire in the "oh, man, not another distraction!" sense.

stutiredboy commented 6 years ago

Second.

brauner commented 6 years ago

Is this still a problem with LXC 2.0.9?

condector commented 6 years ago

Yes, this still a problem with LXC 2.0.11 on Ubuntu 16.04 using python3-lxc lib. For some weird reason, generate two outputs.

brauner commented 6 years ago

Can you try with master too, please?

condector commented 6 years ago

I will try and post here an update.

brauner commented 6 years ago

Thanks!

condector commented 6 years ago

@brauner I tested with version 2.0.8 that I clone from GitHub directly. The problem was: when I create an object to run an LXC container and save its configuration, the production was 2 line of configurations, one:

lxc.cgroup.memory.limit_in_bytes = 
lxc.cgroup.memory.limit_in_bytes = 256M
lxc.cgroup.cpuset.cpus = 
lxc.cgroup.cpuset.cpus = 1

I start to inspect what's causing it... I know that the second line is the effective one... but the configuration file becomes a little bit full of blank lines.