rhtyd closed pull request #2716: configdrive: make fewer mountpoints on hosts
URL: https://github.com/apache/cloudstack/pull/2716
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDrive.java
 
b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDrive.java
index 07cfdc883ca..2fbc590c275 100644
--- 
a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDrive.java
+++ 
b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDrive.java
@@ -19,7 +19,6 @@
 
 public class ConfigDrive {
 
-    public final static String CONFIGDRIVEFILENAME = "configdrive.iso";
     public final static String CONFIGDRIVEDIR = "configdrive";
 
     public static final String cloudStackConfigDriveName = "/cloudstack/";
@@ -27,11 +26,20 @@
 
     /**
      * Creates the path to ISO file relative to mount point.
-     * The config driver path will have the following formated: {@link 
#CONFIGDRIVEDIR} + / + instanceName + / + {@link #CONFIGDRIVEFILENAME}
+     * The config driver path will have the following format: {@link 
#CONFIGDRIVEDIR} + / + instanceName + ".iso"
      *
      * @return config drive ISO file path
      */
     public static String createConfigDrivePath(String instanceName) {
-        return ConfigDrive.CONFIGDRIVEDIR + "/" + instanceName + "/"  + 
ConfigDrive.CONFIGDRIVEFILENAME;
+        return ConfigDrive.CONFIGDRIVEDIR + "/" + 
configIsoFileName(instanceName);
+    }
+
+    /**
+     * Config Drive iso file name for an instance name
+     * @param instanceName
+     * @return
+     */
+    public static String configIsoFileName(String instanceName) {
+        return instanceName + ".iso";
     }
 }
\ No newline at end of file
diff --git 
a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java
 
b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java
index 55e7979a772..0675b43cb4a 100644
--- 
a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java
+++ 
b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java
@@ -79,6 +79,11 @@ public static String fileToBase64String(File isoFile) throws 
IOException {
     public static File base64StringToFile(String encodedIsoData, String 
folder, String fileName) throws IOException {
         byte[] decoded = 
Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII));
         Path destPath = Paths.get(folder, fileName);
+        try {
+            Files.createDirectories(destPath.getParent());
+        } catch (final IOException e) {
+            LOG.warn("Exception hit while trying to recreate directory: " + 
destPath.getParent().toString());
+        }
         return Files.write(destPath, decoded).toFile();
     }
 
diff --git 
a/engine/storage/configdrive/test/org/apache/cloudstack/storage/configdrive/ConfigDriveTest.java
 
b/engine/storage/configdrive/test/org/apache/cloudstack/storage/configdrive/ConfigDriveTest.java
index 81294d4331b..fd3d3db86a3 100644
--- 
a/engine/storage/configdrive/test/org/apache/cloudstack/storage/configdrive/ConfigDriveTest.java
+++ 
b/engine/storage/configdrive/test/org/apache/cloudstack/storage/configdrive/ConfigDriveTest.java
@@ -26,7 +26,7 @@
 
     @Test
     public void testConfigDriveIsoPath() throws IOException {
-        Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), 
"configdrive/i-x-y/configdrive.iso");
+        Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), 
"configdrive/i-x-y.iso");
     }
 
 }
\ No newline at end of file
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java
index 5e4ef485123..6baae85e221 100644
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java
@@ -24,7 +24,6 @@
 import java.nio.file.Paths;
 
 import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
-import org.apache.commons.io.FileUtils;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
@@ -67,7 +66,7 @@ public Answer execute(final HandleConfigDriveIsoCommand 
command, final LibvirtCo
             }
         } else {
             try {
-                FileUtils.deleteDirectory(isoPath.getParent().toFile());
+                Files.deleteIfExists(isoPath);
             } catch (IOException e) {
                 LOG.warn("Failed to delete config drive: " + 
isoPath.toAbsolutePath().toString());
                 return new Answer(command, false, "Failed due to exception: " 
+ e.getMessage());
diff --git 
a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java 
b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
index a304ea43fa2..919d7bd9d18 100644
--- a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
+++ b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
@@ -375,8 +375,9 @@ private boolean createConfigDriveIso(VirtualMachineProfile 
profile, DeployDestin
 
         LOG.debug("Creating config drive ISO for vm: " + 
profile.getInstanceName());
 
+        final String isoFileName = 
ConfigDrive.configIsoFileName(profile.getInstanceName());
         final String isoPath = 
ConfigDrive.createConfigDrivePath(profile.getInstanceName());
-        final String isoData = 
ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), 
ConfigDrive.CONFIGDRIVEFILENAME, profile.getConfigDriveLabel());
+        final String isoData = 
ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), isoFileName, 
profile.getConfigDriveLabel());
         final HandleConfigDriveIsoCommand configDriveIsoCommand = new 
HandleConfigDriveIsoCommand(isoPath, isoData, dataStore.getTO(), true);
 
         final Answer answer = agentManager.easySend(agentId, 
configDriveIsoCommand);
diff --git 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 0bb923f8053..46fa1707a03 100644
--- 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -42,6 +42,7 @@
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.UnknownHostException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
@@ -337,7 +338,7 @@ private Answer execute(HandleConfigDriveIsoCommand cmd) {
             Path tempDir = null;
             try {
                 tempDir = 
java.nio.file.Files.createTempDirectory(ConfigDrive.CONFIGDRIVEDIR);
-                File tmpIsoFile = 
ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), 
tempDir.toAbsolutePath().toString(), ConfigDrive.CONFIGDRIVEFILENAME);
+                File tmpIsoFile = 
ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), 
tempDir.toAbsolutePath().toString(), cmd.getIsoFile());
                 copyLocalToNfs(tmpIsoFile, new File(cmd.getIsoFile()), 
cmd.getDestStore());
             } catch (IOException | ConfigurationException e) {
                 return new Answer(cmd, false, "Failed due to exception: " + 
e.getMessage());
@@ -355,11 +356,11 @@ private Answer execute(HandleConfigDriveIsoCommand cmd) {
             DataStoreTO dstore = cmd.getDestStore();
             if (dstore instanceof NfsTO) {
                 NfsTO nfs = (NfsTO) dstore;
-                String relativeTemplatePath = new 
File(cmd.getIsoFile()).getParent();
+                String relativeTemplatePath = new 
File(cmd.getIsoFile()).getPath();
                 String nfsMountPoint = getRootDir(nfs.getUrl(), _nfsVersion);
                 File tmpltPath = new File(nfsMountPoint, relativeTemplatePath);
                 try {
-                    FileUtils.deleteDirectory(tmpltPath);
+                    Files.deleteIfExists(tmpltPath.toPath());
                 } catch (IOException e) {
                     return new Answer(cmd, e);
                 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to