diff --git a/qubesadmin/base.py b/qubesadmin/base.py index 950841d..2ede90c 100644 --- a/qubesadmin/base.py +++ b/qubesadmin/base.py @@ -324,10 +324,20 @@ class WrapperObjectsCollection(object): def __iter__(self): self.refresh_cache() - for obj in self._names_list: - yield self[obj] + for key in self._names_list: + yield key def keys(self): '''Get list of names.''' self.refresh_cache() - return self._names_list.copy() + return [key for key in self._names_list] + + def items(self): + '''Get list of (key, value) pairs''' + self.refresh_cache() + return [(key, self.get_blind(key)) for key in self._names_list] + + def values(self): + '''Get list of objects''' + self.refresh_cache() + return [self.get_blind(key) for key in self._names_list] diff --git a/qubesadmin/tests/label.py b/qubesadmin/tests/label.py index 16815a5..c38841a 100644 --- a/qubesadmin/tests/label.py +++ b/qubesadmin/tests/label.py @@ -28,11 +28,42 @@ class TC_00_Label(qubesadmin.tests.QubesTestCase): ('dom0', 'admin.label.List', None, None)] = \ b'0\x00green\nred\nblack\n' seen = set() - for label in self.app.labels: + for label in self.app.labels.values(): self.assertNotIn(label.name, seen) seen.add(label.name) self.assertEqual(seen, set(['green', 'red', 'black'])) + def test_001_list_names(self): + self.app.expected_calls[ + ('dom0', 'admin.label.List', None, None)] = \ + b'0\x00green\nred\nblack\n' + seen = set() + for label in self.app.labels: + self.assertNotIn(label, seen) + seen.add(label) + self.assertEqual(seen, set(['green', 'red', 'black'])) + + def test_002_list_keys(self): + self.app.expected_calls[ + ('dom0', 'admin.label.List', None, None)] = \ + b'0\x00green\nred\nblack\n' + seen = set() + for label in self.app.labels.keys(): + self.assertNotIn(label, seen) + seen.add(label) + self.assertEqual(seen, set(['green', 'red', 'black'])) + + def test_003_list_items(self): + self.app.expected_calls[ + ('dom0', 'admin.label.List', None, None)] = \ + b'0\x00green\nred\nblack\n' + seen = set() + for name, label in self.app.labels.items(): + self.assertEqual(name, label.name) + self.assertNotIn(name, seen) + seen.add(name) + self.assertEqual(seen, set(['green', 'red', 'black'])) + def test_010_get(self): self.app.expected_calls[ ('dom0', 'admin.label.List', None, None)] = \ diff --git a/qubesadmin/tests/storage.py b/qubesadmin/tests/storage.py index aa1f7fb..7de7615 100644 --- a/qubesadmin/tests/storage.py +++ b/qubesadmin/tests/storage.py @@ -277,7 +277,7 @@ class TestPool(qubesadmin.tests.QubesTestCase): self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \ b'0\x00file\nlvm\n' seen = set() - for pool in self.app.pools: + for pool in self.app.pools.values(): self.assertIsInstance(pool, qubesadmin.storage.Pool) self.assertIn(pool.name, ('file', 'lvm')) self.assertNotIn(pool.name, seen) diff --git a/qubesadmin/tools/qvm_pool.py b/qubesadmin/tools/qvm_pool.py index 027c055..38137b8 100644 --- a/qubesadmin/tools/qvm_pool.py +++ b/qubesadmin/tools/qvm_pool.py @@ -54,7 +54,7 @@ def pool_info(pool): def list_pools(app): ''' Prints out all known pools and their drivers ''' result = [('NAME', 'DRIVER')] - for pool in app.pools: + for pool in app.pools.values(): result += [(pool.name, pool.driver)] qubesadmin.tools.print_table(result)