Example #1
0
    def test_template_integrity(self):
        inst = model.Model('test:///default', objstore_loc=self.tmp_store)

        with RollbackContext() as rollback:
            net_name = 'test-network'
            net_args = {
                'name': net_name,
                'connection': 'nat',
                'subnet': '127.0.100.0/24'
            }
            inst.networks_create(net_args)

            path = '/tmp/kimchi-iso/'
            if not os.path.exists(path):
                os.makedirs(path)
            iso = path + 'ubuntu12.04.iso'
            iso_gen.construct_fake_iso(iso, True, '12.04', 'ubuntu')

            params = {
                'name': 'test',
                'memory': 1024,
                'cpus': 1,
                'networks': ['test-network'],
                'cdrom': iso
            }
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'test')

            inst.network_delete(net_name)
            shutil.rmtree(path)

            info = inst.template_lookup('test')
            self.assertEquals(info['invalid']['cdrom'], [iso])
            self.assertEquals(info['invalid']['networks'], [net_name])
Example #2
0
def setUpModule():
    global test_server, model

    patch_auth()
    model = MockModel('/tmp/obj-store-test')
    test_server = run_server(test_mode=True, model=model)
    iso_gen.construct_fake_iso(MOCK_ISO, True, '14.04', 'ubuntu')
Example #3
0
    def test_template_integrity(self):
        inst = model.Model('test:///default',
                           objstore_loc=self.tmp_store)

        with RollbackContext() as rollback:
            net_name = 'test-network'
            net_args = {'name': net_name,
                        'connection': 'nat',
                        'subnet': '127.0.100.0/24'}
            inst.networks_create(net_args)

            path = '/tmp/kimchi-iso/'
            if not os.path.exists(path):
                os.makedirs(path)
            iso = path + 'ubuntu12.04.iso'
            iso_gen.construct_fake_iso(iso, True, '12.04', 'ubuntu')

            params = {'name': 'test', 'memory': 1024, 'cpus': 1,
                      'networks': ['test-network'], 'cdrom': iso}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'test')

            inst.network_delete(net_name)
            shutil.rmtree(path)

            info = inst.template_lookup('test')
            self.assertEquals(info['invalid']['cdrom'], [iso])
            self.assertEquals(info['invalid']['networks'], [net_name])
Example #4
0
def setUpModule():
    global test_server, model

    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model
    iso_gen.construct_fake_iso(MOCK_ISO, True, '14.04', 'ubuntu')
Example #5
0
 def setUp(self):
     self.tmp_store = '/tmp/kimchi-store-test'
     self.iso_path = '/tmp/kimchi-model-iso/'
     if not os.path.exists(self.iso_path):
         os.makedirs(self.iso_path)
     self.kimchi_iso = self.iso_path + 'ubuntu12.04.iso'
     iso_gen.construct_fake_iso(self.kimchi_iso, True, '12.04', 'ubuntu')
