Adding early nil return in config_item (when value is empty).
This commit is contained in:
parent
755609c059
commit
2b9f45f8a5
|
@ -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");
|
||||||
|
|
|
@ -41,6 +41,26 @@ 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
|
def test_clear_config
|
||||||
assert_not_nil(@container.config_item('lxc.utsname'))
|
assert_not_nil(@container.config_item('lxc.utsname'))
|
||||||
assert(@container.clear_config)
|
assert(@container.clear_config)
|
||||||
|
|
Loading…
Reference in a new issue