test_nilrt_ip.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. class Nilrt_ipModuleTest(ModuleCase):
  17. '''
  18. Validate the nilrt_ip module
  19. '''
  20. def __init__(self, arg):
  21. super(self.__class__, self).__init__(arg)
  22. self.initialState = {}
  23. def setUp(self):
  24. '''
  25. Get current settings
  26. '''
  27. # save files from var/lib/connman*
  28. os_grain = self.run_function('grains.item', ['os_family'])
  29. if os_grain['os_family'] != 'NILinuxRT':
  30. self.skipTest('Tests applicable only to NILinuxRT')
  31. super(Nilrt_ipModuleTest, self).setUp()
  32. self.run_function('file.copy', ['/var/lib/connman', '/tmp/connman', 'recurse=True', 'remove_existing=True'])
  33. def tearDown(self):
  34. '''
  35. Reset to original settings
  36. '''
  37. # restore files
  38. self.run_function('file.copy', ['/tmp/connman', '/var/lib/connman', 'recurse=True', 'remove_existing=True'])
  39. # restart connman
  40. self.run_function('service.restart', ['connman'])
  41. time.sleep(10) # wait 10 seconds for connman to be fully loaded
  42. interfaces = self.__interfaces()
  43. for interface in interfaces:
  44. self.run_function('ip.up', [interface])
  45. def __connected(self, interface):
  46. return interface['up']
  47. def __interfaces(self):
  48. interfaceList = []
  49. for iface in self.run_function('ip.get_interfaces_details')['interfaces']:
  50. interfaceList.append(iface['connectionid'])
  51. return interfaceList
  52. @pytest.mark.destructive_test
  53. def test_down(self):
  54. interfaces = self.__interfaces()
  55. for interface in interfaces:
  56. result = self.run_function('ip.down', [interface])
  57. self.assertTrue(result)
  58. info = self.run_function('ip.get_interfaces_details')
  59. for interface in info['interfaces']:
  60. self.assertFalse(self.__connected(interface))
  61. @pytest.mark.destructive_test
  62. def test_up(self):
  63. interfaces = self.__interfaces()
  64. #first down all interfaces
  65. for interface in interfaces:
  66. self.run_function('ip.down', [interface])
  67. # up interfaces
  68. for interface in interfaces:
  69. result = self.run_function('ip.up', [interface])
  70. self.assertTrue(result)
  71. info = self.run_function('ip.get_interfaces_details')
  72. for interface in info['interfaces']:
  73. self.assertTrue(self.__connected(interface))
  74. @pytest.mark.destructive_test
  75. def test_set_dhcp_linklocal_all(self):
  76. interfaces = self.__interfaces()
  77. for interface in interfaces:
  78. result = self.run_function('ip.set_dhcp_linklocal_all', [interface])
  79. self.assertTrue(result)
  80. info = self.run_function('ip.get_interfaces_details')
  81. for interface in info['interfaces']:
  82. self.assertEqual(interface['ipv4']['requestmode'], 'dhcp_linklocal')
  83. @pytest.mark.destructive_test
  84. def test_static_all(self):
  85. interfaces = self.__interfaces()
  86. for interface in interfaces:
  87. 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'])
  88. self.assertTrue(result)
  89. info = self.run_function('ip.get_interfaces_details')
  90. for interface in info['interfaces']:
  91. self.assertIn('8.8.4.4', interface['ipv4']['dns'])
  92. self.assertIn('8.8.8.8', interface['ipv4']['dns'])
  93. self.assertEqual(interface['ipv4']['requestmode'], 'static')
  94. self.assertEqual(interface['ipv4']['address'], '192.168.10.4')
  95. self.assertEqual(interface['ipv4']['netmask'], '255.255.255.0')
  96. self.assertEqual(interface['ipv4']['gateway'], '192.168.10.1')