Skip to content

Commit e4390cd

Browse files
author
lin.ma
committed
<fix>[compute]: first create of zone set default
Resolves: ZSTAC-75952 Change-Id: I6c7a6f627a6c76796e656c6b7962796a7570736b
1 parent 24dbedd commit e4390cd

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compute/src/main/java/org/zstack/compute/zone/ZoneManagerImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import org.zstack.core.cloudbus.CloudBus;
66
import org.zstack.core.cloudbus.MessageSafe;
77
import org.zstack.core.componentloader.PluginRegistry;
8-
import org.zstack.core.db.DatabaseFacade;
9-
import org.zstack.core.db.DbEntityLister;
10-
import org.zstack.core.db.SQL;
11-
import org.zstack.core.db.SQLBatch;
8+
import org.zstack.core.db.*;
129
import org.zstack.core.errorcode.ErrorFacade;
1310
import org.zstack.core.thread.ChainTask;
1411
import org.zstack.core.thread.SyncTaskChain;
@@ -160,6 +157,11 @@ protected void scripts() {
160157
}
161158

162159
private void createZone(APICreateZoneMsg msg, ReturnValueCompletion<ZoneInventory> completion) {
160+
Long existCount = Q.New(ZoneVO.class).count();
161+
if (existCount == 0) {
162+
msg.setDefault(true);
163+
}
164+
163165
if (msg.getDefault() == null || !msg.getDefault()) {
164166
completion.success(createZoneFromApiMessage(msg));
165167
return;

test/src/test/groovy/org/zstack/test/integration/compute/ZoneCase.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ZoneCase extends SubCase {
4040
testQueryDefaultZone()
4141
testDeleteDefaultZone()
4242
testBatchUnsetDefaultZone()
43+
testFirstZoneSetDefaultZone()
4344
}
4445
}
4546

@@ -232,4 +233,14 @@ class ZoneCase extends SubCase {
232233
.eq(ZoneVO_.isDefault, true)
233234
.count() == 0
234235
}
236+
237+
void testFirstZoneSetDefaultZone() {
238+
ZoneInventory zone = createZone {
239+
name = "FirstZone"
240+
description = "first zone"
241+
} as ZoneInventory
242+
243+
assert zone != null
244+
assert zone.isDefault
245+
}
235246
}

0 commit comments

Comments
 (0)