@@ -114,30 +114,49 @@ def test_remove_checksum(tmpdir):
114
114
115
115
def test_list_images (tmpdir ):
116
116
117
- path1 = tmpdir / "images1" / "IOS" / "test1.image"
118
- path1 .write (b'\x7f ELF\x01 \x01 \x01 ' , ensure = True )
119
- path1 = force_unix_path (str (path1 ))
120
-
121
- path2 = tmpdir / "images2" / "test2.image"
122
- path2 .write (b'\x7f ELF\x01 \x01 \x01 ' , ensure = True )
123
- path2 = force_unix_path (str (path2 ))
117
+ # IOS image in the images directory
118
+ ios_image_1 = tmpdir / "images1" / "IOS" / "ios_image_1.image"
119
+ ios_image_1 .write (b'\x7f ELF\x01 \x02 \x01 ' , ensure = True )
120
+ ios_image_1 = force_unix_path (str (ios_image_1 ))
124
121
125
- # Invalid image because not a valid elf file
126
- path = tmpdir / "images2" / "test_invalid.image"
127
- path .write (b'NOTANELF' , ensure = True )
122
+ # IOS image in an additional images path
123
+ ios_image_2 = tmpdir / "images2" / "ios_image_2.image"
124
+ ios_image_2 .write (b'\x7f ELF\x01 \x02 \x01 ' , ensure = True )
125
+ ios_image_2 = force_unix_path (str (ios_image_2 ))
128
126
129
- if sys . platform . startswith ( "linux" ):
130
- path3 = tmpdir / "images1" / "IOU " / "test3.bin "
131
- path3 .write (b'\x7f ELF \x02 \x01 \x01 ' , ensure = True )
132
- path3 = force_unix_path (str (path3 ))
127
+ # Not a valid elf file
128
+ not_elf_file = tmpdir / "images1" / "IOS " / "not_elf.image "
129
+ not_elf_file .write (b'NOTANELF ' , ensure = True )
130
+ not_elf_file = force_unix_path (str (not_elf_file ))
133
131
134
- path4 = tmpdir / "images1" / "QEMU" / "test4.qcow2"
135
- path4 . write ( "1" , ensure = True )
136
- path4 = force_unix_path ( str ( path4 ) )
132
+ # Invalid image because it is very small
133
+ small_file = tmpdir / "images1" / "too_small.image"
134
+ small_file . write ( b'1' , ensure = True )
137
135
138
- path5 = tmpdir / "images1" / "QEMU" / "test4.qcow2.md5sum"
139
- path5 .write ("1" , ensure = True )
140
- path5 = force_unix_path (str (path5 ))
136
+ if sys .platform .startswith ("linux" ):
137
+ # 64-bit IOU image
138
+ iou_image_1 = tmpdir / "images1" / "IOU" / "iou64.bin"
139
+ iou_image_1 .write (b'\x7f ELF\x02 \x01 \x01 ' , ensure = True )
140
+ iou_image_1 = force_unix_path (str (iou_image_1 ))
141
+ # 32-bit IOU image
142
+ iou_image_2 = tmpdir / "images1" / "IOU" / "iou32.bin"
143
+ iou_image_2 .write (b'\x7f ELF\x01 \x01 \x01 ' , ensure = True ) # 32-bit IOU image
144
+ iou_image_2 = force_unix_path (str (iou_image_2 ))
145
+
146
+
147
+ # Qemu image
148
+ qemu_image_1 = tmpdir / "images1" / "QEMU" / "qemu_image.qcow2"
149
+ qemu_image_1 .write ("1234567" , ensure = True )
150
+ qemu_image_1 = force_unix_path (str (qemu_image_1 ))
151
+
152
+ # ELF file inside the Qemu
153
+ elf_file = tmpdir / "images1" / "QEMU" / "elf_file.bin"
154
+ elf_file .write (b'\x7f ELF\x02 \x01 \x01 ' , ensure = True ) # ELF file
155
+ elf_file = force_unix_path (str (elf_file ))
156
+
157
+ md5sum_file = tmpdir / "images1" / "QEMU" / "image.qcow2.md5sum"
158
+ md5sum_file .write ("1" , ensure = True )
159
+ md5sum_file = force_unix_path (str (md5sum_file ))
141
160
142
161
with patch ("gns3server.config.Config.get_section_config" , return_value = {
143
162
"images_path" : str (tmpdir / "images1" ),
@@ -146,34 +165,40 @@ def test_list_images(tmpdir):
146
165
147
166
assert list_images ("dynamips" ) == [
148
167
{
149
- 'filename' : 'test1 .image' ,
168
+ 'filename' : 'ios_image_1 .image' ,
150
169
'filesize' : 7 ,
151
- 'md5sum' : 'e573e8f5c93c6c00783f20c7a170aa6c ' ,
152
- 'path' : 'test1 .image'
170
+ 'md5sum' : 'b0d5aa897d937aced5a6b1046e8f7e2e ' ,
171
+ 'path' : 'ios_image_1 .image'
153
172
},
154
173
{
155
- 'filename' : 'test2 .image' ,
174
+ 'filename' : 'ios_image_2 .image' ,
156
175
'filesize' : 7 ,
157
- 'md5sum' : 'e573e8f5c93c6c00783f20c7a170aa6c ' ,
158
- 'path' : str (path2 )
176
+ 'md5sum' : 'b0d5aa897d937aced5a6b1046e8f7e2e ' ,
177
+ 'path' : str (ios_image_2 )
159
178
}
160
179
]
161
180
162
181
if sys .platform .startswith ("linux" ):
163
182
assert list_images ("iou" ) == [
164
183
{
165
- 'filename' : 'test3 .bin' ,
184
+ 'filename' : 'iou64 .bin' ,
166
185
'filesize' : 7 ,
167
186
'md5sum' : 'c73626d23469519894d58bc98bee9655' ,
168
- 'path' : 'test3.bin'
187
+ 'path' : 'iou64.bin'
188
+ },
189
+ {
190
+ 'filename' : 'iou32.bin' ,
191
+ 'filesize' : 7 ,
192
+ 'md5sum' : 'e573e8f5c93c6c00783f20c7a170aa6c' ,
193
+ 'path' : 'iou32.bin'
169
194
}
170
195
]
171
196
172
197
assert list_images ("qemu" ) == [
173
198
{
174
- 'filename' : 'test4 .qcow2' ,
175
- 'filesize' : 1 ,
176
- 'md5sum' : 'c4ca4238a0b923820dcc509a6f75849b ' ,
177
- 'path' : 'test4 .qcow2'
199
+ 'filename' : 'qemu_image .qcow2' ,
200
+ 'filesize' : 7 ,
201
+ 'md5sum' : 'fcea920f7412b5da7be0cf42b8c93759 ' ,
202
+ 'path' : 'qemu_image .qcow2'
178
203
}
179
204
]
0 commit comments