1+ // Licensed to the Apache Software Foundation (ASF) under one
2+ // or more contributor license agreements. See the NOTICE file
3+ // distributed with this work for additional information
4+ // regarding copyright ownership. The ASF licenses this file
5+ // to you under the Apache License, Version 2.0 (the
6+ // "License"); you may not use this file except in compliance
7+ // with the License. You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing,
12+ // software distributed under the License is distributed on an
13+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ // KIND, either express or implied. See the License for the
15+ // specific language governing permissions and limitations
16+ // under the License.
17+ package com .cloud .hypervisor .kvm .storage ;
18+
19+ import org .apache .cloudstack .utils .qemu .QemuImg .PhysicalDiskFormat ;
20+ import org .libvirt .StoragePool ;
21+ import org .mockito .Mockito ;
22+
23+ import com .cloud .storage .Storage .StoragePoolType ;
24+
25+ import junit .framework .TestCase ;
26+
27+ public class LibvirtStoragePoolTest extends TestCase {
28+
29+ public void testAttributes () {
30+ String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da" ;
31+ String name = "myfirstpool" ;
32+
33+ StoragePoolType type = StoragePoolType .NetworkFilesystem ;
34+
35+ StorageAdaptor adapter = Mockito .mock (LibvirtStorageAdaptor .class );
36+ StoragePool storage = Mockito .mock (StoragePool .class );
37+
38+ LibvirtStoragePool pool = new LibvirtStoragePool (uuid , name , type , adapter , storage );
39+ assertEquals (pool .getCapacity (), 0 );
40+ assertEquals (pool .getUsed (), 0 );
41+ assertEquals (pool .getName (), name );
42+ assertEquals (pool .getUuid (), uuid );
43+ assertEquals (pool .getAvailable (), 0 );
44+ assertEquals (pool .getStoragePoolType (), type );
45+
46+ pool .setCapacity (2048 );
47+ pool .setUsed (1024 );
48+ pool .setAvailable (1023 );
49+
50+ assertEquals (pool .getCapacity (), 2048 );
51+ assertEquals (pool .getUsed (), 1024 );
52+ assertEquals (pool .getAvailable (), 1023 );
53+ }
54+
55+ public void testDefaultFormats () {
56+ String uuid = "f40cbf53-1f37-4c62-8912-801edf398f47" ;
57+ String name = "myfirstpool" ;
58+
59+ StorageAdaptor adapter = Mockito .mock (LibvirtStorageAdaptor .class );
60+ StoragePool storage = Mockito .mock (StoragePool .class );
61+
62+ LibvirtStoragePool nfsPool = new LibvirtStoragePool (uuid , name , StoragePoolType .NetworkFilesystem , adapter , storage );
63+ assertEquals (nfsPool .getDefaultFormat (), PhysicalDiskFormat .QCOW2 );
64+ assertEquals (nfsPool .getStoragePoolType (), StoragePoolType .NetworkFilesystem );
65+
66+ LibvirtStoragePool rbdPool = new LibvirtStoragePool (uuid , name , StoragePoolType .RBD , adapter , storage );
67+ assertEquals (rbdPool .getDefaultFormat (), PhysicalDiskFormat .RAW );
68+ assertEquals (rbdPool .getStoragePoolType (), StoragePoolType .RBD );
69+
70+ LibvirtStoragePool clvmPool = new LibvirtStoragePool (uuid , name , StoragePoolType .CLVM , adapter , storage );
71+ assertEquals (clvmPool .getDefaultFormat (), PhysicalDiskFormat .RAW );
72+ assertEquals (clvmPool .getStoragePoolType (), StoragePoolType .CLVM );
73+ }
74+
75+ public void testExternalSnapshot () {
76+ String uuid = "60b46738-c5d0-40a9-a79e-9a4fe6295db7" ;
77+ String name = "myfirstpool" ;
78+
79+ StorageAdaptor adapter = Mockito .mock (LibvirtStorageAdaptor .class );
80+ StoragePool storage = Mockito .mock (StoragePool .class );
81+
82+ LibvirtStoragePool nfsPool = new LibvirtStoragePool (uuid , name , StoragePoolType .NetworkFilesystem , adapter , storage );
83+ assertFalse (nfsPool .isExternalSnapshot ());
84+
85+ LibvirtStoragePool rbdPool = new LibvirtStoragePool (uuid , name , StoragePoolType .RBD , adapter , storage );
86+ assertTrue (rbdPool .isExternalSnapshot ());
87+
88+ LibvirtStoragePool clvmPool = new LibvirtStoragePool (uuid , name , StoragePoolType .CLVM , adapter , storage );
89+ assertTrue (clvmPool .isExternalSnapshot ());
90+ }
91+ }
0 commit comments