Example #6
0
    def test_deep_scan(self):
        inst = model.Model(None, objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            path = '/tmp/kimchi-images/tmpdir'
            if not os.path.exists(path):
                os.makedirs(path)
            iso_gen.construct_fake_iso(
                '/tmp/kimchi-images/tmpdir/'
                'ubuntu12.04.iso', True, '12.04', 'ubuntu')
            iso_gen.construct_fake_iso('/tmp/kimchi-images/sles10.iso', True,
                                       '10', 'sles')

            args = {
                'name': 'kimchi-scanning-pool',
                'path': '/tmp/kimchi-images',
                'type': 'kimchi-iso'
            }
            inst.storagepools_create(args)
            rollback.prependDefer(shutil.rmtree, '/tmp/kimchi-images')
            rollback.prependDefer(shutil.rmtree, args['path'])
            rollback.prependDefer(inst.storagepool_deactivate, args['name'])

            time.sleep(1)
            volumes = inst.storagevolumes_get_list(args['name'])
            self.assertEquals(len(volumes), 2)
Example #7
0
    def test_deep_scan(self):
        inst = model.Model(None, objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            deep_path = os.path.join(TMP_DIR, 'deep-scan')
            subdir_path = os.path.join(deep_path, 'isos')
            if not os.path.exists(subdir_path):
                os.makedirs(subdir_path)
            ubuntu_iso = os.path.join(deep_path, 'ubuntu12.04.iso')
            sles_iso = os.path.join(subdir_path, 'sles10.iso')
            iso_gen.construct_fake_iso(ubuntu_iso, True, '12.04', 'ubuntu')
            iso_gen.construct_fake_iso(sles_iso, True, '10', 'sles')

            args = {
                'name': 'kimchi-scanning-pool',
                'path': deep_path,
                'type': 'kimchi-iso'
            }
            inst.storagepools_create(args)
            rollback.prependDefer(shutil.rmtree, deep_path)
            rollback.prependDefer(shutil.rmtree, args['path'])
            rollback.prependDefer(inst.storagepool_deactivate, args['name'])

            time.sleep(1)
            volumes = inst.storagevolumes_get_list(args['name'])
            self.assertEquals(len(volumes), 2)
Example #8
0
def setUpModule():
    global test_server, model

    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model
    iso_gen.construct_fake_iso(MOCK_ISO, True, '14.04', 'ubuntu')
Example #9
0
def setUpModule():
    global model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    model = mockmodel.MockModel('/tmp/obj-store-test')
    patch_auth()
    test_server = run_server(test_mode=True, model=model)
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #10
0
def setUpModule():
    global model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    model = mockmodel.MockModel('/tmp/obj-store-test')
    patch_auth()
    test_server = run_server(test_mode=True, model=model)
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
def setUpModule():
    global model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #12
0
def setUpModule():
    global model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #13
0
    def test_tmpl_integrity(self):
        mock_iso2 = '/tmp/mock2.iso'
        iso_gen.construct_fake_iso(mock_iso2, True, '14.04', 'ubuntu')
        # Create a network and a pool for testing template integrity
        net = {'name': 'nat-network', 'connection': 'nat'}
        resp = self.request('/plugins/kimchi/networks',
                            json.dumps(net), 'POST')
        self.assertEqual(201, resp.status)

        pool = {'type': 'dir', 'name': 'dir-pool', 'path': '/tmp/dir-pool'}
        resp = self.request('/plugins/kimchi/storagepools',
                            json.dumps(pool), 'POST')
        self.assertEqual(201, resp.status)
        pool_uri = f"/plugins/kimchi/storagepools/{pool['name']}"
        resp = self.request(pool_uri + '/activate', '{}', 'POST')
        self.assertEqual(200, resp.status)

        # Create a template using the custom network and pool
        t = {
            'name': 'test',
            'source_media': {'type': 'disk', 'path': mock_iso2},
            'networks': ['nat-network'],
            'disks': [
                {
                    'pool': {'name': '/plugins/kimchi/storagepools/dir-pool'},
                    'size': 2,
                    'format': 'qcow2',
                }
            ],
        }
        req = json.dumps(t)
        resp = self.request('/plugins/kimchi/templates', req, 'POST')
        self.assertEqual(201, resp.status)

        # Try to delete network
        # It should fail as it is associated to a template
        resp = self.request(
            '/plugins/kimchi/networks/nat-network', '{}', 'DELETE')
        self.assertIn('KCHNET0017E', json.loads(resp.read())['reason'])

        # Update template to release network and then delete it
        params = {'networks': []}
        req = json.dumps(params)
        self.request('/plugins/kimchi/templates/test', req, 'PUT')
        resp = self.request(
            '/plugins/kimchi/networks/nat-network', '{}', 'DELETE')
        self.assertEqual(204, resp.status)

        # Try to delete the storagepool
        # It should fail as it is associated to a template
        resp = self.request(
            '/plugins/kimchi/storagepools/dir-pool', '{}', 'DELETE')
        self.assertEqual(400, resp.status)

        # Verify the template
        os.remove(mock_iso2)
        res = json.loads(self.request('/plugins/kimchi/templates/test').read())
        self.assertEqual(res['invalid']['cdrom'], [mock_iso2])
Example #14
0
    def test_tmpl_integrity(self):
        mock_iso2 = "/tmp/mock2.iso"
        iso_gen.construct_fake_iso(mock_iso2, True, '14.04', 'ubuntu')
        # Create a network and a pool for testing template integrity
        net = {'name': u'nat-network', 'connection': 'nat'}
        self.request('/plugins/kimchi/networks', json.dumps(net), 'POST')

        pool = {'type': 'dir', 'name': 'dir-pool', 'path': '/tmp/dir-pool'}
        self.request('/plugins/kimchi/storagepools', json.dumps(pool), 'POST')
        pool_uri = '/plugins/kimchi/storagepools/%s' \
                   % pool['name'].encode('utf-8')
        self.request(pool_uri + '/activate', '{}', 'POST')

        # Create a template using the custom network and pool
        t = {
            'name':
            'test',
            'source_media': {
                'type': 'disk',
                'path': mock_iso2
            },
            'networks': ['nat-network'],
            'disks': [{
                'pool': {
                    'name': '/plugins/kimchi/storagepools/dir-pool'
                },
                'size': 2,
                'format': 'qcow2'
            }]
        }
        req = json.dumps(t)
        resp = self.request('/plugins/kimchi/templates', req, 'POST')
        self.assertEquals(201, resp.status)

        # Try to delete network
        # It should fail as it is associated to a template
        resp = self.request('/plugins/kimchi/networks/nat-network', '{}',
                            'DELETE')
        self.assertIn("KCHNET0017E", json.loads(resp.read())["reason"])

        # Update template to release network and then delete it
        params = {'networks': []}
        req = json.dumps(params)
        self.request('/plugins/kimchi/templates/test', req, 'PUT')
        resp = self.request('/plugins/kimchi/networks/nat-network', '{}',
                            'DELETE')
        self.assertEquals(204, resp.status)

        # Try to delete the storagepool
        # It should fail as it is associated to a template
        resp = self.request('/plugins/kimchi/storagepools/dir-pool', '{}',
                            'DELETE')
        self.assertEquals(400, resp.status)

        # Verify the template
        os.remove(mock_iso2)
        res = json.loads(self.request('/plugins/kimchi/templates/test').read())
        self.assertEquals(res['invalid']['cdrom'], [mock_iso2])
def setUpModule():
    global TMP_DIR, TMP_EVENT

    if not os.path.exists(TMP_DIR):
        os.makedirs(TMP_DIR)

    TMP_EVENT = tempfile.mktemp()

    iso_gen.construct_fake_iso(UBUNTU_ISO, True, '14.04', 'ubuntu')
Example #16
0
def setUpModule():
    global test_server, model

    patch_auth(sudo=False)
    model = mockmodel.MockModel('/tmp/obj-store-test')
    test_server = run_server(test_mode=True, model=model)

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #17
0
def setUpModule():
    global test_server, model

    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #18
0
def setUpModule():
    global test_server, model

    patch_auth()
    test_server = run_server(test_mode=True)
    model = cherrypy.tree.apps['/plugins/kimchi'].root.model

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
def setUpModule():
    global test_server, model

    patch_auth(sudo=False)
    model = mockmodel.MockModel("/tmp/obj-store-test")
    test_server = run_server(test_mode=True, model=model)

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, "12.04", "ubuntu")
def setUpModule():
    global TMP_DIR, TMP_EVENT

    if not os.path.exists(TMP_DIR):
        os.makedirs(TMP_DIR)

    TMP_EVENT = tempfile.mktemp()

    iso_gen.construct_fake_iso(UBUNTU_ISO, True, '14.04', 'ubuntu')
Example #21
0
def setUpModule():
    global host, port, ssl_port, model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    model = mockmodel.MockModel('/tmp/obj-store-test')
    patch_auth()
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    host = '127.0.0.1'
    test_server = run_server(host, port, ssl_port, test_mode=True, model=model)
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #22
0
def setUpModule():
    if not os.path.exists(ISO_DIR):
        os.makedirs(ISO_DIR)
    iso_gen.construct_fake_iso(UBUNTU_ISO, True, '14.04', 'ubuntu')
    # Some FeatureTests functions depend on server to validate their result.
    # As CapabilitiesModel is a Singleton class it will get the first result
    # from FeatureTests which may be wrong when using the Model instance
    # directly - the case of this test_model.py
    # So clean Singleton instances to make sure to get the right result when
    # running the following tests.
    Singleton._instances = {}
Example #23
0
def setUpModule():
    if not os.path.exists(ISO_DIR):
        os.makedirs(ISO_DIR)
    iso_gen.construct_fake_iso(UBUNTU_ISO, True, '14.04', 'ubuntu')
    # Some FeatureTests functions depend on server to validate their result.
    # As CapabilitiesModel is a Singleton class it will get the first result
    # from FeatureTests which may be wrong when using the Model instance
    # directly - the case of this test_model.py
    # So clean Singleton instances to make sure to get the right result when
    # running the following tests.
    Singleton._instances = {}
Example #24
0
def setUpModule():
    global test_server, model, host, port, ssl_port, cherrypy_port

    patch_auth()
    model = MockModel('/tmp/obj-store-test')
    host = '127.0.0.1'
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    cherrypy_port = get_free_port('cherrypy_port')
    test_server = run_server(host, port, ssl_port, test_mode=True,
                             cherrypy_port=cherrypy_port, model=model)
    iso_gen.construct_fake_iso(MOCK_ISO, True, '14.04', 'ubuntu')
Example #25
0
def setUpModule():
    global host, port, ssl_port, model, test_server, fake_iso
    cherrypy.request.headers = {'Accept': 'application/json'}
    model = mockmodel.MockModel('/tmp/obj-store-test')
    patch_auth()
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    host = '127.0.0.1'
    test_server = run_server(host, port, ssl_port, test_mode=True,
                             model=model)
    fake_iso = '/tmp/fake.iso'
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #26
0
def setUpModule():
    global test_server, model, host, port, ssl_port

    patch_auth(sudo=False)
    model = mockmodel.MockModel('/tmp/obj-store-test')
    host = '127.0.0.1'
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    test_server = run_server(host, port, ssl_port, test_mode=True, model=model)

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
def setUpModule():
    global test_server, model, host, port, ssl_port

    patch_auth(sudo=False)
    model = mockmodel.MockModel('/tmp/obj-store-test')
    host = '127.0.0.1'
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    test_server = run_server(host, port, ssl_port, test_mode=True, model=model)

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
Example #28
0
def setUpModule():
    global test_server, model, host, port, ssl_port

    patch_auth(sudo=False)
    model = kimchi.mockmodel.MockModel("/tmp/obj-store-test")
    host = "127.0.0.1"
    port = get_free_port("http")
    ssl_port = get_free_port("https")
    test_server = run_server(host, port, ssl_port, test_mode=True, model=model)

    # Create fake ISO to do the tests
    construct_fake_iso(fake_iso, True, "12.04", "ubuntu")
Example #29
0
def setUpModule():
    global test_server, model, host, port, ssl_port, cherrypy_port

    patch_auth()
    model = kimchi.mockmodel.MockModel('/tmp/obj-store-test')
    host = '127.0.0.1'
    port = get_free_port('http')
    ssl_port = get_free_port('https')
    cherrypy_port = get_free_port('cherrypy_port')
    test_server = run_server(host, port, ssl_port, test_mode=True,
                             cherrypy_port=cherrypy_port, model=model)

    # Create fake ISO to do the tests
    iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
    iso_gen.construct_fake_iso("/var/lib/libvirt/images/fedora.iso", True,
                               "17", "fedora")
Example #30
0
    def test_deep_scan(self):
        inst = model.Model(None, objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            deep_path = os.path.join(TMP_DIR, "deep-scan")
            subdir_path = os.path.join(deep_path, "isos")
            if not os.path.exists(subdir_path):
                os.makedirs(subdir_path)
            ubuntu_iso = os.path.join(deep_path, "ubuntu12.04.iso")
            sles_iso = os.path.join(subdir_path, "sles10.iso")
            iso_gen.construct_fake_iso(ubuntu_iso, True, "12.04", "ubuntu")
            iso_gen.construct_fake_iso(sles_iso, True, "10", "sles")

            args = {"name": "kimchi-scanning-pool", "path": deep_path, "type": "kimchi-iso"}
            inst.storagepools_create(args)
            rollback.prependDefer(shutil.rmtree, deep_path)
            rollback.prependDefer(shutil.rmtree, args["path"])
            rollback.prependDefer(inst.storagepool_deactivate, args["name"])

            time.sleep(1)
            volumes = inst.storagevolumes_get_list(args["name"])
            self.assertEquals(len(volumes), 2)
Example #31
0
    def test_template_integrity(self):
        inst = model.Model('test:///default',
                           objstore_loc=self.tmp_store)

        with RollbackContext() as rollback:
            net_name = 'test-network'
            net_args = {'name': net_name,
                        'connection': 'nat',
                        'subnet': '127.0.100.0/24'}
            inst.networks_create(net_args)

            path = '/tmp/kimchi-iso/'
            if not os.path.exists(path):
                os.makedirs(path)
            iso = path + 'ubuntu12.04.iso'
            iso_gen.construct_fake_iso(iso, True, '12.04', 'ubuntu')

            args = {'name': 'test-pool',
                    'path': '/tmp/kimchi-images',
                    'type': 'dir'}
            inst.storagepools_create(args)
            rollback.prependDefer(inst.storagepool_delete, 'test-pool')

            params = {'name': 'test', 'memory': 1024, 'cpus': 1,
                      'networks': ['test-network'], 'cdrom': iso,
                      'storagepool': '/storagepools/test-pool'}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'test')

            # Try to delete network
            # It should fail as it is associated to a template
            self.assertRaises(InvalidOperation, inst.network_delete, net_name)
            # Update template to release network and then delete it
            params = {'networks': []}
            inst.template_update('test', params)
            inst.network_delete(net_name)

            shutil.rmtree(path)
            info = inst.template_lookup('test')
            self.assertEquals(info['invalid']['cdrom'], [iso])
Example #32
0
    def test_deep_scan(self):
        inst = model.Model('qemu:///system',
                           objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            path = '/tmp/kimchi-images/tmpdir'
            if not os.path.exists(path):
                os.makedirs(path)
            iso_gen.construct_fake_iso('/tmp/kimchi-images/tmpdir/'
                                       'ubuntu12.04.iso', True,
                                       '12.04', 'ubuntu')
            iso_gen.construct_fake_iso('/tmp/kimchi-images/sles10.iso',
                                       True, '10', 'sles')

            args = {'name': 'kimchi-scanning-pool',
                    'path': '/tmp/kimchi-images',
                    'type': 'kimchi-iso'}
            inst.storagepools_create(args)
            rollback.prependDefer(inst.storagepool_deactivate, args['name'])

            time.sleep(1)
            volumes = inst.storagevolumes_get_list(args['name'])
            self.assertEquals(len(volumes), 2)
Example #33
0
    def test_deep_scan(self):
        inst = model.Model(None,
                           objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            deep_path = os.path.join(TMP_DIR, 'deep-scan')
            subdir_path = os.path.join(deep_path, 'isos')
            if not os.path.exists(subdir_path):
                os.makedirs(subdir_path)
            ubuntu_iso = os.path.join(deep_path, 'ubuntu12.04.iso')
            sles_iso = os.path.join(subdir_path, 'sles10.iso')
            iso_gen.construct_fake_iso(ubuntu_iso, True, '12.04', 'ubuntu')
            iso_gen.construct_fake_iso(sles_iso, True, '10', 'sles')

            args = {'name': 'kimchi-scanning-pool',
                    'path': deep_path,
                    'type': 'kimchi-iso'}
            inst.storagepools_create(args)
            rollback.prependDefer(shutil.rmtree, deep_path)
            rollback.prependDefer(shutil.rmtree, args['path'])
            rollback.prependDefer(inst.storagepool_deactivate, args['name'])

            time.sleep(1)
            volumes = inst.storagevolumes_get_list(args['name'])
            self.assertEquals(len(volumes), 2)
Example #34
0
 def setUp(self):
     self.iso = '/tmp/mock.iso'
     iso_gen.construct_fake_iso(self.iso, True, '12.04', 'ubuntu')
Example #35
0
 def setUp(self):
     self.iso = '/tmp/mock.iso'
     iso_gen.construct_fake_iso(self.iso, True, '12.04', 'ubuntu')
Example #36
0
    def test_vm_disk(self):
        disk_path = os.path.join(TMP_DIR, 'existent2.iso')
        open(disk_path, 'w').close()
        modern_disk_bus = osinfo.get_template_default('modern', 'disk_bus')

        def _attach_disk(expect_bus=modern_disk_bus):
            disk_args = {"type": "disk",
                         "pool": pool,
                         "vol": vol}
            disk = inst.vmstorages_create(vm_name, disk_args)
            storage_list = inst.vmstorages_get_list(vm_name)
            self.assertEquals(prev_count + 1, len(storage_list))

            # Check the bus type to be 'virtio'
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u'disk', disk_info['type'])
            self.assertEquals(vol_path, disk_info['path'])
            self.assertEquals(expect_bus, disk_info['bus'])
            return disk

        inst = model.Model(objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            path = os.path.join(TMP_DIR, 'kimchi-images')
            pool = 'test-pool'
            vol = 'test-volume.img'
            vol_path = "%s/%s" % (path, vol)
            if not os.path.exists(path):
                os.mkdir(path)
            rollback.prependDefer(shutil.rmtree, path)

            args = {'name': pool,
                    'path': path,
                    'type': 'dir'}
            inst.storagepools_create(args)
            rollback.prependDefer(inst.storagepool_delete, pool)

            # Activate the pool before adding any volume
            inst.storagepool_activate(pool)
            rollback.prependDefer(inst.storagepool_deactivate, pool)

            params = {'name': vol,
                      'capacity': 1073741824,  # 1 GiB
                      'allocation': 536870912,  # 512 MiB
                      'format': 'qcow2'}
            task_id = inst.storagevolumes_create(pool, params)['id']
            rollback.prependDefer(inst.storagevolume_delete, pool, vol)
            inst.task_wait(task_id)

            vm_name = 'kimchi-cdrom'
            params = {'name': 'test', 'disks': [], 'cdrom': UBUNTU_ISO}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'test')
            params = {'name': vm_name,
                      'template': '/plugins/kimchi/templates/test'}
            task1 = inst.vms_create(params)
            inst.task_wait(task1['id'])
            rollback.prependDefer(inst.vm_delete, vm_name)

            prev_count = len(inst.vmstorages_get_list(vm_name))
            self.assertEquals(1, prev_count)

            # Volume format with mismatched type raise error
            cdrom_args = {"type": "cdrom", "pool": pool, "vol": vol}
            self.assertRaises(InvalidParameter, inst.vmstorages_create,
                              vm_name, cdrom_args)

            # Cold plug and unplug a disk
            disk = _attach_disk()
            inst.vmstorage_delete(vm_name, disk)

            # Hot plug a disk
            inst.vm_start(vm_name)
            disk = _attach_disk()

            # VM disk still there after powered off
            inst.vm_poweroff(vm_name)
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u'disk', disk_info['type'])
            inst.vmstorage_delete(vm_name, disk)

            # Specifying pool and path at same time will fail
            disk_args = {"type": "disk",
                         "pool": pool,
                         "vol": vol,
                         "path": disk_path}
            self.assertRaises(
                InvalidParameter, inst.vmstorages_create, vm_name, disk_args)

            old_distro_iso = TMP_DIR + 'rhel4_8.iso'
            iso_gen.construct_fake_iso(old_distro_iso, True, '4.8', 'rhel')

            vm_name = 'kimchi-ide-bus-vm'
            params = {'name': 'old_distro_template', 'disks': [],
                      'cdrom': old_distro_iso}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'old_distro_template')
            params = {
                'name': vm_name,
                'template': '/plugins/kimchi/templates/old_distro_template'
            }
            task2 = inst.vms_create(params)
            inst.task_wait(task2['id'])
            rollback.prependDefer(inst.vm_delete, vm_name)

            # Need to check the right disk_bus for old distro
            disk = _attach_disk(osinfo.get_template_default('old', 'disk_bus'))
            inst.vmstorage_delete('kimchi-ide-bus-vm', disk)

            # Hot plug IDE bus disk does not work
            inst.vm_start(vm_name)
            self.assertRaises(InvalidOperation, _attach_disk)
            inst.vm_poweroff(vm_name)
