Exemple #1
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     for col, val in self.col_values:
         # TODO(twilson) Ugh, the OVS library doesn't like OrderedDict
         # We're only using it to make a unit test work, so we should fix
         # this soon.
         if isinstance(val, collections.OrderedDict):
             val = dict(val)
         if isinstance(val, dict):
             # NOTE(twilson) OVS 2.6's Python IDL has mutate methods that
             # would make this cleaner, but it's too early to rely on them.
             existing = getattr(record, col, {})
             existing.update(val)
             val = existing
         setattr(record, col, idlutils.db_replace_record(val))
Exemple #2
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     for value in self.values:
         if isinstance(value, collections.Mapping):
             # We should be doing an add on a 'map' column. If the key is
             # already set, do nothing, otherwise set the key to the value
             # Since this operation depends on the previous value, verify()
             # must be called.
             field = getattr(record, self.column, {})
             for k, v in six.iteritems(value):
                 if k in field:
                     continue
                 field[k] = v
         else:
             # We should be appending to a 'set' column.
             try:
                 record.addvalue(self.column,
                                 idlutils.db_replace_record(value))
                 continue
             except AttributeError:  # OVS < 2.6
                 field = getattr(record, self.column, [])
                 field.append(value)
         record.verify(self.column)
         setattr(record, self.column, idlutils.db_replace_record(field))
Exemple #3
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     for col, val in self.col_values:
         # TODO(twilson) Ugh, the OVS library doesn't like OrderedDict
         # We're only using it to make a unit test work, so we should fix
         # this soon.
         if isinstance(val, collections.OrderedDict):
             val = dict(val)
         if isinstance(val, dict):
             # NOTE(twilson) OVS 2.6's Python IDL has mutate methods that
             # would make this cleaner, but it's too early to rely on them.
             existing = getattr(record, col, {})
             existing.update(val)
             val = existing
         setattr(record, col, idlutils.db_replace_record(val))
Exemple #4
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     for value in self.values:
         field = getattr(record, self.column)
         if isinstance(value, collections.Mapping):
             # We should be doing an add on a 'map' column. If the key is
             # already set, do nothing, otherwise set the key to the value
             for k, v in six.iteritems(value):
                 if k in field:
                     continue
                 field[k] = v
         else:
             # We should be appending to a 'set' column.
             field.append(value)
         record.verify(self.column)
         setattr(record, self.column, idlutils.db_replace_record(field))
Exemple #5
0
 def run_idl(self, txn):
     record = idlutils.row_by_record(self.api.idl, self.table, self.record)
     for value in self.values:
         field = getattr(record, self.column)
         if isinstance(value, collections.Mapping):
             # We should be doing an add on a 'map' column. If the key is
             # already set, do nothing, otherwise set the key to the value
             for k, v in six.iteritems(value):
                 if k in field:
                     continue
                 field[k] = v
         else:
             # We should be appending to a 'set' column.
             field.append(value)
         record.verify(self.column)
         setattr(record, self.column, idlutils.db_replace_record(field))
Exemple #6
0
 def test_db_replace_record_list(self):
     obj = [1, 2, 3]
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #7
0
 def test_db_replace_record_dict_cmd(self):
     obj = {'a': 1, 'b': MockCommand(2)}
     res = {'a': 1, 'b': 2}
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #8
0
 def test_db_replace_record_dict(self):
     obj = {'a': 1, 'b': 2}
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #9
0
 def test_db_replace_record_cmd(self):
     obj = MockCommand("test")
     self.assertEqual("test", idlutils.db_replace_record(obj))
Exemple #10
0
 def test_db_replace_record_tuple_cmd(self):
     obj = (1, MockCommand(2), 3)
     res = (1, 2, 3)
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #11
0
 def test_db_replace_record_tuple_cmd(self):
     obj = (1, MockCommand(2), 3)
     res = (1, 2, 3)
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #12
0
 def test_db_replace_record_tuple(self):
     obj = (1, 2, 3)
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #13
0
 def test_db_replace_record_list_cmd(self):
     obj = [1, MockCommand(2), 3]
     res = [1, 2, 3]
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #14
0
 def test_db_replace_record_list(self):
     obj = [1, 2, 3]
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #15
0
 def test_db_replace_record_list_cmd(self):
     obj = [1, MockCommand(2), 3]
     res = [1, 2, 3]
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #16
0
 def test_db_replace_record_tuple(self):
     obj = (1, 2, 3)
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #17
0
 def test_db_replace_record(self):
     obj = "test"
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #18
0
 def test_db_replace_record(self):
     obj = "test"
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #19
0
 def test_db_replace_record_cmd(self):
     obj = MockCommand("test")
     self.assertEqual("test", idlutils.db_replace_record(obj))
Exemple #20
0
 def run_idl(self, txn):
     row = txn.insert(self.api._tables[self.table])
     for col, val in self.columns.items():
         setattr(row, col, idlutils.db_replace_record(val))
     # This is a temporary row to be used within the transaction
     self.result = row
Exemple #21
0
 def test_db_replace_record_dict(self):
     obj = {"a": 1, "b": 2}
     self.assertIs(obj, idlutils.db_replace_record(obj))
Exemple #22
0
 def test_db_replace_record_dict_cmd(self):
     obj = {"a": 1, "b": MockCommand(2)}
     res = {"a": 1, "b": 2}
     self.assertEqual(res, idlutils.db_replace_record(obj))
Exemple #23
0
 def run_idl(self, txn):
     row = txn.insert(self.api._tables[self.table])
     for col, val in self.columns.items():
         setattr(row, col, idlutils.db_replace_record(val))
     # This is a temporary row to be used within the transaction
     self.result = row