コード例 #1
0
def change_iface_bridge(ifname, new_bridge, ovs=None):
    """
    Change bridge on which interface was added.

    @param ifname: Iface name or Iface struct.
    @param new_bridge: Name of new bridge.
    """
    if ovs is None:
        ovs = __ovs
    br_manager_new = find_bridge_manager(new_bridge, ovs)
    if br_manager_new is None:
        raise BRNotExistError(new_bridge, "")

    if type(ifname) is str:
        (br_manager_old, br_old) = find_current_bridge(ifname, ovs)
        if not br_manager_old is None:
            br_manager_old.del_port(br_old, ifname)
        br_manager_new.add_port(new_bridge, ifname)
    elif issubclass(type(ifname), VirtIface):
        br_manager_old = find_bridge_manager(ifname.netdst, ovs)
        if not br_manager_old is None:
            br_manager_old.del_port(ifname.netdst, ifname.ifname)
        br_manager_new.add_port(new_bridge, ifname.ifname)
        ifname.netdst = new_bridge
    else:
        raise error.AutotestError("Network interface %s is wrong type %s." %
                                  (ifname, new_bridge))
コード例 #2
0
    def setup(self,
              tarball='oprofile-0.9.4.tar.bz2',
              local=None,
              *args,
              **dargs):
        if local is True:
            return

        try:
            self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
            utils.extract_tarball_to_dir(self.tarball, self.srcdir)
            os.chdir(self.srcdir)

            patch = os.path.join(self.bindir, "oprofile-69455.patch")
            utils.system('patch -p1 < %s' % patch)
            utils.configure('--with-kernel-support --prefix=' + self.srcdir)
            utils.make('-j %d' % utils.count_cpus())
            utils.make('install')
        except Exception:
            # Build from source failed.
            # But maybe can still use the local copy
            local_opcontrol = os.path.exists('/usr/bin/opcontrol')
            local_opreport = os.path.exists('/usr/bin/opreport')
            if local is False or not local_opcontrol or not local_opreport:
                raise error.AutotestError('No oprofile available')
        else:
            # if we managed to build, try again to pick binaries
            self._pick_binaries(True)
コード例 #3
0
def _validate_args(args, dargs, *funcs):
    """Verify that arguments are appropriate for at least one callable.

    Given a list of callables as additional parameters, verify that
    the proposed keyword arguments in dargs will each be accepted by at least
    one of the callables.

    NOTE: args is currently not supported and must be empty.

    Args:
      args: A tuple of proposed positional arguments.
      dargs: A dictionary of proposed keyword arguments.
      *funcs: Callables to be searched for acceptance of args and dargs.
    Raises:
      error.AutotestError: if an arg won't be accepted by any of *funcs.
    """
    all_co_flags = 0
    all_varnames = ()
    for func in funcs:
        all_co_flags |= func.func_code.co_flags
        all_varnames += func.func_code.co_varnames[:func.func_code.co_argcount]

    # Check if given args belongs to at least one of the methods below.
    if len(args) > 0:
        # Current implementation doesn't allow the use of args.
        raise error.TestError('Unnamed arguments not accepted. Please '
                              'call job.run_test with named args only')

    # Check if given dargs belongs to at least one of the methods below.
    if len(dargs) > 0:
        if not all_co_flags & 0x08:
            # no func accepts *dargs, so:
            for param in dargs:
                if not param in all_varnames:
                    raise error.AutotestError('Unknown parameter: %s' % param)
コード例 #4
0
ファイル: partition.py プロジェクト: andykobewu/autotest-1
    def __init__(self, file_img, file_size):
        """
        Creates a virtual partition, keeping record of the device created
        under /dev/mapper (device attribute) so test writers can use it
        on their filesystem tests.

        :param file_img: Path to the desired disk image file.
        :param file_size: Size of the desired image in Bytes.
        """
        logging.debug('Sanity check before attempting to create virtual '
                      'partition')
        try:
            os_dep.commands('sfdisk', 'losetup', 'kpartx')
        except ValueError as e:
            e_msg = 'Unable to create virtual partition: %s' % e
            raise error.AutotestError(e_msg)

        logging.debug('Creating virtual partition')
        self.img = self._create_disk_img(file_img, file_size)
        self.loop = self._attach_img_loop(self.img)
        self._create_single_partition(self.loop)
        self.device = self._create_entries_partition(self.loop)
        logging.debug('Virtual partition successfully created')
        logging.debug('Image disk: %s', self.img)
        logging.debug('Loopback device: %s', self.loop)
        logging.debug('Device path: %s', self.device)
コード例 #5
0
ファイル: readprofile.py プロジェクト: vi-patel/autotest
    def initialize(self):
        self.job.require_gcc()

        try:
            utils.system('grep -iq " profile=" /proc/cmdline')
        except error.CmdError:
            raise error.AutotestError('readprofile not enabled')

        self.cmd = self.srcdir + '/sys-utils/readprofile'
