// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.hypervisor.ovm3.objects; import static org.junit.Assert.assertNotNull; import org.junit.Test; import com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties; import com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails; public class StoragePluginTest { ConnectionTest con = new ConnectionTest(); StoragePlugin sPt = new StoragePlugin(con); XmlTestResultTest results = new XmlTestResultTest(); String NFSHOST = "nfs-store-1"; String NFSPATH = "/volumes/cs-data/primary"; String NFSMNT = "/nfsmnt"; String FSPROPUUID = sPt.deDash(sPt.newUuid()); String FSMNTUUID = sPt.newUuid(); String POOLUUID = sPt.deDash(FSMNTUUID); String FILE = "a.file"; Long SIZE = 2096898048L; String STORAGEPLUGINXML = "<string>" + "<?xml version=\"1.0\" ?>" + "<Discover_Storage_Plugins_Result>" + "<storage_plugin_info_list>" + "<storage_plugin_info plugin_impl_name=\"oracle.ocfs2.OCFS2.OCFS2Plugin\">" + "<fs_api_version>1,2,7</fs_api_version>" + "<generic_plugin>False</generic_plugin>" + "<plugin_version>0.1.0-38</plugin_version>" + "<filesys_type>LocalFS</filesys_type>" + "<extended_api_version>None</extended_api_version>" + "<plugin_desc>Oracle OCFS2 File system Storage Connect Plugin</plugin_desc>" + "<cluster_required>True</cluster_required>" + "<plugin_name>Oracle OCFS2 File system</plugin_name>" + "<fs_extra_info_help>None</fs_extra_info_help>" + "<required_api_vers>1,2,7</required_api_vers>" + "<file_extra_info_help>None</file_extra_info_help>" + "<ss_extra_info_help>None</ss_extra_info_help>" + "<filesys_name>ocfs2</filesys_name>" + "<vendor_name>Oracle</vendor_name>" + "<plugin_type>ifs</plugin_type>" + "<abilities>" + "<resize_is_sync>YES</resize_is_sync>" + "<clone_is_sync>YES</clone_is_sync>" + "<access_control>NO</access_control>" + "<custom_clone_name>YES</custom_clone_name>" + "<require_storage_name>NO</require_storage_name>" + "<backing_device_type>DEVICE_SINGLE</backing_device_type>" + "<splitclone_while_open>NO</splitclone_while_open>" + "<custom_snap_name>YES</custom_snap_name>" + "<snapshot>ONLINE</snapshot>" + "<splitclone>UNSUPPORTED</splitclone>" + "<snap_is_sync>YES</snap_is_sync>" + "<snapclone>ONLINE</snapclone>" + "<splitclone_is_sync>NO</splitclone_is_sync>" + "<clone>ONLINE</clone>" + "<resize>ONLINE</resize>" + "<snapclone_is_sync>YES</snapclone_is_sync>" + "</abilities>" + "</storage_plugin_info>" + "<storage_plugin_info plugin_impl_name=\"oracle.generic.SCSIPlugin.GenericPlugin\">" + "<storage_types>SAN,iSCSI</storage_types>" + "<generic_plugin>True</generic_plugin>" + "<plugin_version>1.1.0</plugin_version>" + "<extended_api_version>1,2,9</extended_api_version>" + "<plugin_desc>Oracle Storage Connect Plugin for Generic FC and iSCSI</plugin_desc>" + "<plugin_name>Oracle Generic SCSI Plugin</plugin_name>" + "<sa_api_version>1,2,7</sa_api_version>" + "<required_api_vers>1,2,7</required_api_vers>" + "<ss_extra_info_help>None</ss_extra_info_help>" + "<se_extra_info_help>None</se_extra_info_help>" + "<vendor_name>Oracle</vendor_name>" + "<plugin_type>isa</plugin_type>" + "<abilities>" + "<resize_is_sync>UNSUPPORTED</resize_is_sync>" + "<clone_is_sync>UNSUPPORTED</clone_is_sync>" + "<access_control>NO</access_control>" + "<custom_clone_name>UNSUPPORTED</custom_clone_name>" + "<require_storage_name>UNSUPPORTED</require_storage_name>" + "<custom_snap_name>UNSUPPORTED</custom_snap_name>" + "<snapshot>UNSUPPORTED</snapshot>" + "<splitclone>UNSUPPORTED</splitclone>" + "<snap_is_sync>UNSUPPORTED</snap_is_sync>" + "<snapclone>UNSUPPORTED</snapclone>" + "<splitclone_is_sync>UNSUPPORTED</splitclone_is_sync>" + "<clone>UNSUPPORTED</clone>" + "<resize>UNSUPPORTED</resize>" + "<snapclone_is_sync>UNSUPPORTED</snapclone_is_sync>" + "</abilities>" + "</storage_plugin_info>" + "<storage_plugin_info plugin_impl_name=\"oracle.generic.NFSPlugin.GenericNFSPlugin\">" + "<fs_api_version>1,2,7</fs_api_version>" + "<generic_plugin>True</generic_plugin>" + "<plugin_version>1.1.0</plugin_version>" + "<filesys_type>NetworkFS</filesys_type>" + "<extended_api_version>None</extended_api_version>" + "<plugin_desc>Oracle Generic Network File System Storage Connect Plugin</plugin_desc>" + "<cluster_required>False</cluster_required>" + "<plugin_name>Oracle Generic Network File System</plugin_name>" + "<fs_extra_info_help>None</fs_extra_info_help>" + "<required_api_vers>1,2,7</required_api_vers>" + "<file_extra_info_help>None</file_extra_info_help>" + "<ss_extra_info_help>None</ss_extra_info_help>" + "<filesys_name>NFS</filesys_name>" + "<vendor_name>Oracle</vendor_name>" + "<plugin_type>ifs</plugin_type>" + "<abilities>" + "<resize_is_sync>UNSUPPORTED</resize_is_sync>" + "<clone_is_sync>UNSUPPORTED</clone_is_sync>" + "<access_control>NO</access_control>" + "<custom_clone_name>UNSUPPORTED</custom_clone_name>" + "<require_storage_name>NO</require_storage_name>" + "<backing_device_type>UNSUPPORTED</backing_device_type>" + "<splitclone_while_open>UNSUPPORTED</splitclone_while_open>" + "<custom_snap_name>UNSUPPORTED</custom_snap_name>" + "<snapshot>UNSUPPORTED</snapshot>" + "<splitclone>UNSUPPORTED</splitclone>" + "<snap_is_sync>UNSUPPORTED</snap_is_sync>" + "<snapclone>UNSUPPORTED</snapclone>" + "<splitclone_is_sync>UNSUPPORTED</splitclone_is_sync>" + "<clone>UNSUPPORTED</clone>" + "<resize>UNSUPPORTED</resize>" + "<snapclone_is_sync>UNSUPPORTED</snapclone_is_sync>" + "</abilities>" + "</storage_plugin_info>" + "</storage_plugin_info_list>" + "</Discover_Storage_Plugins_Result>" + "</string>"; String NFSMOUNTRESPONSEXML = "<struct>" + "<member>" + "<name>status</name>" + "<value><string></string></value>" + "</member>" + "<member>" + "<name>uuid</name>" + "<value><string>" + FSPROPUUID + "</string></value>" + "</member>" + "<member>" + "<name>ss_uuid</name>" + "<value><string>" + FSMNTUUID + "</string></value>" + "</member>" + "<member>" + "<name>size</name>" + "<value><string>263166853120</string></value>" + "</member>" + "<member>" + "<name>free_sz</name>" + "<value><string>259377299456</string></value>" + "</member>" + "<member>" + "<name>state</name>" + "<value><string>1</string></value>" + "</member>" + "<member>" + "<name>mount_options</name>" + "<value><array><data>" + "</data></array></value>" + "</member>" + "<member>" + "<name>access_grp_names</name>" + "<value><array><data>" + "</data></array></value>" + "</member>" + "<member>" + "<name>access_path</name>" + "<value><string>" + NFSHOST + ":" + NFSPATH + "</string></value>" + "</member>" + "<member>" + "<name>name</name>" + "<value><string>nfs:" + NFSPATH + "</string></value>" + "</member>" + "</struct>"; public String getNfsMountResponseXml() { return NFSMOUNTRESPONSEXML; } public String getNfsFileSystemInfo() { return NFSFILESYSTEMINFO; } public String getFileCreateXml() { return FILECREATEXML; } public Long getFileSize() { return SIZE; } public String getPoolUuid() { return POOLUUID; } public String getFileName() { return FILE; } String NFSFILESYSTEMINFO = NFSMOUNTRESPONSEXML; String FILECREATEXML = "<struct>" + "<member>" + "<name>fr_type</name>" + "<value><string>File</string></value>" + "</member>" + "<member>" + "<name>ondisk_sz</name>" + "<value><string>0</string></value>" + "</member>" + "<member>" + "<name>fs_uuid</name>" + "<value><string>" + FSMNTUUID + "</string></value>" + "</member>" + "<member>" + "<name>file_path</name>" + "<value><string>/OVS/Repositories/" + POOLUUID + "/VirtualDisks/" + FILE + "</string></value>" + "</member>" + "<member>" + "<name>file_sz</name>" + "<value><string>" + SIZE + "</string></value>" + "</member>" + "</struct>"; @Test public void testNFSStorageMountCreation() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(NFSMOUNTRESPONSEXML)); StorageDetails sd = sPt.storagePluginMountNFS(NFSHOST, NFSPATH, FSMNTUUID, NFSMNT); con.setResult(results.simpleResponseWrapWrapper(NFSMOUNTRESPONSEXML)); NFSMNT = NFSMNT + "/" + FSMNTUUID; sd = sPt.storagePluginMountNFS(NFSHOST, NFSPATH, FSMNTUUID, NFSMNT); results.basicLongTest(Long.valueOf(sd.getSize()), 263166853120L); results.basicLongTest(Long.valueOf(sd.getFreeSize()), 259377299456L); results.basicStringTest(sd.getName(), "nfs:" + NFSPATH); results.basicStringTest(sd.getUuid(), FSPROPUUID); results.basicStringTest(sd.getDetailsRelationalUuid(),FSMNTUUID); } @Test public void testNFSStorageUnmount() throws Ovm3ResourceException { con.setResult(results.getNil()); results.basicBooleanTest(sPt.storagePluginUnmountNFS(NFSHOST, NFSPATH, FSMNTUUID, NFSMNT)); } @Test(expected = Ovm3ResourceException.class) public void testStoragePluginIncorrectSsUuid() throws Ovm3ResourceException { sPt.getStorageDetails().setDetailsRelationalUuid(FSMNTUUID); } @Test(expected = Ovm3ResourceException.class) public void testStoragePluginIncorrectMntUuid() throws Ovm3ResourceException { sPt.getStorageDetails().setUuid(FSPROPUUID); } @Test(expected = Ovm3ResourceException.class) public void testStoragePluginIncorrectUuid() throws Ovm3ResourceException { sPt.getStorageServer().setUuid(FSMNTUUID); } @Test(expected = Ovm3ResourceException.class) public void testStoragePluginNFSmountInvalidUuid() throws Ovm3ResourceException { NFSMOUNTRESPONSEXML = NFSMOUNTRESPONSEXML.replaceAll(FSPROPUUID, sPt.deDash(FSMNTUUID)); con.setResult(results.simpleResponseWrapWrapper(NFSMOUNTRESPONSEXML)); assertNotNull(sPt.storagePluginMountNFS(NFSHOST, NFSPATH, FSPROPUUID, NFSMNT)); } @Test public void testStorageFileCreation() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(FILECREATEXML)); FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false); file.getOnDiskSize(); } @Test(expected = Ovm3ResourceException.class) public void testStorageFileCreationFileExistS() throws Ovm3ResourceException { con.setResult(results .errorResponseWrap("exceptions OSError:[Errno.17] File exists " + FILE)); FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false); file.getSize(); } @Test public void testStorageFileInfo() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(FILECREATEXML)); FileProperties file = sPt.storagePluginGetFileInfo(FSMNTUUID, NFSHOST, FILE); file.getName(); file.getUuid(); file.getType(); file.getSize(); } @Test public void testDiscoverStoragePlugins() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(STORAGEPLUGINXML)); for (String plugin : sPt.discoverStoragePlugins()) { sPt.checkStoragePluginProperties(plugin, "plugin_version"); sPt.checkStoragePluginAbility(plugin, "snapshot"); } } @Test(expected = Ovm3ResourceException.class) public void testCheckStoragePluginBogusPlugin() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(STORAGEPLUGINXML)); sPt.checkStoragePluginProperties("bogus", "plugin_version"); } @Test(expected = Ovm3ResourceException.class) public void testCheckStoragePluginBogusProperty() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(STORAGEPLUGINXML)); sPt.checkStoragePluginAbility(sPt.getPluginType(), "blabla"); } @Test public void testMounts() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(NFSMOUNTRESPONSEXML)); sPt.storagePluginListFs(NFSHOST); } @Test public void testGetFileSystemInfo() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(NFSMOUNTRESPONSEXML)); sPt.storagePluginGetFileSystemInfo(FSPROPUUID, FSMNTUUID, NFSHOST, NFSPATH); } @Test public void testStoragepluginDestroy() throws Ovm3ResourceException { con.setResult(results.getNil()); sPt.storagePluginDestroy(FSMNTUUID, FILE); } @Test(expected = Ovm3ResourceException.class) public void testStoragepluginDestroyWrongUUID() throws Ovm3ResourceException { con.setResult(results.getNil()); sPt.storagePluginDestroy(FSPROPUUID, FILE); } @Test public void testStoragePluginSwitch() throws Ovm3ResourceException { con.setResult(results.simpleResponseWrapWrapper(STORAGEPLUGINXML)); sPt.setISCSI(); sPt.setNFS(); sPt.setOCFS2(); } }