Updated Branches:
  refs/heads/master aa6dddc77 -> 3ef560d92

CLOUDSTACK-5873: [Automation] Failed to attach volume to VM, if the vm is 
created with option startvm=false


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3ef560d9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3ef560d9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3ef560d9

Branch: refs/heads/master
Commit: 3ef560d9250835eb02ffe8df9f17a0b6c928c88d
Parents: aa6dddc
Author: Mike Tutkowski <mike.tutkow...@solidfire.com>
Authored: Tue Jan 14 19:40:14 2014 -0700
Committer: Mike Tutkowski <mike.tutkow...@solidfire.com>
Committed: Thu Jan 16 12:15:18 2014 -0700

----------------------------------------------------------------------
 .../apache/cloudstack/storage/volume/VolumeServiceImpl.java | 6 ++++--
 .../xen/src/com/cloud/hypervisor/XenServerGuru.java         | 6 +++++-
 server/src/com/cloud/storage/VolumeApiServiceImpl.java      | 9 ++++++---
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ef560d9/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
 
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index ac507cf..3e5a546 100644
--- 
a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ 
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -158,8 +158,9 @@ public class VolumeServiceImpl implements VolumeService {
         return null;
     }
 
+    @Override
     public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, 
DataStore dataStore) {
-        DataStoreDriver dataStoreDriver = dataStore.getDriver();
+        DataStoreDriver dataStoreDriver = dataStore != null ? 
dataStore.getDriver() : null;
 
         if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
             return 
((PrimaryDataStoreDriver)dataStoreDriver).connectVolumeToHost(volumeInfo, host, 
dataStore);
@@ -168,8 +169,9 @@ public class VolumeServiceImpl implements VolumeService {
         return false;
     }
 
+    @Override
     public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, 
DataStore dataStore) {
-        DataStoreDriver dataStoreDriver = dataStore.getDriver();
+        DataStoreDriver dataStoreDriver = dataStore != null ? 
dataStore.getDriver() : null;
 
         if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
             
((PrimaryDataStoreDriver)dataStoreDriver).disconnectVolumeFromHost(volumeInfo, 
host, dataStore);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ef560d9/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java 
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java
index 4f21a02..529e261 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java
@@ -108,7 +108,11 @@ public class XenServerGuru extends HypervisorGuruBase 
implements HypervisorGuru
                 if (volume.getVolumeType() == Volume.Type.DATADISK) {
                     StoragePoolVO storagePool = 
_storagePoolDao.findById(volume.getPoolId());
 
-                    if (storagePool.isManaged()) {
+                    // storagePool should be null if we are expunging a volume 
that was never
+                    // attached to a VM that was started (the "trick" for 
storagePool to be null
+                    // is that none of the VMs this volume may have been 
attached to were ever started,
+                    // so the volume was never assigned to a storage pool)
+                    if (storagePool != null && storagePool.isManaged()) {
                         DataTO volTO = 
_volFactory.getVolume(volume.getId()).getTO();
                         DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), 
volume.getPath(), volume.getVolumeType());
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ef560d9/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index ac0c438..8d475dd 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -1482,12 +1482,13 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
             }
         }
 
-        DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), 
DataStoreRole.Primary);
-
         if (!sendCommand || (answer != null && answer.getResult())) {
             // Mark the volume as detached
             _volsDao.detachVolume(volume.getId());
 
+            // volume.getPoolId() should be null if the VM we are attaching 
the disk to has never been started before
+            DataStore dataStore = volume.getPoolId() != null ? 
dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary) : null;
+
             
volService.disconnectVolumeFromHost(volFactory.getVolume(volume.getId()), host, 
dataStore);
 
             return _volsDao.findById(volumeId);
@@ -1955,10 +1956,12 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
             }
         }
 
-        DataStore dataStore = 
dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), 
DataStoreRole.Primary);
+        // volumeToAttachStoragePool should be null if the VM we are attaching 
the disk to has never been started before
+        DataStore dataStore = volumeToAttachStoragePool != null ? 
dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), 
DataStoreRole.Primary) : null;
 
         boolean queryForChap = true;
 
+        // if we don't have a host, the VM we are attaching the disk to has 
never been started before
         if (host != null) {
             try {
                 // if connectVolumeToHost returns true, then we do not want to 
use CHAP because the volume is already connected to the host(s)

Reply via email to