def test_modify_add_network(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_interfaces = dom_xml.xpath('//devices/interface') assert len(test_interfaces) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_ADD, json_data=json.dumps({'devices': {"interface": [{ "dev": "52:54:00:c4:d3:b2", "properties": { "type": "bridge", "source": "vswitch0", "model_type": "virtio", "driver_name": "vhost" } }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) interfaces = dom_xml.xpath('//devices/interface') assert len(test_interfaces) + 1 == len(interfaces) assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_umount(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_disks = dom_xml.xpath('//devices/disk') assert len(test_disks) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_UMOUNT, json_data=json.dumps({'devices': {"disk": [{ "dev": "hda" }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) disks = dom_xml.xpath('//devices/disk') assert len(disks) > 0 assert len(dom_xml.xpath('//devices/disk/target[@dev="hda"]')) > 0 for disk_xml in disks: if len(disk_xml.xpath('./target[@dev="hda"]')) > 0: assert len(disk_xml.xpath('./source')) == 0 assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_update_disk_target(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_disks = dom_xml.xpath('//devices/disk') assert len(test_disks) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'devices': {"disk": [{ "dev": "hda", "properties": { "target_dev": "hdd" } }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) target = dom_xml.xpath('//devices/disk/target[@dev="hdd"]') assert len(target) > 0 assert "hdd" == target[0].attrib['dev'] assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_mount(self): envoy.run(">/tmp/test_mount.iso") dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_disks = dom_xml.xpath('//devices/disk') assert len(test_disks) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_MOUNT, json_data=json.dumps({'devices': {"disk": [{ "dev": "hda", "properties": { "source": "/tmp/test_mount.iso" } }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) assert len(dom_xml.xpath('//devices/disk/source[@file="/tmp/test_mount.iso"]')) > 0 assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is '' envoy.run(">/tmp/test_mount.iso")
def test_modify_add_disk(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_disks = dom_xml.xpath('//devices/disk') assert len(test_disks) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_ADD, json_data=json.dumps({'devices': {"disk": [{ "properties": { "type": "file", "device": "cdrom", "driver_type": "raw", "driver_name": "qemu", "source": "/vms/isos/CentOS-7-x86_64-DVD-1810.iso", "target_bus": "ide" } }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) disks = dom_xml.xpath('//devices/disk') assert len(test_disks) + 1 == len(disks) assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_vcpu(self): res = None test_size = '8' request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'vcpu': { 'num': test_size, 'current': 2 }, 'cpu': { 'sockets': '2', 'cores': '4' } })) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) vcpu = dom_xml.xpath('//vcpu') assert len(vcpu) == 1 assert test_size == vcpu[0].text assert pb.LIBVIRT_ERR_OK == res.code assert '' == res.err_msg
def test_modify_memory(self): test_size = '111111' request = pb.DomainModifyReq(uuid=self.uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'memory': test_size})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: assert 0 dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) memory = dom_xml.xpath('./memory') assert len(memory) == 1 assert test_size == memory[0].text assert pb.LIBVIRT_ERR_OK == res.code assert '' == res.err_msg
def test_modify_vcpu_failed(self): res = None test_size = 'test_err' request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'vcpu': { 'num': test_size, 'current': 2 }})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass assert pb.LIBVIRT_ERR_XML_ERROR == res.code assert res.err_msg != ''
def test_modify_update_network_mac(self): request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'devices': {"interface": [{ "dev": "88:54:00:c8:ed:00", "properties": { "mac": "52:54:00:c4:d3:b2" } }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) mac = dom_xml.xpath('//devices/interface/mac[@address="52:54:00:c4:d3:b2"]') assert len(mac) > 0 assert "52:54:00:c4:d3:b2" == mac[0].attrib['address'] assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_delete_network(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_interfaces = dom_xml.xpath('//devices/interface') assert len(test_interfaces) > 0 request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_DELETE, json_data=json.dumps({'devices': {"interface": [{ "dev": "88:54:00:c8:ed:00" }]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) interfaces = dom_xml.xpath('//devices/interface') assert len(test_interfaces) - 1 == len(interfaces) assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_modify_delete_disk(self): dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) test_targets = dom_xml.xpath('//devices/disk/target') assert len(test_targets) > 0 test_target = test_targets[0].get('dev') assert 'hda' == test_target request = pb.DomainModifyReq( uuid=self.uuid, type=pb.OPERATION_TYPE_DELETE, json_data=json.dumps({'devices': {"disk": [{"dev": test_target}]}})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: pass dom = self.conn.lookupByUUIDString(self.uuid) dom_xml = etree.XML(dom.XMLDesc()) target = dom_xml.xpath('//devices/disk/target') assert len(test_targets) - 1 == len(target) assert pb.LIBVIRT_ERR_OK == res.code assert res.err_msg is ''
def test_migrate_domain_offline_with_snapshots(self): if not self.has_env: return cmd = envoy.run('virsh destroy test_%s' % self._uuid) assert cmd.std_err == '' test_size = '2048000' request = pb.DomainModifyReq(uuid=self._uuid, type=pb.OPERATION_TYPE_UPDATE, json_data=json.dumps({'memory': test_size})) try: res = self.stub.ModifyDomain(request, timeout=10) except Exception: assert 0 cmd = envoy.run('virsh snapshot-create-as --domain test_%s xxx' % self._uuid) assert cmd.std_err == '' assert cmd.std_err == '' cmd = envoy.run('virsh snapshot-create-as --domain test_%s yyy' % self._uuid) assert cmd.std_err == '' cmd = envoy.run('virsh snapshot-list --domain test_%s' % self._uuid) assert 'xxx' in cmd.std_out assert 'yyy' in cmd.std_out cmd = envoy.run('virsh start test_%s' % self._uuid) assert cmd.std_err == '' _job_id = -1 dom_ref = None request = pb.DomainMigrateReq( uuid=self._uuid, destination="test_migration_host", no_need_notify=True, postcopy=True, time_out=300) try: res = self.stub.MigrateDomain(request, timeout=10) _job_id = res.job_id except Exception: assert 0 assert self.conn is not None try: dom_ref = self.conn.lookupByUUIDString(self._uuid) except libvirt.libvirtError as e: assert libvirt.VIR_ERR_NO_DOMAIN == e.get_error_code() assert pb.LIBVIRT_ERR_OK == res.code assert '' == res.err_msg start = time.time() while True: try: res = self.stub.QueryJob(request=pb.QueryJobReq(job_id=_job_id), timeout=10) except Exception: assert 0 assert res.code == 0 assert time.time() - start < 15 if res.process == 100: break time.sleep(0.5) try: res = self.stub.ListDomains(request=empty_pb.Empty(), timeout=10) except Exception: assert 0 cmd = envoy.run('ssh root@test_migration_host virsh snapshot-list test_%s' % self._uuid) assert cmd.std_err == '' assert 'xxx' in cmd.std_out assert 'yyy' in cmd.std_out cmd = envoy.run('ssh root@test_migration_host virsh snapshot-dumpxml test_%s yyy' % self._uuid) assert test_size in cmd.std_out assert self._uuid not in res.domains assert self.uuid in res.domains