示例#1
0
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'
示例#2
0
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
示例#3
0
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
示例#4
0
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'
示例#5
0
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"
示例#6
0
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'
示例#7
0
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')
示例#8
0
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')
示例#9
0
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')
示例#10
0
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'
示例#11
0
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')
示例#12
0
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")
示例#13
0
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')
示例#14
0
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')
示例#15
0
def test_run_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert run("whoami") == "root"
示例#16
0
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')
示例#17
0
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')
示例#18
0
def test_sudo_nobody_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert sudo('whoami', user='******') == 'nobody'
示例#19
0
def test_sudo_root_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert sudo('whoami') == 'root'
示例#20
0
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()
示例#21
0
def install():
    with guest(VM):
        update()
        get_CF()
示例#22
0
def test_sudo_nobody_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert sudo('whoami', user='******') == 'nobody'
示例#23
0
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()
示例#24
0
def test_sudo_nobody_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert sudo("whoami", user="******") == "nobody"
示例#25
0
def test_sudo_root_in_guest_context_manager(container):
    from fabtools.openvz import guest

    with guest(container):
        assert sudo('whoami') == 'root'