Skip to content

Commit 4d1d4f4

Browse files
author
Dingane Hlaluku
committed
* Fix marvin test failure
* Add new marvin negative tests cases * Remove hard-coded hypervisor types in marvin tests
1 parent cbe0d71 commit 4d1d4f4

File tree

3 files changed

+305
-214
lines changed

3 files changed

+305
-214
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4973,7 +4973,7 @@ protected void persistExtraConfigXenServer(String decodedUrl, UserVm vm) {
49734973
userVmDetailsDao.addDetail(vm.getId(), extraConfigKey + String.valueOf(i), cfg, true);
49744974
i++;
49754975
} else {
4976-
throw new CloudRuntimeException("Configuration " + cfg + " contains a blacklisted key by Root admin");
4976+
throw new CloudRuntimeException("Extra config " + cfg + " is not on the list of allowed keys for XenServer hypervisor hosts.");
49774977
}
49784978
}
49794979
} else {
@@ -5067,7 +5067,6 @@ protected void persistExtraConfigKvm(String decodedUrl, UserVm vm) {
50675067
*/
50685068
protected void validateKvmExtraConfig(String decodedUrl) {
50695069
String[] allowedConfigOptionList = KvmAdditionalConfigAllowList.value().split(",");
5070-
String msg = "An invalid extra configuration option has been supplied: ";
50715070
// Skip allowed keys validation validation for DPDK
50725071
if (!decodedUrl.contains(":")) {
50735072
try {
@@ -5080,7 +5079,7 @@ protected void validateKvmExtraConfig(String decodedUrl) {
50805079
NodeList nodeList = doc.getElementsByTagName(tag.trim());
50815080
// Node list should not be empty to show that allowed command is contained in passed XML
50825081
if (nodeList.getLength() == 0) {
5083-
throw new CloudRuntimeException(msg + tag);
5082+
throw new CloudRuntimeException(String.format("Extra config %s is not on the list of allowed keys for KVM hypervisor hosts", tag));
50845083
}
50855084
}
50865085
} catch (ParserConfigurationException | IOException | SAXException e) {

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
2323
import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
2424
import org.apache.cloudstack.context.CallContext;
25-
import org.junit.Assert;
2625
import org.junit.Before;
2726
import org.junit.Test;
2827
import org.junit.runner.RunWith;
@@ -48,6 +47,10 @@
4847
import com.cloud.vm.dao.UserVmDao;
4948
import com.cloud.vm.dao.UserVmDetailsDao;
5049

50+
import static org.junit.Assert.assertEquals;
51+
import static org.junit.Assert.assertFalse;
52+
import static org.junit.Assert.assertTrue;
53+
5154
@RunWith(PowerMockRunner.class)
5255
public class UserVmManagerImplTest {
5356

@@ -274,6 +277,18 @@ private void configureValidateOrReplaceMacAddressTest(int times, String macAddre
274277
String returnedMacAddress = userVmManagerImpl.validateOrReplaceMacAddress(macAddress, 1l);
275278

276279
Mockito.verify(networkModel, Mockito.times(times)).getNextAvailableMacAddressInNetwork(Mockito.anyLong());
277-
Assert.assertEquals(expectedMacAddress, returnedMacAddress);
280+
assertEquals(expectedMacAddress, returnedMacAddress);
281+
}
282+
283+
@Test
284+
public void testValidatekeyValuePair() throws Exception {
285+
assertTrue(userVmManagerImpl.isValidKeyValuePair("is-a-template=true\nHVM-boot-policy=\nPV-bootloader=pygrub\nPV-args=hvc0"));
286+
assertTrue(userVmManagerImpl.isValidKeyValuePair("is-a-template=true HVM-boot-policy= PV-bootloader=pygrub PV-args=hvc0"));
287+
assertTrue(userVmManagerImpl.isValidKeyValuePair("nvp.vm-uuid=34b3d5ea-1c25-4bb0-9250-8dc3388bfa9b"));
288+
assertFalse(userVmManagerImpl.isValidKeyValuePair("key"));
289+
//key-1=value1, param:key-2=value2, my.config.v0=False"
290+
assertTrue(userVmManagerImpl.isValidKeyValuePair("key-1=value1"));
291+
assertTrue(userVmManagerImpl.isValidKeyValuePair("param:key-2=value2"));
292+
assertTrue(userVmManagerImpl.isValidKeyValuePair("my.config.v0=False"));
278293
}
279294
}

0 commit comments

Comments
 (0)