|
| 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 static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertFalse; |
| 21 | +import static org.junit.Assert.assertSame; |
| 22 | +import static org.junit.Assert.assertTrue; |
| 23 | + |
| 24 | +import java.lang.reflect.Modifier; |
| 25 | +import java.util.Set; |
| 26 | + |
| 27 | +import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; |
| 28 | +import org.junit.Test; |
| 29 | +import org.reflections.Reflections; |
| 30 | + |
| 31 | +import com.cloud.storage.Storage.StoragePoolType; |
| 32 | + |
| 33 | +public class OntapIscsiStorageAdaptorTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + public void getStoragePoolTypeReturnsOntapIscsi() { |
| 37 | + assertEquals(StoragePoolType.OntapiSCSI, new OntapIscsiStorageAdaptor().getStoragePoolType()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void createdPoolCarriesOntapIscsiTypeAndRawFormat() { |
| 42 | + OntapIscsiStorageAdaptor adaptor = new OntapIscsiStorageAdaptor(); |
| 43 | + |
| 44 | + KVMStoragePool pool = adaptor.createStoragePool("ontap-iscsi-pool-uuid", "10.0.0.1", 3260, null, null, |
| 45 | + StoragePoolType.OntapiSCSI, null, true); |
| 46 | + |
| 47 | + assertEquals(StoragePoolType.OntapiSCSI, pool.getType()); |
| 48 | + // Attach builds a block-based disk off the physical disk format rather than the pool type, |
| 49 | + // which is why splitting OntapiSCSI out of Iscsi leaves the generated domain XML unchanged. |
| 50 | + assertEquals(PhysicalDiskFormat.RAW, pool.getDefaultFormat()); |
| 51 | + assertSame(pool, adaptor.getStoragePool("ontap-iscsi-pool-uuid")); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * KVMStoragePoolManager discovers adaptors by a Reflections scan of its own package, instantiating |
| 56 | + * each concrete implementation through a no-arg constructor and keying it on getStoragePoolType(). |
| 57 | + * A type with no adaptor silently falls back to LibvirtStorageAdaptor instead of failing at |
| 58 | + * startup, so this reproduces the discovery preconditions rather than waiting for the symptom. |
| 59 | + * The manager itself is not constructed here because doing so also instantiates |
| 60 | + * MultipathSCSIAdapterBase, which requires agent scripts resolvable from the working directory. |
| 61 | + */ |
| 62 | + @Test |
| 63 | + public void adaptorSatisfiesThePoolManagerDiscoveryContract() throws ReflectiveOperationException { |
| 64 | + String scannedPackage = KVMStoragePoolManager.class.getPackage().getName(); |
| 65 | + Set<Class<? extends StorageAdaptor>> discovered = |
| 66 | + new Reflections(scannedPackage).getSubTypesOf(StorageAdaptor.class); |
| 67 | + |
| 68 | + assertTrue("OntapIscsiStorageAdaptor must live in " + scannedPackage + " to be discovered", |
| 69 | + discovered.contains(OntapIscsiStorageAdaptor.class)); |
| 70 | + assertFalse("An abstract adaptor is skipped by the scan", |
| 71 | + Modifier.isAbstract(OntapIscsiStorageAdaptor.class.getModifiers())); |
| 72 | + |
| 73 | + StorageAdaptor adaptor = OntapIscsiStorageAdaptor.class.getDeclaredConstructor().newInstance(); |
| 74 | + assertEquals(StoragePoolType.OntapiSCSI, adaptor.getStoragePoolType()); |
| 75 | + assertEquals("The superclass must keep serving the other iSCSI vendors", |
| 76 | + StoragePoolType.Iscsi, new IscsiAdmStorageAdaptor().getStoragePoolType()); |
| 77 | + } |
| 78 | +} |
0 commit comments