Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix virt.get_hypervisor() #55351

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3309,7 +3309,7 @@ def get_hypervisor():
# To add a new 'foo' hypervisor, add the _is_foo_hyper function,
# add 'foo' to the list below and add it to the docstring with a .. versionadded::
hypervisors = ['kvm', 'xen']
result = [hyper for hyper in hypervisors if getattr(sys.modules[__name__], '_is_{}_hyper').format(hyper)()]
result = [hyper for hyper in hypervisors if getattr(sys.modules[__name__], '_is_{}_hyper'.format(hyper))()]
return result[0] if result else None


Expand Down
14 changes: 14 additions & 0 deletions tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2663,3 +2663,17 @@ def test_pool_list_volumes(self):
self.mock_conn.storagePoolLookupByName.return_value = mock_pool
# pylint: enable=no-member
self.assertEqual(names, virt.pool_list_volumes('default'))

@patch('salt.modules.virt._is_kvm_hyper', return_value=True)
@patch('salt.modules.virt._is_xen_hyper', return_value=False)
def test_get_hypervisor(self, isxen_mock, iskvm_mock):
'''
test the virt.get_hypervisor() function
'''
self.assertEqual('kvm', virt.get_hypervisor())

iskvm_mock.return_value = False
self.assertIsNone(virt.get_hypervisor())

isxen_mock.return_value = True
self.assertEqual('xen', virt.get_hypervisor())