Skip to content

Commit 18af707

Browse files
authored
Merge pull request #1725 from yvsubhash/CLOUDSTACK-9559
CLOUDSTACK-9559 Why allow deleting zone without deleting the seconda…
2 parents 0dc55f1 + a2a1f25 commit 18af707

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

engine/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646
<modules>
4747
<module>api</module>
4848
<module>orchestration</module>
49+
<module>schema</module>
4950
<module>storage</module>
5051
<module>storage/volume</module>
5152
<module>storage/image</module>
5253
<module>storage/datamotion</module>
5354
<module>storage/cache</module>
5455
<module>storage/snapshot</module>
5556
<module>components-api</module>
56-
<module>schema</module>
5757
<module>network</module>
5858
<module>service</module>
5959
</modules>

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import com.google.common.base.MoreObjects;
3838
import org.apache.commons.collections.CollectionUtils;
3939
import org.apache.commons.collections.MapUtils;
40+
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
41+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
4042
import org.apache.log4j.Logger;
4143

4244
import org.apache.cloudstack.acl.SecurityChecker;
@@ -84,7 +86,6 @@
8486
import org.apache.cloudstack.region.Region;
8587
import org.apache.cloudstack.region.RegionVO;
8688
import org.apache.cloudstack.region.dao.RegionDao;
87-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
8889
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
8990
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
9091
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
@@ -346,6 +347,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
346347
@Inject
347348
ImageStoreDetailsDao _imageStoreDetailsDao;
348349

350+
349351
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
350352
@Inject
351353
protected DataCenterLinkLocalIpAddressDao _linkLocalIpAllocDao;
@@ -1353,7 +1355,6 @@ protected void checkIfZoneIsDeletable(final long zoneId) {
13531355
final String errorMsg = "The zone cannot be deleted because ";
13541356

13551357

1356-
13571358
// Check if there are any non-removed hosts in the zone.
13581359
if (!_hostDao.listByDataCenterId(zoneId).isEmpty()) {
13591360
throw new CloudRuntimeException(errorMsg + "there are servers in this zone.");
@@ -1389,6 +1390,11 @@ protected void checkIfZoneIsDeletable(final long zoneId) {
13891390
throw new CloudRuntimeException(errorMsg + "there are physical networks in this zone.");
13901391
}
13911392

1393+
//check if there are any secondary stores attached to the zone
1394+
if(!_imageStoreDao.findByScope(new ZoneScope(zoneId)).isEmpty()) {
1395+
throw new CloudRuntimeException(errorMsg + "there are Secondary storages in this zone");
1396+
}
1397+
13921398
// Check if there are any non-removed VMware datacenters in the zone.
13931399
//if (_vmwareDatacenterZoneMapDao.findByZoneId(zoneId) != null) {
13941400
// throw new CloudRuntimeException(errorMsg + "there are VMware datacenters in this zone.");

server/test/com/cloud/configuration/ConfigurationManagerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import java.util.UUID;
3737

3838
import com.cloud.user.User;
39+
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
40+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
41+
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
3942
import org.apache.log4j.Logger;
4043
import org.junit.After;
4144
import org.junit.Assert;
@@ -143,6 +146,8 @@ public class ConfigurationManagerTest {
143146
HostPodDao _podDao;
144147
@Mock
145148
PhysicalNetworkDao _physicalNetworkDao;
149+
@Mock
150+
ImageStoreDao _imageStoreDao;
146151

147152
VlanVO vlan = new VlanVO(Vlan.VlanType.VirtualNetwork, "vlantag", "vlangateway", "vlannetmask", 1L, "iprange", 1L, 1L, null, null, null);
148153

@@ -174,6 +179,7 @@ public void setup() throws Exception {
174179
configurationMgr._clusterDao = _clusterDao;
175180
configurationMgr._podDao = _podDao;
176181
configurationMgr._physicalNetworkDao = _physicalNetworkDao;
182+
configurationMgr._imageStoreDao = _imageStoreDao;
177183

178184

179185
Account account = new AccountVO("testaccount", 1, "networkdomain", (short)0, UUID.randomUUID().toString());
@@ -679,6 +685,7 @@ public void checkIfZoneIsDeletableSuccessTest() {
679685
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
680686
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
681687
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
688+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
682689

683690
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
684691
}
@@ -696,6 +703,7 @@ public void checkIfZoneIsDeletableFailureOnHostTest() {
696703
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
697704
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
698705
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
706+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
699707

700708
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
701709
}
@@ -713,6 +721,7 @@ public void checkIfZoneIsDeletableFailureOnPodTest() {
713721
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
714722
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
715723
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
724+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
716725

717726
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
718727
}
@@ -726,6 +735,7 @@ public void checkIfZoneIsDeletableFailureOnPrivateIpAddressTest() {
726735
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
727736
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
728737
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
738+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
729739

730740
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
731741
}
@@ -739,6 +749,7 @@ public void checkIfZoneIsDeletableFailureOnPublicIpAddressTest() {
739749
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
740750
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
741751
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
752+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
742753

743754
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
744755
}
@@ -756,6 +767,7 @@ public void checkIfZoneIsDeletableFailureOnVmInstanceTest() {
756767
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(arrayList);
757768
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
758769
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
770+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
759771

760772
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
761773
}
@@ -773,6 +785,7 @@ public void checkIfZoneIsDeletableFailureOnVolumeTest() {
773785
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
774786
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(arrayList);
775787
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
788+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
776789

777790
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
778791
}
@@ -790,6 +803,7 @@ public void checkIfZoneIsDeletableFailureOnPhysicalNetworkTest() {
790803
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
791804
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
792805
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(arrayList);
806+
Mockito.when(_imageStoreDao.findByScope(any(ZoneScope.class))).thenReturn(new ArrayList<ImageStoreVO>());
793807

794808
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
795809
}

server/test/resources/createNetworkOffering.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@
5353
<bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl" />
5454
<bean id="userIpAddressDetailsDao" class="org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDaoImpl" />
5555
<bean id="loadBalancerVMMapDaoImpl" class="com.cloud.network.dao.LoadBalancerVMMapDaoImpl" />
56-
56+
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl" />
5757
</beans>

0 commit comments

Comments
 (0)