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