Beispiel #1
0
def test_replace():
    with warnings.catch_warnings():
        fname = os.tmpnam()
    
    t1 = 'some data'
    t2 = 'other text'
    header = '-' * 50
    footer = '=' * 50
    
    mkfl = lambda x : header + '\n' + x + '\n' + footer
    
    core.put_rf(fname, mkfl(t1))
    try:
        ok(core.replace_in_file(fname, t2, t1)) == False
        ok(core.replace_in_file(fname, t1, t2)) == True
        ok(core.get_rf(fname)) == mkfl(t2)
        
        sudo('chown root.root ' + fname)
        sudo('chmod o-w ' + fname)
        
        ok(lambda : core.replace_in_file(fname, t2, t1)).raises(SystemExit)
        
        ok(core.replace_in_file(fname, t1, t2, use_sudo=True)) == False
        ok(core.replace_in_file(fname, t2, t1, use_sudo=True)) == True
        
        ok(core.get_rf(fname)) == mkfl(t1)
    finally:
        sudo('rm ' + fname)
Beispiel #2
0
def prepare_node():
    with settings(hide('warnings', 'stderr'), warn_only=True):
        stop_riak()

    ip = env.host_string.split('@')[1]
    
    if replace_in_file('/etc/riak/vm.args',
                       '-name [email protected]',
                       '-name riak@' + ip,
                       use_sudo=True):
        
        replace_in_file('/etc/riak/app.config',
                '{http, [ {"127.0.0.1", 8098 } ]}',
                '{{http, [ {{"{0}", 8098 }} ]}}'.format(ip),
                 use_sudo=True)

        with settings(hide('warnings', 'stderr'), warn_only=True):
            sudo("riak-admin reip [email protected] riak@{0}".format(
                 env.host_string.split('@')[1]))
Beispiel #3
0
def install_nova(ip,
                 net,
                 net_prefix,
                 lvm_dev,
                 ext_network,
                 proj_name,
                 nova_adm='ubuntu',
                 dbpasswd='nova',
                 compute_backend='lxc'):
    install('bridge-utils,postgresql,python-psycopg2')
    
    replace_in_file("/etc/postgresql/9.1/main/postgresql.conf",
            "#listen_addresses\s+=\s+'localhost'(.*)",
            r"listen_addresses = '*'\1", use_sudo=True)
        
    
    pg_hba = '/etc/postgresql/9.1/main/pg_hba.conf'
    add = "host    all         all             0.0.0.0/0       md5"
    
    sudo("chmod a+rw " + pg_hba)
    try:
        append(pg_hba, add)
    finally:
        sudo("chmod 640 " + pg_hba)
    
    
    sudo("/etc/init.d/postgresql restart")
    
    install('glance')
    cmd = "CREATE user glancedbadmin;\n" + \
          "ALTER user glancedbadmin with password '{0}';\n" + \
          'CREATE DATABASE glance;\n' + \
          'GRANT ALL PRIVILEGES ON database glance TO glancedbadmin;\n'
    
    psql(cmd.format(dbpasswd))
    
    replace_in_file("/etc/glance/glance-registry.conf",
            'sql_connection = .*?$',
            'sql_connection = postgresql://glancedbadmin:{0}@{1}/glance'\
                                .format(dbpasswd,ip),
            use_sudo=True)
    
    sudo('restart glance-registry')
    
    install('rabbitmq-server,nova-common,nova-doc,python-nova,nova-api,' + \
      'nova-network,nova-volume,nova-objectstore,nova-scheduler,' + \
      'nova-compute,euca2ools,unzip,nova-compute-' + compute_backend)
    
    
    cmd = 'CREATE user novadbadmin;\n' + \
          "ALTER user novadbadmin with password '{0}';\n" + \
          'CREATE DATABASE nova;\n' + \
          'GRANT ALL PRIVILEGES ON database nova TO novadbadmin;\n'
    
    psql(cmd.format(dbpasswd))

    cfg = nova_config.format(ip, net, '8', dbpasswd, net_prefix)
    put_rf('/etc/nova/nova.conf', cfg , use_sudo=True)

    use_lvm = False
    if use_lvm:
        install('iscsitarget,iscsitarget-dkms')
    
        sudo("sed -i 's/false/true/g' /etc/default/iscsitarget")
        sudo("service iscsitarget restart")
        sudo("pvcreate " + lvm_dev)
        sudo("vgcreate nova-volumes " + lvm_dev)

    sudo("chown -R root:nova /etc/nova")
    sudo("chmod 644 /etc/nova/nova.conf")
    
    all_nova_services = ('libvirt-bin,nova-network,nova-compute,nova-api,' + \
                'nova-objectstore,nova-scheduler,' + \
                'glance-api,glance-registry,nova-volume').split(',')
     
    for service in all_nova_services:
        upstart_restart(service)
    
    sudo('nova-manage db sync')

    sudo('nova-manage network create private {0} 1 255'.format(net))
    sudo('nova-manage floating create --ip_range=' + ext_network)
    sudo('nova-manage user admin novaadmin')
    sudo('nova-manage project create {0} novaadmin'.format(proj_name))

    for service in all_nova_services:
        upstart_restart(service)

    sudo('mkdir -p /home/{0}/creds'.format(nova_adm))
    
    sudo('nova-manage project zipfile proj novaadmin ' + \
         '/home/{0}/creds/novacreds.zip'.format(nova_adm))
    
    with cd('/home/{0}/creds'.format(nova_adm)):
        sudo('unzip novacreds.zip')
        sudo('chown {0}:{0} /home/{0}/creds -R'.format(nova_adm))

    res = sudo('nova-manage user exports novaadmin')
    
    EC2_ACCESS_KEY = None
    EC2_SECRET_KEY = None
    
    for string in str(res).split('\n'):
        string = string.strip()
        if string.startswith('export EC2_ACCESS_KEY='):
            EC2_ACCESS_KEY = string[len('export EC2_ACCESS_KEY='):]
        elif string.startswith('export EC2_SECRET_KEY='):
            EC2_SECRET_KEY = string[len('export EC2_SECRET_KEY='):]


    replace_in_file('/home/{0}/creds/novarc'.format(nova_adm),
            'export EC2_ACCESS_KEY="novaadmin:proj"'.format(proj_name),
            'export EC2_ACCESS_KEY="{0}:{1}"'.format(EC2_ACCESS_KEY, proj_name))

    replace_in_file('/home/{0}/creds/novarc'.format(nova_adm),
            'export NOVA_PROJECT_ID="proj"',
            'export NOVA_PROJECT_ID="{0}"'.format(proj_name))

    return