1
0

test_fibre_channel.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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
  9. from tests.support.mock import (
  10. patch,
  11. mock_open,
  12. MagicMock,
  13. )
  14. # Import Salt Libs
  15. import salt.grains.fibre_channel as fibre_channel
  16. class FibreChannelGrainsTestCase(TestCase):
  17. '''
  18. Test cases for iscsi grains
  19. '''
  20. def test_windows_fibre_channel_wwns_grains(self):
  21. wwns = ['20:00:00:25:b5:11:11:4c',
  22. '20:00:00:25:b5:11:11:5c',
  23. '20:00:00:25:b5:44:44:4c',
  24. '20:00:00:25:b5:44:44:5c']
  25. cmd_run_mock = MagicMock(return_value=wwns)
  26. with patch('salt.modules.cmdmod.powershell', cmd_run_mock):
  27. ret = fibre_channel._windows_wwns()
  28. assert ret == wwns, ret
  29. def test_linux_fibre_channel_wwns_grains(self):
  30. contents = ['0x500143802426baf4', '0x500143802426baf5']
  31. files = ['file1', 'file2']
  32. with patch('glob.glob', MagicMock(return_value=files)), \
  33. patch('salt.utils.files.fopen', mock_open(read_data=contents)):
  34. ret = fibre_channel._linux_wwns()
  35. assert ret == ['500143802426baf4', '500143802426baf5'], ret