Extend transaction with multiple commands

Allow user to extend transaction with multiple commands in one call.
This is convenient when transaction is created in main scope, but
commands are created and returned from other functions.

Change-Id: Idf3b3a4a840b0db3cf91ead82d36d638cbb3f379
This commit is contained in:
Petr Horáček 2017-11-30 20:21:18 +02:00
parent 124b52c425
commit 15836d3df2
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):