def test_list_container_ids(container): from fabtools.openvz import list_ctids assert 'debian' in list_ctids()
def setup_containers(): require.deb.package('vzctl') NAME = 'debian' TEMPLATE = 'debian-6.0-x86_64' IPADD = '192.168.1.100' NAMESERVERS = fabtools.network.nameservers() require.openvz.template(TEMPLATE) with container(NAME, TEMPLATE, hostname=NAME, ipadd=IPADD) as ct: # Make sure the container is started if not ct.running(): ct.start() # Set up name servers ct.set(nameserver=NAMESERVERS) # Wait until we can ping the container from the host with settings(warn_only=True): timeout = 0 while True: if run('ping -c 1 %s' % IPADD).succeeded: break time.sleep(1) timeout += 1 assert timeout < 10, "Timeout trying to ping container" # Check run/sudo with guest(NAME): assert run('whoami') == 'root' assert sudo('whoami') == 'root' assert sudo('whoami', user='******') == 'nobody' # Check put with guest(name): local('echo "toto" > /tmp/toto') put('/tmp/toto', '/tmp/toto') assert run('test -f /tmp/toto').succeeded # Run more complex tasks inside container with guest(NAME): # Check require.file() require.file('/tmp/foo') assert fabtools.files.is_file('/tmp/foo') # Check cd() inside container with cd('/tmp'): run('touch bar') assert fabtools.files.is_file('bar') assert fabtools.files.is_file('/tmp/bar') # This directory does not exist in the host require.directory('/tmp/newdir') with cd('/tmp/newdir'): run('touch baz') assert fabtools.files.is_file('/tmp/newdir/baz') # Check that sudo as user works with cd('/tmp'): sudo('touch tata', user='******') assert run('stat -c "%U" tata') == 'nobody' # Check Debian package install fabtools.deb.update_index() require.deb.package('htop') assert fabtools.files.is_file('/usr/bin/htop') # Install Redis require.redis.instance('test') assert fabtools.files.is_file('/etc/redis/test.conf') assert run('echo PING | /opt/redis-2.4.15/redis-cli') == 'PONG' assert 'debian' in openvz.list_ctids() # Stop and destroy container with container(NAME, TEMPLATE, hostname=NAME, ipadd=IPADD) as ct: ct.stop() ct.destroy() assert 'debian' not in openvz.list_ctids()