-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathtest_storagepoolxml.py
191 lines (186 loc) · 6.48 KB
/
test_storagepoolxml.py
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#
# Project Kimchi
#
# Copyright IBM Corp, 2015-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest
import lxml.etree as ET
from wok.plugins.kimchi.model.libvirtstoragepool import StoragePoolDef
class StoragepoolXMLTests(unittest.TestCase):
def test_get_storagepool_xml(self):
poolDefs = [
{
'def': {
'type': 'dir',
'name': 'unitTestDirPool',
'path': '/var/temp/images',
},
'xml': """
<pool type='dir'>
<name>unitTestDirPool</name>
<target>
<path>/var/temp/images</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'netfs',
'name': 'unitTestNFSPool',
'source': {'host': '127.0.0.1', 'path': '/var/export'},
},
'xml': """
<pool type='netfs'>
<name>unitTestNFSPool</name>
<source>
<host name='127.0.0.1'/>
<dir path='/var/export'/>
</source>
<target>
<path>/var/lib/kimchi/nfs_mount/unitTestNFSPool</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'logical',
'name': 'unitTestLogicalPool',
'source': {'devices': ['/dev/hda', '/dev/hdb']},
},
'xml': """
<pool type='logical'>
<name>unitTestLogicalPool</name>
<source>
<device path="/dev/hda" />
<device path="/dev/hdb" />
</source>
<target>
<path>/dev/unitTestLogicalPool</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'iscsi',
'name': 'unitTestISCSIPool',
'source': {
'host': '127.0.0.1',
'target': 'iqn.2003-01.org.linux-iscsi.localhost',
},
},
'xml': """
<pool type='iscsi'>
<name>unitTestISCSIPool</name>
<source>
<host name='127.0.0.1' />
<device path='iqn.2003-01.org.linux-iscsi.localhost'/>
</source>
<target>
<path>/dev/disk/by-id</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'iscsi',
'name': 'unitTestISCSIPoolPort',
'source': {
'host': '127.0.0.1',
'port': 3266,
'target': 'iqn.2003-01.org.linux-iscsi.localhost',
},
},
'xml': """
<pool type='iscsi'>
<name>unitTestISCSIPoolPort</name>
<source>
<host name='127.0.0.1' port='3266' />
<device path='iqn.2003-01.org.linux-iscsi.localhost'/>
</source>
<target>
<path>/dev/disk/by-id</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'iscsi',
'name': 'unitTestISCSIPoolAuth',
'source': {
'host': '127.0.0.1',
'target': 'iqn.2003-01.org.linux-iscsi.localhost',
'auth': {
'username': 'testUser',
'password': 'ActuallyNotUsedInPoolXML',
},
},
},
'xml': """
<pool type='iscsi'>
<name>unitTestISCSIPoolAuth</name>
<source>
<host name='127.0.0.1' />
<device path='iqn.2003-01.org.linux-iscsi.localhost'/>
<auth type='chap' username='testUser'>
<secret type='iscsi' usage='unitTestISCSIPoolAuth'/>
</auth>
</source>
<target>
<path>/dev/disk/by-id</path>
</target>
</pool>
""",
},
{
'def': {
'type': 'scsi',
'name': 'unitTestSCSIFCPool',
'path': '/dev/disk/by-path',
'source': {
'name': 'scsi_host3',
'adapter': {
'type': 'fc_host',
'wwpn': '0123456789abcdef',
'wwnn': 'abcdef0123456789',
},
},
},
'xml': """
<pool type='scsi'>
<name>unitTestSCSIFCPool</name>
<source>
<adapter type='fc_host' name='scsi_host3'
wwnn='abcdef0123456789' wwpn='0123456789abcdef'></adapter>
</source>
<target>
<path>/dev/disk/by-path</path>
</target>
</pool>
""",
},
]
for poolDef in poolDefs:
defObj = StoragePoolDef.create(poolDef['def'])
xmlStr = defObj.xml
parser = ET.XMLParser(remove_blank_text=True)
t1 = ET.fromstring(xmlStr, parser)
t2 = ET.fromstring(poolDef['xml'], parser)
self.assertEqual(ET.tostring(t1), ET.tostring(t2))