Restore support for zero instance filtering in binary cnf store queries
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 20 Apr 2022 07:45:23 +0000 (10:45 +0300)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Tue, 17 May 2022 02:35:40 +0000 (05:35 +0300)
Some cnfvars like NICs support zero instance numbers and without
this fix the query would simply return all cnfvars in a cnf list
if we need `get_cnf CNFVAR 0` from the query.

src/cnfvar/binary.py

index 63311cc..d707daa 100644 (file)
@@ -105,7 +105,8 @@ class CnfBinary:
         elif instance is not None and not isinstance(instance, int):
             raise TypeError(f"`instance` is of wrong type {type(instance)}")
 
-        cmd = f"{BIN_GET_CNF} {name or ''} {instance or ''}"
+        # make sure 0 instance cnfvars like e.g. NICs can also be filtered by instance
+        cmd = f"{BIN_GET_CNF} {name or ''} {instance if instance is not None else ''}"
 
         encoding = ENCODING
         if no_children: