cloudbase / cloudbase-init

Cross-platform instance initialization
http://openstack.org
Apache License 2.0
408 stars 149 forks source link

Network interface renaming is not working on Win Server 2022 Core #101

Closed alexandrovas closed 2 months ago

alexandrovas commented 1 year ago

Hello!

I have issue with network interface renaming on Windows 2022 Core. Environment:

Cloudbase-init log:

2022-11-26 12:45:43.964 2916 DEBUG cloudbaseinit.plugins.common.networkconfig [-] Setting MTU on network adapter "tap31bc296d-b5": 1500 _process_link_common C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\networkconfig.py:182
2022-11-26 12:45:43.980 2916 DEBUG cloudbaseinit.utils.retry_decorator [-] Got expected exception Network interface with name "tap31bc296d-b5" not found while calling function cloudbaseinit.osutils.windows.WindowsUtils.set_network_adapter_mtu. Retries left: 3. Time left: undefined. Time elapsed: 0.0 Retrying in 1 seconds. inner C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\retry_decorator.py:83
2022-11-26 12:45:45.058 2916 DEBUG cloudbaseinit.utils.retry_decorator [-] Got expected exception Network interface with name "tap31bc296d-b5" not found while calling function cloudbaseinit.osutils.windows.WindowsUtils.set_network_adapter_mtu. Retries left: 2. Time left: undefined. Time elapsed: 1.0781581401824951 Retrying in 1 seconds. inner C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\retry_decorator.py:83
2022-11-26 12:45:46.074 2916 DEBUG cloudbaseinit.utils.retry_decorator [-] Got expected exception Network interface with name "tap31bc296d-b5" not found while calling function cloudbaseinit.osutils.windows.WindowsUtils.set_network_adapter_mtu. Retries left: 1. Time left: undefined. Time elapsed: 2.0941057205200195 Retrying in 1 seconds. inner C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\retry_decorator.py:83
2022-11-26 12:45:47.105 2916 ERROR cloudbaseinit.init [-] plugin 'NetworkConfigPlugin' failed with error 'Network interface with name "tap31bc296d-b5" not found': cloudbaseinit.exception.ItemNotFoundException: Network interface with name "tap31bc296d-b5" not found
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init [-] Network interface with name "tap31bc296d-b5" not found: cloudbaseinit.exception.ItemNotFoundException: Network interface with name "tap31bc296d-b5" not found
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init Traceback (most recent call last):
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\init.py", line 67, in _exec_plugin
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     shared_data)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\networkconfig.py", line 307, in execute
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     return self._process_network_details_v2(network_details)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\networkconfig.py", line 296, in _process_network_details_v2
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     osutils, network_details)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\networkconfig.py", line 207, in _process_physical_links
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     NetworkConfigPlugin._process_link_common(osutils, link)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\networkconfig.py", line 183, in _process_link_common
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     osutils.set_network_adapter_mtu(link.name, link.mtu)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\retry_decorator.py", line 84, in inner
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     time.sleep(sleep_time)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_utils\excutils.py", line 220, in __exit__
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     self.force_reraise()
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_utils\excutils.py", line 196, in force_reraise
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     six.reraise(self.type_, self.value, self.tb)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\six.py", line 703, in reraise
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     raise value
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\retry_decorator.py", line 47, in inner
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     return f(*args, **kwargs)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py", line 837, in set_network_adapter_mtu
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init     name)
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init cloudbaseinit.exception.ItemNotFoundException: Network interface with name "tap31bc296d-b5" not found
2022-11-26 12:45:47.120 2916 ERROR cloudbaseinit.init 
2022-11-26 12:45:47.339 2916 INFO cloudbaseinit.init [-] Executing plugin 'CreateUserPlugin'

As result network configuration of VM is failed and VM is not accessible by network.

After machine created I logged in to it and checked network config. Network interface is not renamed and left with name Ethernet: image

I tried to rename interface manually by the same command as in cloudbase-init code: image

Looks like this command is not working in Windows 2022 Core.

After this I tried to rename network interface by Powershell command Get-NetAdapter -Name "Ethernet" | Rename-NetworkAdapter -NewName "tap31bc296d-b5": image

And network interface was successfully renamed by this Powershell command. After renaming interface I restarted VM to continue cloudbase-init initialization progress and it successfully finished too.

