-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathQEmuManagerTest.java
More file actions
85 lines (77 loc) · 3.45 KB
/
QEmuManagerTest.java
File metadata and controls
85 lines (77 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anarres.qemu.manager;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;
import org.anarres.qemu.exec.QEmuCommandLine;
import org.anarres.qemu.exec.QEmuCpusOption;
import org.anarres.qemu.exec.QEmuTestUtils;
import org.anarres.qemu.exec.recipe.QEmuVirtioDriveRecipe;
import org.anarres.qemu.image.QEmuImageFormat;
import org.anarres.qemu.qapi.api.BlockdevAddCommand;
import org.anarres.qemu.qapi.api.BlockdevAioOptions;
import org.anarres.qemu.qapi.api.BlockdevCacheOptions;
import org.anarres.qemu.qapi.api.BlockdevOptions;
import org.anarres.qemu.qapi.api.BlockdevOptionsFile;
import org.anarres.qemu.qapi.api.OnOffAuto;
import org.anarres.qemu.qapi.api.QueryBlockCommand;
import org.anarres.qemu.qapi.common.QApiConnection;
import org.anarres.qemu.qapi.common.QApiException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
/**
*
* @author shevek
*/
public class QEmuManagerTest {
private static final Logger LOG = LoggerFactory.getLogger(QEmuManagerTest.class);
@Test
public void testManager() throws Exception {
File dir = QEmuTestUtils.newTemporaryDirectory();
QEmuCommandLine commandLine = QEmuTestUtils.newCommandLine();
commandLine.addOptions(
new QEmuCpusOption(4).withSockets(2).withCores(2),
new QEmuVirtioDriveRecipe(0, QEmuTestUtils.newTemporaryDisk(dir, "sda"))
.withFormat(QEmuImageFormat.raw));
QEmuProcess process = QEmuTestUtils.newQEmuProcess(commandLine);
try {
QApiConnection connection = process.getConnection(10, TimeUnit.SECONDS);
QEmuTestUtils.inspect(connection);
try {
File file = QEmuTestUtils.newTemporaryDiskFile(dir, "sdb");
BlockdevOptions options = BlockdevOptions.file(
new BlockdevOptionsFile(
file.getAbsolutePath(),
null,
OnOffAuto.auto,
BlockdevAioOptions._native,
null));
options.withReadOnly(true);
options.withNodeName("test-file-node");
options.withCache(new BlockdevCacheOptions().withDirect(true));
connection.call(new BlockdevAddCommand(options));
LOG.info("Blocks is " + connection.call(new QueryBlockCommand()));
} catch (QApiException e) {
// Perhaps we are running on QEmu 1.0.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
assertTrue("QApiException: " + e.toString() + " Stack: " + baos.toString(),
e.getMessage().contains("has not been found"));
LOG.warn("Limited testing available on QEmu <1.7", e);
}
// connection.call(new NbdServerStartCommand(new SocketAddress().withInet(new InetSocketAddress().withHost("localhost").withPort("4446"))));
// connection.call(new NbdServerAddCommand("foo", Boolean.FALSE));
Thread.sleep(5000);
} finally {
process.destroy();
}
}
}