Example #37
0
    def test_vm_disk(self):
        disk_path = os.path.join(TMP_DIR, 'existent2.iso')
        open(disk_path, 'w').close()
        modern_disk_bus = osinfo.get_template_default('modern', 'disk_bus')

        def _attach_disk(expect_bus=modern_disk_bus):
            disk_args = {"type": "disk",
                         "pool": pool,
                         "vol": vol}
            disk = inst.vmstorages_create(vm_name, disk_args)
            storage_list = inst.vmstorages_get_list(vm_name)
            self.assertEquals(prev_count + 1, len(storage_list))

            # Check the bus type to be 'virtio'
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u'disk', disk_info['type'])
            self.assertEquals(vol_path, disk_info['path'])
            self.assertEquals(expect_bus, disk_info['bus'])
            return disk

        inst = model.Model(objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            path = os.path.join(TMP_DIR, 'kimchi-images')
            pool = 'test-pool'
            vol = 'test-volume.img'
            vol_path = "%s/%s" % (path, vol)
            if not os.path.exists(path):
                os.mkdir(path)
            rollback.prependDefer(shutil.rmtree, path)

            args = {'name': pool,
                    'path': path,
                    'type': 'dir'}
            inst.storagepools_create(args)
            rollback.prependDefer(inst.storagepool_delete, pool)

            # Activate the pool before adding any volume
            inst.storagepool_activate(pool)
            rollback.prependDefer(inst.storagepool_deactivate, pool)

            params = {'name': vol,
                      'capacity': 1073741824,  # 1 GiB
                      'allocation': 536870912,  # 512 MiB
                      'format': 'qcow2'}
            task_id = inst.storagevolumes_create(pool, params)['id']
            rollback.prependDefer(inst.storagevolume_delete, pool, vol)
            inst.task_wait(task_id)

            vm_name = 'kimchi-cdrom'
            params = {'name': 'test', 'disks': [], 'cdrom': UBUNTU_ISO}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'test')
            params = {'name': vm_name,
                      'template': '/plugins/kimchi/templates/test'}
            task1 = inst.vms_create(params)
            inst.task_wait(task1['id'])
            rollback.prependDefer(inst.vm_delete, vm_name)

            prev_count = len(inst.vmstorages_get_list(vm_name))
            self.assertEquals(1, prev_count)

            # Volume format with mismatched type raise error
            cdrom_args = {"type": "cdrom", "pool": pool, "vol": vol}
            self.assertRaises(InvalidParameter, inst.vmstorages_create,
                              vm_name, cdrom_args)

            # Cold plug and unplug a disk
            disk = _attach_disk()
            inst.vmstorage_delete(vm_name, disk)

            # Hot plug a disk
            inst.vm_start(vm_name)
            disk = _attach_disk()

            # VM disk still there after powered off
            inst.vm_poweroff(vm_name)
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u'disk', disk_info['type'])
            inst.vmstorage_delete(vm_name, disk)

            # Specifying pool and path at same time will fail
            disk_args = {"type": "disk",
                         "pool": pool,
                         "vol": vol,
                         "path": disk_path}
            self.assertRaises(
                InvalidParameter, inst.vmstorages_create, vm_name, disk_args)

            old_distro_iso = TMP_DIR + 'rhel4_8.iso'
            iso_gen.construct_fake_iso(old_distro_iso, True, '4.8', 'rhel')

            vm_name = 'kimchi-ide-bus-vm'
            params = {'name': 'old_distro_template', 'disks': [],
                      'cdrom': old_distro_iso}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, 'old_distro_template')
            params = {
                'name': vm_name,
                'template': '/plugins/kimchi/templates/old_distro_template'
            }
            task2 = inst.vms_create(params)
            inst.task_wait(task2['id'])
            rollback.prependDefer(inst.vm_delete, vm_name)

            # Need to check the right disk_bus for old distro
            disk = _attach_disk(osinfo.get_template_default('old', 'disk_bus'))
            inst.vmstorage_delete('kimchi-ide-bus-vm', disk)

            # Hot plug IDE bus disk does not work
            inst.vm_start(vm_name)
            self.assertRaises(InvalidOperation, _attach_disk)
            inst.vm_poweroff(vm_name)
