App-LXC-Container

 view release on metacpan or  search on metacpan

t/06-update.t  view on Meta::CPAN

$_->_parse_packages();
is_deeply($_->{package_sources},
	  ['30-PKG-default.packages', 'u2-PKG-update-test-2.packages'],
	  'packages test 2 has correct source list');
if (6 == @{$_->{packages}})
{
    is_deeply($_->{packages},
	      [qw(coreutils dash libc-bin util-linux chromium evince)],
	      'packages test 2 has correct content');
}
else
{
    is_deeply($_->{packages},
	      [qw(coreutils libc-bin util-linux chromium evince)],
	      'packages test 2a has correct content');
}
is($_->{package_source}{chromium}, 'u2-PKG-update-test-2.packages',
   'packages test 2 chromium entry is correct');
is($_->{package_source}{evince}, 'u2-PKG-update-test-2.packages',
   'packages test 2 evince entry is correct');

$_ = App::LXC::Container::Update->new('update-test-1', 'update-test-2');
$_->_parse_packages();
is_deeply($_->{package_sources},
	  ['30-PKG-default.packages',
	   'u1-PKG-update-test-1.packages',
	   'u2-PKG-update-test-2.packages'],
	  'packages test 3 has correct source list');
if (6 == @{$_->{packages}})
{
    is_deeply($_->{packages},
	      [qw(coreutils dash libc-bin util-linux chromium evince)],
	      'packages test 3 has correct content');
}
else
{
    is_deeply($_->{packages},
	      [qw(coreutils libc-bin util-linux chromium evince)],
	      'packages test 3a has correct content');
}
is($_->{package_source}{chromium}, 'u1-PKG-update-test-1.packages',
   'packages test 3 chromium entry is correct');
is($_->{package_source}{evince}, 'u2-PKG-update-test-2.packages',
   'packages test 3 evince entry is correct');

$_ = App::LXC::Container::Update->new('update-test-2', 'update-test-1');
$_->_parse_master();		# now with audio packages!
$_->_parse_packages();
is_deeply($_->{package_sources},
	  ['30-PKG-default.packages',
	   '31-PKG-network.packages',
	   '60-PKG-X11.packages',
	   '70-PKG-audio.packages',
	   'u2-PKG-update-test-2.packages',
	   'u1-PKG-update-test-1.packages'],
	  'packages test 4 has correct source list');
if (9 == @{$_->{packages}})
{
    is_deeply($_->{packages},
	      [qw(coreutils dash libc-bin util-linux iproute2
		  fontconfig-config pulseaudio-utils chromium evince)],
	      'packages test 4 has correct content');
}
else
{
    diag(join(' ', 'PACKAGES:', @{$_->{packages}}));
    is_deeply($_->{packages},
	      [qw(coreutils libc-bin util-linux iproute2
		  fontconfig-config pulseaudio-utils chromium evince)],
	      'packages test 4a has correct content');
}
is($_->{package_source}{evince}, 'u2-PKG-update-test-2.packages',
   'packages test 4 evince entry is correct');
is($_->{package_source}{'pulseaudio-utils'}, '70-PKG-audio.packages',
   'packages test 4 evince entry is correct');

#########################################################################
# test for mounts files:
my $path2something = TMP_PATH . '/usr/bin/2something';
_setup_file('/lxc/conf/u1-MNT-update-test-1.mounts',
	    '# 1st gets overwritten by 2nd',
	    '',
	    TMP_PATH . '/usr/bin/2something create=unused tmpfs',
	    $path2something);
_setup_file('/lxc/conf/u2-MNT-update-test-2.mounts',
	    '# same as in u1...',
	    '',
	    $path2something);
_setup_file('/lxc/conf/u1-SPC-update-test-1.special',
	    '# special test entry:',
	    '',
	    'lxc.namespace.keep=ipc');

$update_object = App::LXC::Container::Update->new('update-test-1');
$update_object->_parse_mounts();
obj_keys_in_range('mount_entry', 8, 12,
		  'mounts test 1 has correct entry count');
obj_keys_in_range('mount_source', 8, 12,
		  'mounts test 1 has correct source count');
