-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34373 from jtand/network_state_integration_test
Network state integration test
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dummy0: | ||
network.managed: | ||
- enabled: True | ||
- type: eth | ||
- ipaddr: 10.1.0.1 | ||
- netmask: 255.255.255.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
routes: | ||
network.routes: | ||
- name: dummy0 | ||
- routes: | ||
- name: secure_network | ||
ipaddr: 10.2.0.0 | ||
netmask: 255.255.255.0 | ||
gateway: 10.1.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
system: | ||
network.system: | ||
- enabled: True | ||
- hostname: server1.example.com | ||
- gateway: 10.1.0.1 | ||
- gatewaydev: dummy0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- 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 | ||
import salt.utils | ||
|
||
# Salttesting libs | ||
from salttesting import skipIf | ||
from salttesting.helpers import destructiveTest, ensure_in_syspath | ||
|
||
ensure_in_syspath('../../') | ||
|
||
|
||
def _check_arch_linux(): | ||
with salt.utils.fopen('/etc/os-release', 'r') as f: | ||
release = f.readline() | ||
r = release.split('=')[1].strip().strip('"') | ||
return r | ||
|
||
|
||
@destructiveTest | ||
@skipIf(_check_arch_linux() == 'Arch Linux', 'Network state not supported on Arch') | ||
class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn): | ||
''' | ||
Validate network state module | ||
''' | ||
def setUp(self): | ||
self.run_function('cmd.run', ['ip link add name dummy0 type dummy']) | ||
|
||
def tearDown(self): | ||
self.run_function('cmd.run', ['ip link delete dev dummy0']) | ||
|
||
def test_managed(self): | ||
''' | ||
network.managed | ||
''' | ||
if_name = 'dummy0' | ||
ipaddr = '10.1.0.1' | ||
netmask = '255.255.255.0' | ||
broadcast = '10.1.0.255' | ||
|
||
expected_if_ret = [{ | ||
"broadcast": broadcast, | ||
"netmask": netmask, | ||
"label": if_name, | ||
"address": ipaddr | ||
}] | ||
|
||
ret = self.run_function('state.sls', mods='network.managed') | ||
self.assertSaltTrueReturn(ret) | ||
|
||
interface = self.run_function('network.interface', [if_name]) | ||
self.assertEqual(interface, expected_if_ret) | ||
|
||
def test_routes(self): | ||
''' | ||
network.routes | ||
''' | ||
state_key = 'network_|-routes_|-dummy0_|-routes' | ||
expected_changes = {'network_routes': 'Added interface dummy0 routes.'} | ||
|
||
ret = self.run_function('state.sls', mods='network.routes') | ||
|
||
self.assertSaltTrueReturn(ret) | ||
self.assertEqual(ret[state_key]['changes'], expected_changes) | ||
|
||
def test_system(self): | ||
''' | ||
network.system | ||
''' | ||
state_key = 'network_|-system_|-system_|-system' | ||
|
||
ret = self.run_function('state.sls', mods='network.system') | ||
|
||
self.assertSaltTrueReturn(ret) | ||
self.assertIn('network_settings', ret[state_key]['changes']) | ||
|
||
|
||
if __name__ == '__main__': | ||
from integration import run_tests | ||
run_tests(NetworkTest) |