1
0

test_fibre_channel.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: :email:`Shane Lee <slee@saltstack.com>`
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase, skipIf
  9. from tests.support.mock import (
  10. patch,
  11. mock_open,
  12. MagicMock,
  13. NO_MOCK,
  14. NO_MOCK_REASON
  15. )
  16. # Import Salt Libs
  17. import salt.grains.fibre_channel as fibre_channel
  18. @skipIf(NO_MOCK, NO_MOCK_REASON)
  19. class FibreChannelGrainsTestCase(TestCase):
  20. '''
  21. Test cases for iscsi grains
  22. '''
  23. def test_windows_fibre_channel_wwns_grains(self):
  24. wwns = ['20:00:00:25:b5:11:11:4c',
  25. '20:00:00:25:b5:11:11:5c',
  26. '20:00:00:25:b5:44:44:4c',
  27. '20:00:00:25:b5:44:44:5c']
  28. cmd_run_mock = MagicMock(return_value=wwns)
  29. with patch('salt.modules.cmdmod.powershell', cmd_run_mock):
  30. ret = fibre_channel._windows_wwns()
  31. assert ret == wwns, ret
  32. def test_linux_fibre_channel_wwns_grains(self):
  33. contents = ['0x500143802426baf4', '0x500143802426baf5']
  34. files = ['file1', 'file2']
  35. with patch('glob.glob', MagicMock(return_value=files)), \
  36. patch('salt.utils.files.fopen', mock_open(read_data=contents)):
  37. ret = fibre_channel._linux_wwns()
  38. assert ret == ['500143802426baf4', '500143802426baf5'], ret