Beispiel #1
0
 def test_get(self):
     vmimage.get(
         self.vmimage_name,
         self.vmimage_version,
         self.vmimage_build,
         self.vmimage_arch,
     )
Beispiel #2
0
    def download_boot(self):
        self.log.debug('Looking for and selecting a qemu-img binary to be '
                       'used to create the bootable snapshot image')
        # If qemu-img has been built, use it, otherwise the system wide one
        # will be used.  If none is available, the test will cancel.
        qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
        if not os.path.exists(qemu_img):
            qemu_img = find_command('qemu-img', False)
        if qemu_img is False:
            self.cancel('Could not find "qemu-img", which is required to '
                        'create the bootable image')
        vmimage.QEMU_IMG = qemu_img

        self.log.info('Downloading/preparing boot image')
        # Fedora 31 only provides ppc64le images
        image_arch = self.arch
        if image_arch == 'ppc64':
            image_arch = 'ppc64le'
        try:
            boot = vmimage.get('fedora',
                               arch=image_arch,
                               version='31',
                               checksum=self.chksum,
                               algorithm='sha256',
                               cache_dir=self.cache_dirs[0],
                               snapshot_dir=self.workdir)
        except:
            self.cancel('Failed to download/prepare boot image')
        return boot.path
Beispiel #3
0
def download_image(distro, version=None, arch=None):
    """
    Downloads the vmimage to the cache directory if doesn't already exist

    :param distro: Name of image distribution
    :type distro: str
    :param version: Version of image
    :type version: str
    :param arch: Architecture of image
    :type arch: str
    :raise AttributeError: When image can't be downloaded
    :return: Information about downloaded image
    :rtype: dict
    """
    cache_dir = data_dir.get_cache_dirs()[0]
    image_info = vmimage.get(name=distro,
                             version=version,
                             arch=arch,
                             cache_dir=cache_dir)
    file_path = image_info.base_image
    image = {
        'name': distro,
        'version': image_info.version,
        'arch': image_info.arch,
        'file': file_path
    }
    return image
Beispiel #4
0
def download_image(distro, version=None, arch=None):
    """
    Downloads the vmimage to the cache directory if doesn't already exist

    :param distro: Name of image distribution
    :type distro: str
    :param version: Version of image
    :type version: str
    :param arch: Architecture of image
    :type arch: str
    :raise AttributeError: When image can't be downloaded
    :return: Information about downloaded image
    :rtype: dict
    """
    cache_dir = settings.as_dict().get("datadir.paths.cache_dirs")[0]
    image_info = vmimage.get(name=distro,
                             version=version,
                             arch=arch,
                             cache_dir=cache_dir)
    file_path = image_info.base_image
    image = {
        "name": distro,
        "version": image_info.version,
        "arch": image_info.arch,
        "file": file_path,
    }
    return image
    def setUp(self):
        """
        configure the virtual machine that will be used in the tests
        """
        self.cmd_run = self.params.get('command', default=None)
        self.debug = self.params.get('debug', default=False)
        self.iso_src = self.params.get('minishift_iso_src_path',
                                       default='~/.contra-env-setup/minishift')
        self.iso_dest = self.params.get(
            'minishift_iso_dest_path', default='~/.contra-env-setup/minishift')
        self.username = self.params.get('username', default='avocado')
        self.password = self.params.get('password', default='avocado')
        self.vm_name = self.params.get('vm_name',
                                       default='contra-env-setup-01')
        self.extra_cmd_run = self.params.get('extra_command', default=None)
        self.distro = self.params.get('distro', default='Fedora')
        self.pkg_mgm = self.params.get('pkg_mgm', default='dnf')
        self.os_variant = self.params.get('os_variant', default='fedora27')

        project = 'https://github.com/CentOS-PaaS-SIG/contra-env-setup.git'
        repo = self.params.get('repo', default=project)
        branch = self.params.get('branch', default='master')

        git.get_repo(repo, branch=branch, destination_dir=self.workdir)

        self.image = vmimage.get(self.distro,
                                 cache_dir='~/avocado/data/cache/')

        process.run('{qemu} resize '
                    '{image_path} 40G'.format(qemu=_QEMU_BIN,
                                              image_path=self.image.path))

        cmd = [
            _VIRTINST_BIN, '--import', '--noautoconsole', '--connect',
            'qemu:///system', '--name', self.vm_name, '--disk',
            '%s,size=40' % self.image.path, '--graphics', 'vnc', '--cpu',
            'host', '--memory', '7168', '--vcpus', '4', '--os-variant',
            self.os_variant, '--disk',
            '%s,device=cdrom,format=iso' %
            create_cloudinit_cdrom(self.vm_name, self.username, self.password)
        ]

        process.run(' '.join(cmd))

        wait.wait_for(ip_available, timeout=60, args=[self.vm_name])

        cmd = [
            _VIRSH_BIN, '--connect', 'qemu:///system', 'domifaddr',
            self.vm_name
        ]
        result = process.run(' '.join(cmd))

        for line in result.stdout_text.splitlines():
            if 'ipv4' in line:
                self.vm_ip = line.split()[3].split('/')[0]

        wait.wait_for(ssh_available,
                      timeout=60,
                      args=[self.vm_ip, self.username])
def main():
    for image in KNOWN_IMAGES:
        name, version, arch, checksum, algorithm = image
        print("%s version %s (%s): " % (name, version, arch), end='')
        download = vmimage.get(name=name, version=version, arch=arch,
                               checksum=checksum, algorithm=algorithm,
                               cache_dir=data_dir.get_cache_dirs()[0])
        print(download.base_image)
Beispiel #7
0
def main():
    for image in KNOWN_IMAGES:
        name, version, arch, checksum, algorithm = image
        print(f"{name} version {version} ({arch}): ", end='')
        cache_dir = settings.as_dict().get('datadir.paths.cache_dirs')[0]
        download = vmimage.get(name=name, version=version, arch=arch,
                               checksum=checksum, algorithm=algorithm,
                               cache_dir=cache_dir)
        print(download.base_image)
Beispiel #8
0
    def setUp(self):
        repo = self.params.get(
            'repo',
            default='https://github.com/CentOS-PaaS-SIG/contra-env-setup.git')
        branch = self.params.get('branch', default='master')
        git.get_repo(repo, branch=branch, destination_dir=self.workdir)

        # VM Image
        distro = self.params.get('distro', default='Fedora')
        image = vmimage.get(distro, cache_dir='~/avocado/data/cache/')

        # Resize storage of VM
        qemu_img_bin = utils_path.find_command('qemu-img')
        process.run('%s resize %s +20G' % (qemu_img_bin, image.path))

        self.vm.add_image(image.path, cloudinit=True, snapshot=False)

        # Network
        self.vm.args.extend([
            '-device',
            'virtio-net-pci,id=avocado_nic,netdev=device_avocado_nic'
        ])
        self.vm.args.extend(
            ['-netdev', 'user,id=device_avocado_nic,hostfwd=tcp::12345-:22'])

        # CPU/Memmory
        self.vm.args.extend(['-m', '7168'])
        self.vm.args.extend(['-cpu', 'host'])
        self.vm.args.extend(['-accel', 'kvm'])

        # Headless
        self.vm.args.extend(['-display', 'none', '-vga', 'none'])

        # Run!
        self.vm.launch()

        # Wait VM to be UP
        with GetConsole(self.vm) as console:
            console.sendline('sudo resize2fs /dev/sda1')