def test_sudo_nobody_file_ownership_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): with cd('/tmp'): sudo('touch tata', user='******') assert run('stat -c "%U" tata') == 'nobody'
def test_put_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): local('echo "toto" > /tmp/toto') put('/tmp/toto', '/tmp/toto') assert run('test -f /tmp/toto').succeeded
def test_sudo_nobody_file_ownership_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): with cd("/tmp"): sudo("touch tata", user="******") assert run('stat -c "%U" tata') == "nobody"
def test_install_redis_in_guest_context_manager(container): from fabtools.openvz import guest from fabtools.require.redis import VERSION, instance with guest(container): instance('test') assert is_file('/etc/redis/test.conf') assert run('echo PING | /opt/redis-%s/redis-cli' % VERSION) == 'PONG'
def test_require_directory_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): require_directory('/tmp/newdir') with cd('/tmp/newdir'): run('touch baz') assert is_file('/tmp/newdir/baz')
def test_cd_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): with cd('/tmp'): run('touch bar') assert is_file('bar') assert is_file('/tmp/bar')
def test_cd_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): with cd("/tmp"): run("touch bar") assert is_file("bar") assert is_file("/tmp/bar")
def test_install_debian_package_in_guest_context_manager(container): from fabtools.deb import update_index from fabtools.openvz import guest from fabtools.require.deb import package with guest(container): update_index() package('htop') assert is_file('/usr/bin/htop')
def test_run_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): assert run("whoami") == "root"
def test_require_file_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): require_file('/tmp/foo') assert is_file('/tmp/foo')
def test_sudo_nobody_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): assert sudo('whoami', user='******') == 'nobody'
def test_sudo_root_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): assert sudo('whoami') == 'root'
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()
def install(): with guest(VM): update() get_CF()
def test_sudo_nobody_in_guest_context_manager(container): from fabtools.openvz import guest with guest(container): assert sudo("whoami", user="******") == "nobody"