salt/tests/integration/states/test_host.py

47 lines
1.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-05-15 05:56:45 +00:00
'''
tests for host state
'''
# Import python libs
from __future__ import absolute_import
2012-05-15 05:56:45 +00:00
import os
import shutil
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.paths import FILES, TMP
2017-04-02 16:09:47 +00:00
from tests.support.mixins import SaltReturnAssertsMixin
2012-05-15 05:56:45 +00:00
# Import salt libs
import salt.utils
2012-05-15 05:56:45 +00:00
HFILE = os.path.join(TMP, 'hosts')
2012-05-15 05:56:45 +00:00
2012-05-29 16:40:20 +00:00
class HostTest(ModuleCase, SaltReturnAssertsMixin):
'''
Validate the host state
'''
def setUp(self):
shutil.copyfile(os.path.join(FILES, 'hosts'), HFILE)
super(HostTest, self).setUp()
def tearDown(self):
if os.path.exists(HFILE):
os.remove(HFILE)
super(HostTest, self).tearDown()
2012-05-15 05:56:45 +00:00
def test_present(self):
'''
host.present
'''
name = 'spam.bacon'
ip = '10.10.10.10'
ret = self.run_state('host.present', name=name, ip=ip)
self.assertSaltTrueReturn(ret)
with salt.utils.fopen(HFILE) as fp_:
output = fp_.read()
self.assertIn('{0}\t\t{1}'.format(ip, name), output)