Beispiel #1
0
    def test_non_list_config(self):
        config = {}

        ret = network_settings.validate(config)

        self.assertEqual(ret, (False, 'Configuration for network_settings'
                                      ' beacon must be a list.'))
Beispiel #2
0
    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, [])
Beispiel #3
0
def test_non_list_config():
    config = {}

    ret = network_settings.validate(config)

    assert ret == (False,
                   "Configuration for network_settings beacon must be a list.")
Beispiel #4
0
    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)
Beispiel #5
0
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
Beispiel #6
0
    def test_empty_config(self):
        config = [{}]

        ret = network_settings.validate(config)

        self.assertEqual(ret, (True, 'Valid beacon configuration'))
Beispiel #7
0
def test_empty_config():
    config = [{}]

    ret = network_settings.validate(config)

    assert ret == (True, "Valid beacon configuration")