~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-checkbox/bin/virtualization

  • Committer: Daniel Manrique
  • Author(s): Sylvain Pineau
  • Date: 2014-12-18 19:26:57 UTC
  • mfrom: (3512.1.1 launchpad/fix-1403933)
  • Revision ID: daniel_manrique-20141218192657-h1e1rd733ikbawz4
"automatic merge of lp:~sylvain-pineau/checkbox/fix-1403933/ by tarmac [r=sylvain-pineau][bug=1403933][author=sylvain-pineau]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from argparse import ArgumentParser
27
27
import configparser
28
 
from enum import Enum
29
28
import os
30
29
import re
31
30
import logging
56
55
# on architectures that don't (yet) have a bootloader
57
56
# in the disk image that we can chain to, and instead
58
57
# we need to have qemu load boot files externally
59
 
CLOUD_IMAGE_TYPE = Enum('CLOUD_IMAGE_TYPE', 'TAR DISK')
60
 
QEMU_DISK_TYPE = Enum('QEMU_DISK_TYPE', 'SD VIRTIO VIRTIO_BLK')
 
58
CLOUD_IMAGE_TYPE_TAR = 1
 
59
CLOUD_IMAGE_TYPE_DISK = 2
 
60
 
 
61
QEMU_DISK_TYPE_SD = 1
 
62
QEMU_DISK_TYPE_VIRTIO = 2
 
63
QEMU_DISK_TYPE_VIRTIO_BLK = 3
61
64
 
62
65
QEMU_ARCH_CONFIG = {
63
66
    'arm64': {
64
 
        'cloudimg_type': CLOUD_IMAGE_TYPE.TAR,
 
67
        'cloudimg_type': CLOUD_IMAGE_TYPE_TAR,
65
68
        'cloudimg_arch': 'arm64',
66
69
        'qemu_bin': 'qemu-system-aarch64',
67
 
        'qemu_disk_type': QEMU_DISK_TYPE.VIRTIO_BLK,
 
70
        'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO_BLK,
68
71
        'qemu_extra_args': [
69
72
            '-machine', 'virt',
70
73
            '-cpu', 'host',
73
76
        ],
74
77
    },
75
78
    'armhf': {
76
 
        'cloudimg_type': CLOUD_IMAGE_TYPE.TAR,
 
79
        'cloudimg_type': CLOUD_IMAGE_TYPE_TAR,
77
80
        'cloudimg_arch': 'armhf',
78
81
        'qemu_bin': 'qemu-system-arm',
79
 
        'qemu_disk_type': QEMU_DISK_TYPE.VIRTIO_BLK,
 
82
        'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO_BLK,
80
83
        'qemu_extra_args': [
81
84
            '-machine', 'virt',
82
85
            '-cpu', 'host',
85
88
        ],
86
89
    },
87
90
    'amd64': {
88
 
        'cloudimg_type': CLOUD_IMAGE_TYPE.DISK,
 
91
        'cloudimg_type': CLOUD_IMAGE_TYPE_DISK,
89
92
        'cloudimg_arch': 'i386',
90
93
        'qemu_bin': 'qemu-system-x86_64',
91
 
        'qemu_disk_type': QEMU_DISK_TYPE.VIRTIO,
 
94
        'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO,
92
95
        'qemu_extra_args': [
93
96
            '-machine', 'accel=kvm:tcg',
94
97
        ],
95
98
    },
96
99
    'i386': {
97
 
        'cloudimg_type': CLOUD_IMAGE_TYPE.DISK,
 
100
        'cloudimg_type': CLOUD_IMAGE_TYPE_DISK,
98
101
        'cloudimg_arch': 'i386',
99
102
        'qemu_bin': 'qemu-system-x86_64',
100
 
        'qemu_disk_type': QEMU_DISK_TYPE.VIRTIO,
 
103
        'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO,
101
104
        'qemu_extra_args': [
102
105
            '-machine', 'accel=kvm:tcg',
103
106
        ],
123
126
            self.params = self.params + self.config['qemu_extra_args']
124
127
 
125
128
        self.append = []
126
 
        if self.config['cloudimg_type'] == CLOUD_IMAGE_TYPE.TAR:
 
129
        if self.config['cloudimg_type'] == CLOUD_IMAGE_TYPE_TAR:
127
130
            self.append = self.append + [
128
131
                'console=ttyAMA0',
129
132
                'earlyprintk=serial',
143
146
 
144
147
    def add_drive(self, cloudimg):
145
148
        drive = ["-drive"]
146
 
        if self.config['qemu_disk_type'] == QEMU_DISK_TYPE.SD:
 
149
        if self.config['qemu_disk_type'] == QEMU_DISK_TYPE_SD:
147
150
            drive = drive + ["file=%s,if=sd,cache=writeback" % (cloudimg)]
148
 
        elif self.config['qemu_disk_type'] == QEMU_DISK_TYPE.VIRTIO:
 
151
        elif self.config['qemu_disk_type'] == QEMU_DISK_TYPE_VIRTIO:
149
152
            drive = drive + ["file=%s,if=virtio" % (cloudimg)]
150
 
        elif self.config['qemu_disk_type'] == QEMU_DISK_TYPE.VIRTIO_BLK:
 
153
        elif self.config['qemu_disk_type'] == QEMU_DISK_TYPE_VIRTIO_BLK:
151
154
            drive = drive + [ "file=%s,if=none,id=disk.%d"
152
155
                              % (cloudimg, self.drive_id) ]
153
156
            drive = drive + [ "-device", "virtio-blk-device,drive=disk.%d"
181
184
        # Construct URL
182
185
        cloud_url = "http://cloud-images.ubuntu.com"
183
186
 
184
 
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE.TAR:
 
187
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_TAR:
185
188
            cloud_iso = "%s-server-cloudimg-%s.tar.gz" % (release, self.qemu_config['cloudimg_arch'])
186
 
        elif self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE.DISK:
 
189
        elif self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_DISK:
187
190
            cloud_iso = "%s-server-cloudimg-%s-disk1.img" % (release, self.qemu_config['cloudimg_arch'])
188
191
        else:
189
192
            logging.error("Unknown cloud image type")
204
207
            return False
205
208
 
206
209
        # Unpack img file from tar
207
 
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE.TAR:
 
210
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_TAR:
208
211
            cloud_iso_tgz = tarfile.open(cloud_iso)
209
212
            cloud_iso = cloud_iso.replace('tar.gz', 'img')
210
213
            cloud_iso_tgz.extract(cloud_iso)
227
230
        # Assume that a tar type image is not self-bootable, so
228
231
        # therefore requires explicit bootfiles (otherwise, why
229
232
        # not just use the disk format directly?
230
 
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE.TAR:
 
233
        if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_TAR:
231
234
            for dir in ['/boot', '/']:
232
235
                kernel = os.path.join(dir, 'vmlinuz')
233
236
                initrd = os.path.join(dir, 'initrd.img')