problem adding new shared network NIC to VM "A NIC with this MAC address exits for network:"
ISSUE TYPE
- Bug Report
COMPONENT NAME
Network
CLOUDSTACK VERSION
4.11
CONFIGURATION
OS / ENVIRONMENT
SUMMARY
We're unable to create more than one NIC on a shared network through the Web-UI.
STEPS TO REPRODUCE
Log in to Web-UI
Create new shared network.
Add NIC on this new network to a VM. (works)
Add NIC on this new network to another VM. Fails with "A NIC with this MAC address exits for network: (uuid of the current (other NIC) network)"
EXPECTED RESULTS
The second NIC should be added correctly.
ACTUAL RESULTS
Adding the NIC fails with "A NIC with this MAC address exits for network: (uuid of the current (other NIC) network)"
Stephan investigated the issue and found a temporary patch, which works for us. He gave this information:
After digging into the code, I think I've found the problem, but am too bad in java to provide a sustainable fix. I've attached a patch which obviously (with own manual tests) fixes that issue by simply commenting out the respective codeblock. As far as I dug into the code, the third parameter of NicProfile is handled by NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value()) inside NicProfileHelperImpl.java I assume createSequenceBasedMacAddress can handle null as MAC, but doesn't get called at all if _nicDao.findByNetworkIdAndMacAddress(networkId, macAddress) results != null if macAddress is null.
cloudstack-4.11.0-stephans-duplicate-nicaddress-fix.diff.txt
Duplicates: https://issues.apache.org/jira/browse/CLOUDSTACK-10350. I closed the issue on Jira.
I was able to reproduce this using mentioned steps:
2018-05-09 11:54:34,243 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-4:ctx-93641744 job-151) (logid:01cf6a76) Executing AsyncJobVO {id:151, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.AddNicToVMCmdByAdmin, cmdInfo: {"virtualmachineid":"5be800c6-c06a-4944-97be-0b2339cf9fff","response":"json","ctxUserId":"2","httpmethod":"GET","networkid":"cafc6944-64fe-488a-bf2c-916ed89090b3","ctxStartEventId":"349","ctxDetails":"{\"interface com.cloud.vm.VirtualMachine\":\"5be800c6-c06a-4944-97be-0b2339cf9fff\",\"interface com.cloud.network.Network\":\"cafc6944-64fe-488a-bf2c-916ed89090b3\"}","ctxAccountId":"2","cmdEventType":"NIC.CREATE","_":"1525866874211"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 5071960016, completeMsid: null, lastUpdated: null, lastPolled: null, created: null}
2018-05-09 11:54:34,244 DEBUG [c.c.a.ApiServlet] (qtp1096283470-12:ctx-89cce544 ctx-21b232ff) (logid:05f9e858) ===END=== 192.168.1.108 -- GET command=addNicToVirtualMachine&response=json&virtualmachineid=5be800c6-c06a-4944-97be-0b2339cf9fff&networkid=cafc6944-64fe-488a-bf2c-916ed89090b3&_=1525866874211
2018-05-09 11:54:34,300 ERROR [c.c.a.ApiAsyncJobDispatcher] (API-Job-Executor-4:ctx-93641744 job-151) (logid:01cf6a76) Unexpected exception while executing org.apache.cloudstack.api.command.admin.vm.AddNicToVMCmdByAdmin
com.cloud.utils.exception.CloudRuntimeException: A NIC with this MAC address exists for network: cafc6944-64fe-488a-bf2c-916ed89090b3
at com.cloud.vm.UserVmManagerImpl.addNicToVirtualMachine(UserVmManagerImpl.java:1204)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
@GabrielBrascher can you help fix this, thanks.
Yes @rhtyd, I will take a look to fix it.
I have the same problem, I installed a fresh Cloudstack 4.11 and the same thing. Do you know how to fixed?
@covalle1428, removing the conditional as @mdesaive showed is an emergency fix; however, I am analyzing other approaches. I will cite the PR here when created.
Sorry I don't have the source package I'm installed from the .rpm normal package, how and where can remove this conditional?
@covalle1428 if you intend to do an urgent fix, you can follow a few steps.
Bear in mind that this can be tricky and it would be risky to launch on a production environment before testing it on a test environment.
-
get the 4.11 source code
-
remove/comment
if(_nicDao.findByNetworkIdAndMacAddress(networkId, macAddress) != null) {
throw new CloudRuntimeException("A NIC with this MAC address exists for network: " + network.getUuid());
}
That code is in method addNicToVirtualMachine(AddNicToVMCmd cmd) from class UserVmManagerImpl.java
@GabrielBrascher any update on this, thanks.
I would like to avoid the solution that just removes the conditional. What do you think of that solution @rhtyd? I am evaluating some alternatives yet.
@GabrielBrascher I think the ideal fix would be to ensure that mac address is uniquely created considering a zoneid, network id, nic/slot id and mgmt server id, and perhaps other parameters. Fixing the logic that creates unique mac address should fix the issue of mac address conflict.
The issue happens whenever nic2/slot2 is plugged on the same shared network for different VMs.
@rhtyd @GabrielBrascher network id should not matter, a vm can be re-plugged into another network. Also the exception in the code that @GabrielBrascher shows above should/can actually be handled by creating a new MAC that is unique.
@GabrielBrascher , I think some iusers will need plugable macaddress generation algorithms but for this specific issue we could just add the following bit
if(null == macAddress) {
try {
macAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
} catch (InsufficientAddressCapacityException e) {
throw new CloudRuntimeException("A MAC address can not be generated for this NIC in network: " + network.getUuid());
}
}
before
if(_nicDao.findByNetworkIdAndMacAddress(networkId, macAddress) != null) {
throw new CloudRuntimeException("A NIC with this MAC address exists for network: " + network.getUuid());
}
as it seems to be a problem when the macaddress given is null. If it is an actual MAC it is a user mistake.
@DaanHoogland I agree with you. Let's keep your approach (getNextAvailableMacAddressInNetwork) to this issue and then open a new issue/PR in future with mac generation.