2016-06-29 20:28:36 +00:00
# -*- encoding: utf-8 -*-
'''
: codeauthor : : email : ` Justin Anderson < janderson @saltstack.com > `
tests . integration . states . network
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
'''
# Python libs
from __future__ import absolute_import
# Salt libs
import integration
# Salttesting libs
from salttesting . helpers import destructiveTest , ensure_in_syspath
ensure_in_syspath ( ' ../../ ' )
@destructiveTest
class NetworkTest ( integration . ModuleCase , integration . SaltReturnAssertsMixIn ) :
'''
Validate network state module
'''
def setUp ( self ) :
2016-07-06 17:43:09 +00:00
os_family = self . run_function ( ' grains.get ' , [ ' os_family ' ] )
if os_family not in ( ' RedHat ' , ' Debian ' ) :
self . skipTest ( ' Network state only supported on RedHat and Debian based systems ' )
2016-06-29 20:28:36 +00:00
def test_managed ( self ) :
'''
network . managed
'''
2016-07-07 18:27:18 +00:00
state_key =
ret = self . run_function ( ' state.sls ' , mods = ' network.managed ' , test = True )
2016-07-11 20:35:25 +00:00
2016-07-07 18:27:18 +00:00
out = ret [ ' network_|-dummy0_|-dummy0_|-managed ' ] [ ' comment ' ] . split ( ' \n ' )
2016-07-11 20:35:25 +00:00
2016-07-07 18:27:18 +00:00
self . assertIn ( ' Interface dummy0 is set to be updated: ' , out )
self . assertIn ( ' DEVICE= " dummy0 " ' , out )
self . assertIn ( ' USERCTL= " no " ' , out )
self . assertIn ( ' ONBOOT= " yes " ' , out )
self . assertIn ( ' IPADDR= " 10.1.0.1 " ' , out )
2016-07-11 20:35:25 +00:00
2016-06-29 20:28:36 +00:00
def test_routes ( self ) :
2016-07-11 20:35:25 +00:00
'''
2016-06-29 20:28:36 +00:00
network . routes
2016-07-11 20:35:25 +00:00
'''
2016-06-29 20:28:36 +00:00
state_key = ' network_|-routes_|-dummy0_|-routes '
2016-07-07 18:27:18 +00:00
expected_changes = ' Interface dummy0 routes are set to be added. '
2016-07-11 20:35:25 +00:00
2016-07-07 18:27:18 +00:00
ret = self . run_function ( ' state.sls ' , mods = ' network.routes ' , test = True )
print ( ret )
2016-07-11 20:35:25 +00:00
2016-07-07 18:27:18 +00:00
self . assertEqual ( ret [ state_key ] [ ' comment ' ] , expected_changes )
2016-07-11 20:35:25 +00:00
2016-06-29 20:28:36 +00:00
def test_system ( self ) :
2016-07-11 20:35:25 +00:00
'''
2016-06-29 20:28:36 +00:00
network . system
2016-07-11 20:35:25 +00:00
'''
2016-06-29 20:28:36 +00:00
state_key = ' network_|-system_|-system_|-system '
2016-07-07 18:27:18 +00:00
comment_out = ' Global network settings are set to be updated: \n --- \n +++ \n @@ -1 +1,4 @@ \n -# Created by anaconda \n +NETWORKING=yes \n +HOSTNAME=server1.example.com \n +GATEWAY=10.1.0.1 \n +GATEWAYDEV=dummy0 '
2016-07-11 20:35:25 +00:00
2016-07-07 18:27:18 +00:00
ret = self . run_function ( ' state.sls ' , mods = ' network.system ' , test = True )
self . assertEqual ( ret [ state_key ] [ ' comment ' ] , comment_out )
2016-06-29 20:28:36 +00:00
if __name__ == ' __main__ ' :
from integration import run_tests
run_tests ( NetworkTest )