Skip to content

Commit

Permalink
Remove ports from update queue after failed update
Browse files Browse the repository at this point in the history
Change-Id: I0c53763484e6451ec1f0f087d5dd0321bc41e6a8
Closes-Bug: #1778008
  • Loading branch information
aszc-dev committed Jun 21, 2018
1 parent 47c3322 commit e6702e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cvm/services.py
Expand Up @@ -263,12 +263,22 @@ def __init__(self, vrouter_api_client, database):
self._database = database

def sync_ports(self):
self._delete_ports()
self._update_ports()

def _delete_ports(self):
for uuid in self._database.ports_to_delete:
self._delete_port(uuid)
self._database.ports_to_delete.remove(uuid)

def _delete_port(self, uuid):
self._vrouter_api_client.delete_port(uuid)

def _update_ports(self):
for vmi_model in self._database.ports_to_update:
if self._port_needs_an_update(vmi_model):
self._update_port(vmi_model)
self._database.ports_to_update.remove(vmi_model)

def _port_needs_an_update(self, vmi_model):
vrouter_port = self._vrouter_api_client.read_port(vmi_model.uuid)
Expand All @@ -284,8 +294,3 @@ def _update_port(self, vmi_model):
self._vrouter_api_client.delete_port(vmi_model.uuid)
self._vrouter_api_client.add_port(vmi_model)
self._vrouter_api_client.enable_port(vmi_model.uuid)
self._database.ports_to_update.remove(vmi_model)

def _delete_port(self, uuid):
self._vrouter_api_client.delete_port(uuid)
self._database.ports_to_delete.remove(uuid)
1 change: 1 addition & 0 deletions tests/test_services.py
Expand Up @@ -620,6 +620,7 @@ def test_no_update(self):
self.assertEqual(0, self.vrouter_api_client.delete_port.call_count)
self.assertEqual(0, self.vrouter_api_client.add_port.call_count)
self.assertEqual(0, self.vrouter_api_client.enable_port.call_count)
self.assertEqual([], self.database.ports_to_update)

def test_delete_port(self):
self.database.ports_to_delete.append('fe71b44d-0654-36aa-9841-ab9b78d628c5')
Expand Down

0 comments on commit e6702e9

Please sign in to comment.