1
0

test_shell.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test salt-call --proxyid commands
  4. tests.integration.proxy.test_shell
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Import python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. import sys
  10. import json
  11. import logging
  12. # Import Salt Libs
  13. import salt.ext.six as six
  14. import salt.utils.json as json
  15. # Import salt tests libs
  16. from tests.support.case import ShellCase
  17. log = logging.getLogger(__name__)
  18. class ProxyCallerSimpleTestCase(ShellCase):
  19. '''
  20. Test salt-call --proxyid <proxyid> commands
  21. '''
  22. @staticmethod
  23. def _load_return(ret):
  24. try:
  25. return json.loads('\n'.join(ret))
  26. except ValueError:
  27. log.warning('Failed to JSON decode: \'%s\'', ret)
  28. six.reraise(*sys.exc_info())
  29. def test_can_it_ping(self):
  30. '''
  31. Ensure the proxy can ping
  32. '''
  33. ret = self._load_return(self.run_call('--proxyid proxytest --out=json test.ping'))
  34. self.assertEqual(ret['local'], True)
  35. def test_list_pkgs(self):
  36. '''
  37. Package test 1, really just tests that the virtual function capability
  38. is working OK.
  39. '''
  40. ret = self._load_return(self.run_call('--proxyid proxytest --out=json pkg.list_pkgs'))
  41. self.assertIn('coreutils', ret['local'])
  42. self.assertIn('apache', ret['local'])
  43. self.assertIn('redbull', ret['local'])
  44. def test_upgrade(self):
  45. ret = self._load_return(self.run_call('--proxyid proxytest --out=json pkg.upgrade'))
  46. self.assertEqual(ret['local']['coreutils']['new'], '2.0')
  47. self.assertEqual(ret['local']['redbull']['new'], '1000.99')
  48. def test_service_list(self):
  49. ret = self._load_return(self.run_call('--proxyid proxytest --out=json service.list'))
  50. self.assertIn('ntp', ret['local'])
  51. def test_service_start(self):
  52. ret = self._load_return(self.run_call('--proxyid proxytest --out=json service.start samba'))
  53. ret = self._load_return(self.run_call('--proxyid proxytest --out=json service.status samba'))
  54. self.assertTrue(ret)
  55. def test_service_get_all(self):
  56. ret = self._load_return(self.run_call('--proxyid proxytest --out=json service.get_all'))
  57. self.assertIn('samba', ret['local'])
  58. def test_grains_items(self):
  59. ret = self._load_return(self.run_call('--proxyid proxytest --out=json grains.items'))
  60. self.assertEqual(ret['local']['kernel'], 'proxy')
  61. self.assertEqual(ret['local']['kernelrelease'], 'proxy')