From 84a36369fa0821fcaee8f8b580329c0182d8736f Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Wed, 29 Jun 2016 14:28:36 -0600 Subject: [PATCH 1/4] Added network state integration test --- tests/integration/states/network.py | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/integration/states/network.py diff --git a/tests/integration/states/network.py b/tests/integration/states/network.py new file mode 100644 index 000000000000..9925b36861f0 --- /dev/null +++ b/tests/integration/states/network.py @@ -0,0 +1,89 @@ +# -*- encoding: utf-8 -*- +''' + :codeauthor: :email: `Justin Anderson ` + + 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) From 76c90b2ef64d7fe11526b2496d4144796c1b6a3e Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Wed, 29 Jun 2016 14:30:23 -0600 Subject: [PATCH 2/4] network.managed sls file --- tests/integration/files/file/base/network/managed.sls | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/integration/files/file/base/network/managed.sls diff --git a/tests/integration/files/file/base/network/managed.sls b/tests/integration/files/file/base/network/managed.sls new file mode 100644 index 000000000000..0cfb45103661 --- /dev/null +++ b/tests/integration/files/file/base/network/managed.sls @@ -0,0 +1,6 @@ +dummy0: + network.managed: + - enabled: True + - type: eth + - ipaddr: 10.1.0.1 + - netmask: 255.255.255.0 From 4a9e6af542f3a8f0aa9f95464d7504b1b8ae164f Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Wed, 29 Jun 2016 14:31:07 -0600 Subject: [PATCH 3/4] network.routes sls file --- tests/integration/files/file/base/network/routes.sls | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/integration/files/file/base/network/routes.sls diff --git a/tests/integration/files/file/base/network/routes.sls b/tests/integration/files/file/base/network/routes.sls new file mode 100644 index 000000000000..a6310eaedfec --- /dev/null +++ b/tests/integration/files/file/base/network/routes.sls @@ -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 From 1d24053e364a34bdc88726673b322c3e3a514be9 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Wed, 29 Jun 2016 14:31:46 -0600 Subject: [PATCH 4/4] network.system sls file --- tests/integration/files/file/base/network/system.sls | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/integration/files/file/base/network/system.sls diff --git a/tests/integration/files/file/base/network/system.sls b/tests/integration/files/file/base/network/system.sls new file mode 100644 index 000000000000..8e478ec4b2e5 --- /dev/null +++ b/tests/integration/files/file/base/network/system.sls @@ -0,0 +1,6 @@ +system: + network.system: + - enabled: True + - hostname: server1.example.com + - gateway: 10.1.0.1 + - gatewaydev: dummy0