2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-05-15 05:56:45 +00:00
|
|
|
'''
|
|
|
|
tests for host state
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2012-05-15 05:56:45 +00:00
|
|
|
import os
|
2012-06-30 19:20:53 +00:00
|
|
|
import shutil
|
2012-11-18 18:57:10 +00:00
|
|
|
|
2013-06-27 12:41:36 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
2012-05-15 05:56:45 +00:00
|
|
|
# Import salt libs
|
2013-06-27 12:41:36 +00:00
|
|
|
import integration
|
2012-11-18 18:57:10 +00:00
|
|
|
import salt.utils
|
2012-05-15 05:56:45 +00:00
|
|
|
|
|
|
|
HFILE = os.path.join(integration.TMP, 'hosts')
|
|
|
|
|
2012-05-29 16:40:20 +00:00
|
|
|
|
2012-12-07 16:35:20 +00:00
|
|
|
class HostTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
2012-06-30 20:54:23 +00:00
|
|
|
'''
|
|
|
|
Validate the host state
|
|
|
|
'''
|
|
|
|
|
2012-06-30 19:20:53 +00:00
|
|
|
def setUp(self):
|
2012-06-30 20:54:23 +00:00
|
|
|
shutil.copyfile(os.path.join(integration.FILES, 'hosts'), HFILE)
|
|
|
|
super(HostTest, self).setUp()
|
2012-06-30 19:20:53 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2012-06-30 20:54:23 +00:00
|
|
|
if os.path.exists(HFILE):
|
|
|
|
os.remove(HFILE)
|
|
|
|
super(HostTest, self).tearDown()
|
2012-06-30 19:20:53 +00:00
|
|
|
|
2012-05-15 05:56:45 +00:00
|
|
|
def test_present(self):
|
|
|
|
'''
|
|
|
|
host.present
|
|
|
|
'''
|
2012-06-30 18:47:48 +00:00
|
|
|
name = 'spam.bacon'
|
|
|
|
ip = '10.10.10.10'
|
|
|
|
ret = self.run_state('host.present', name=name, ip=ip)
|
2012-12-07 16:35:20 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-11-18 18:57:10 +00:00
|
|
|
with salt.utils.fopen(HFILE) as fp_:
|
2012-06-30 18:47:48 +00:00
|
|
|
output = fp_.read()
|
|
|
|
self.assertIn('{0}\t\t{1}'.format(ip, name), output)
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(HostTest)
|