Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add time.sleep call before set VLAN call for port in vCenter to avoid…
… race in vmware code Add new handler for VmRegisteredEvent Refactored VLAN ID assignment logic Partial-Bug: #1792538 Change-Id: I28bc48c0cf3622cfb3130671c33adfa2d442317b Depends-on: Ic332e37c3de9462c32dac81bc370b313460935be (cherry picked from commit 44ca1b6)
- Loading branch information
1 parent
2395a76
commit b8d6c8a
Showing
7 changed files
with
139 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from tests.utils import assert_vmi_model_state, reserve_vlan_ids | ||
|
||
|
||
def test_vmotion_vlan_unavailable(controller, database, vcenter_api_client, vm_registered_update, vn_model_1, | ||
vlan_id_pool): | ||
""" When the VLAN ID is unavailable on a host, we should change it to a new value""" | ||
# Virtual Networks are already created for us and after synchronization, | ||
# their models are stored in our database | ||
database.save(vn_model_1) | ||
|
||
# Some vlan ids should be already reserved | ||
reserve_vlan_ids(vlan_id_pool, [0, 1, 5]) | ||
|
||
# When we ask vCenter for the VLAN ID it turns out that the VLAN ID has already been overridden | ||
vcenter_api_client.get_vlan_id.return_value = 5 | ||
|
||
# A new update containing VmRegisteredEvent arrives and is being handled by the controller | ||
controller.handle_update(vm_registered_update) | ||
|
||
# Check if VLAN ID has been changed | ||
vmi_model = database.get_all_vmi_models()[0] | ||
vcenter_api_client.set_vlan_id.assert_called_once_with(vmi_model.vcenter_port) | ||
|
||
# Check inner VMI model state | ||
vm_model = database.get_vm_model_by_uuid('vmware-vm-uuid-1') | ||
assert_vmi_model_state( | ||
vmi_model, | ||
mac_address='mac-address', | ||
ip_address='192.168.100.5', | ||
vlan_id=2, | ||
display_name='vmi-DPG1-VM1', | ||
vn_model=vn_model_1, | ||
vm_model=vm_model | ||
) | ||
|
||
|
||
def test_vmotion_vlan_available(controller, database, vcenter_api_client, vm_registered_update, vn_model_1, | ||
vlan_id_pool): | ||
""" When the VLAN ID is available on a host, we should not change it""" | ||
# Virtual Networks are already created for us and after synchronization, | ||
# their models are stored in our database | ||
database.save(vn_model_1) | ||
|
||
# Some vlan ids should be already reserved | ||
reserve_vlan_ids(vlan_id_pool, [0, 1]) | ||
|
||
# When we ask vCenter for the VLAN ID it turns out that the VLAN ID has already been overridden | ||
vcenter_api_client.get_vlan_id.return_value = 5 | ||
|
||
# A new update containing VmRegisteredEvent arrives and is being handled by the controller | ||
controller.handle_update(vm_registered_update) | ||
|
||
# Check if VLAN ID has been changed | ||
vmi_model = database.get_all_vmi_models()[0] | ||
vcenter_api_client.set_vlan_id.assert_not_called() | ||
|
||
# Check inner VMI model state | ||
vm_model = database.get_vm_model_by_uuid('vmware-vm-uuid-1') | ||
assert_vmi_model_state( | ||
vmi_model, | ||
mac_address='mac-address', | ||
ip_address='192.168.100.5', | ||
vlan_id=5, | ||
display_name='vmi-DPG1-VM1', | ||
vn_model=vn_model_1, | ||
vm_model=vm_model | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters