Browse Source

tools/qvm-ls: fix handling columns with underscore

Mangling column type was inconsistent, resulting in
KeyError('VIRT_MODE').
Marek Marczykowski-Górecki 6 years ago
parent
commit
917df5a8c5
2 changed files with 13 additions and 1 deletions
  1. 11 0
      qubesadmin/tests/tools/qvm_ls.py
  2. 2 1
      qubesadmin/tools/qvm_ls.py

+ 11 - 0
qubesadmin/tests/tools/qvm_ls.py

@@ -86,6 +86,17 @@ class TC_50_List(qubesadmin.tests.QubesTestCase):
             'dom0     Running  TestVM  black  -         -\n'
             'test-vm  Running  TestVM  green  template  sys-net\n')
 
+    def test_101_list_with_underscore(self):
+        app = TestApp()
+        app.domains['test-vm'].virt_mode = 'pv'
+        app.domains['test-vm'].label = 'green'
+        app.domains['dom0'].label = 'black'
+        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
+            qubesadmin.tools.qvm_ls.main(['-O', 'name,virt_mode,class'], app=app)
+        self.assertEqual(stdout.getvalue(),
+            'NAME     VIRT-MODE  CLASS\n'
+            'dom0     -          TestVM\n'
+            'test-vm  pv         TestVM\n')
 
 class TC_90_List_with_qubesd_calls(qubesadmin.tests.QubesTestCase):
     def test_100_list_with_status(self):

+ 2 - 1
qubesadmin/tools/qvm_ls.py

@@ -389,7 +389,8 @@ class Table(object):
     '''
     def __init__(self, app, colnames, spinner, raw_data=False):
         self.app = app
-        self.columns = tuple(Column.columns[col.upper()] for col in colnames)
+        self.columns = tuple(Column.columns[col.upper().replace('_', '-')]
+                for col in colnames)
         self.spinner = spinner
         self.raw_data = raw_data