public function generateCVMP($cvmp, $vm) { //TODO prettify this $newCvmps = []; $pm = $cvmp['vmp'][$vm]; Cvmp::removeVm($cvmp, $vm); $pms = $cvmp['pmp']; unset($pms[$pm]); $pms = array_keys($pms); foreach ($pms as $pm) { if (RulesFreeOfContext::isAllowed($vm, $pm)) { $newCvmp = $cvmp; Cvmp::addVm($newCvmp, $vm, $pm); if (RulesSensitiveToTheContext::isAllowed($newCvmp)) { $newCvmps[] = $newCvmp; } } } return $newCvmps; }
/** * @depends testAdd * @depends testRemove */ public function testLastAdded() { $vm6 = 'v6'; $vm7 = 'v7'; $pm = 'p1'; $places = ['v1' => 'p1', 'v2' => 'p1', 'v3' => 'p2', 'v4' => 'p2', 'v5' => 'p3']; $cvmp = Cvmp::buildCVmpByPlacements($places); $this->assertFalse(isset($cvmp[OC_LAST_ADD_VM]), "lastAddedVM pms !match"); $this->assertFalse(isset($cvmp[OC_LAST_ADD_PM]), "lastAddedPM pms !match"); Cvmp::addVm($cvmp, $vm6, $pm); $this->assertEquals($vm6, $cvmp[OC_LAST_ADD_VM], "lastAddedVM pms !match"); $this->assertEquals($pm, $cvmp[OC_LAST_ADD_PM], "lastAddedPM pms !match"); Cvmp::addVm($cvmp, $vm7, $pm); $this->assertEquals($vm7, $cvmp[OC_LAST_ADD_VM], "lastAddedVM pms !match"); $this->assertEquals($pm, $cvmp[OC_LAST_ADD_PM], "lastAddedPM pms !match"); Cvmp::removeVm($cvmp, $vm7); $this->assertFalse(isset($cvmp[OC_LAST_ADD_VM]), "lastAddedVM pms !match"); $this->assertFalse(isset($cvmp[OC_LAST_ADD_PM]), "lastAddedPM pms !match"); return $cvmp; }