コード例 #6
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
 def _remove_disk_img(self):
     """
     Removes the disk image.
     """
     logging.debug('Removing disk image %s', self.img)
     try:
         os.remove(self.img)
     except Exception:
         e_msg = 'Error removing image file %s' % self.img
         raise error.AutotestError(e_msg)
コード例 #7
0
 def convert_version_to_int(version):
     """
     :param version: (int) Converted from version string 1.4.0 => int 140
     """
     if (isinstance(version, int)):
         return version
     try:
         int_ver = int(version.replace(".", ""))
     except:
         raise error.AutotestError("Wrong version format '%s'" % (version))
     return int_ver
コード例 #8
0
ファイル: openvswitch.py プロジェクト: xuesong-zhang/autotest
 def convert_version_to_int(version):
     """
     :param version: (int) Converted from version string 1.4.0 => int 140
     """
     if isinstance(version, int):
         return version
     try:
         a = re.findall('^(\d+)\.?(\d+)\.?(\d+)\-?', version)[0]
         int_ver = ''.join(a)
     except:
         raise error.AutotestError("Wrong version format '%s'" % version)
     return int_ver
コード例 #9
0
ファイル: cpuset.py プロジェクト: yumingfei/autotest
def create_container_with_mbytes_and_specific_cpus(name,
                                                   mbytes,
                                                   cpus=None,
                                                   root=SUPER_ROOT,
                                                   io={},
                                                   move_in=True,
                                                   timeout=0):
    """\
    Create a cpuset container and move job's current pid into it
    Allocate the list "cpus" of cpus to that container

            name = arbitrary string tag
            mbytes = reqested memory for job in megabytes
            cpus = list of cpu indicies to associate with the cpuset
                  defaults to all cpus avail with given root
            root = the parent cpuset to nest this new set within
                   '': unnested top-level container
            io = arguments for proportional IO containers
            move_in = True: Move current process into the new container now.
            timeout = must be 0: persist until explicitly deleted.
    """
    need_mem_containers()
    if not container_exists(root):
        raise error.AutotestError('Parent container "%s" does not exist' %
                                  root)
    if cpus is None:
        # default to biggest container we can make under root
        cpus = get_cpus(root)
    else:
        cpus = set(cpus)  # interface uses list
    if not cpus:
        raise error.AutotestError('Creating container with no cpus')
    name = os.path.join(root, name)  # path relative to super_root
    if os.path.exists(full_path(name)):
        raise error.AutotestError('Container %s already exists' % name)
    create_container_directly(name, mbytes, cpus)
    set_io_controls(name, **io)
    if move_in:
        move_self_into_container(name)
    return name
コード例 #10
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
 def _detach_img_loop(self):
     """
     Detaches the image file from the loopback device.
     """
     logging.debug('Detaching image %s from loop device %s', self.img,
                   self.loop)
     try:
         cmd = 'losetup -d %s' % self.loop
         utils.run(cmd)
     except error.CmdError, e:
         e_msg = ('Error detaching image %s from loop device %s: %s' %
                  (self.img, self.loop, e))
         raise error.AutotestError(e_msg)
コード例 #11
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
 def _remove_entries_partition(self):
     """
     Removes the entries under /dev/mapper for the partition associated
     to the loopback device.
     """
     logging.debug('Removing the entry on /dev/mapper for %s loop dev',
                   self.loop)
     try:
         cmd = 'kpartx -d %s' % self.loop
         utils.run(cmd)
     except error.CmdError, e:
         e_msg = 'Error removing entries for loop %s: %s' % (self.loop, e)
         raise error.AutotestError(e_msg)
コード例 #12
0
    def _create_disk_img(self, img_path, size):
        """
        Creates a disk image using dd.

        :param img_path: Path to the desired image file.
        :param size: Size of the desired image in Bytes.
        :return: Path of the image created.
        """
        logging.debug('Creating disk image %s, size = %d Bytes', img_path, size)
        try:
            cmd = 'dd if=/dev/zero of=%s bs=1024 count=%d' % (img_path, size)
            utils.run(cmd)
        except error.CmdError, e:
            e_msg = 'Error creating disk image %s: %s' % (img_path, e)
            raise error.AutotestError(e_msg)
コード例 #13
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
    def __init__(self, file_img, file_size):
        """
        Creates a virtual partition, keeping record of the device created
        under /dev/mapper (device attribute) so test writers can use it
        on their filesystem tests.

        @param file_img: Path to the desired disk image file.
        @param file_size: Size of the desired image in Bytes.
        """
        logging.debug('Sanity check before attempting to create virtual '
                      'partition')
        try:
            os_dep.commands('sfdisk', 'losetup', 'kpartx')
        except ValueError, e:
            e_msg = 'Unable to create virtual partition: %s' % e
            raise error.AutotestError(e_msg)
