1
0

test_network_settings.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # coding: utf-8
  2. # Python libs
  3. from __future__ import absolute_import
  4. # Salt testing libs
  5. from tests.support.unit import skipIf, TestCase
  6. from tests.support.mixins import LoaderModuleMockMixin
  7. try:
  8. from pyroute2 import IPDB
  9. HAS_PYROUTE2 = True
  10. except ImportError:
  11. HAS_PYROUTE2 = False
  12. # Salt libs
  13. import salt.beacons.network_settings as network_settings
  14. import logging
  15. log = logging.getLogger(__name__)
  16. class NetworkSettingsBeaconTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test case for salt.beacons.network_settings
  19. '''
  20. def setup_loader_modules(self):
  21. return {
  22. network_settings: {
  23. '__context__': {},
  24. '__salt__': {},
  25. }
  26. }
  27. def test_non_list_config(self):
  28. config = {}
  29. ret = network_settings.validate(config)
  30. self.assertEqual(ret, (False, 'Configuration for network_settings'
  31. ' beacon must be a list.'))
  32. def test_empty_config(self):
  33. config = [{}]
  34. ret = network_settings.validate(config)
  35. self.assertEqual(ret, (True, 'Valid beacon configuration'))
  36. @skipIf(not HAS_PYROUTE2, 'no pyroute2 installed, skipping')
  37. class Pyroute2TestCase(TestCase):
  38. def test_interface_dict_fields(self):
  39. with IPDB() as ipdb:
  40. for attr in network_settings.ATTRS:
  41. # ipdb.interfaces is a dict-like object, that
  42. # contains interface definitions. Interfaces can
  43. # be referenced both with indices and names.
  44. #
  45. # ipdb.interfaces[1] is an interface with index 1,
  46. # that is the loopback interface.
  47. self.assertIn(attr, ipdb.interfaces[1])