From ac7016c4c5f15bf20b21e7d34e93d8b963aab231 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 2 Oct 2020 20:57:51 +0200 Subject: Implement BareMetalDriver using SimMachine This change creates an implementation of the BareMetalDriver interface using the simulation logic of SimMachine. This implementation will eventually replace the SimpleBareMetalDriver implementation. --- .../core/image/FlopsApplicationImageTest.kt | 4 +- .../compute/metal/driver/SimBareMetalDriverTest.kt | 90 ++++++++++++++++++++++ .../metal/driver/SimpleBareMetalDriverTest.kt | 4 +- .../metal/service/SimpleProvisioningServiceTest.kt | 33 +++++--- .../org/opendc/compute/virt/HypervisorTest.kt | 4 +- 5 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimBareMetalDriverTest.kt (limited to 'simulator/opendc-compute/src/test') diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt index 309dceb8..8870f138 100644 --- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt @@ -1,7 +1,5 @@ /* - * MIT License - * - * Copyright (c) 2020 atlarge-research + * Copyright (c) 2020 AtLarge Research * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimBareMetalDriverTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimBareMetalDriverTest.kt new file mode 100644 index 00000000..584dcef4 --- /dev/null +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimBareMetalDriverTest.kt @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2020 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.compute.metal.driver + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.TestCoroutineScope +import kotlinx.coroutines.withContext +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.opendc.compute.core.ServerEvent +import org.opendc.compute.core.ServerState +import org.opendc.compute.core.image.SimWorkloadImage +import org.opendc.simulator.compute.SimMachineModel +import org.opendc.simulator.compute.model.MemoryUnit +import org.opendc.simulator.compute.model.ProcessingNode +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.workload.SimFlopsWorkload +import org.opendc.simulator.utils.DelayControllerClockAdapter +import java.util.UUID + +@OptIn(ExperimentalCoroutinesApi::class) +internal class SimBareMetalDriverTest { + private lateinit var machineModel: SimMachineModel + + @BeforeEach + fun setUp() { + val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 4) + + machineModel = SimMachineModel( + cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 2000.0) }, + memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) } + ) + } + + @Test + fun testFlopsWorkload() { + val testScope = TestCoroutineScope() + val clock = DelayControllerClockAdapter(testScope) + + var finalState: ServerState = ServerState.BUILD + var finalTime = 0L + + testScope.launch { + val driver = SimBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), machineModel) + val image = SimWorkloadImage(UUID.randomUUID(), "", emptyMap(), SimFlopsWorkload(4_000, 2, utilization = 1.0)) + + // Batch driver commands + withContext(coroutineContext) { + driver.init() + driver.setImage(image) + val server = driver.start().server!! + server.events.collect { event -> + when (event) { + is ServerEvent.StateChanged -> { + finalState = event.server.state + finalTime = clock.millis() + } + } + } + } + } + + testScope.advanceUntilIdle() + assertEquals(ServerState.SHUTOFF, finalState) + assertEquals(1001, finalTime) + } +} diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt index 9c9dc864..23c9408d 100644 --- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt @@ -52,9 +52,9 @@ internal class SimpleBareMetalDriverTest { var finalState: ServerState = ServerState.BUILD testScope.launch { val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 4) - val cpus = List(4) { ProcessingUnit(cpuNode, it, 2400.0) } + val cpus = List(4) { ProcessingUnit(cpuNode, it, 2000.0) } val driver = SimpleBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), cpus, emptyList()) - val image = FlopsApplicationImage(UUID.randomUUID(), "", emptyMap(), 1_000, 2) + val image = FlopsApplicationImage(UUID.randomUUID(), "", emptyMap(), 4_000, 2, utilization = 1.0) // Batch driver commands withContext(coroutineContext) { diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt index 91d4787c..6f13e557 100644 --- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/service/SimpleProvisioningServiceTest.kt @@ -27,11 +27,15 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestCoroutineScope +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.opendc.compute.core.ProcessingNode -import org.opendc.compute.core.ProcessingUnit -import org.opendc.compute.core.image.FlopsApplicationImage -import org.opendc.compute.metal.driver.SimpleBareMetalDriver +import org.opendc.compute.core.image.SimWorkloadImage +import org.opendc.compute.metal.driver.SimBareMetalDriver +import org.opendc.simulator.compute.SimMachineModel +import org.opendc.simulator.compute.model.MemoryUnit +import org.opendc.simulator.compute.model.ProcessingNode +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.workload.SimFlopsWorkload import org.opendc.simulator.utils.DelayControllerClockAdapter import java.util.UUID @@ -40,20 +44,29 @@ import java.util.UUID */ @OptIn(ExperimentalCoroutinesApi::class) internal class SimpleProvisioningServiceTest { + private lateinit var machineModel: SimMachineModel + + @BeforeEach + fun setUp() { + val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 4) + + machineModel = SimMachineModel( + cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 2000.0) }, + memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) } + ) + } + /** * A basic smoke test. */ @Test - fun smoke() { + fun testSmoke() { val testScope = TestCoroutineScope() val clock = DelayControllerClockAdapter(testScope) testScope.launch { - val image = FlopsApplicationImage(UUID.randomUUID(), "", emptyMap(), 1000, 2) - - val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 4) - val cpus = List(4) { ProcessingUnit(cpuNode, it, 2400.0) } - val driver = SimpleBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), cpus, emptyList()) + val image = SimWorkloadImage(UUID.randomUUID(), "", emptyMap(), SimFlopsWorkload(1000, 2)) + val driver = SimBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), machineModel) val provisioner = SimpleProvisioningService() provisioner.create(driver) diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt index 68efb1a3..369b9538 100644 --- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt @@ -75,7 +75,7 @@ internal class HypervisorTest { delay(5) - val flavor = Flavor(1, 0) + val flavor = org.opendc.compute.core.Flavor(1, 0) val vmDriver = metalDriver.refresh().server!!.services[VirtDriver] vmDriver.events.onEach { println(it) }.launchIn(this) val vmA = vmDriver.spawn("a", workloadA, flavor) @@ -140,7 +140,7 @@ internal class HypervisorTest { delay(5) - val flavor = Flavor(2, 0) + val flavor = org.opendc.compute.core.Flavor(2, 0) val vmDriver = metalDriver.refresh().server!!.services[VirtDriver] vmDriver.events .onEach { event -> -- cgit v1.2.3