Skip to content

Commit

Permalink
Fix virt.get_hypervisor()
Browse files Browse the repository at this point in the history
virt.get_hypervisor resulted in:

  AttributeError: module 'salt.loader.dev-srv.tf.local.int.module.virt' has no attribute '_is_{}_hyper'

This was due to missplaced parenthese.
  • Loading branch information
cbosdo committed Nov 20, 2019
1 parent ae6ca7e commit 1d3f7d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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())

0 comments on commit 1d3f7d6

Please sign in to comment.