Skip to content

Commit

Permalink
detect a problem when a virtual storage device is allocated on a fail…
Browse files Browse the repository at this point in the history
…ing disk

Bug-Url: kerubistan#242
Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
  • Loading branch information
K0zka committed Jan 2, 2019
1 parent 9292e77 commit fd94719
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
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()
}
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
)
)
}
}
}

0 comments on commit fd94719

Please sign in to comment.