test_nilrt_ip.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- coding: utf-8 -*-
  2. '''
  3. integration tests for nilirt_ip
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import time
  8. import pytest
  9. # Import Salt Testing libs
  10. from tests.support.case import ModuleCase
  11. from tests.support.unit import skipIf
  12. # Import Salt libs
  13. import salt.utils.platform
  14. @pytest.mark.skip_if_not_root
  15. @skipIf(not salt.utils.platform.is_linux(), 'These tests can only be run on linux')
  16. @pytest.mark.windows_whitelisted
  17. class Nilrt_ipModuleTest(ModuleCase):
  18. '''
  19. Validate the nilrt_ip module
  20. '''
  21. def __init__(self, arg):
  22. super(self.__class__, self).__init__(arg)
  23. self.initialState = {}
  24. def setUp(self):
  25. '''
  26. Get current settings
  27. '''
  28. # save files from var/lib/connman*
  29. os_grain = self.run_function('grains.item', ['os_family'])
  30. if os_grain['os_family'] != 'NILinuxRT':
  31. self.skipTest('Tests applicable only to NILinuxRT')
  32. super(Nilrt_ipModuleTest, self).setUp()
  33. self.run_function('file.copy', ['/var/lib/connman', '/tmp/connman', 'recurse=True', 'remove_existing=True'])
  34. def tearDown(self):
  35. '''
  36. Reset to original settings
  37. '''
  38. # restore files
  39. self.run_function('file.copy', ['/tmp/connman', '/var/lib/connman', 'recurse=True', 'remove_existing=True'])
  40. # restart connman
  41. self.run_function('service.restart', ['connman'])
  42. time.sleep(10) # wait 10 seconds for connman to be fully loaded
  43. interfaces = self.__interfaces()
  44. for interface in interfaces:
  45. self.run_function('ip.up', [interface])
  46. def __connected(self, interface):
  47. return interface['up']
  48. def __interfaces(self):
  49. interfaceList = []
  50. for iface in self.run_function('ip.get_interfaces_details')['interfaces']:
  51. interfaceList.append(iface['connectionid'])
  52. return interfaceList
  53. @pytest.mark.destructive_test
  54. def test_down(self):
  55. interfaces = self.__interfaces()
  56. for interface in interfaces:
  57. result = self.run_function('ip.down', [interface])
  58. self.assertTrue(result)
  59. info = self.run_function('ip.get_interfaces_details')
  60. for interface in info['interfaces']:
  61. self.assertFalse(self.__connected(interface))
  62. @pytest.mark.destructive_test
  63. def test_up(self):
  64. interfaces = self.__interfaces()
  65. #first down all interfaces
  66. for interface in interfaces:
  67. self.run_function('ip.down', [interface])
  68. # up interfaces
  69. for interface in interfaces:
  70. result = self.run_function('ip.up', [interface])
  71. self.assertTrue(result)
  72. info = self.run_function('ip.get_interfaces_details')
  73. for interface in info['interfaces']:
  74. self.assertTrue(self.__connected(interface))
  75. @pytest.mark.destructive_test
  76. def test_set_dhcp_linklocal_all(self):
  77. interfaces = self.__interfaces()
  78. for interface in interfaces:
  79. result = self.run_function('ip.set_dhcp_linklocal_all', [interface])
  80. self.assertTrue(result)
  81. info = self.run_function('ip.get_interfaces_details')
  82. for interface in info['interfaces']:
  83. self.assertEqual(interface['ipv4']['requestmode'], 'dhcp_linklocal')
  84. @pytest.mark.destructive_test
  85. def test_static_all(self):
  86. interfaces = self.__interfaces()
  87. for interface in interfaces:
  88. result = self.run_function('ip.set_static_all', [interface, '192.168.10.4', '255.255.255.0', '192.168.10.1', '8.8.4.4 8.8.8.8'])
  89. self.assertTrue(result)
  90. info = self.run_function('ip.get_interfaces_details')
  91. for interface in info['interfaces']:
  92. self.assertIn('8.8.4.4', interface['ipv4']['dns'])
  93. self.assertIn('8.8.8.8', interface['ipv4']['dns'])
  94. self.assertEqual(interface['ipv4']['requestmode'], 'static')
  95. self.assertEqual(interface['ipv4']['address'], '192.168.10.4')
  96. self.assertEqual(interface['ipv4']['netmask'], '255.255.255.0')
  97. self.assertEqual(interface['ipv4']['gateway'], '192.168.10.1')