App-LXC-Container

 view release on metacpan or  search on metacpan

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

	 '#+ 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')
    {
	output_like		# last name becomes container name!
	{   App::LXC::Container::update($network);   }
	qr{^$},
	qr{\A$re_err2$re_err3\Z},
	'test run for container "' . $network . '" had expected output';

	my $conf_file = CONF_ROOT . '/' . $network . '.conf';
	ok(-f $conf_file,
	   'LXC configuration file has been created - ' . $network);
	my $net_key = $network eq 'network' ? 'G' : 'L';
	my $net_id = $network eq 'network' ? 3 : 2;
	$re = join
	    ("\n",
	     '^# container description created by App::LXC::Container::Update',
	     '# MASTER: ' . $net_key . $net_id . ',-,-',
	     'lxc\.uts\.name = ' . $network,
	     'lxc\.rootfs\.path = /.+/tmp/lxc/' . $network,
	     'lxc\.rootfs\.options = idmap=container',
	     '',
	     '#+ ' . $network . ', 10-NET-default\.conf #+',
	     'lxc\.net\.0\.type = veth',
	     'lxc\.net\.0\.flags = up',
	     'lxc\.net\.0\.link = lxcbr0',
	     'lxc\.net\.0\.name = eth0',
	     'lxc\.net\.0\.ipv4\.address = 10\.0\.3\.' . $net_id . '/24',
	     'lxc\.net\.0\.hwaddr = 00:16:3e:xx:xx:xx',
	     '',
	     '#+ 20-DEV-default\.conf #+',
	     'lxc\.pty\.max = 8',
	     'lxc\.mount\.auto = cgroup:ro proc:mixed sys:ro',
	     '',
	     '#+ -no privileged users- #+',
	     'lxc\.idmap = u 0 100000 65536',
	     'lxc\.idmap = g 0 100000 65536',
	     '',
	     '#+ 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',
	     '',
	     '#+ 30-PKG-default\.packages #+',
	     '# coreutils',
	     '# dash',
	     '# libc-bin',
	     '# util-linux',
	     '#+ 31-PKG-network.packages #+',
	     '# iproute2',
	     '',
	     '#+ empty filters #+',
	     'lxc.mount.entry = tmpfs var/log tmpfs create=dir,rw 0 0',
	     '',
	     '#+ mounts derived from above packages #+',
	     'lxc\.mount\.entry = /.+/tmp/usr/bin/2something .+/tmp/usr/bin/2something none create=file,ro,bind 0 0'
# helper expression to update test after modifying Data/*.pm (move up/down):
#(1?():(
#))
	    );
	if (-f $conf_file)
	{
	    open my $in, '<', $conf_file
		or  die "can't open ", $conf_file . ': ', $!;
	    $conf = join('', <$in>);
	    close $in;
	}
	like($conf, qr{^$re}s,
	     'LXC configuration file looks correct - ' . $network);

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

} # end of big SKIP block



( run in 1.945 second using v1.01-cache-2.11-cpan-ceb78f64989 )