Skip to content

Commit dfebdd2

Browse files
committed
externalize xml input and -result for test
1 parent 4e43b83 commit dfebdd2

File tree

3 files changed

+279
-224
lines changed

3 files changed

+279
-224
lines changed

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java

Lines changed: 19 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -20,233 +20,28 @@
2020

2121
import static org.junit.Assert.assertTrue;
2222

23+
import java.io.IOException;
24+
25+
import org.apache.commons.io.Charsets;
26+
import org.junit.BeforeClass;
2327
import org.junit.Test;
2428

29+
import com.google.common.io.Resources;
30+
2531
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+
}
25045

25146
@Test
25247
public void testReplaceIpForVNCInDescFile() {
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<?xml version="1.0" encoding="UTF-8"?>
20+
<domain type='kvm' id='4'>
21+
<name>i-6-6-VM</name>
22+
<uuid>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</uuid>
23+
<description>Other PV (64-bit)</description>
24+
<memory unit='KiB'>262144</memory>
25+
<currentMemory unit='KiB'>262144</currentMemory>
26+
<vcpu placement='static'>1</vcpu>
27+
<cputune>
28+
<shares>100</shares>
29+
</cputune>
30+
<resource>
31+
<partition>/machine</partition>
32+
</resource>
33+
<sysinfo type='smbios'>
34+
<system>
35+
<entry name='manufacturer'>Apache Software Foundation</entry>
36+
<entry name='product'>CloudStack KVM Hypervisor</entry>
37+
<entry name='uuid'>f197b32b-8da2-4a57-bb8a-d01bacc5cd33</entry>
38+
</system>
39+
</sysinfo>
40+
<os>
41+
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
42+
<boot dev='cdrom'/>
43+
<boot dev='hd'/>
44+
<smbios mode='sysinfo'/>
45+
</os>
46+
<features>
47+
<acpi/>
48+
<apic/>
49+
<pae/>
50+
</features>
51+
<clock offset='utc'>
52+
<timer name='kvmclock'/>
53+
</clock>
54+
<on_poweroff>destroy</on_poweroff>
55+
<on_reboot>restart</on_reboot>
56+
<on_crash>destroy</on_crash>
57+
<devices>
58+
<emulator>/usr/libexec/qemu-kvm</emulator>
59+
<disk type='file' device='disk'>
60+
<driver name='qemu' type='qcow2' cache='none'/>
61+
<source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/4650a2f7-fce5-48e2-beaa-bcdf063194e6'/>
62+
<backingStore type='file' index='1'>
63+
<format type='raw'/>
64+
<source file='/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/bb4d4df4-c004-11e5-94ed-5254001daa61'/>
65+
<backingStore/>
66+
</backingStore>
67+
<target dev='vda' bus='virtio'/>
68+
<serial>4650a2f7fce548e2beaa</serial>
69+
<alias name='virtio-disk0'/>
70+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
71+
</disk>
72+
<disk type='file' device='cdrom'>
73+
<driver name='qemu' type='raw' cache='none'/>
74+
<backingStore/>
75+
<target dev='hdc' bus='ide'/>
76+
<readonly/>
77+
<alias name='ide0-1-0'/>
78+
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
79+
</disk>
80+
<controller type='usb' index='0'>
81+
<alias name='usb'/>
82+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
83+
</controller>
84+
<controller type='pci' index='0' model='pci-root'>
85+
<alias name='pci.0'/>
86+
</controller>
87+
<controller type='ide' index='0'>
88+
<alias name='ide'/>
89+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
90+
</controller>
91+
<interface type='bridge'>
92+
<mac address='06:fe:b4:00:00:06'/>
93+
<source bridge='breth0-50'/>
94+
<bandwidth>
95+
<inbound average='25600' peak='25600'/>
96+
<outbound average='25600' peak='25600'/>
97+
</bandwidth>
98+
<target dev='vnet4'/>
99+
<model type='virtio'/>
100+
<alias name='net0'/>
101+
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
102+
</interface>
103+
<serial type='pty'>
104+
<source path='/dev/pts/2'/>
105+
<target port='0'/>
106+
<alias name='serial0'/>
107+
</serial>
108+
<console type='pty' tty='/dev/pts/2'>
109+
<source path='/dev/pts/2'/>
110+
<target type='serial' port='0'/>
111+
<alias name='serial0'/>
112+
</console>
113+
<input type='tablet' bus='usb'>
114+
<alias name='input0'/>
115+
</input>
116+
<input type='mouse' bus='ps2'/>
117+
<input type='keyboard' bus='ps2'/>
118+
<graphics type='vnc' port='5902' autoport='yes' listen='192.168.22.21'>
119+
<listen type='address' address='192.168.22.21'/>
120+
</graphics>
121+
<video>
122+
<model type='cirrus' vram='16384' heads='1'/>
123+
<alias name='video0'/>
124+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
125+
</video>
126+
<memballoon model='none'>
127+
<alias name='balloon0'/>
128+
</memballoon>
129+
</devices>
130+
</domain>

0 commit comments

Comments
 (0)