python3-lxc icon indicating copy to clipboard operation
python3-lxc copied to clipboard

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

Open amezin opened this issue 7 years ago • 18 comments

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

amezin avatar Apr 03 '17 09:04 amezin

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

brauner avatar Apr 03 '17 15:04 brauner

Closing as this is expected behavior.

brauner avatar Apr 21 '17 09:04 brauner

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

amezin avatar Apr 21 '17 10:04 amezin

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?

brauner avatar Apr 21 '17 11:04 brauner

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

amezin avatar Apr 21 '17 12:04 amezin

Right, sorry I misunderstood. :)

brauner avatar Apr 21 '17 12:04 brauner

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 =

sobczyk avatar Jun 23 '17 15:06 sobczyk

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

brauner avatar Jun 23 '17 16:06 brauner

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.

dankegel avatar Jul 28 '17 13:07 dankegel

@dankegel, what exactly?

brauner avatar Jul 28 '17 13:07 brauner

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.

dankegel avatar Jul 28 '17 14:07 dankegel

Second.

stutiredboy avatar Nov 22 '17 09:11 stutiredboy

Is this still a problem with LXC 2.0.9?

brauner avatar Nov 22 '17 11:11 brauner

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.

condector avatar Jul 18 '18 14:07 condector

Can you try with master too, please?

brauner avatar Jul 19 '18 08:07 brauner

I will try and post here an update.

condector avatar Jul 21 '18 18:07 condector

Thanks!

brauner avatar Jul 22 '18 10:07 brauner

@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.

condector avatar Jul 23 '18 18:07 condector