Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import org.zstack.core.cloudbus.CloudBus;
import org.zstack.core.cloudbus.MessageSafe;
import org.zstack.core.componentloader.PluginRegistry;
import org.zstack.core.db.DatabaseFacade;
import org.zstack.core.db.DbEntityLister;
import org.zstack.core.db.SQL;
import org.zstack.core.db.SQLBatch;
import org.zstack.core.db.*;
import org.zstack.core.errorcode.ErrorFacade;
import org.zstack.core.thread.ChainTask;
import org.zstack.core.thread.SyncTaskChain;
Expand Down Expand Up @@ -160,6 +157,11 @@ protected void scripts() {
}

private void createZone(APICreateZoneMsg msg, ReturnValueCompletion<ZoneInventory> completion) {
Long existCount = Q.New(ZoneVO.class).count();
if (existCount == 0) {
msg.setDefault(true);
}

if (msg.getDefault() == null || !msg.getDefault()) {
completion.success(createZoneFromApiMessage(msg));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ZoneCase extends SubCase {
@Override
void test() {
env.create {
testFirstZoneSetDefaultZone()
testCreateZoneAsDefaultZone()
testBatchCreateZoneAsDefaultZone()
testUpdateZoneToDefaultZone()
Expand All @@ -48,6 +49,16 @@ class ZoneCase extends SubCase {
env.delete()
}

void testFirstZoneSetDefaultZone() {
ZoneInventory zone = createZone {
name = "FirstZone"
description = "first zone"
} as ZoneInventory

assert zone != null
assert zone.isDefault
}

void testCreateZoneAsDefaultZone() {
ZoneInventory zone = createZone {
name = "zone1"
Expand Down