Add support for new NIC_COMMENT field
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Sat, 1 Feb 2020 18:26:30 +0000 (19:26 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 13 Feb 2020 15:13:48 +0000 (16:13 +0100)
The comment field on NICs moves from the parent NIC
to a new NIC_COMMENT cnfvar.

src/cnfline/build_nic.py
test/test_cnfline.py [changed mode: 0755->0644]

index 9fea9c1..3d870e5 100644 (file)
@@ -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
old mode 100755 (executable)
new mode 100644 (file)
index 212b5df..6999ab6
@@ -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()