Merge pull request #18 from NiR-/fix-empty-config

Fixing clear_config & config_item value
This commit is contained in:
Andre Nathan 2014-06-06 11:21:41 -03:00
commit c0daae000d
2 changed files with 34 additions and 1 deletions

View file

@ -1238,6 +1238,9 @@ container_config_item(VALUE self, VALUE rb_key)
if (len1 < 0) if (len1 < 0)
rb_raise(Error, "invalid configuration key: %s", key); rb_raise(Error, "invalid configuration key: %s", key);
if (len1 == 0)
return Qnil;
value = malloc(sizeof(char) * len1 + 1); value = malloc(sizeof(char) * len1 + 1);
if (value == NULL) if (value == NULL)
rb_raise(rb_eNoMemError, "unable to allocate configuration value"); rb_raise(rb_eNoMemError, "unable to allocate configuration value");
@ -2121,7 +2124,7 @@ Init_lxc(void)
rb_define_method(Container, "add_device_node", rb_define_method(Container, "add_device_node",
container_add_device_node, -1); container_add_device_node, -1);
rb_define_method(Container, "attach", container_attach, -1); rb_define_method(Container, "attach", container_attach, -1);
rb_define_method(Container, "clear_config", container_clear_config, -1); rb_define_method(Container, "clear_config", container_clear_config, 0);
rb_define_method(Container, "clear_config_item", rb_define_method(Container, "clear_config_item",
container_clear_config_item, 1); container_clear_config_item, 1);
rb_define_method(Container, "clone", container_clone, -1); rb_define_method(Container, "clone", container_clone, -1);

View file

@ -28,6 +28,7 @@ class TestLXCCreated < Test::Unit::TestCase
def test_container_configuration def test_container_configuration
capdrop = @container.config_item('lxc.cap.drop') capdrop = @container.config_item('lxc.cap.drop')
assert_instance_of(Array, @container.config_item('lxc.cap.drop'))
@container.clear_config_item('lxc.cap.drop') @container.clear_config_item('lxc.cap.drop')
@container.set_config_item('lxc.cap.drop', capdrop[0...-1]) @container.set_config_item('lxc.cap.drop', capdrop[0...-1])
@container.set_config_item('lxc.cap.drop', capdrop[-1]) @container.set_config_item('lxc.cap.drop', capdrop[-1])
@ -40,6 +41,35 @@ class TestLXCCreated < Test::Unit::TestCase
assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr')) assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr'))
end end
def test_container_fstab
config_path = @container.config_path + '/' + @name + '/config'
fstab_path = @container.config_path + '/' + @name + '/fstab'
@container.set_config_item('lxc.mount', fstab_path)
@container.save_config(config_path)
assert_instance_of(String, @container.config_item('lxc.mount'))
assert_not_nil(@container.config_item('lxc.mount'))
f = File.readlines(config_path)
f.reject! { |l| /^lxc\.mount = (.*)$/ =~ l }
File.write(config_path, f.join)
@container.clear_config
@container.load_config(config_path)
assert(@container.config_item('lxc.mount').nil?)
end
def test_clear_config
assert_not_nil(@container.config_item('lxc.utsname'))
assert(@container.clear_config)
assert_raise(LXC::Error) do
@container.config_item('lxc.utsname').nil?
end
end
def test_container_mount_points def test_container_mount_points
assert_instance_of(Array, @container.config_item('lxc.mount.entry')) assert_instance_of(Array, @container.config_item('lxc.mount.entry'))
end end