2013-12-06 17:43:19 +01:00
|
|
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
2013-12-05 20:29:25 +01:00
|
|
|
|
2013-12-06 17:43:19 +01:00
|
|
|
require 'test/unit'
|
|
|
|
require 'lxc'
|
2013-12-05 20:29:25 +01:00
|
|
|
|
|
|
|
class TestLXCCreated < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
if Process::Sys::geteuid != 0
|
2014-03-24 23:39:25 +01:00
|
|
|
raise 'This test must be run as root'
|
2013-12-05 20:29:25 +01:00
|
|
|
end
|
2013-12-06 17:43:19 +01:00
|
|
|
@name = 'test'
|
2013-12-05 20:29:25 +01:00
|
|
|
@container = LXC::Container.new(@name)
|
2013-12-06 17:43:19 +01:00
|
|
|
@container.create('ubuntu') unless @container.defined?
|
2014-03-24 23:39:25 +01:00
|
|
|
# Make sure the renamed_test container does not exist, for the rename test
|
|
|
|
@new_name = "renamed_#{@name}"
|
|
|
|
new_container = LXC::Container.new(@new_name)
|
|
|
|
new_container.destroy if new_container.defined?
|
2013-12-05 20:29:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_container_defined
|
|
|
|
assert(@container.defined?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_container_name
|
|
|
|
assert_equal(@name, @container.name)
|
|
|
|
assert_equal(@name, @container.config_item('lxc.utsname'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_container_configuration
|
|
|
|
capdrop = @container.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[-1])
|
|
|
|
@container.save_config
|
|
|
|
assert_equal(capdrop, @container.config_item('lxc.cap.drop'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_container_networking
|
|
|
|
assert(@container.keys('lxc.network.0').include?('name'))
|
|
|
|
assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr'))
|
|
|
|
end
|
2013-12-23 18:59:41 +01:00
|
|
|
|
2014-03-06 14:19:17 +01:00
|
|
|
def test_container_mount_points
|
|
|
|
assert_instance_of(Array, @container.config_item('lxc.mount.entry'))
|
|
|
|
end
|
|
|
|
|
2013-12-23 18:59:41 +01:00
|
|
|
def test_container_rename
|
2014-03-25 21:20:20 +01:00
|
|
|
@container.stop if @container.running?
|
2014-03-24 23:39:25 +01:00
|
|
|
renamed = @container.rename(@new_name)
|
|
|
|
assert_equal(@new_name, renamed.name)
|
2013-12-23 18:59:41 +01:00
|
|
|
rerenamed = renamed.rename(@name)
|
|
|
|
assert_equal(@name, rerenamed.name)
|
|
|
|
end
|
2013-12-05 20:29:25 +01:00
|
|
|
end
|