I think this code with netsh call should be replaced to WMI MSFT_NetAdapter interface or Powershell Rename-NetAdapter cmdlet because netsh is obsoleted.

ader1990 commented 1 year ago

Hello,

The usage of netsh was due to the fact that we are running cloudbase-init during the very early first boot - specialize step, where WMI is not available. If netsh is not working anymore, we ll need to find an alternative that works during the early boot.

Thank you, Adrian Vladu

ader1990 commented 1 year ago

Hello,

We are currently using opendev for patches, if you can add your patch to the review queue there, would be great. https://review.opendev.org/q/project:x/cloudbase-init

How to create an account and contribute to: https://docs.openstack.org/contributors/common/setup-gerrit.html

Otherwise, I can cherry-pick your commit, but it is a more complicated issue, as during the opendev onboarding there is a Licensing document that needs to be aprroved: https://docs.openstack.org/contributors/common/setup-gerrit.html#individual-contributor-license-agreement-icla . Please let me know if you can add it as a opendev patch (former Gerrit).

Thank you, Adrian Vladu.

dgrauet commented 4 months ago

Hello, any news about this issue ?

aiso-net commented 2 months ago

We are having the same issue here, Core 2022 not setting the IP address on deployment in openstack

ader1990 commented 2 months ago

Hello, work is in progress here to fix the issue -> https://review.opendev.org/c/x/cloudbase-init/+/898713 I have built an installer with the fix here: https://github.com/ader1990/cloudbase-init-installer-1/actions/runs/8506367466 (see the artifacts tab) If you can try it out to confirm the fix, that would be awesome!

Thank you.

aiso-net commented 2 months ago

Hello, work is in progress here to fix the issue -> https://review.opendev.org/c/x/cloudbase-init/+/898713 I have built an installer with the fix here: https://github.com/ader1990/cloudbase-init-installer-1/actions/runs/8506367466 (see the artifacts tab) If you can try it out to confirm the fix, that would be awesome!

Thank you.

I will test and let you know.

dgrauet commented 2 months ago

Not working on my side

ERROR cloudbaseinit.init [-] plugin 'NetworkConfigPlugin' failed with error 'Renaming interface "Ethernet" to "tapb498e43f-0c" failed': cloudbaseinit.exception.CloudbaseInitException: Renaming interface "Ethernet" to "tapb498e43f-0c" failed
aiso-net commented 2 months ago

Hello,

The usage of netsh was due to the fact that we are running cloudbase-init during the very early first boot - specialize step, where WMI is not available. If netsh is not working anymore, we ll need to find an alternative that works during the early boot.

Thank you, Adrian Vladu

Couldnt you just rename in the registry (although this may require a reboot) or wmic ?

ader1990 commented 2 months ago

@dgrauet I will recheck, can you please provide a systeminfo output of the Windows exact version, to make sure I can reliably reproduce the issue? @aiso-net the fix uses a lower level WMI implementation (Windows API MI), so it should definitely work if the API is respected.

dgrauet commented 2 months ago

OS Name: Microsoft Windows Server 2022 Standard OS Version: 10.0.20348 N/A Build 20348

ader1990 commented 2 months ago

Hello @dgrauet, I have tried to reproduce the issue using the ISO from https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022 (10.0.20348 with latest updates).

But both the latest nightly and https://github.com/ader1990/cloudbase-init-installer-1/actions/runs/8506367466 work as expected, tried with both Standard and Datacenter. I think this might be an issue with the VirtIO drivers in some situations. Can you please give more details on how you created the Windows VM and what hypervisor version, virtio driver version are you using?

Thank you, Adrian Vladu

ader1990 commented 2 months ago

Hello again, I managed to reproduce the issue, seems that I was not using the correct ISO in my testing.

I have observed that only MSFT_NetAdapter.rename method can be used to rename the adapter on the Core version and changed the code accordingly: https://review.opendev.org/c/x/cloudbase-init/+/898713

For example, this fix is not working https://github.com/cloudbase/cloudbase-init/pull/102/files#diff-bde815550dd2cbe6c3cd4c1f2d266c63c38f5dbaed128ac207d9556757ebc596R865 and neither using the Win32_NetworkAdapter class.

The MSI installer with the fix should be built shortly and available here https://github.com/ader1990/cloudbase-init-installer-1/actions/runs/8736432020

Thank you, Adrian Vladu

dgrauet commented 2 months ago

LGTM, will you release 1.1.6 with this patch ?