is($update_object->{mount_entry}{$path2something},
   $path2something . ' ' . substr($path2something, 1)
   . ' none create=file,ro,bind 0 0',
   'mounts test 1 source entry is correct');
is($update_object->{mount_source}{$path2something}, 'u1-MNT-update-test-1.mounts',
   'mounts test 1 source entry is correct');

$update_object = App::LXC::Container::Update->new('update-test-2');
$update_object->_parse_master();		# now with X11 mounts!
$update_object->_parse_mounts();
obj_keys_in_range('mount_entry', 18, 22,
		  'mounts test 2 has correct entry count');
obj_keys_in_range('mount_source', 18, 22,
		  'mounts test 2 has correct source count');
is($update_object->{mount_entry}{$path2something},
   $path2something . ' ' . substr($path2something, 1)
   . ' none create=file,ro,bind 0 0',
   'mounts test 2 source entry is correct');
is($update_object->{mount_source}{$path2something}, 'u2-MNT-update-test-2.mounts',
   'mounts test 2 source entry is correct');
is($update_object->{mount_entry}{'/usr/share/icons'},
   '/usr/share/icons usr/share/icons none create=dir,ro,bind 0 0',
   'mounts test 2 source entry for X11 is correct');
is($update_object->{mount_source}{'/usr/share/icons'}, '61-MNT-X11.mounts',
   'mounts test 2 source entry for X11 is correct');

$update_object = App::LXC::Container::Update->new('update-test-1', 'update-test-2');
$update_object->_parse_mounts();
obj_keys_in_range('mount_entry', 8, 12,
		  'mounts test 3 has correct entry count');

t/06-update.t  view on Meta::CPAN

	 '#+ update-test-2, update-test-1 #+',
	 '# root:',
	 'lxc\.idmap = u 0 0 1',
	 'lxc\.idmap = u 1 100001 1000',
	 '# u1:',
	 'lxc\.idmap = u 1001 1001 1',
	 '# u2:',
	 'lxc\.idmap = u 1002 1002 1',
	 '# u3:',
	 'lxc\.idmap = u 1003 1003 1',
	 'lxc\.idmap = u 1004 101004 64532',
	 '# root:',
	 'lxc\.idmap = g 0 0 1',
	 'lxc\.idmap = g 1 100001 1000',
	 '# u1:',
	 'lxc\.idmap = g 1001 1001 1',
	 '# u2:',
	 'lxc\.idmap = g 1002 1002 1',
	 '# u3:',
	 'lxc\.idmap = g 1003 1003 1',
	 'lxc\.idmap = g 1004 101004 64532',
	 '',
	 '#+ special configuration #+',
	 'lxc.namespace.keep=ipc',
	 '',
	 '#+ container users #+',
	 '',
	 '#+ 40-MNT-default\.mounts #+',
	 # distributions may have additional non-symlink directories here,
	 # some are missing /dev/shm:
	 '.*(lxc\.mount\.entry = tmpfs dev/shm tmpfs create=dir,rw 0 0',
	 ')?lxc\.mount\.entry = /etc/login.defs etc/login.defs none create=file,ro,bind 0 0',
	 'lxc\.mount\.entry = /etc/pam.d etc/pam.d none create=dir,ro,bind 0 0',
	 'lxc\.mount\.entry = /etc/security etc/security none create=dir,ro,bind 0 0',
	 '.*lxc\.mount\.entry = tmpfs root tmpfs create=dir,rw,mode=700 0 0',
	 '.*lxc\.mount\.entry = /tmp tmp none create=dir,rw,bind 0 0',
	 'lxc\.mount\.entry = tmpfs var/tmp tmpfs create=dir,rw 0 0',
	 '(lxc\.mount\.entry = /etc/debian_version etc/debian_version none create=file,ro,bind 0 0',
	 ')?',
	 '#+ 41-MNT-network\.mounts #+',
	 'lxc\.mount\.entry = /etc/ssl/certs etc/ssl/certs none create=dir,ro,bind 0 0',
	 'lxc\.mount\.entry = /usr/lib/ssl usr/lib/ssl none create=dir,ro,bind 0 0',
	 'lxc\.mount\.entry = /usr/share/ca-certificates usr/share/ca-certificates none create=dir,ro,bind 0 0',
	 'lxc\.mount\.entry = /usr/share/ssl-cert usr/share/ssl-cert none create=dir,ro,bind 0 0',
	 '',
	 '#+ 61-MNT-X11\.mounts #+',
	 '[^#]+#+ u2-MNT-update-test-2\.mounts #+',
	 '',
	 '#+ u1-MNT-update-test-1\.mounts #+',
	 'lxc\.mount\.entry = /.+/bin/2something none create=file,ro,bind 0 0',
	 'lxc\.mount\.entry = /.+/bin/2something none create=file,ro,bind 0 0',
	 '',
	 '#+ 30-PKG-default\.packages #+',
	 '# coreutils',
	 '# dash',
	 '# libc-bin',
	 '# util-linux',
	 '#+ 31-PKG-network.packages #+',
	 '# iproute2',
	 '#+ 60-PKG-X11.packages #+',
	 '# fontconfig-config',
	 '#+ 70-PKG-audio\.packages #+',
	 '# pulseaudio-utils',
	 '#+ u2-PKG-update-test-2\.packages #+',
	 '# chromium',
	 '# evince',
	 '#+ u1-PKG-update-test-1\.packages #+',
	 '',
	 '#+ empty filters #+',
	 'lxc\.mount\.entry = tmpfs .+/tmp/var/log tmpfs create=dir,rw 0 0',
	 'lxc\.mount\.entry = tmpfs var/log tmpfs create=dir,rw 0 0',
	 '',
	 '#+ mounts derived from above packages #+',
	 'lxc\.mount\.entry = /.+/tmp/usr/bin/1chromium .+/tmp/usr/bin/1chromium none create=file,ro,bind 0 0',
	 'lxc\.mount\.entry = /.+/tmp/usr/lib/some/directory/with .+/tmp/usr/lib/some/directory/with none create=dir,ro,bind 0 0'
