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 @@ -19,6 +19,10 @@ public static String convertCbdPathToZbsPath(String cbdPath) {
return cbdPath.replaceFirst(".+?/", "zbs://");
}

public static String normalizeToZbsPath(String path) {
return path != null && path.startsWith("cbd:") ? convertCbdPathToZbsPath(path) : path;
}

public static String convertZbsPathToCbdPath(String zbsPath, Function<String, String> physicalPoolGetter) {
String logicalPool = getPoolFromVolumePath(zbsPath);
String physicalPool = physicalPoolGetter.apply(logicalPool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ public void success(FlattenVolumeRsp returnValue) {
stats.setSize(returnValue.getSize());
stats.setActualSize(returnValue.getActualSize());
stats.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
stats.setParentUri(returnValue.getParentUri());
stats.setParentUri(ZbsHelper.normalizeToZbsPath(returnValue.getParentUri()));
comp.success(stats);
}

Expand All @@ -1046,7 +1046,7 @@ public void success(QueryVolumeRsp returnValue) {
stats.setSize(returnValue.getSize());
stats.setActualSize(returnValue.getActualSize());
stats.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
stats.setParentUri(returnValue.getParentUri());
stats.setParentUri(ZbsHelper.normalizeToZbsPath(returnValue.getParentUri()));
comp.success(stats);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.zstack.test.integration.storage.primary.addon.zbs

import org.springframework.http.HttpEntity
import org.zstack.core.cloudbus.CloudBus
import org.zstack.core.cloudbus.EventCallback
import org.zstack.core.cloudbus.EventFacade
import org.zstack.core.db.DatabaseFacade
import org.zstack.core.db.Q
import org.zstack.header.message.MessageReply
import org.zstack.header.storage.primary.GetVolumeBackingChainFromPrimaryStorageMsg
import org.zstack.header.storage.primary.GetVolumeBackingChainFromPrimaryStorageReply
import org.zstack.header.storage.primary.PrimaryStorageConstant
import org.zstack.header.storage.addon.primary.ExternalPrimaryStorageVO
import org.zstack.header.storage.addon.primary.ExternalPrimaryStorageSpaceVO
import org.zstack.header.storage.addon.primary.ExternalPrimaryStorageVO_
Expand Down Expand Up @@ -191,6 +196,7 @@ class ZbsPrimaryStorageCase extends SubCase {
testDataVolumeNegativeScenario()
testDecodeMdsUriWithSpecialPassword()
testMdsReconnectAfterMaximumPingFailures()
testGetBackingChainNormalizesCbdParentUri()
}
}

Expand Down Expand Up @@ -1095,6 +1101,41 @@ class ZbsPrimaryStorageCase extends SubCase {
env.cleanAfterSimulatorHandlers()
}

void testGetBackingChainNormalizesCbdParentUri() {
String childSnapPath = "zbs://lpool1/volume_child@snapshot_s1"
String parentZbsPath = "zbs://lpool1/volume_parent"
String parentCbdPath = "cbd:pool1/lpool1/volume_parent"

env.simulator(ZbsStorageController.QUERY_VOLUME_PATH) { HttpEntity<String> e, EnvSpec spec ->
def cmd = JSONObjectUtil.toObject(e.body, ZbsStorageController.QueryVolumeCmd.class)
def rsp = new ZbsStorageController.QueryVolumeRsp()
rsp.size = SizeUnit.GIGABYTE.toByte(8)
rsp.actualSize = SizeUnit.MEGABYTE.toByte(1)
if (cmd.path.contains("volume_child")) {
rsp.parentUri = parentCbdPath
} else {
rsp.parentUri = null
}
return rsp
}

CloudBus bus = bean(CloudBus.class)
GetVolumeBackingChainFromPrimaryStorageMsg msg = new GetVolumeBackingChainFromPrimaryStorageMsg()
msg.setPrimaryStorageUuid(ps.uuid)
msg.setVolumeUuid(childSnapPath)
msg.setRootInstallPaths([childSnapPath])
bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, ps.uuid)
MessageReply reply = bus.call(msg)

assert reply.isSuccess() : "backing chain walk must not fail on cbd-form parentUri: ${reply.error}"
GetVolumeBackingChainFromPrimaryStorageReply r = reply as GetVolumeBackingChainFromPrimaryStorageReply
List<String> chain = r.getBackingChainInstallPath(childSnapPath)
assert chain != null && chain.contains(parentZbsPath) :
"parent must be resolved as a zbs:// path, got ${chain}"

env.cleanSimulatorHandlers()
}

void deleteVolume(String volUuid) {
deleteDataVolume {
uuid = volUuid
Expand Down