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
|
2017-04-03 16:04:09 +00:00
|
|
|
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
|
2013-06-27 12:41:36 +00:00
|
|
|
|
2012-05-15 05:56:45 +00:00
|
|
|
# Import salt libs
|
2012-11-18 18:57:10 +00:00
|
|
|
import salt.utils
|
2012-05-15 05:56:45 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
HFILE = os.path.join(TMP, 'hosts')
|
2012-05-15 05:56:45 +00:00
|
|
|
|
2012-05-29 16:40:20 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class HostTest(ModuleCase, SaltReturnAssertsMixin):
|
2012-06-30 20:54:23 +00:00
|
|
|
'''
|
|
|
|
Validate the host state
|
|
|
|
'''
|
|
|
|
|
2012-06-30 19:20:53 +00:00
|
|
|
def setUp(self):
|
2017-04-03 16:04:09 +00:00
|
|
|
shutil.copyfile(os.path.join(FILES, 'hosts'), HFILE)
|
2012-06-30 20:54:23 +00:00
|
|
|
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)
|