Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #658 from 01org/sameo/topic/qemu
Browse files Browse the repository at this point in the history
qemu: Support creating multiple QMP sockets
  • Loading branch information
markdryan authored Oct 11, 2016
2 parents c9661cf + de08837 commit 0333062
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
36 changes: 18 additions & 18 deletions qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ type Config struct {
// Machine
Machine Machine

// QMPSocket is the QMP socket description.
QMPSocket QMPSocket
// QMPSockets is a slice of QMP socket description.
QMPSockets []QMPSocket

// Devices is a list of devices for qemu to create and drive.
Devices []Device
Expand Down Expand Up @@ -777,24 +777,24 @@ func (config *Config) appendCPUModel() {
}
}

func (config *Config) appendQMPSocket() {
if config.QMPSocket.Valid() == false {
return
}

var qmpParams []string
func (config *Config) appendQMPSockets() {
for _, q := range config.QMPSockets {
if q.Valid() == false {
continue
}

qmpParams = append(qmpParams, fmt.Sprintf("%s:", config.QMPSocket.Type))
qmpParams = append(qmpParams, fmt.Sprintf("%s", config.QMPSocket.Name))
if config.QMPSocket.Server == true {
qmpParams = append(qmpParams, ",server")
if config.QMPSocket.NoWait == true {
qmpParams = append(qmpParams, ",nowait")
qmpParams := append([]string{}, fmt.Sprintf("%s:", q.Type))
qmpParams = append(qmpParams, fmt.Sprintf("%s", q.Name))
if q.Server == true {
qmpParams = append(qmpParams, ",server")
if q.NoWait == true {
qmpParams = append(qmpParams, ",nowait")
}
}
}

config.qemuParams = append(config.qemuParams, "-qmp")
config.qemuParams = append(config.qemuParams, strings.Join(qmpParams, ""))
config.qemuParams = append(config.qemuParams, "-qmp")
config.qemuParams = append(config.qemuParams, strings.Join(qmpParams, ""))
}
}

func (config *Config) appendDevices() {
Expand Down Expand Up @@ -935,7 +935,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
config.appendUUID()
config.appendMachine()
config.appendCPUModel()
config.appendQMPSocket()
config.appendQMPSockets()
config.appendMemory()
config.appendCPUs()
config.appendDevices()
Expand Down
41 changes: 33 additions & 8 deletions qemu/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ func testAppend(structure interface{}, expected string, t *testing.T) {
config.appendCPUs()

case QMPSocket:
config.QMPSocket = s
config.appendQMPSocket()
config.QMPSockets = []QMPSocket{s}
config.appendQMPSockets()

case []QMPSocket:
config.QMPSockets = s
config.appendQMPSockets()

case RTC:
config.RTC = s
Expand Down Expand Up @@ -232,28 +236,49 @@ func TestAppendCPUs(t *testing.T) {
testAppend(smp, cpusString, t)
}

var qmpSocketServerString = "-qmp unix:cc-qmp,server,nowait"
var qmpSocketString = "-qmp unix:cc-qmp"
var qmpSingleSocketServerString = "-qmp unix:cc-qmp,server,nowait"
var qmpSingleSocketString = "-qmp unix:cc-qmp"

func TestAppendQMPSocketServer(t *testing.T) {
func TestAppendSingleQMPSocketServer(t *testing.T) {
qmp := QMPSocket{
Type: "unix",
Name: "cc-qmp",
Server: true,
NoWait: true,
}

testAppend(qmp, qmpSocketServerString, t)
testAppend(qmp, qmpSingleSocketServerString, t)
}

func TestAppendQMPSocket(t *testing.T) {
func TestAppendSingleQMPSocket(t *testing.T) {
qmp := QMPSocket{
Type: Unix,
Name: "cc-qmp",
Server: false,
}

testAppend(qmp, qmpSocketString, t)
testAppend(qmp, qmpSingleSocketString, t)
}

var qmpSocketServerString = "-qmp unix:cc-qmp-1,server,nowait -qmp unix:cc-qmp-2,server,nowait"

func TestAppendQMPSocketServer(t *testing.T) {
qmp := []QMPSocket{
{
Type: "unix",
Name: "cc-qmp-1",
Server: true,
NoWait: true,
},
{
Type: "unix",
Name: "cc-qmp-2",
Server: true,
NoWait: true,
},
}

testAppend(qmp, qmpSocketServerString, t)
}

var qemuString = "-name cc-qemu -cpu host -uuid " + testutil.AgentUUID
Expand Down

0 comments on commit 0333062

Please sign in to comment.