~rackspace-titan/nova/lp824601

« back to all changes in this revision

Viewing changes to nova/virt/libvirt/connection.py

  • Committer: Tarmac
  • Author(s): Thierry Carrez
  • Date: 2011-08-11 12:34:04 UTC
  • mfrom: (1380.3.11 privsep1)
  • Revision ID: tarmac-20110811123404-43rtqmht9n2gx7un
* Removes rogue direct usage of subprocess module by proper utils.execute calls
* Adds a run_as_root parameter to utils.execute, that prefixes your command with FLAG.root_helper (which defaults to 'sudo')
* Turns all sudo calls into run_as_root=True calls
* Update fakes accordingly
* Replaces usage of "sudo -E" and "addl_env" parameter into passing environment in the command (allows it to be compatible with alternative sudo_helpers)
* Additionally, forces close_fds=True on all utils.execute calls, since it's a more secure default

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import random
44
44
import re
45
45
import shutil
46
 
import subprocess
47
46
import sys
48
47
import tempfile
49
48
import time
612
611
 
613
612
        if virsh_output.startswith('/dev/'):
614
613
            LOG.info(_("cool, it's a device"))
615
 
            out, err = utils.execute('sudo', 'dd',
 
614
            out, err = utils.execute('dd',
616
615
                                     "if=%s" % virsh_output,
617
616
                                     'iflag=nonblock',
 
617
                                     run_as_root=True,
618
618
                                     check_exit_code=False)
619
619
            return out
620
620
        else:
637
637
        console_log = os.path.join(FLAGS.instances_path, instance['name'],
638
638
                                   'console.log')
639
639
 
640
 
        utils.execute('sudo', 'chown', os.getuid(), console_log)
 
640
        utils.execute('chown', os.getuid(), console_log, run_as_root=True)
641
641
 
642
642
        if FLAGS.libvirt_type == 'xen':
643
643
            # Xen is special
685
685
        ajaxterm_cmd = 'sudo socat - %s' \
686
686
                       % get_pty_for_instance(instance['name'])
687
687
 
688
 
        cmd = '%s/tools/ajaxterm/ajaxterm.py --command "%s" -t %s -p %s' \
689
 
              % (utils.novadir(), ajaxterm_cmd, token, port)
 
688
        cmd = ['%s/tools/ajaxterm/ajaxterm.py' % utils.novadir(),
 
689
               '--command', ajaxterm_cmd, '-t', token, '-p', port]
690
690
 
691
 
        subprocess.Popen(cmd, shell=True)
 
691
        utils.execute(cmd)
692
692
        return {'token': token, 'host': host, 'port': port}
693
693
 
694
694
    def get_host_ip_addr(self):
947
947
                        ' data into image %(img_id)s (%(e)s)') % locals())
948
948
 
949
949
        if FLAGS.libvirt_type == 'uml':
950
 
            utils.execute('sudo', 'chown', 'root', basepath('disk'))
 
950
            utils.execute('chown', 'root', basepath('disk'), run_as_root=True)
951
951
 
952
952
    if FLAGS.libvirt_type == 'uml':
953
953
        _disk_prefix = 'ubd'