Skip to content

Commit

Permalink
qvm-template: by default list only latest available template
Browse files Browse the repository at this point in the history
But add --all-versions option to get all the available versions.
  • Loading branch information
marmarek committed Feb 7, 2021
1 parent 86326b5 commit 4f9757c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
81 changes: 80 additions & 1 deletion qubesadmin/tests/tools/qvm_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,7 @@ def test_150_list_templates_installed_success(self, mock_query):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand Down Expand Up @@ -2150,6 +2151,7 @@ def f(*args):
available=True,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['fedora-32', 'fedora-31']
Expand Down Expand Up @@ -2179,6 +2181,19 @@ def f(*args):
@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',
Expand All @@ -2191,14 +2206,68 @@ def test_151_list_templates_available_all_success(self, mock_query):
'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=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=[]
Expand Down Expand Up @@ -2283,6 +2352,7 @@ def test_152_list_templates_extras_success(self, mock_query):
available=False,
extras=True,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand Down Expand Up @@ -2385,6 +2455,7 @@ def test_153_list_templates_upgrades_success(self, mock_query):
available=False,
extras=False,
upgrades=True,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand Down Expand Up @@ -2463,6 +2534,7 @@ def test_154_list_templates_all_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand All @@ -2482,6 +2554,7 @@ def test_155_list_templates_all_implicit_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand All @@ -2501,6 +2574,7 @@ def test_156_list_templates_info_all_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=['test-vm*']
Expand All @@ -2520,6 +2594,7 @@ def test_157_list_templates_list_all_machinereadable_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=True,
machine_readable_json=False,
templates=['test-vm*']
Expand All @@ -2537,6 +2612,7 @@ def test_158_list_templates_info_all_machinereadable_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=True,
machine_readable_json=False,
templates=['test-vm*']
Expand All @@ -2554,6 +2630,7 @@ def test_159_list_templates_list_all_machinereadablejson_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=True,
templates=['test-vm*']
Expand All @@ -2570,6 +2647,7 @@ def test_160_list_templates_info_all_machinereadablejson_success(self):
available=False,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=True,
templates=['test-vm*']
Expand All @@ -2588,6 +2666,7 @@ def test_161_list_templates_noresults_fail(self, mock_query):
available=True,
extras=False,
upgrades=False,
all_versions=True,
machine_readable=False,
machine_readable_json=False,
templates=[]
Expand Down
4 changes: 4 additions & 0 deletions qubesadmin/tools/qvm_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def parser_add_command(cmd, help_str):
' 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.')
Expand Down Expand Up @@ -1128,6 +1130,8 @@ def check_append(name, evr):
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:
Expand Down

0 comments on commit 4f9757c

Please sign in to comment.