Merge "Extend transaction with multiple commands"

This commit is contained in:
Zuul 2017-12-18 10:28:17 +00:00 committed by Gerrit Code Review
commit bbb3ce9f02
2 changed files with 13 additions and 3 deletions

View File

@ -44,7 +44,17 @@ class Transaction(object):
@abc.abstractmethod
def add(self, command):
"""Append an OVSDB operation to the transaction"""
"""Append an OVSDB operation to the transaction
Operation is returned back as a convenience.
"""
def extend(self, commands):
"""Add multiple OVSDB operations to the transaction
List of operations is returned back as a convenience.
"""
return [self.add(command) for command in commands]
def __enter__(self):
return self

View File

@ -75,8 +75,8 @@ class TestOvsdbIdl(base.FunctionalTestCase):
def _test_add_port(self):
pname = utils.get_rand_device_name()
with self.api.transaction(check_error=True) as txn:
txn.add(self.api.add_br(self.brname))
txn.add(self.api.add_port(self.brname, pname))
txn.extend([self.api.add_br(self.brname),
self.api.add_port(self.brname, pname)])
return pname
def test_add_port(self):