test_shell.py 2.4 KB

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