Example #38
0
    def test_vm_disk(self):
        disk_path = os.path.join(TMP_DIR, "existent2.iso")
        open(disk_path, "w").close()
        modern_disk_bus = osinfo.get_template_default("modern", "disk_bus")

        def _attach_disk(expect_bus=modern_disk_bus):
            disk_args = {"type": "disk", "pool": pool, "vol": vol}
            disk = inst.vmstorages_create(vm_name, disk_args)
            storage_list = inst.vmstorages_get_list(vm_name)
            self.assertEquals(prev_count + 1, len(storage_list))

            # Check the bus type to be 'virtio'
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u"disk", disk_info["type"])
            self.assertEquals(vol_path, disk_info["path"])
            self.assertEquals(expect_bus, disk_info["bus"])
            return disk

        inst = model.Model(objstore_loc=self.tmp_store)
        with RollbackContext() as rollback:
            path = os.path.join(TMP_DIR, "kimchi-images")
            pool = "test-pool"
            vol = "test-volume.img"
            vol_path = "%s/%s" % (path, vol)
            if not os.path.exists(path):
                os.mkdir(path)
            rollback.prependDefer(shutil.rmtree, path)

            args = {"name": pool, "path": path, "type": "dir"}
            inst.storagepools_create(args)
            rollback.prependDefer(inst.storagepool_delete, pool)

            # Activate the pool before adding any volume
            inst.storagepool_activate(pool)
            rollback.prependDefer(inst.storagepool_deactivate, pool)

            params = {
                "name": vol,
                "capacity": 1073741824,  # 1 GiB
                "allocation": 536870912,  # 512 MiB
                "format": "qcow2",
            }
            task_id = inst.storagevolumes_create(pool, params)["id"]
            rollback.prependDefer(inst.storagevolume_delete, pool, vol)
            inst.task_wait(task_id)

            vm_name = "kimchi-cdrom"
            params = {"name": "test", "disks": [], "cdrom": UBUNTU_ISO}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, "test")
            params = {"name": vm_name, "template": "/plugins/kimchi/templates/test"}
            task1 = inst.vms_create(params)
            inst.task_wait(task1["id"])
            rollback.prependDefer(inst.vm_delete, vm_name)

            prev_count = len(inst.vmstorages_get_list(vm_name))
            self.assertEquals(1, prev_count)

            # Volume format with mismatched type raise error
            cdrom_args = {"type": "cdrom", "pool": pool, "vol": vol}
            self.assertRaises(InvalidParameter, inst.vmstorages_create, vm_name, cdrom_args)

            # Cold plug and unplug a disk
            disk = _attach_disk()
            inst.vmstorage_delete(vm_name, disk)

            # Hot plug a disk
            inst.vm_start(vm_name)
            disk = _attach_disk()

            # VM disk still there after powered off
            inst.vm_poweroff(vm_name)
            disk_info = inst.vmstorage_lookup(vm_name, disk)
            self.assertEquals(u"disk", disk_info["type"])
            inst.vmstorage_delete(vm_name, disk)

            # Specifying pool and path at same time will fail
            disk_args = {"type": "disk", "pool": pool, "vol": vol, "path": disk_path}
            self.assertRaises(InvalidParameter, inst.vmstorages_create, vm_name, disk_args)

            old_distro_iso = TMP_DIR + "rhel4_8.iso"
            iso_gen.construct_fake_iso(old_distro_iso, True, "4.8", "rhel")

            vm_name = "kimchi-ide-bus-vm"
            params = {"name": "old_distro_template", "disks": [], "cdrom": old_distro_iso}
            inst.templates_create(params)
            rollback.prependDefer(inst.template_delete, "old_distro_template")
            params = {"name": vm_name, "template": "/plugins/kimchi/templates/old_distro_template"}
            task2 = inst.vms_create(params)
            inst.task_wait(task2["id"])
            rollback.prependDefer(inst.vm_delete, vm_name)

            # Need to check the right disk_bus for old distro
            disk = _attach_disk(osinfo.get_template_default("old", "disk_bus"))
            inst.vmstorage_delete("kimchi-ide-bus-vm", disk)

            # Hot plug IDE bus disk does not work
            inst.vm_start(vm_name)
            self.assertRaises(InvalidOperation, _attach_disk)
            inst.vm_poweroff(vm_name)
Example #39
0
 def setUp(self):
     self.iso = "/tmp/mock.iso"
     iso_gen.construct_fake_iso(self.iso, True, "12.04", "ubuntu")