check for QEMU response errors
When performing QEMU monitor commands, libvirt will return StatusOK even when the underlying QEMU process fails to perform the command. This modifies Run() to check for QEMU errors. I'm not entirely happy with the hacky modifications to the test library to handle this scenario. The test framework is in obvious need for a complete refactor. For now this will have to work.
This commit is contained in:
		| @@ -120,6 +120,32 @@ var testRunReply = []byte{ | ||||
| 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||||
| } | ||||
|  | ||||
| var testRunReplyFail = []byte{ | ||||
| 	0x00, 0x00, 0x00, 0x8c, // length | ||||
| 	0x20, 0x00, 0x80, 0x87, // program | ||||
| 	0x00, 0x00, 0x00, 0x01, // version | ||||
| 	0x00, 0x00, 0x00, 0x01, // procedure | ||||
| 	0x00, 0x00, 0x00, 0x01, // type | ||||
| 	0x00, 0x00, 0x00, 0x0a, // serial | ||||
| 	0x00, 0x00, 0x00, 0x00, // status | ||||
|  | ||||
| 	// {"id":"libvirt-68","error":{"class":"CommandNotFound","desc":"The command drive-foo has not been found"}}` | ||||
| 	0x00, 0x00, 0x00, 0x69, 0x7b, 0x22, 0x69, 0x64, | ||||
| 	0x22, 0x3a, 0x22, 0x6c, 0x69, 0x62, 0x76, 0x69, | ||||
| 	0x72, 0x74, 0x2d, 0x36, 0x38, 0x22, 0x2c, 0x22, | ||||
| 	0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3a, 0x7b, | ||||
| 	0x22, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x22, 0x3a, | ||||
| 	0x22, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, | ||||
| 	0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e, 0x64, | ||||
| 	0x22, 0x2c, 0x22, 0x64, 0x65, 0x73, 0x63, 0x22, | ||||
| 	0x3a, 0x22, 0x54, 0x68, 0x65, 0x20, 0x63, 0x6f, | ||||
| 	0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x72, | ||||
| 	0x69, 0x76, 0x65, 0x2d, 0x66, 0x6f, 0x6f, 0x20, | ||||
| 	0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, | ||||
| 	0x62, 0x65, 0x65, 0x6e, 0x20, 0x66, 0x6f, 0x75, | ||||
| 	0x6e, 0x64, 0x22, 0x7d, 0x7d, 0x00, 0x00, 0x00, | ||||
| } | ||||
|  | ||||
| var testDomainsReply = []byte{ | ||||
| 	0x00, 0x00, 0x00, 0x6c, // length | ||||
| 	0x20, 0x00, 0x80, 0x86, // program | ||||
| @@ -171,6 +197,7 @@ var testVersionReply = []byte{ | ||||
| type MockLibvirt struct { | ||||
| 	net.Conn | ||||
| 	Test   net.Conn | ||||
| 	Fail   bool | ||||
| 	serial uint32 | ||||
| } | ||||
|  | ||||
| @@ -233,7 +260,11 @@ func (m *MockLibvirt) handleQEMU(procedure uint32, conn net.Conn) { | ||||
| 	case constants.QEMUConnectDomainMonitorEventDeregister: | ||||
| 		conn.Write(m.reply(testDeregisterEvent)) | ||||
| 	case constants.QEMUDomainMonitor: | ||||
| 		conn.Write(m.reply(testRunReply)) | ||||
| 		if m.Fail { | ||||
| 			conn.Write(m.reply(testRunReplyFail)) | ||||
| 		} else { | ||||
| 			conn.Write(m.reply(testRunReply)) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user