test_host.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. '''
  3. tests for host state
  4. '''
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. import shutil
  9. # Import Salt Testing libs
  10. from tests.support.case import ModuleCase
  11. from tests.support.paths import FILES, TMP
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. # Import salt libs
  14. import salt.utils.files
  15. import salt.utils.stringutils
  16. HFILE = os.path.join(TMP, 'hosts')
  17. class HostTest(ModuleCase, SaltReturnAssertsMixin):
  18. '''
  19. Validate the host state
  20. '''
  21. def setUp(self):
  22. shutil.copyfile(os.path.join(FILES, 'hosts'), HFILE)
  23. super(HostTest, self).setUp()
  24. def tearDown(self):
  25. if os.path.exists(HFILE):
  26. os.remove(HFILE)
  27. super(HostTest, self).tearDown()
  28. def test_present(self):
  29. '''
  30. host.present
  31. '''
  32. name = 'spam.bacon'
  33. ip = '10.10.10.10'
  34. ret = self.run_state('host.present', name=name, ip=ip)
  35. self.assertSaltTrueReturn(ret)
  36. with salt.utils.files.fopen(HFILE) as fp_:
  37. output = salt.utils.stringutils.to_unicode(fp_.read())
  38. self.assertIn('{0}\t\t{1}'.format(ip, name), output)