コード例 #14
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
    def _create_single_partition(self, loop_path):
        """
        Creates a single partition encompassing the whole 'disk' using cfdisk.

        @param loop_path: Path to the loopback device.
        """
        logging.debug('Creating single partition on %s', loop_path)
        try:
            single_part_cmd = '0,,c\n'
            sfdisk_file_path = '/tmp/create_partition.sfdisk'
            sfdisk_cmd_file = open(sfdisk_file_path, 'w')
            sfdisk_cmd_file.write(single_part_cmd)
            sfdisk_cmd_file.close()
            utils.run('sfdisk %s < %s' % (loop_path, sfdisk_file_path))
        except error.CmdError, e:
            e_msg = 'Error partitioning device %s: %s' % (loop_path, e)
            raise error.AutotestError(e_msg)
コード例 #15
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
    def _attach_img_loop(self, img_path):
        """
        Attaches a file image to a loopback device using losetup.

        @param img_path: Path of the image file that will be attached to a
                loopback device
        @returns: Path of the loopback device associated.
        """
        logging.debug('Attaching image %s to a loop device', img_path)
        try:
            cmd = 'losetup -f'
            loop_path = utils.system_output(cmd)
            cmd = 'losetup -f %s' % img_path
            utils.run(cmd)
        except error.CmdError, e:
            e_msg = ('Error attaching image %s to a loop device: %s' %
                     (img_path, e))
            raise error.AutotestError(e_msg)
コード例 #16
0
ファイル: partition.py プロジェクト: vincentInsz/autotest
    def _create_entries_partition(self, loop_path):
        """
        Takes the newly created partition table on the loopback device and
        makes all its devices available under /dev/mapper. As we previously
        have partitioned it using a single partition, only one partition
        will be returned.

        @param loop_path: Path to the loopback device.
        """
        logging.debug('Creating entries under /dev/mapper for %s loop dev',
                      loop_path)
        try:
            cmd = 'kpartx -a %s' % loop_path
            utils.run(cmd)
            l_cmd = 'kpartx -l %s | cut -f1 -d " "' % loop_path
            device = utils.system_output(l_cmd)
        except error.CmdError, e:
            e_msg = 'Error creating entries for %s: %s' % (loop_path, e)
            raise error.AutotestError(e_msg)
コード例 #17
0
ファイル: cpuset.py プロジェクト: yumingfei/autotest
def set_io_controls(container_name,
                    disks=[],
                    ioprio_classes=[PROPIO_NORMAL],
                    io_shares=[95],
                    io_limits=[0]):
    # set the propio controls for one container, for selected disks
    # writing directly to /dev/cgroup/container_name/io.io_service_level
    #    without using containerd or container.py
    # See wiki ProportionalIOScheduler for definitions
    # ioprio_classes: list of service classes, one per disk
    #    using numeric propio service classes as used by kernel API, namely
    #       1: RT, Real Time, aka PROPIO_PRIO
    #       2: BE, Best Effort, aka PROPIO_NORMAL
    #       3: PROPIO_IDLE
    # io_shares: list of disk-time-fractions, one per disk,
    #       as percentage integer 0..100
    # io_limits: list of limit on/off, one per disk
    #       0: no limit, shares use of other containers' unused disk time
    #       1: limited, container's use of disk time is capped to given DTF
    # ioprio_classes defaults to best-effort
    # io_limit defaults to no limit, use slack time
    if not disks:  # defaults to all drives
        disks = all_drive_names()
        io_shares = [io_shares[0]] * len(disks)
        ioprio_classes = [ioprio_classes[0]] * len(disks)
        io_limits = [io_limits[0]] * len(disks)
    if not (len(disks) == len(ioprio_classes) and len(disks) == len(io_shares)
            and len(disks) == len(io_limits)):
        raise error.AutotestError('Unequal number of values for io controls')
    service_level = io_attr(container_name, 'io_service_level')
    if not os.path.exists(service_level):
        return  # kernel predates propio features
        # or io cgroup is mounted separately from cpusets
    disk_infos = []
    for disk, ioclass, limit, share in zip(disks, ioprio_classes, io_limits,
                                           io_shares):
        parts = (disk, str(ioclass), str(limit), str(share))
        disk_info = ' '.join(parts)
        utils.write_one_line(service_level, disk_info)
        disk_infos.append(disk_info)
    logging.debug('set_io_controls of %s to %s', container_name,
                  ', '.join(disk_infos))
コード例 #18
0
ファイル: cpuset.py プロジェクト: yumingfei/autotest
def need_fake_numa():
    discover_container_style()
    if not fake_numa_containers:
        raise error.AutotestError('fake=numa not enabled by latest reboot')
コード例 #19
0
ファイル: cpuset.py プロジェクト: yumingfei/autotest
def need_mem_containers():
    discover_container_style()
    if not mem_isolation_on:
        raise error.AutotestError('Mem-isolation containers not enabled '
                                  'by latest reboot')