def test_interface_no_change(self): config = [{"interfaces": {"enp14s0u1u2": {"promiscuity": None}}}] LAST_STATS = network_settings._copy_interfaces_info( {"enp14s0u1u2": { "family": "0", "promiscuity": "0", "group": "0" }}) NEW_STATS = network_settings._copy_interfaces_info( {"enp14s0u1u2": { "family": "0", "promiscuity": "0", "group": "0" }}) ret = network_settings.validate(config) self.assertEqual(ret, (True, "Valid beacon configuration")) with patch.object(network_settings, "LAST_STATS", {}), patch.object( network_settings, "IP", MockIPClass), patch( "salt.beacons.network_settings._copy_interfaces_info", MagicMock(side_effect=[LAST_STATS, NEW_STATS]), ): ret = network_settings.beacon(config) self.assertEqual(ret, []) ret = network_settings.beacon(config) self.assertEqual(ret, [])
def test_interface(self): config = [{'interfaces': {'enp14s0u1u2': {'promiscuity': None}}}] LAST_STATS = network_settings._copy_interfaces_info({'enp14s0u1u2': {'family': '0', 'promiscuity': '0', 'group': '0'}}) NEW_STATS = network_settings._copy_interfaces_info({'enp14s0u1u2': {'family': '0', 'promiscuity': '1', 'group': '0'}}) ret = network_settings.validate(config) self.assertEqual(ret, (True, 'Valid beacon configuration')) with patch.object(network_settings, 'LAST_STATS', {}), \ patch.object(network_settings, 'IP', MockIPClass), \ patch('salt.beacons.network_settings._copy_interfaces_info', MagicMock(side_effect=[LAST_STATS, NEW_STATS])): ret = network_settings.beacon(config) self.assertEqual(ret, []) ret = network_settings.beacon(config) _expected = [{'interface': 'enp14s0u1u2', 'tag': 'enp14s0u1u2', 'change': {'promiscuity': '1'} }] self.assertEqual(ret, _expected)
def beacon(config): ''' Watch for changes on network settings on the gateway interface. By default, the beacon will emit when there is a value change on one of the settings on watch. The config also support the onvalue parameter for each setting, which instruct the beacon to only emit if the setting changed to the value defined. Example Config .. code-block:: yaml beacons: default_network_interface_settings: interval: 5 watch: ipaddr: promiscuity: onvalue: 1 ''' default_interface = __salt__['network.default_route']()[0]['interface'] config = {default_interface: config['watch']} if __salt__['test.version']() >= '2018.3.0': config = [{'interfaces': config}] log.debug( "Newer salt version - adjusted config format: {0}".format(config)) return network_settings.beacon(config)
def beacon(config): ''' Watch for changes on network settings on the gateway interface. By default, the beacon will emit when there is a value change on one of the settings on watch. The config also support the onvalue parameter for each setting, which instruct the beacon to only emit if the setting changed to the value defined. Example Config .. code-block:: yaml beacons: default_network_interface_settings: interval: 5 watch: ipaddr: promiscuity: onvalue: 1 ''' default_interface = __salt__['network.default_route']()[0]['interface'] return network_settings.beacon({default_interface: config['watch']})
def test_interface(): config = [{"interfaces": {"enp14s0u1u2": {"promiscuity": None}}}] LAST_STATS = network_settings._copy_interfaces_info( {"enp14s0u1u2": { "family": "0", "promiscuity": "0", "group": "0" }}) NEW_STATS = network_settings._copy_interfaces_info( {"enp14s0u1u2": { "family": "0", "promiscuity": "1", "group": "0" }}) ret = network_settings.validate(config) assert ret == (True, "Valid beacon configuration") with patch.object(network_settings, "LAST_STATS", {}), patch.object( network_settings, "IP", MockIPClass), patch( "salt.beacons.network_settings._copy_interfaces_info", MagicMock(side_effect=[LAST_STATS, NEW_STATS]), ): ret = network_settings.beacon(config) assert ret == [] ret = network_settings.beacon(config) _expected = [{ "interface": "enp14s0u1u2", "tag": "enp14s0u1u2", "change": { "promiscuity": "1" }, }] assert ret == _expected