From 07f762f8a1d3b9a5d2c41d49087241b721b37ef6 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 1 Feb 2020 19:26:30 +0100 Subject: [PATCH] Add support for new NIC_COMMENT field The comment field on NICs moves from the parent NIC to a new NIC_COMMENT cnfvar. --- src/cnfline/build_nic.py | 7 ++++++- test/test_cnfline.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletions(-) mode change 100755 => 100644 test/test_cnfline.py diff --git a/src/cnfline/build_nic.py b/src/cnfline/build_nic.py index 9fea9c1..3d870e5 100644 --- a/src/cnfline/build_nic.py +++ b/src/cnfline/build_nic.py @@ -25,11 +25,12 @@ from .build_cnfvar import BuildCnfVar class BuildNIC(BuildCnfVar): def __init__(self, data='', instance=0, line_no=1): - BuildCnfVar.__init__(self, 'NIC', instance, data, line_no) + BuildCnfVar.__init__(self, 'NIC', instance, '', line_no) # the bare defaults the UI adds upon # creation of new groups defaults = { + 'NIC_COMMENT': data, 'NIC_DRIVER': 'virtio_net', 'NIC_LAN_DNS_RELAYING_ALLOWED': "0", 'NIC_LAN_EMAIL_RELAYING_ALLOWED': "0", @@ -44,6 +45,10 @@ class BuildNIC(BuildCnfVar): self.add_defaults(defaults) + def comment(self, comment): + self.update_cnf('NIC_COMMENT', 0, comment) + return self + def nic_type(self, nic_type): self.update_cnf('NIC_TYPE', 0, nic_type) return self diff --git a/test/test_cnfline.py b/test/test_cnfline.py old mode 100755 new mode 100644 index 212b5df..6999ab6 --- a/test/test_cnfline.py +++ b/test/test_cnfline.py @@ -22,6 +22,7 @@ import unittest from src.cnfline.cnfline import CnfLine +from src.cnfline.build_nic import BuildNIC class CnfLineTest(unittest.TestCase): @@ -50,5 +51,24 @@ class CnfLineTest(unittest.TestCase): line = CnfLine('MY_NAME', 123, 'my_data', 10, 456) self.assertEqual('10 (456) MY_NAME,123: "my_data"', str(line)) + +class BuildNICTest(unittest.TestCase): + def test_nic_comment(self): + nic = BuildNIC('my comment', 10, 100) + + cnf_text = str(nic) + self.assertTrue('NIC_COMMENT,0: "my comment"' in cnf_text) + self.assertEqual('', nic.data) + + def test_change_comment(self): + nic = BuildNIC('initial comment', 10, 100) + nic.comment('new comment') + + cnf_text = str(nic) + self.assertTrue('NIC_COMMENT,0: "new comment"' in cnf_text) + self.assertTrue('initial comment"' not in cnf_text) + self.assertEqual('', nic.data) + + if __name__ == '__main__': unittest.main() -- 1.7.1