forked from kerubistan/kerub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect a problem when a virtual storage device is allocated on a fail…
…ing disk Bug-Url: kerubistan#242 Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.../issues/problems/hosts/hardware/VirtualStorageAllocationOnFailingStorageDeviceDetector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.kerubistan.kerub.planner.issues.problems.hosts.hardware | ||
|
||
import com.github.kerubistan.kerub.model.VolumeManagerStorageCapability | ||
import com.github.kerubistan.kerub.model.collection.HostDataCollection | ||
import com.github.kerubistan.kerub.planner.Plan | ||
import com.github.kerubistan.kerub.utils.join | ||
|
||
object VirtualStorageAllocationOnFailingStorageDeviceDetector | ||
: AbstractFailingStorageDeviceDetector<VirtualStorageAllocationOnFailingStorageDevice>() { | ||
override fun createProblems(host: HostDataCollection, device: String, plan: Plan) = | ||
host.stat.capabilities?.storageCapabilities?.filterIsInstance<VolumeManagerStorageCapability>()?.filter { | ||
device in it.storageDevices | ||
}?.map { failingCapability -> | ||
plan.state.allocatedStorage.mapNotNull { vdisk -> | ||
vdisk.dynamic?.allocations?.mapNotNull { allocation -> | ||
if (allocation.capabilityId == failingCapability.id) { | ||
VirtualStorageAllocationOnFailingStorageDevice( | ||
host = host.stat, | ||
capability = failingCapability, | ||
storageDevice = vdisk.stat, | ||
allocation = allocation | ||
) | ||
} else null | ||
} | ||
} | ||
}?.join()?.join() | ||
} |
90 changes: 90 additions & 0 deletions
90
...ues/problems/hosts/hardware/VirtualStorageAllocationOnFailingStorageDeviceDetectorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.github.kerubistan.kerub.planner.issues.problems.hosts.hardware | ||
|
||
import com.github.kerubistan.kerub.GB | ||
import com.github.kerubistan.kerub.TB | ||
import com.github.kerubistan.kerub.hostUp | ||
import com.github.kerubistan.kerub.model.dynamic.VirtualStorageDeviceDynamic | ||
import com.github.kerubistan.kerub.model.dynamic.VirtualStorageLvmAllocation | ||
import com.github.kerubistan.kerub.planner.OperationalState | ||
import com.github.kerubistan.kerub.planner.Plan | ||
import com.github.kerubistan.kerub.testDisk | ||
import com.github.kerubistan.kerub.testHost | ||
import com.github.kerubistan.kerub.testHostCapabilities | ||
import com.github.kerubistan.kerub.testLvmCapability | ||
import org.junit.Test | ||
import java.util.UUID | ||
import kotlin.test.assertTrue | ||
import kotlin.test.expect | ||
|
||
class VirtualStorageAllocationOnFailingStorageDeviceDetectorTest { | ||
|
||
@Test | ||
fun detect() { | ||
expect(listOf(), "blank state - no problem") { | ||
VirtualStorageAllocationOnFailingStorageDeviceDetector.detect( | ||
Plan(OperationalState.fromLists()) | ||
) | ||
} | ||
assertTrue("virtual disk on failing capability") { | ||
val dieingCapability = testLvmCapability.copy( | ||
id = UUID.randomUUID(), | ||
volumeGroupName = "dieing-vg", | ||
size = 1.TB, | ||
physicalVolumes = mapOf( | ||
"/dev/sdb" to 1.TB | ||
) | ||
) | ||
val healthyCapability = testLvmCapability.copy( | ||
id = UUID.randomUUID(), | ||
volumeGroupName = "healthy-vg", | ||
size = 1.TB, | ||
physicalVolumes = mapOf( | ||
"/dev/sdc" to 1.TB | ||
) | ||
) | ||
val host = testHost.copy( | ||
capabilities = testHostCapabilities.copy( | ||
storageCapabilities = listOf( | ||
healthyCapability, | ||
dieingCapability | ||
) | ||
) | ||
) | ||
val hostDynamic = hostUp(host).copy( | ||
storageDeviceHealth = mapOf( | ||
"/dev/sdb" to false, | ||
"/dev/sdc" to true | ||
) | ||
) | ||
val allocationOnFailingVg = VirtualStorageLvmAllocation( | ||
hostId = host.id, | ||
path = "", | ||
capabilityId = dieingCapability.id, | ||
actualSize = 2.GB, | ||
vgName = dieingCapability.volumeGroupName | ||
) | ||
VirtualStorageAllocationOnFailingStorageDeviceDetector.detect( | ||
Plan(OperationalState.fromLists( | ||
hosts = listOf(host), | ||
hostDyns = listOf(hostDynamic), | ||
vStorage = listOf(testDisk), | ||
vStorageDyns = listOf( | ||
VirtualStorageDeviceDynamic( | ||
id = testDisk.id, | ||
allocations = listOf( | ||
allocationOnFailingVg | ||
) | ||
) | ||
) | ||
)) | ||
) == listOf( | ||
VirtualStorageAllocationOnFailingStorageDevice( | ||
host = host, | ||
allocation = allocationOnFailingVg, | ||
capability = dieingCapability, | ||
storageDevice = testDisk | ||
) | ||
) | ||
} | ||
} | ||
} |