def test_create_domain_uuid_exists(self):
        request = pb.DomainCreateReq(os_type='linux', json_data=self.json_template % (self.name, self.uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            pass

        assert pb.VIRT_AGENT_ERR_INVALID_UUID == res.code
        assert '' != res.err_msg
    def test_create_domain_name_exists(self):
        request = pb.DomainCreateReq(os_type='linux', json_data=self.json_template %
                                     (self.name, str(uuid.uuid4())))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            pass

        assert pb.LIBVIRT_ERR_OPERATION_FAILED == res.code
        assert '' != res.err_msg
    def test_create_domain(self):
        _uuid = str(uuid.uuid4())
        request = pb.DomainCreateReq(os_type='linux', json_data=self.json_template % (_uuid, _uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0

        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg

        domain = self.conn.lookupByUUIDString(_uuid)
        dom_xml = etree.XML(domain.XMLDesc())
        node_tags = []
        device_tags = []
        for c in dom_xml.getchildren():
            node_tags.append(c.tag)
            if c.tag == 'devices':
                for t in c:
                    device_tags.append(t.tag)

        assert 'title' in node_tags
        assert 'name' in node_tags
        assert 'uuid' in node_tags
        assert 'memory' in node_tags
        assert 'currentMemory' in node_tags
        assert 'vcpu' in node_tags
        assert 'os' in node_tags
        assert 'metadata' in node_tags
        assert 'features' in node_tags
        assert 'cpu' in node_tags
        assert 'pm' in node_tags
        assert 'devices' in node_tags
        assert 'on_poweroff' in node_tags
        assert 'on_reboot' in node_tags
        assert 'on_crash' in node_tags
        assert 'emulator' in device_tags
        assert 'controller' in device_tags
        assert 'input' in device_tags
        assert 'graphics' in device_tags
        assert 'video' in device_tags
        assert 'serial' in device_tags
        assert 'console' in device_tags
        assert 'hub' in device_tags
        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg

        request = pb.DomainDeleteReq(uuid=_uuid)
        try:
            res = self.stub.DeleteDomain(request, timeout=10)
        except Exception:
            assert 0
Beispiel #4
0
    def setup(self):
        super(TestCasePrecheckMigration, self).setup()
        cmd = envoy.run('ping test_migration_host -c 3')
        if cmd.std_err != '':
            print('Test host for migration not found: ', cmd.str_err)
            return

        self.has_env = True
        self._uuid = str(uuid.uuid4())
        self.json_template = """{
                                "type": "qemu",
                                "name": "test_%s",
                                "uuid": "%s",
                                "memory": "1048576",
                                "currentMemory": "1048576",
                                "vcpu":{
                                    "num":"1",
                                    "current":"1"
                                },
                                "cpu":  {
                                    "cores":"1",
                                    "sockets":"1"
                                },
                                "clock": {
                                    "offset":"localtime"
                                },
                                "title": "test_domain_title",
                                "metadata":"",
                                "os": {
                                    "boot": [
                                        {
                                            "dev":"hd"
                                        },
                                        {
                                            "dev":"cdrom"
                                        }
                                    ]
                                },
                                "devices": {
                                    "disk":[{
                                        "dev":"vda",
                                        "properties": {
                                            "type":"file",
                                            "device":"disk",
                                            "driver_type":"qcow2",
                                            "driver_name":"qemu",
                                            "source":"/vms/images/test_%s.qcow2",
                                            "target_bus":"virtio"
                                        }
                                    }],
                                    "interface": [{
                                        "dev":"52:54:00:c4:d3:b2",
                                        "properties": {
                                            "type": "network",
                                            "source": "default",
                                            "model_type":"virtio",
                                            "driver_name":"vhost"
                                        }
                                    }]
                                }}"""

        cmd = envoy.run('qemu-img create -f qcow2 /vms/images/test_base_%s.qcow2 1M' % self._uuid)
        if cmd.std_err != '':
            return

        cmd = envoy.run(
            'qemu-img create -f qcow2 -b /vms/images/test_base_%s.qcow2 /vms/images/test_%s.qcow2 1M' %
            (self._uuid, self._uuid))
        if cmd.std_err != '':
            return

        request = pb.DomainCreateReq(
            os_type='linux', json_data=self.json_template %
            (self._uuid, self._uuid, self._uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0
        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg

        cmd = envoy.run('virsh start test_%s' % self._uuid)
        if cmd.std_err != '':
            print(cmd.std_err)
            return
        sys_res = None
        try:
            with grpc.insecure_channel("test_migration_host:6020") as channel:
                stub = sysagent_pb2_grpc.SysAgentStub(channel)
                request = sysagent_pb2.HostInfoGetRequest()
                sys_res = stub.GetHostInfo(request, timeout=10)
        except grpc.RpcError:
            print('connecting to sys-agentd failed')
            assert 0
        self.remote_ip = sys_res.body.host_ip
Beispiel #5
0
    def setup(self):
        super(TestCaseFinishMigration, self).setup()
        self.json_template = """{
                                "type": "qemu",
                                "name": "test_%s",
                                "uuid": "%s",
                                "memory": "1048576",
                                "currentMemory": "1048576",
                                "vcpu":{
                                    "num":"1",
                                    "current":"1"
                                },
                                "cpu":  {
                                    "cores":"1",
                                    "sockets":"1"
                                },
                                "clock": {
                                    "offset":"localtime"
                                },
                                "title": "test_domain_title",
                                "metadata":"",
                                "os": {
                                    "boot": [
                                        {
                                            "dev":"hd"
                                        },
                                        {
                                            "dev":"cdrom"
                                        }
                                    ]
                                },
                                "devices": {
                                    "disk":[
                                        {
                                            "dev":"vda",
                                            "properties": {
                                                "type":"file",
                                                "device":"disk",
                                                "driver_type":"qcow2",
                                                "driver_name":"qemu",
                                                "source":"/vms/images/test_%s_1.qcow2",
                                                "target_bus":"virtio"
                                            }
                                        },
                                        {
                                            "dev":"vdb",
                                            "properties": {
                                                "type":"file",
                                                "device":"disk",
                                                "driver_type":"qcow2",
                                                "driver_name":"qemu",
                                                "source":"/vms/images/test_%s_2.qcow2",
                                                "target_bus":"virtio"
                                            }

                                    }],
                                    "interface": [{
                                        "dev":"52:54:00:c4:d3:b2",
                                        "properties": {
                                            "type": "network",
                                            "source": "default",
                                            "model_type":"virtio",
                                            "driver_name":"vhost"
                                        }
                                    }]
                                }}"""
        self._uuid = str(uuid.uuid4())
        request = pb.DomainCreateReq(
            os_type='linux', json_data=self.json_template %
            (self._uuid, self._uuid, self._uuid, self._uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0

        cmd = envoy.run('qemu-img create -f qcow2 /vms/images/test_%s_1.qcow2 1M' % self._uuid)
        if cmd.std_err != '':
            return
        cmd = envoy.run('qemu-img create -f qcow2 /vms/images/test_%s_2.qcow2 1M' % self._uuid)
        if cmd.std_err != '':
            return

        cmd = envoy.run('virsh start test_%s' % self._uuid)
        if cmd.std_err != '':
            return
Beispiel #6
0
    def setup(self):
        super(TestCaseMigrateDomain, self).setup()
        cmd = envoy.run('ping test_migration_host -c 3')
        if cmd.std_err != '':
            print('Test host for migration not found: ', cmd.str_err)
            return

        self.has_env = True
        self._uuid = str(uuid.uuid4())
        self.json_template = """{
                                "type": "qemu",
                                "name": "test_%s",
                                "uuid": "%s",
                                "memory": "1048576",
                                "currentMemory": "1048576",
                                "vcpu":{
                                    "num":"1",
                                    "current":"1"
                                },
                                "cpu":  {
                                    "cores":"1",
                                    "sockets":"1"
                                },
                                "clock": {
                                    "offset":"localtime"
                                },
                                "title": "test_domain_title",
                                "metadata":"",
                                "os": {
                                    "boot": [
                                        {
                                            "dev":"hd"
                                        },
                                        {
                                            "dev":"cdrom"
                                        }
                                    ]
                                },
                                "devices": {
                                    "disk":[{
                                        "dev":"vda",
                                        "properties": {
                                            "type":"file",
                                            "device":"disk",
                                            "driver_type":"qcow2",
                                            "driver_name":"qemu",
                                            "source":"/vms/images/test_%s.qcow2",
                                            "target_bus":"virtio"
                                        }
                                    }],
                                    "interface": [{
                                        "dev":"52:54:00:c4:d3:b2",
                                        "properties": {
                                            "type": "network",
                                            "source": "default",
                                            "model_type":"virtio",
                                            "driver_name":"vhost"
                                        }
                                    }]
                                }}"""

        cmd = envoy.run('qemu-img create -f qcow2 /vms/images/test_%s.qcow2 1M' % self._uuid)
        if cmd.std_err != '':
            return

        request = pb.DomainCreateReq(
            os_type='linux', json_data=self.json_template %
            (self._uuid, self._uuid, self._uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0

        cmd = envoy.run('virsh start test_%s' % self._uuid)
        if cmd.std_err != '':
            print(cmd.std_err)
            return
        # wait for domain start
        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg
    def test_create_domain_multi_interfaces(self):
        _uuid = str(uuid.uuid4())
        self.json_template = """{
                                "type": "qemu",
                                "name": "test_%s",
                                "uuid": "%s",
                                "memory": "1048576",
                                "currentMemory": "1048576",
                                "vcpu":{
                                    "num":"1",
                                    "current":"1"
                                },
                                "cpu":  {
                                    "sockets":"1",
                                    "cores":"1"
                                },
                                "title": "test_domain_title",
                                "metadata":"",
                                "os": {
                                    "boot": [
                                        {
                                            "dev":"hd"
                                        },
                                        {
                                            "dev":"cdrom"
                                        }
                                    ]
                                },
                                "devices": {
                                    "disk":[{
                                        "dev":"hda",
                                        "properties": {
                                            "type":"file",
                                            "device":"cdrom",
                                            "driver_type":"raw",
                                            "driver_name":"qemu",
                                            "source":"/tmp/test_base.iso",
                                            "target_bus":"ide"
                                        }
                                    }],
                                    "interface": [{
                                            "dev":"88:54:00:c8:ed:00",
                                            "properties": {
                                                "type": "bridge",
                                                "source": "vswitch0",
                                                "model_type":"virtio",
                                                "driver_name":"vhost"
                                            }
                                        },
                                        {
                                            "dev":"52:54:00:c4:d3:b2",
                                            "properties": {
                                                "type": "bridge",
                                                "source": "vswitch0",
                                                "model_type":"virtio",
                                                "driver_name":"vhost"
                                            }
                                    }]
                                }}"""
        request = pb.DomainCreateReq(os_type='linux', json_data=self.json_template % (_uuid, _uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0

        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg

        domain = self.conn.lookupByUUIDString(_uuid)
        dom_xml = etree.XML(domain.XMLDesc())
        node_tags = []
        device_tags = []
        for c in dom_xml.getchildren():
            node_tags.append(c.tag)
            if c.tag == 'devices':
                for t in c:
                    device_tags.append(t.tag)

        dom = self.conn.lookupByUUIDString(_uuid)
        dom_xml = etree.XML(dom.XMLDesc())
        addresses = []
        macs = dom_xml.xpath('//mac')
        for c in macs:
            addresses.append(c.get('address'))
        assert len(macs) == 2
        assert "88:54:00:c8:ed:00" in addresses
        assert "52:54:00:c4:d3:b2"in addresses
        assert 'title' in node_tags
        assert 'name' in node_tags
        assert 'uuid' in node_tags
        assert 'memory' in node_tags
        assert 'currentMemory' in node_tags
        assert 'vcpu' in node_tags
        assert 'os' in node_tags
        assert 'metadata' in node_tags
        assert 'features' in node_tags
        assert 'cpu' in node_tags
        assert 'pm' in node_tags
        assert 'devices' in node_tags
        assert 'on_poweroff' in node_tags
        assert 'on_reboot' in node_tags
        assert 'on_crash' in node_tags
        assert 'emulator' in device_tags
        assert 'controller' in device_tags
        assert 'input' in device_tags
        assert 'graphics' in device_tags
        assert 'video' in device_tags
        assert 'serial' in device_tags
        assert 'console' in device_tags
        assert 'hub' in device_tags
        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg

        request = pb.DomainDeleteReq(uuid=_uuid)
        try:
            res = self.stub.DeleteDomain(request, timeout=10)
        except Exception:
            assert 0
Beispiel #8
0
    def setup(self):
        """Setup and teardown for each test case to support parrallel tests.
    """
        super(TestCaseDomainBase, self).setup()
        envoy.run("touch /vms/images/test_base.iso")
        envoy.run("qemu-img create -f qcow2 /vms/images/test_base.qcow2 1M")

        self.uuid = str(uuid.uuid4())
        self.name = self.uuid
        self.json_template = """{
                                "type": "qemu",
                                "name": "test_%s",
                                "uuid": "%s",
                                "memory": "1048576",
                                "currentMemory": "1048576",
                                "vcpu":{
                                    "num":"1",
                                    "current":"1"
                                },
                                "cpu":  {
                                    "cores":"1",
                                    "sockets":"1"
                                },
                                "clock": {
                                    "offset":"localtime"
                                },
                                "title": "test_domain_title",
                                "metadata":"",
                                "os": {
                                    "boot": [
                                        {
                                            "dev":"hd"
                                        },
                                        {
                                            "dev":"cdrom"
                                        }
                                    ]
                                },
                                "devices": {
                                    "disk":[{
                                        "dev":"hda",
                                        "properties": {
                                            "type":"file",
                                            "device":"cdrom",
                                            "driver_type":"raw",
                                            "driver_name":"qemu",
                                            "source":"/tmp/test_base.iso",
                                            "target_bus":"ide"
                                        }
                                      },
                                      {
                                        "dev":"vda",
                                        "properties": {
                                            "type":"file",
                                            "device":"disk",
                                            "driver_type":"qcow2",
                                            "driver_name":"qemu",
                                            "source":"/vms/images/test_base.qcow2",
                                            "target_bus":"virtio"
                                        }
                                    }],
                                    "interface": [{
                                        "dev":"88:54:00:c8:ed:00",
                                        "properties": {
                                            "type": "bridge",
                                            "source": "vswitch0",
                                            "model_type":"virtio",
                                            "driver_name":"vhost"
                                        }
                                    }]
                                }}"""
        request = pb.DomainCreateReq(os_type='linux', json_data=self.json_template % (self.name, self.uuid))
        try:
            res = self.stub.CreateDomain(request, timeout=10)
        except Exception:
            assert 0

        assert pb.LIBVIRT_ERR_OK == res.code
        assert '' == res.err_msg