diff --git a/qubesadmin/tests/tools/qvm_template.py b/qubesadmin/tests/tools/qvm_template.py index 348b39c..6a5d6e1 100644 --- a/qubesadmin/tests/tools/qvm_template.py +++ b/qubesadmin/tests/tools/qvm_template.py @@ -2088,6 +2088,7 @@ qubes-template-fedora-32|0|4.1|20200101|qubes-templates-itl|1048576|2020-01-23 0 available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2150,6 +2151,7 @@ qubes-template-fedora-32|0|4.1|20200101|qubes-templates-itl|1048576|2020-01-23 0 available=True, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['fedora-32', 'fedora-31'] @@ -2179,6 +2181,19 @@ f'''Available Templates @mock.patch('qubesadmin.tools.qvm_template.qrexec_repoquery') def test_151_list_templates_available_all_success(self, mock_query): mock_query.return_value = [ + qubesadmin.tools.qvm_template.Template( + 'fedora-31', + '1', + '4.1', + '20190101', + 'qubes-templates-itl', + 1048576, + datetime.datetime(2019, 1, 23, 4, 56), + 'GPL', + 'https://qubes-os.org', + 'Qubes template for fedora-31', + 'Qubes template\n for fedora-31\n' + ), qubesadmin.tools.qvm_template.Template( 'fedora-31', '1', @@ -2191,7 +2206,7 @@ f'''Available Templates 'https://qubes-os.org', 'Qubes template for fedora-31', 'Qubes template\n for fedora-31\n' - ) + ), ] args = argparse.Namespace( all=False, @@ -2199,6 +2214,60 @@ f'''Available Templates available=True, extras=False, upgrades=False, + all_versions=True, + machine_readable=False, + machine_readable_json=False, + templates=[] + ) + with mock.patch('sys.stdout', new=io.StringIO()) as mock_out: + qubesadmin.tools.qvm_template.list_templates( + args, self.app, 'list') + self.assertEqual(mock_out.getvalue(), +'''Available Templates +[('fedora-31', '1:4.1-20190101', 'qubes-templates-itl'), ('fedora-31', '1:4.1-20200101', 'qubes-templates-itl')] +''') + self.assertEqual(mock_query.mock_calls, [ + mock.call(args, self.app) + ]) + self.assertAllCalled() + + @mock.patch('qubesadmin.tools.qvm_template.qrexec_repoquery') + def test_151_list_templates_available_only_latest_success(self, mock_query): + mock_query.return_value = [ + qubesadmin.tools.qvm_template.Template( + 'fedora-31', + '1', + '4.1', + '20190101', + 'qubes-templates-itl', + 1048576, + datetime.datetime(2019, 1, 23, 4, 56), + 'GPL', + 'https://qubes-os.org', + 'Qubes template for fedora-31', + 'Qubes template\n for fedora-31\n' + ), + qubesadmin.tools.qvm_template.Template( + 'fedora-31', + '1', + '4.1', + '20200101', + 'qubes-templates-itl', + 1048576, + datetime.datetime(2020, 1, 23, 4, 56), + 'GPL', + 'https://qubes-os.org', + 'Qubes template for fedora-31', + 'Qubes template\n for fedora-31\n' + ), + ] + args = argparse.Namespace( + all=False, + installed=False, + available=True, + extras=False, + upgrades=False, + all_versions=False, machine_readable=False, machine_readable_json=False, templates=[] @@ -2283,6 +2352,7 @@ f'''Available Templates available=False, extras=True, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2385,6 +2455,7 @@ f'''Available Templates available=False, extras=False, upgrades=True, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2463,6 +2534,7 @@ f'''Available Templates available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2482,6 +2554,7 @@ Available Templates available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2501,6 +2574,7 @@ Available Templates available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=['test-vm*'] @@ -2520,6 +2594,7 @@ Available Templates available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=True, machine_readable_json=False, templates=['test-vm*'] @@ -2537,6 +2612,7 @@ available|test-vm|2:4.1-2020|qubes-templates-itl available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=True, machine_readable_json=False, templates=['test-vm*'] @@ -2554,6 +2630,7 @@ available|test-vm|2|4.1|2020|qubes-templates-itl|1048576|2020-09-01 14:30:00||GP available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=True, templates=['test-vm*'] @@ -2570,6 +2647,7 @@ available|test-vm|2|4.1|2020|qubes-templates-itl|1048576|2020-09-01 14:30:00||GP available=False, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=True, templates=['test-vm*'] @@ -2588,6 +2666,7 @@ r'''{"installed": [{"name": "test-vm-2", "epoch": "1", "version": "4.0", "releas available=True, extras=False, upgrades=False, + all_versions=True, machine_readable=False, machine_readable_json=False, templates=[] diff --git a/qubesadmin/tools/qvm_template.py b/qubesadmin/tools/qvm_template.py index 0daeab9..b15292e 100644 --- a/qubesadmin/tools/qvm_template.py +++ b/qubesadmin/tools/qvm_template.py @@ -176,6 +176,8 @@ def get_parser() -> argparse.ArgumentParser: ' locally but not in repos) templates.')) parser_x.add_argument('--upgrades', action='store_true', help='Show available upgrades.') + parser_x.add_argument('--all-versions', action='store_true', + help='Show all available versions, not only the latest.') readable = parser_x.add_mutually_exclusive_group() readable.add_argument('--machine-readable', action='store_true', help='Enable machine-readable output.') @@ -1128,6 +1130,8 @@ def list_templates(args: argparse.Namespace, query_res = list(query_res_set) else: query_res = qrexec_repoquery(args, app) + if not args.all_versions: + query_res = filter_version(query_res, app) if args.installed or args.all: for vm in app.domains: