|
20 | 20 |
|
21 | 21 | import static org.junit.Assert.assertTrue; |
22 | 22 |
|
| 23 | +import java.io.IOException; |
| 24 | + |
| 25 | +import org.apache.commons.io.Charsets; |
| 26 | +import org.junit.BeforeClass; |
23 | 27 | import org.junit.Test; |
24 | 28 |
|
| 29 | +import com.google.common.io.Resources; |
| 30 | + |
25 | 31 | public class LibvirtMigrateCommandWrapperTest { |
26 | | - String fullfile = |
27 | | -"<domain type='kvm' id='4'>\n" + |
28 | | -" <name>i-6-6-VM</name>\n" + |
29 | | -" <uuid>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</uuid>\n" + |
30 | | -" <description>Other PV (64-bit)</description>\n" + |
31 | | -" <memory unit='KiB'>262144</memory>\n" + |
32 | | -" <currentMemory unit='KiB'>262144</currentMemory>\n" + |
33 | | -" <vcpu placement='static'>1</vcpu>\n" + |
34 | | -" <cputune>\n" + |
35 | | -" <shares>100</shares>\n" + |
36 | | -" </cputune>\n" + |
37 | | -" <resource>\n" + |
38 | | -" <partition>/machine</partition>\n" + |
39 | | -" </resource>\n" + |
40 | | -" <sysinfo type='smbios'>\n" + |
41 | | -" <system>\n" + |
42 | | -" <entry name='manufacturer'>Apache Software Foundation</entry>\n" + |
43 | | -" <entry name='product'>CloudStack KVM Hypervisor</entry>\n" + |
44 | | -" <entry name='uuid'>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</entry>\n" + |
45 | | -" </system>\n" + |
46 | | -" </sysinfo>\n" + |
47 | | -" <os>\n" + |
48 | | -" <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>\n" + |
49 | | -" <boot dev='cdrom'/>\n" + |
50 | | -" <boot dev='hd'/>\n" + |
51 | | -" <smbios mode='sysinfo'/>\n" + |
52 | | -" </os>\n" + |
53 | | -" <features>\n" + |
54 | | -" <acpi/>\n" + |
55 | | -" <apic/>\n" + |
56 | | -" <pae/>\n" + |
57 | | -" </features>\n" + |
58 | | -" <clock offset='utc'>\n" + |
59 | | -" <timer name='kvmclock'/>\n" + |
60 | | -" </clock>\n" + |
61 | | -" <on_poweroff>destroy</on_poweroff>\n" + |
62 | | -" <on_reboot>restart</on_reboot>\n" + |
63 | | -" <on_crash>destroy</on_crash>\n" + |
64 | | -" <devices>\n" + |
65 | | -" <emulator>/usr/libexec/qemu-kvm</emulator>\n" + |
66 | | -" <disk type='file' device='disk'>\n" + |
67 | | -" <driver name='qemu' type='qcow2' cache='none'/>\n" + |
68 | | -" <source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/4650a2f7-fce5-48e2-beaa-bcdf063194e6'/>\n" + |
69 | | -" <backingStore type='file' index='1'>\n" + |
70 | | -" <format type='raw'/>\n" + |
71 | | -" <source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/bb4d4df4-c004-11e5-94ed-5254001daa61'/>\n" + |
72 | | -" <backingStore/>\n" + |
73 | | -" </backingStore>\n" + |
74 | | -" <target dev='vda' bus='virtio'/>\n" + |
75 | | -" <serial>4650a2f7fce548e2beaa</serial>\n" + |
76 | | -" <alias name='virtio-disk0'/>\n" + |
77 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>\n" + |
78 | | -" </disk>\n" + |
79 | | -" <disk type='file' device='cdrom'>\n" + |
80 | | -" <driver name='qemu' type='raw' cache='none'/>\n" + |
81 | | -" <backingStore/>\n" + |
82 | | -" <target dev='hdc' bus='ide'/>\n" + |
83 | | -" <readonly/>\n" + |
84 | | -" <alias name='ide0-1-0'/>\n" + |
85 | | -" <address type='drive' controller='0' bus='1' target='0' unit='0'/>\n" + |
86 | | -" </disk>\n" + |
87 | | -" <controller type='usb' index='0'>\n" + |
88 | | -" <alias name='usb'/>\n" + |
89 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>\n" + |
90 | | -" </controller>\n" + |
91 | | -" <controller type='pci' index='0' model='pci-root'>\n" + |
92 | | -" <alias name='pci.0'/>\n" + |
93 | | -" </controller>\n" + |
94 | | -" <controller type='ide' index='0'>\n" + |
95 | | -" <alias name='ide'/>\n" + |
96 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>\n" + |
97 | | -" </controller>\n" + |
98 | | -" <interface type='bridge'>\n" + |
99 | | -" <mac address='06:fe:b4:00:00:06'/>\n" + |
100 | | -" <source bridge='breth0-50'/>\n" + |
101 | | -" <bandwidth>\n" + |
102 | | -" <inbound average='25600' peak='25600'/>\n" + |
103 | | -" <outbound average='25600' peak='25600'/>\n" + |
104 | | -" </bandwidth>\n" + |
105 | | -" <target dev='vnet4'/>\n" + |
106 | | -" <model type='virtio'/>\n" + |
107 | | -" <alias name='net0'/>\n" + |
108 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>\n" + |
109 | | -" </interface>\n" + |
110 | | -" <serial type='pty'>\n" + |
111 | | -" <source path='/dev/pts/2'/>\n" + |
112 | | -" <target port='0'/>\n" + |
113 | | -" <alias name='serial0'/>\n" + |
114 | | -" </serial>\n" + |
115 | | -" <console type='pty' tty='/dev/pts/2'>\n" + |
116 | | -" <source path='/dev/pts/2'/>\n" + |
117 | | -" <target type='serial' port='0'/>\n" + |
118 | | -" <alias name='serial0'/>\n" + |
119 | | -" </console>\n" + |
120 | | -" <input type='tablet' bus='usb'>\n" + |
121 | | -" <alias name='input0'/>\n" + |
122 | | -" </input>\n" + |
123 | | -" <input type='mouse' bus='ps2'/>\n" + |
124 | | -" <input type='keyboard' bus='ps2'/>\n" + |
125 | | -" <graphics type='vnc' port='5902' autoport='yes' listen='192.168.22.22'>\n" + |
126 | | -" <listen type='address' address='192.168.22.22'/>\n" + |
127 | | -" </graphics>\n" + |
128 | | -" <video>\n" + |
129 | | -" <model type='cirrus' vram='16384' heads='1'/>\n" + |
130 | | -" <alias name='video0'/>\n" + |
131 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>\n" + |
132 | | -" </video>\n" + |
133 | | -" <memballoon model='none'>\n" + |
134 | | -" <alias name='balloon0'/>\n" + |
135 | | -" </memballoon>\n" + |
136 | | -" </devices>\n" + |
137 | | -"</domain>"; |
138 | | - String targetfile = |
139 | | -"<domain type='kvm' id='4'>\n" + |
140 | | -" <name>i-6-6-VM</name>\n" + |
141 | | -" <uuid>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</uuid>\n" + |
142 | | -" <description>Other PV (64-bit)</description>\n" + |
143 | | -" <memory unit='KiB'>262144</memory>\n" + |
144 | | -" <currentMemory unit='KiB'>262144</currentMemory>\n" + |
145 | | -" <vcpu placement='static'>1</vcpu>\n" + |
146 | | -" <cputune>\n" + |
147 | | -" <shares>100</shares>\n" + |
148 | | -" </cputune>\n" + |
149 | | -" <resource>\n" + |
150 | | -" <partition>/machine</partition>\n" + |
151 | | -" </resource>\n" + |
152 | | -" <sysinfo type='smbios'>\n" + |
153 | | -" <system>\n" + |
154 | | -" <entry name='manufacturer'>Apache Software Foundation</entry>\n" + |
155 | | -" <entry name='product'>CloudStack KVM Hypervisor</entry>\n" + |
156 | | -" <entry name='uuid'>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</entry>\n" + |
157 | | -" </system>\n" + |
158 | | -" </sysinfo>\n" + |
159 | | -" <os>\n" + |
160 | | -" <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>\n" + |
161 | | -" <boot dev='cdrom'/>\n" + |
162 | | -" <boot dev='hd'/>\n" + |
163 | | -" <smbios mode='sysinfo'/>\n" + |
164 | | -" </os>\n" + |
165 | | -" <features>\n" + |
166 | | -" <acpi/>\n" + |
167 | | -" <apic/>\n" + |
168 | | -" <pae/>\n" + |
169 | | -" </features>\n" + |
170 | | -" <clock offset='utc'>\n" + |
171 | | -" <timer name='kvmclock'/>\n" + |
172 | | -" </clock>\n" + |
173 | | -" <on_poweroff>destroy</on_poweroff>\n" + |
174 | | -" <on_reboot>restart</on_reboot>\n" + |
175 | | -" <on_crash>destroy</on_crash>\n" + |
176 | | -" <devices>\n" + |
177 | | -" <emulator>/usr/libexec/qemu-kvm</emulator>\n" + |
178 | | -" <disk type='file' device='disk'>\n" + |
179 | | -" <driver name='qemu' type='qcow2' cache='none'/>\n" + |
180 | | -" <source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/4650a2f7-fce5-48e2-beaa-bcdf063194e6'/>\n" + |
181 | | -" <backingStore type='file' index='1'>\n" + |
182 | | -" <format type='raw'/>\n" + |
183 | | -" <source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/bb4d4df4-c004-11e5-94ed-5254001daa61'/>\n" + |
184 | | -" <backingStore/>\n" + |
185 | | -" </backingStore>\n" + |
186 | | -" <target dev='vda' bus='virtio'/>\n" + |
187 | | -" <serial>4650a2f7fce548e2beaa</serial>\n" + |
188 | | -" <alias name='virtio-disk0'/>\n" + |
189 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>\n" + |
190 | | -" </disk>\n" + |
191 | | -" <disk type='file' device='cdrom'>\n" + |
192 | | -" <driver name='qemu' type='raw' cache='none'/>\n" + |
193 | | -" <backingStore/>\n" + |
194 | | -" <target dev='hdc' bus='ide'/>\n" + |
195 | | -" <readonly/>\n" + |
196 | | -" <alias name='ide0-1-0'/>\n" + |
197 | | -" <address type='drive' controller='0' bus='1' target='0' unit='0'/>\n" + |
198 | | -" </disk>\n" + |
199 | | -" <controller type='usb' index='0'>\n" + |
200 | | -" <alias name='usb'/>\n" + |
201 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>\n" + |
202 | | -" </controller>\n" + |
203 | | -" <controller type='pci' index='0' model='pci-root'>\n" + |
204 | | -" <alias name='pci.0'/>\n" + |
205 | | -" </controller>\n" + |
206 | | -" <controller type='ide' index='0'>\n" + |
207 | | -" <alias name='ide'/>\n" + |
208 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>\n" + |
209 | | -" </controller>\n" + |
210 | | -" <interface type='bridge'>\n" + |
211 | | -" <mac address='06:fe:b4:00:00:06'/>\n" + |
212 | | -" <source bridge='breth0-50'/>\n" + |
213 | | -" <bandwidth>\n" + |
214 | | -" <inbound average='25600' peak='25600'/>\n" + |
215 | | -" <outbound average='25600' peak='25600'/>\n" + |
216 | | -" </bandwidth>\n" + |
217 | | -" <target dev='vnet4'/>\n" + |
218 | | -" <model type='virtio'/>\n" + |
219 | | -" <alias name='net0'/>\n" + |
220 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>\n" + |
221 | | -" </interface>\n" + |
222 | | -" <serial type='pty'>\n" + |
223 | | -" <source path='/dev/pts/2'/>\n" + |
224 | | -" <target port='0'/>\n" + |
225 | | -" <alias name='serial0'/>\n" + |
226 | | -" </serial>\n" + |
227 | | -" <console type='pty' tty='/dev/pts/2'>\n" + |
228 | | -" <source path='/dev/pts/2'/>\n" + |
229 | | -" <target type='serial' port='0'/>\n" + |
230 | | -" <alias name='serial0'/>\n" + |
231 | | -" </console>\n" + |
232 | | -" <input type='tablet' bus='usb'>\n" + |
233 | | -" <alias name='input0'/>\n" + |
234 | | -" </input>\n" + |
235 | | -" <input type='mouse' bus='ps2'/>\n" + |
236 | | -" <input type='keyboard' bus='ps2'/>\n" + |
237 | | -" <graphics type='vnc' port='5902' autoport='yes' listen='192.168.22.21'>\n" + |
238 | | -" <listen type='address' address='192.168.22.21'/>\n" + |
239 | | -" </graphics>\n" + |
240 | | -" <video>\n" + |
241 | | -" <model type='cirrus' vram='16384' heads='1'/>\n" + |
242 | | -" <alias name='video0'/>\n" + |
243 | | -" <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>\n" + |
244 | | -" </video>\n" + |
245 | | -" <memballoon model='none'>\n" + |
246 | | -" <alias name='balloon0'/>\n" + |
247 | | -" </memballoon>\n" + |
248 | | -" </devices>\n" + |
249 | | -"</domain>"; |
| 32 | + static String fullfile; |
| 33 | + static String targetfile; |
| 34 | + |
| 35 | + @BeforeClass |
| 36 | + public static void setup() { |
| 37 | + try { |
| 38 | + fullfile = Resources.toString(Resources.getResource("original.xml"), Charsets.UTF_8); |
| 39 | + targetfile = Resources.toString(Resources.getResource("expected.xml"), Charsets.UTF_8); |
| 40 | + } catch (IOException e) { |
| 41 | + // TODO Auto-generated catch block |
| 42 | + e.printStackTrace(); |
| 43 | + } |
| 44 | + } |
250 | 45 |
|
251 | 46 | @Test |
252 | 47 | public void testReplaceIpForVNCInDescFile() { |
|
0 commit comments