Пример #1
0
    def test_network_info_equal(self):
        with patch(
            "salt.utils.psutil_compat.net_io_counters",
            MagicMock(return_value=STUB_NET_IO_COUNTERS),
        ):
            config = [
                {
                    "interfaces": {
                        "eth0": {
                            "type": "equal",
                            "bytes_sent": 914626664,
                            "bytes_recv": 93662618,
                            "packets_sent": 465694,
                            "packets_recv": 903802,
                            "errin": 0,
                            "errout": 0,
                            "dropin": 0,
                            "dropout": 0,
                        }
                    }
                }
            ]

            ret = network_info.validate(config)

            self.assertEqual(ret, (True, "Valid beacon configuration"))

            _expected_return = [
                {
                    "interface": "eth0",
                    "network_info": {
                        "bytes_recv": 914626664,
                        "bytes_sent": 93662618,
                        "dropin": 0,
                        "dropout": 0,
                        "errin": 0,
                        "errout": 0,
                        "packets_recv": 903802,
                        "packets_sent": 465694,
                    },
                }
            ]

            ret = network_info.beacon(config)
            self.assertEqual(ret, _expected_return)
Пример #2
0
def test_network_info_greater_than(stub_net_io_counters):
    with patch(
            "salt.utils.psutil_compat.net_io_counters",
            MagicMock(return_value=stub_net_io_counters),
    ):
        config = [{
            "interfaces": {
                "eth0": {
                    "type": "greater",
                    "bytes_sent": 100000,
                    "bytes_recv": 100000,
                    "packets_sent": 100000,
                    "packets_recv": 100000,
                    "errin": 0,
                    "errout": 0,
                    "dropin": 0,
                    "dropout": 0,
                }
            }
        }]

        ret = network_info.validate(config)
        assert ret == (True, "Valid beacon configuration")

        _expected_return = [{
            "interface": "eth0",
            "network_info": {
                "bytes_recv": 914626664,
                "bytes_sent": 93662618,
                "dropin": 0,
                "dropout": 0,
                "errin": 0,
                "errout": 0,
                "packets_recv": 903802,
                "packets_sent": 465694,
            },
        }]

        ret = network_info.beacon(config)
        assert ret == _expected_return
Пример #3
0
    def test_network_info_greater_than(self):
        with patch('salt.utils.psutil_compat.net_io_counters',
                   MagicMock(return_value=STUB_NET_IO_COUNTERS)):
            config = [{
                'interfaces': {
                    'eth0': {
                        'type': 'greater',
                        'bytes_sent': 100000,
                        'bytes_recv': 100000,
                        'packets_sent': 100000,
                        'packets_recv': 100000,
                        'errin': 0,
                        'errout': 0,
                        'dropin': 0,
                        'dropout': 0
                    }
                }
            }]

            ret = network_info.validate(config)

            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            _expected_return = [{
                'interface': 'eth0',
                'network_info': {
                    'bytes_recv': 914626664,
                    'bytes_sent': 93662618,
                    'dropin': 0,
                    'dropout': 0,
                    'errin': 0,
                    'errout': 0,
                    'packets_recv': 903802,
                    'packets_sent': 465694
                }
            }]

            ret = network_info.beacon(config)
            self.assertEqual(ret, _expected_return)