Skip to content

Commit

Permalink
Stop adding ContrailVMs to VNC
Browse files Browse the repository at this point in the history
Depends-On: I2a6378e230b1f9160dcdb13a828c1586aa581b05
Change-Id: If059fb42e1e53051d967d13344e55f0811062318
Closes-Bug: #1778009
  • Loading branch information
aszc-dev committed Jun 21, 2018
1 parent edc7a33 commit e8a02ca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -107,4 +107,7 @@ config.yaml
.idea/

# pytest
.pytest_cache/
.pytest_cache/

# Sandesh generated files
cvm/sandesh/
3 changes: 2 additions & 1 deletion cvm/services.py
Expand Up @@ -60,7 +60,8 @@ def _update(self, vm_model, vmware_vm, vm_properties):
def _create(self, vmware_vm, vm_properties):
vm_model = VirtualMachineModel(vmware_vm, vm_properties)
self._add_property_filter_for_vm(vm_model, ['guest.toolsRunningStatus', 'guest.net'])
self._vnc_api_client.update_or_create_vm(vm_model.vnc_vm)
if not vm_model.is_contrail_vm:
self._vnc_api_client.update_or_create_vm(vm_model.vnc_vm)
self._database.save(vm_model)
return vm_model

Expand Down
33 changes: 33 additions & 0 deletions tests/test_events.py
Expand Up @@ -88,6 +88,14 @@ def vm_properties_renamed():
}


@pytest.fixture()
def contrail_vm_properties():
return {
'config.instanceUuid': '12345678-1234-1234-1234-123456789012',
'name': 'ContrailVM'
}


def assign_ip_to_instance_ip(instance_ip):
instance_ip.set_instance_ip_address('192.168.100.5')
return instance_ip
Expand Down Expand Up @@ -476,3 +484,28 @@ def test_vm_created_vlan_id(vcenter_api_client, vn_model_1, vm_created_update,
vn_model=vn_model_1,
vm_model=vm_model
)


def test_contrail_vm(vcenter_api_client, vm_created_update, esxi_api_client,
vnc_api_client, contrail_vm_properties):
""" We need ContrailVM only in database. It should not be created in VNC. """
vrouter_api_client = Mock()
database = Database()
vm_service = VirtualMachineService(esxi_api_client, vnc_api_client, database)
vmi_service = VirtualMachineInterfaceService(vcenter_api_client, vnc_api_client, database)
vrouter_port_service = VRouterPortService(vrouter_api_client, database)
esxi_api_client.read_vm_properties.return_value = contrail_vm_properties
controller = VmwareController(vm_service, None, vmi_service, vrouter_port_service, [])

# A new update containing VmCreatedEvent arrives and is being handled by the controller
controller.handle_update(vm_created_update)

# Check if VM Model has been saved in the database
assert len(database.get_all_vm_models()) == 1

# There were no calls to vnc_api
vnc_api_client.update_or_create_vm.assert_not_called()
vnc_api_client.update_or_create_vmi.assert_not_called()

# There were no calls to vrouter_api
vrouter_api_client.add_port.assert_not_called()
2 changes: 1 addition & 1 deletion tests/test_services.py
Expand Up @@ -78,7 +78,7 @@ def test_update_existing_vm(self):

self.assertEqual(old_vm_model, new_vm_model)
old_vm_model.update.assert_called_once_with(self.vmware_vm, self.vm_properties)
self.vnc_client.update_vm.assert_not_called()
self.vnc_client.update_or_create_vm.assert_not_called()

def test_sync_vms(self):
self.esxi_api_client.get_all_vms.return_value = [self.vmware_vm]
Expand Down

0 comments on commit e8a02ca

Please sign in to comment.