Issue
I recently noticed a problem with Genymotion emulators and virtual box configurations. So far I only used one genymotion emulator, which once I started all the time had one static IP address, and my Java script automation tests hasn't given me any problem because it was configured to call exactly this IP and run tests on emulator. Recently I decided to add several other emulators to my list, and now those IP got messed up. Sometimes IP from one device (if it shut down) is being assigned to another emulator, or IP from last created emulator is assigned to the first one and so on. Let's assume I have 4 devices in the list; I noticed order of priority how IPs are assigned. If I start virtual box, open genymotion and start for instance first device, it gets 192.168.155.101 ; second device 192.168.155.102 ; third device 192.168.155.103 ; and so on respectively. But if I close and than open again genymotion and virtual box, decide to first launch fourth device, it gets IP address from the first one 192.168.155.101 which brings me configuration problems with the Appium / Selenium scripts. Is it possible to assign certain IPs to particular devices in genymotion so after relaunching virtual box and genymotion they will be the same?
Solution
From your post, I'm not sure what host operating system you are using. I'm on Linux (Ubuntu 16.04). If you are on something else, the details may be different than what is below, but the concepts are the same.
Genymotion relies on a VirtualBox host-only adapter (e.g., vboxnet0
and subnet 192.168.56.0
if you are running a typical Linux host) for adb
connectivity to things like Android Studio. When you deploy a Genymotion VM, this adapter is created and a DHCP server built-in to VirtualBox is enabled on it. Thus, after booting, you'll see something like this with multiple VMs started:
$ adb devices
List of devices attached
192.168.56.101:5555 device
192.168.56.102:5555 device
As long as you don't restart VirtualBox, you can shutdown and restart these VMs and they will get the same address each time. However, as you observed, if you restart VirtualBox, there is no memory of their previous address and the addressing will depend on boot order.
Most full-featured DHCP servers (even those in cheap home routers) allow for MAC registration for fixed IP leases. Unfortunately, as it currently stands, the built-in VirtualBox DHCP server does not support this.
One idea I had for a workaround was to disable the VirtualBox DHCP server on the host-only networked connected to the VMs, run my own listening on the host's vboxnet0
adapter, and configure it to supply fixed IPs for the Genymotion VMs based on their individual MAC addresses. You can disable DHCP for the VirtualBox host-only adapters under File->Preferences->Network->Host-only Networks. A snippet from the DHCP server configuration file on my host machine looks like this:
subnet 192.168.56.0 netmask 255.255.255.0 {
range 192.168.56.101 192.168.56.200;
}
host n5_2 {
hardware ethernet 08:00:27:1F:F2:7E;
fixed-address 192.168.56.123;
}
where 192.168.56.0
refers to the vboxnet0
subnet assignment, and the hardware ethernet
address is the one shown on the advanced portion of Settings->Network->Adapter 1 for each of the VMs you wish to have fixed IP assignments.
This basically works except for one aggravating problem: the Genymotion Launcher checks the network configuration each time a VM is started. When it sees the VM using a host-only adapter with DHCP disabled, it will create a new one if none exists (e.g., vboxnet1
, subnet 192.168.57.0
) with DHCP enabled, and change the VM's network configuration to point to this adapter. Thus after booting, you'll have this (notice the new subnet .57 as compared to before):
$ adb devices
List of devices attached
192.168.57.101:5555 device
192.168.57.102:5555 device
In the short amount of time I experimented, the only way I found to prevent the Genymotion Launcher from changing the network settings at boot was to have the corresponding VirtualBox Settings panel open while starting each VM from the Genymotion Launcher. I guess having it open puts some kind of lock on the configuration file, making the Launcher unable to change anything. When I did this, with the VM set to use the non-DHCP adapter and my host DHCP server configured as above, the one device gets the fixed IP in accordance with the DHCP configuration, while the others get addresses based on boot order:
$ adb devices
List of devices attached
192.168.56.101:5555 device
192.168.56.123:5555 device
If you can set up a DHCP server on your host, and don't mind opening the Settings panels each time you start each VM, I guess you could consider this a workaround. To me, it's not very practical and better options include:
- VirtualBox adds support for MAC registrations in its built-in DHCP server.
- Genymotion removes (or optionalizes) configuration checks during boot.
- Figure out how/why having Settings open locks the VM configuration and then just permanently lock it.
Answered By - Paul Ratazzi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.