# helper expression to update test after modifying Data/*.pm (move up/down):
#(1?():(
##))
	);
    my $conf = '';
    if (-f CONF_ROOT . '/update-test-1.conf')
    {
	open my $in, '<', CONF_ROOT . '/update-test-1.conf'
	    or  die "can't open ", CONF_ROOT, '/update-test-1.conf: ', $!;
	$conf = join('', <$in>);
	close $in;
    }
    like($conf, qr{^$re}s, 'LXC configuration file looks correct');

    foreach (qw(bin lib lib32 lib64 libx32 sbin))
    {
    SKIP:{
	    -l '/' . $_  or  skip "/$_ not symbolic link on $os", 1;
	    ok(-l CONF_ROOT . '/update-test-1/' . $_,  'got link: /' . $_);
	}
    }
    my $tmp_sub = substr(TMP_PATH, 1);
    foreach (qw(root tmp var var/log),
	     map { $tmp_sub . '/' . $_ }
	     qw(usr usr/bin usr/lib usr/lib/some/directory/with var var/log))
    {
	ok(-d CONF_ROOT . '/update-test-1/' . $_,  'got directory: /' . $_);
    }
    ok(! -e  CONF_ROOT . '/update-test-1/usr/lib/some/directory/with/file-1.txt',
       'no file-1.txt in /update-test-1/usr/lib/some/directory/with');
    foreach my $bin (qw(1chromium 2something 3link))
    {
	$_ = $tmp_sub . '/usr/bin/' . $bin;
	ok(-f CONF_ROOT . '/update-test-1/' . $_,  'got file: /' . $_);
    }
    $_ = $tmp_sub . '/usr/bin/3link';
    ok(-l CONF_ROOT . '/update-test-1/' . $_,  'got link: /' . $_);
    is((stat(CONF_ROOT . '/update-test-1/root'))[2] & 07777, 0700,
       '/root has correct permission');
    is((stat(CONF_ROOT . '/update-test-1/tmp'))[2] & 07777, 01777,
       '/tmp has correct permission');

    #####################################################################
    # tests of local-network and network container:
    foreach my $network ('local-network', 'network')
    {



( run in 1.004 second using v1.01-cache-2.11-cpan-5735350b133 )