| 1 |
# Copyright (c) Ansible Project |
| 2 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
# Make coding more python3-ish |
| 6 |
from __future__ import (absolute_import, division, print_function) |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import patch, MagicMock |
| 10 |
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase |
| 11 |
|
| 12 |
from ansible_collections.community.routeros.tests.unit.plugins.modules.fake_api import FakeLibRouterosError, Key, fake_ros_api |
| 13 |
from ansible_collections.community.routeros.plugins.modules import api_facts |
| 14 |
|
| 15 |
|
| 16 |
API_RESPONSES = { |
| 17 |
('interface', ): [ |
| 18 |
{ |
| 19 |
'.id': '*1', |
| 20 |
'name': 'first-ether', |
| 21 |
'default-name': 'ether1', |
| 22 |
'type': 'ether', |
| 23 |
'mtu': 1500, |
| 24 |
'actual-mtu': 1500, |
| 25 |
'l2mtu': 1598, |
| 26 |
'max-l2mtu': 4074, |
| 27 |
'mac-address': '00:11:22:33:44:55', |
| 28 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 29 |
'link-downs': 0, |
| 30 |
'rx-byte': 1234, |
| 31 |
'tx-byte': 1234, |
| 32 |
'rx-packet': 1234, |
| 33 |
'tx-packet': 1234, |
| 34 |
'rx-drop': 1234, |
| 35 |
'tx-drop': 1234, |
| 36 |
'tx-queue-drop': 1234, |
| 37 |
'rx-error': 1234, |
| 38 |
'tx-error': 1234, |
| 39 |
'fp-rx-byte': 1234, |
| 40 |
'fp-tx-byte': 1234, |
| 41 |
'fp-rx-packet': 1234, |
| 42 |
'fp-tx-packet': 1234, |
| 43 |
'running': True, |
| 44 |
'disabled': False, |
| 45 |
}, |
| 46 |
{ |
| 47 |
'.id': '*2', |
| 48 |
'name': 'second-ether', |
| 49 |
'default-name': 'ether2', |
| 50 |
'type': 'ether', |
| 51 |
'mtu': 1500, |
| 52 |
'actual-mtu': 1500, |
| 53 |
'l2mtu': 1598, |
| 54 |
'max-l2mtu': 4074, |
| 55 |
'mac-address': '00:11:22:33:44:66', |
| 56 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 57 |
'link-downs': 0, |
| 58 |
'rx-byte': 1234, |
| 59 |
'tx-byte': 1234, |
| 60 |
'rx-packet': 1234, |
| 61 |
'tx-packet': 1234, |
| 62 |
'rx-drop': 1234, |
| 63 |
'tx-drop': 1234, |
| 64 |
'tx-queue-drop': 1234, |
| 65 |
'rx-error': 1234, |
| 66 |
'tx-error': 1234, |
| 67 |
'fp-rx-byte': 1234, |
| 68 |
'fp-tx-byte': 1234, |
| 69 |
'fp-rx-packet': 1234, |
| 70 |
'fp-tx-packet': 1234, |
| 71 |
'running': True, |
| 72 |
'slave': True, |
| 73 |
'disabled': False, |
| 74 |
}, |
| 75 |
{ |
| 76 |
'.id': '*3', |
| 77 |
'name': 'third-ether', |
| 78 |
'default-name': 'ether3', |
| 79 |
'type': 'ether', |
| 80 |
'mtu': 1500, |
| 81 |
'actual-mtu': 1500, |
| 82 |
'l2mtu': 1598, |
| 83 |
'max-l2mtu': 4074, |
| 84 |
'mac-address': '00:11:22:33:44:77', |
| 85 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 86 |
'link-downs': 0, |
| 87 |
'rx-byte': 1234, |
| 88 |
'tx-byte': 1234, |
| 89 |
'rx-packet': 1234, |
| 90 |
'tx-packet': 1234, |
| 91 |
'rx-drop': 1234, |
| 92 |
'tx-drop': 1234, |
| 93 |
'tx-queue-drop': 1234, |
| 94 |
'rx-error': 1234, |
| 95 |
'tx-error': 1234, |
| 96 |
'fp-rx-byte': 1234, |
| 97 |
'fp-tx-byte': 1234, |
| 98 |
'fp-rx-packet': 1234, |
| 99 |
'fp-tx-packet': 1234, |
| 100 |
'running': True, |
| 101 |
'slave': True, |
| 102 |
'disabled': False, |
| 103 |
}, |
| 104 |
{ |
| 105 |
'.id': '*4', |
| 106 |
'name': 'fourth-ether', |
| 107 |
'default-name': 'ether4', |
| 108 |
'type': 'ether', |
| 109 |
'mtu': 1500, |
| 110 |
'actual-mtu': 1500, |
| 111 |
'l2mtu': 1598, |
| 112 |
'max-l2mtu': 4074, |
| 113 |
'mac-address': '00:11:22:33:44:88', |
| 114 |
'last-link-down-time': 'apr/23/2022 08:22:50', |
| 115 |
'last-link-up-time': 'apr/23/2022 08:22:52', |
| 116 |
'link-downs': 2, |
| 117 |
'rx-byte': 1234, |
| 118 |
'tx-byte': 1234, |
| 119 |
'rx-packet': 1234, |
| 120 |
'tx-packet': 1234, |
| 121 |
'rx-drop': 1234, |
| 122 |
'tx-drop': 1234, |
| 123 |
'tx-queue-drop': 1234, |
| 124 |
'rx-error': 1234, |
| 125 |
'tx-error': 1234, |
| 126 |
'fp-rx-byte': 1234, |
| 127 |
'fp-tx-byte': 1234, |
| 128 |
'fp-rx-packet': 1234, |
| 129 |
'fp-tx-packet': 1234, |
| 130 |
'running': True, |
| 131 |
'disabled': False, |
| 132 |
}, |
| 133 |
{ |
| 134 |
'.id': '*5', |
| 135 |
'name': 'fifth-ether', |
| 136 |
'default-name': 'ether5', |
| 137 |
'type': 'ether', |
| 138 |
'mtu': 1500, |
| 139 |
'actual-mtu': 1500, |
| 140 |
'l2mtu': 1598, |
| 141 |
'max-l2mtu': 4074, |
| 142 |
'mac-address': '00:11:22:33:44:99', |
| 143 |
'last-link-down-time': 'may/02/2022 18:12:32', |
| 144 |
'last-link-up-time': 'may/02/2022 18:08:01', |
| 145 |
'link-downs': 14, |
| 146 |
'rx-byte': 1234, |
| 147 |
'tx-byte': 1234, |
| 148 |
'rx-packet': 1234, |
| 149 |
'tx-packet': 1234, |
| 150 |
'rx-drop': 1234, |
| 151 |
'tx-drop': 1234, |
| 152 |
'tx-queue-drop': 1234, |
| 153 |
'rx-error': 1234, |
| 154 |
'tx-error': 1234, |
| 155 |
'fp-rx-byte': 1234, |
| 156 |
'fp-tx-byte': 1234, |
| 157 |
'fp-rx-packet': 1234, |
| 158 |
'fp-tx-packet': 1234, |
| 159 |
'running': False, |
| 160 |
'slave': True, |
| 161 |
'disabled': False, |
| 162 |
}, |
| 163 |
{ |
| 164 |
'.id': '*7', |
| 165 |
'name': 'my-bridge', |
| 166 |
'type': 'bridge', |
| 167 |
'mtu': 'auto', |
| 168 |
'actual-mtu': 1500, |
| 169 |
'l2mtu': 1598, |
| 170 |
'mac-address': '00:11:22:33:44:66', |
| 171 |
'last-link-up-time': 'apr/22/2022 07:54:48', |
| 172 |
'link-downs': 0, |
| 173 |
'rx-byte': 1234, |
| 174 |
'tx-byte': 1234, |
| 175 |
'rx-packet': 1234, |
| 176 |
'tx-packet': 1234, |
| 177 |
'rx-drop': 1234, |
| 178 |
'tx-drop': 1234, |
| 179 |
'tx-queue-drop': 1234, |
| 180 |
'rx-error': 1234, |
| 181 |
'tx-error': 1234, |
| 182 |
'fp-rx-byte': 1234, |
| 183 |
'fp-tx-byte': 1234, |
| 184 |
'fp-rx-packet': 1234, |
| 185 |
'fp-tx-packet': 1234, |
| 186 |
'running': True, |
| 187 |
'disabled': False, |
| 188 |
}, |
| 189 |
], |
| 190 |
('ip', 'address', ): [ |
| 191 |
{ |
| 192 |
'.id': '*1', |
| 193 |
'address': '192.168.1.1/24', |
| 194 |
'network': '192.168.1.0', |
| 195 |
'interface': 'my-bridge', |
| 196 |
'actual-interface': 'my-bridge', |
| 197 |
'invalid': False, |
| 198 |
'dynamic': False, |
| 199 |
'disabled': False, |
| 200 |
'comment': 'Wohnung', |
| 201 |
}, |
| 202 |
{ |
| 203 |
'.id': '*5', |
| 204 |
'address': '192.168.2.1/24', |
| 205 |
'network': '192.168.2.0', |
| 206 |
'interface': 'fourth-ether', |
| 207 |
'actual-interface': 'fourth-ether', |
| 208 |
'invalid': False, |
| 209 |
'dynamic': False, |
| 210 |
'disabled': False, |
| 211 |
'comment': 'VoIP', |
| 212 |
}, |
| 213 |
{ |
| 214 |
'.id': '*6', |
| 215 |
'address': '1.2.3.4/21', |
| 216 |
'network': '84.73.216.0', |
| 217 |
'interface': 'first-ether', |
| 218 |
'actual-interface': 'first-ether', |
| 219 |
'invalid': False, |
| 220 |
'dynamic': True, |
| 221 |
'disabled': False, |
| 222 |
}, |
| 223 |
], |
| 224 |
('ipv6', 'address', ): [ |
| 225 |
{ |
| 226 |
'.id': '*1', |
| 227 |
'address': 'fe80::1:2:3/64', |
| 228 |
'from-pool': '', |
| 229 |
'interface': 'my-bridge', |
| 230 |
'actual-interface': 'my-bridge', |
| 231 |
'eui-64': False, |
| 232 |
'advertise': False, |
| 233 |
'no-dad': False, |
| 234 |
'invalid': False, |
| 235 |
'dynamic': True, |
| 236 |
'link-local': True, |
| 237 |
'disabled': False, |
| 238 |
}, |
| 239 |
{ |
| 240 |
'.id': '*2', |
| 241 |
'address': 'fe80::1:2:4/64', |
| 242 |
'from-pool': '', |
| 243 |
'interface': 'fourth-ether', |
| 244 |
'actual-interface': 'fourth-ether', |
| 245 |
'eui-64': False, |
| 246 |
'advertise': False, |
| 247 |
'no-dad': False, |
| 248 |
'invalid': False, |
| 249 |
'dynamic': True, |
| 250 |
'link-local': True, |
| 251 |
'disabled': False, |
| 252 |
}, |
| 253 |
{ |
| 254 |
'.id': '*3', |
| 255 |
'address': 'fe80::1:2:5/64', |
| 256 |
'from-pool': '', |
| 257 |
'interface': 'first-ether', |
| 258 |
'actual-interface': 'first-ether', |
| 259 |
'eui-64': False, |
| 260 |
'advertise': False, |
| 261 |
'no-dad': False, |
| 262 |
'invalid': False, |
| 263 |
'dynamic': True, |
| 264 |
'link-local': True, |
| 265 |
'disabled': False, |
| 266 |
}, |
| 267 |
], |
| 268 |
('ip', 'neighbor', ): [], |
| 269 |
('system', 'identity', ): [ |
| 270 |
{ |
| 271 |
'name': 'MikroTik', |
| 272 |
}, |
| 273 |
], |
| 274 |
('system', 'resource', ): [ |
| 275 |
{ |
| 276 |
'uptime': '2w3d4h5m6s', |
| 277 |
'version': '6.49.6 (stable)', |
| 278 |
'build-time': 'Apr/07/2022 17:53:31', |
| 279 |
'free-memory': 12345678, |
| 280 |
'total-memory': 23456789, |
| 281 |
'cpu': 'MIPS 24Kc V7.4', |
| 282 |
'cpu-count': 1, |
| 283 |
'cpu-frequency': 400, |
| 284 |
'cpu-load': 48, |
| 285 |
'free-hdd-space': 123456789, |
| 286 |
'total-hdd-space': 234567890, |
| 287 |
'write-sect-since-reboot': 1234, |
| 288 |
'write-sect-total': 12345, |
| 289 |
'bad-blocks': 0, |
| 290 |
'architecture-name': 'mipsbe', |
| 291 |
'board-name': 'RB750GL', |
| 292 |
'platform': 'MikroTik', |
| 293 |
}, |
| 294 |
], |
| 295 |
('system', 'routerboard', ): [ |
| 296 |
{ |
| 297 |
'routerboard': True, |
| 298 |
'model': '750GL', |
| 299 |
'serial-number': '0123456789AB', |
| 300 |
'firmware-type': 'ar7240', |
| 301 |
'factory-firmware': '3.09', |
| 302 |
'current-firmware': '6.49.6', |
| 303 |
'upgrade-firmware': '6.49.6', |
| 304 |
}, |
| 305 |
], |
| 306 |
('routing', 'bgp', 'peer', ): [], |
| 307 |
('routing', 'bgp', 'vpnv4-route', ): [], |
| 308 |
('routing', 'bgp', 'instance', ): [ |
| 309 |
{ |
| 310 |
'.id': '*0', |
| 311 |
'name': 'default', |
| 312 |
'as': 65530, |
| 313 |
'router-id': '0.0.0.0', |
| 314 |
'redistribute-connected': False, |
| 315 |
'redistribute-static': False, |
| 316 |
'redistribute-rip': False, |
| 317 |
'redistribute-ospf': False, |
| 318 |
'redistribute-other-bgp': False, |
| 319 |
'out-filter': '', |
| 320 |
'client-to-client-reflection': True, |
| 321 |
'ignore-as-path-len': False, |
| 322 |
'routing-table': '', |
| 323 |
'default': True, |
| 324 |
'disabled': False, |
| 325 |
}, |
| 326 |
], |
| 327 |
('ip', 'route', ): [ |
| 328 |
{ |
| 329 |
'.id': '*30000001', |
| 330 |
'dst-address': '0.0.0.0/0', |
| 331 |
'gateway': '1.2.3.0', |
| 332 |
'gateway-status': '1.2.3.0 reachable via first-ether', |
| 333 |
'distance': 1, |
| 334 |
'scope': 30, |
| 335 |
'target-scope': 10, |
| 336 |
'vrf-interface': 'first-ether', |
| 337 |
'active': True, |
| 338 |
'dynamic': True, |
| 339 |
'static': True, |
| 340 |
'disabled': False, |
| 341 |
}, |
| 342 |
{ |
| 343 |
'.id': '*40162F13', |
| 344 |
'dst-address': '84.73.216.0/21', |
| 345 |
'pref-src': '1.2.3.4', |
| 346 |
'gateway': 'first-ether', |
| 347 |
'gateway-status': 'first-ether reachable', |
| 348 |
'distance': 0, |
| 349 |
'scope': 10, |
| 350 |
'active': True, |
| 351 |
'dynamic': True, |
| 352 |
'connect': True, |
| 353 |
'disabled': False, |
| 354 |
}, |
| 355 |
{ |
| 356 |
'.id': '*4016AA23', |
| 357 |
'dst-address': '192.168.2.0/24', |
| 358 |
'pref-src': '192.168.2.1', |
| 359 |
'gateway': 'fourth-ether', |
| 360 |
'gateway-status': 'fourth-ether reachable', |
| 361 |
'distance': 0, |
| 362 |
'scope': 10, |
| 363 |
'active': True, |
| 364 |
'dynamic': True, |
| 365 |
'connect': True, |
| 366 |
'disabled': False, |
| 367 |
}, |
| 368 |
{ |
| 369 |
'.id': '*40168E05', |
| 370 |
'dst-address': '192.168.1.0/24', |
| 371 |
'pref-src': '192.168.1.1', |
| 372 |
'gateway': 'my-bridge', |
| 373 |
'gateway-status': 'my-bridge reachable', |
| 374 |
'distance': 0, |
| 375 |
'scope': 10, |
| 376 |
'active': True, |
| 377 |
'dynamic': True, |
| 378 |
'connect': True, |
| 379 |
'disabled': False, |
| 380 |
}, |
| 381 |
], |
| 382 |
('routing', 'ospf', 'instance', ): [ |
| 383 |
{ |
| 384 |
'.id': '*0', |
| 385 |
'name': 'default', |
| 386 |
'router-id': '0.0.0.0', |
| 387 |
'distribute-default': 'never', |
| 388 |
'redistribute-connected': False, |
| 389 |
'redistribute-static': False, |
| 390 |
'redistribute-rip': False, |
| 391 |
'redistribute-bgp': False, |
| 392 |
'redistribute-other-ospf': False, |
| 393 |
'metric-default': 1, |
| 394 |
'metric-connected': 20, |
| 395 |
'metric-static': 20, |
| 396 |
'metric-rip': 20, |
| 397 |
'metric-bgp': 'auto', |
| 398 |
'metric-other-ospf': 'auto', |
| 399 |
'in-filter': 'ospf-in', |
| 400 |
'out-filter': 'ospf-out', |
| 401 |
'state': 'down', |
| 402 |
'default': True, |
| 403 |
'disabled': False, |
| 404 |
}, |
| 405 |
], |
| 406 |
('routing', 'ospf', 'neighbor', ): [], |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
class TestRouterosApiFactsModule(ModuleTestCase): |
| 411 |
|
| 412 |
def setUp(self): |
| 413 |
super(TestRouterosApiFactsModule, self).setUp() |
| 414 |
self.module = api_facts |
| 415 |
self.module.LibRouterosError = FakeLibRouterosError |
| 416 |
self.module.connect = MagicMock(new=fake_ros_api) |
| 417 |
self.module.check_has_library = MagicMock() |
| 418 |
self.patch_create_api = patch('ansible_collections.community.routeros.plugins.modules.api_facts.create_api', MagicMock(new=fake_ros_api)) |
| 419 |
self.patch_create_api.start() |
| 420 |
self.patch_query_path = patch('ansible_collections.community.routeros.plugins.modules.api_facts.FactsBase.query_path', self.query_path) |
| 421 |
self.patch_query_path.start() |
| 422 |
self.module.Key = MagicMock(new=Key) |
| 423 |
self.config_module_args = { |
| 424 |
'username': 'admin', |
| 425 |
'password': 'pаss', |
| 426 |
'hostname': '127.0.0.1', |
| 427 |
} |
| 428 |
|
| 429 |
def tearDown(self): |
| 430 |
self.patch_query_path.stop() |
| 431 |
self.patch_create_api.stop() |
| 432 |
|
| 433 |
def query_path(self, path): |
| 434 |
response = API_RESPONSES.get(tuple(path)) |
| 435 |
if response is None: |
| 436 |
raise Exception('Unexpected command: %s' % repr(path)) |
| 437 |
return response |
| 438 |
|
| 439 |
def test_module_fail_when_required_args_missing(self): |
| 440 |
with self.assertRaises(AnsibleFailJson) as exc: |
| 441 |
with set_module_args({}): |
| 442 |
self.module.main() |
| 443 |
|
| 444 |
result = exc.exception.args[0] |
| 445 |
self.assertEqual(result['failed'], True) |
| 446 |
|
| 447 |
def test_module_fail_when_invalid_gather_subset(self): |
| 448 |
with self.assertRaises(AnsibleFailJson) as exc: |
| 449 |
module_args = self.config_module_args.copy() |
| 450 |
module_args['gather_subset'] = ['!foobar'] |
| 451 |
with set_module_args(module_args): |
| 452 |
self.module.main() |
| 453 |
|
| 454 |
result = exc.exception.args[0] |
| 455 |
self.assertEqual(result['failed'], True) |
| 456 |
self.assertEqual(result['msg'], 'Bad subset: foobar') |
| 457 |
|
| 458 |
def test_full_run(self): |
| 459 |
with self.assertRaises(AnsibleExitJson) as exc: |
| 460 |
with set_module_args(self.config_module_args.copy()): |
| 461 |
self.module.main() |
| 462 |
|
| 463 |
result = exc.exception.args[0] |
| 464 |
self.assertEqual(result['changed'], False) |
| 465 |
self.assertEqual(result['ansible_facts']['ansible_net_all_ipv4_addresses'], [ |
| 466 |
'192.168.1.1', |
| 467 |
'192.168.2.1', |
| 468 |
'1.2.3.4', |
| 469 |
]) |
| 470 |
self.assertEqual(result['ansible_facts']['ansible_net_all_ipv6_addresses'], [ |
| 471 |
'fe80::1:2:3', |
| 472 |
'fe80::1:2:4', |
| 473 |
'fe80::1:2:5', |
| 474 |
]) |
| 475 |
self.assertEqual(result['ansible_facts']['ansible_net_arch'], 'mipsbe') |
| 476 |
self.assertEqual(result['ansible_facts']['ansible_net_bgp_instance'], { |
| 477 |
'default': { |
| 478 |
'as': 65530, |
| 479 |
'client-to-client-reflection': True, |
| 480 |
'default': True, |
| 481 |
'disabled': False, |
| 482 |
'ignore-as-path-len': False, |
| 483 |
'name': 'default', |
| 484 |
'out-filter': '', |
| 485 |
'redistribute-connected': False, |
| 486 |
'redistribute-ospf': False, |
| 487 |
'redistribute-other-bgp': False, |
| 488 |
'redistribute-rip': False, |
| 489 |
'redistribute-static': False, |
| 490 |
'router-id': '0.0.0.0', |
| 491 |
'routing-table': '' |
| 492 |
}, |
| 493 |
}) |
| 494 |
self.assertEqual(result['ansible_facts']['ansible_net_bgp_peer'], {}) |
| 495 |
self.assertEqual(result['ansible_facts']['ansible_net_bgp_vpnv4_route'], {}) |
| 496 |
self.assertEqual(result['ansible_facts']['ansible_net_cpu_load'], 48) |
| 497 |
self.assertEqual(result['ansible_facts']['ansible_net_gather_subset'], [ |
| 498 |
'default', |
| 499 |
'hardware', |
| 500 |
'interfaces', |
| 501 |
'routing', |
| 502 |
]) |
| 503 |
self.assertEqual(result['ansible_facts']['ansible_net_hostname'], 'MikroTik') |
| 504 |
self.assertEqual(result['ansible_facts']['ansible_net_interfaces'], { |
| 505 |
'my-bridge': { |
| 506 |
'actual-mtu': 1500, |
| 507 |
'disabled': False, |
| 508 |
'fp-rx-byte': 1234, |
| 509 |
'fp-rx-packet': 1234, |
| 510 |
'fp-tx-byte': 1234, |
| 511 |
'fp-tx-packet': 1234, |
| 512 |
'ipv4': [ |
| 513 |
{ |
| 514 |
'address': '192.168.1.1', |
| 515 |
'subnet': 24 |
| 516 |
} |
| 517 |
], |
| 518 |
'ipv6': [ |
| 519 |
{ |
| 520 |
'address': 'fe80::1:2:3', |
| 521 |
'subnet': 64 |
| 522 |
} |
| 523 |
], |
| 524 |
'l2mtu': 1598, |
| 525 |
'last-link-up-time': 'apr/22/2022 07:54:48', |
| 526 |
'link-downs': 0, |
| 527 |
'mac-address': '00:11:22:33:44:66', |
| 528 |
'mtu': 'auto', |
| 529 |
'name': 'my-bridge', |
| 530 |
'running': True, |
| 531 |
'rx-byte': 1234, |
| 532 |
'rx-drop': 1234, |
| 533 |
'rx-error': 1234, |
| 534 |
'rx-packet': 1234, |
| 535 |
'tx-byte': 1234, |
| 536 |
'tx-drop': 1234, |
| 537 |
'tx-error': 1234, |
| 538 |
'tx-packet': 1234, |
| 539 |
'tx-queue-drop': 1234, |
| 540 |
'type': 'bridge' |
| 541 |
}, |
| 542 |
'first-ether': { |
| 543 |
'actual-mtu': 1500, |
| 544 |
'default-name': 'ether1', |
| 545 |
'disabled': False, |
| 546 |
'fp-rx-byte': 1234, |
| 547 |
'fp-rx-packet': 1234, |
| 548 |
'fp-tx-byte': 1234, |
| 549 |
'fp-tx-packet': 1234, |
| 550 |
'ipv4': [ |
| 551 |
{ |
| 552 |
'address': '1.2.3.4', |
| 553 |
'subnet': 21 |
| 554 |
} |
| 555 |
], |
| 556 |
'ipv6': [ |
| 557 |
{ |
| 558 |
'address': 'fe80::1:2:5', |
| 559 |
'subnet': 64 |
| 560 |
} |
| 561 |
], |
| 562 |
'l2mtu': 1598, |
| 563 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 564 |
'link-downs': 0, |
| 565 |
'mac-address': '00:11:22:33:44:55', |
| 566 |
'max-l2mtu': 4074, |
| 567 |
'mtu': 1500, |
| 568 |
'name': 'first-ether', |
| 569 |
'running': True, |
| 570 |
'rx-byte': 1234, |
| 571 |
'rx-drop': 1234, |
| 572 |
'rx-error': 1234, |
| 573 |
'rx-packet': 1234, |
| 574 |
'tx-byte': 1234, |
| 575 |
'tx-drop': 1234, |
| 576 |
'tx-error': 1234, |
| 577 |
'tx-packet': 1234, |
| 578 |
'tx-queue-drop': 1234, |
| 579 |
'type': 'ether' |
| 580 |
}, |
| 581 |
'second-ether': { |
| 582 |
'actual-mtu': 1500, |
| 583 |
'default-name': 'ether2', |
| 584 |
'disabled': False, |
| 585 |
'fp-rx-byte': 1234, |
| 586 |
'fp-rx-packet': 1234, |
| 587 |
'fp-tx-byte': 1234, |
| 588 |
'fp-tx-packet': 1234, |
| 589 |
'l2mtu': 1598, |
| 590 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 591 |
'link-downs': 0, |
| 592 |
'mac-address': '00:11:22:33:44:66', |
| 593 |
'max-l2mtu': 4074, |
| 594 |
'mtu': 1500, |
| 595 |
'name': 'second-ether', |
| 596 |
'running': True, |
| 597 |
'rx-byte': 1234, |
| 598 |
'rx-drop': 1234, |
| 599 |
'rx-error': 1234, |
| 600 |
'rx-packet': 1234, |
| 601 |
'slave': True, |
| 602 |
'tx-byte': 1234, |
| 603 |
'tx-drop': 1234, |
| 604 |
'tx-error': 1234, |
| 605 |
'tx-packet': 1234, |
| 606 |
'tx-queue-drop': 1234, |
| 607 |
'type': 'ether' |
| 608 |
}, |
| 609 |
'third-ether': { |
| 610 |
'actual-mtu': 1500, |
| 611 |
'default-name': 'ether3', |
| 612 |
'disabled': False, |
| 613 |
'fp-rx-byte': 1234, |
| 614 |
'fp-rx-packet': 1234, |
| 615 |
'fp-tx-byte': 1234, |
| 616 |
'fp-tx-packet': 1234, |
| 617 |
'l2mtu': 1598, |
| 618 |
'last-link-up-time': 'apr/22/2022 07:54:55', |
| 619 |
'link-downs': 0, |
| 620 |
'mac-address': '00:11:22:33:44:77', |
| 621 |
'max-l2mtu': 4074, |
| 622 |
'mtu': 1500, |
| 623 |
'name': 'third-ether', |
| 624 |
'running': True, |
| 625 |
'rx-byte': 1234, |
| 626 |
'rx-drop': 1234, |
| 627 |
'rx-error': 1234, |
| 628 |
'rx-packet': 1234, |
| 629 |
'slave': True, |
| 630 |
'tx-byte': 1234, |
| 631 |
'tx-drop': 1234, |
| 632 |
'tx-error': 1234, |
| 633 |
'tx-packet': 1234, |
| 634 |
'tx-queue-drop': 1234, |
| 635 |
'type': 'ether' |
| 636 |
}, |
| 637 |
'fourth-ether': { |
| 638 |
'actual-mtu': 1500, |
| 639 |
'default-name': 'ether4', |
| 640 |
'disabled': False, |
| 641 |
'fp-rx-byte': 1234, |
| 642 |
'fp-rx-packet': 1234, |
| 643 |
'fp-tx-byte': 1234, |
| 644 |
'fp-tx-packet': 1234, |
| 645 |
'ipv4': [ |
| 646 |
{ |
| 647 |
'address': '192.168.2.1', |
| 648 |
'subnet': 24 |
| 649 |
} |
| 650 |
], |
| 651 |
'ipv6': [ |
| 652 |
{ |
| 653 |
'address': 'fe80::1:2:4', |
| 654 |
'subnet': 64 |
| 655 |
} |
| 656 |
], |
| 657 |
'l2mtu': 1598, |
| 658 |
'last-link-down-time': 'apr/23/2022 08:22:50', |
| 659 |
'last-link-up-time': 'apr/23/2022 08:22:52', |
| 660 |
'link-downs': 2, |
| 661 |
'mac-address': '00:11:22:33:44:88', |
| 662 |
'max-l2mtu': 4074, |
| 663 |
'mtu': 1500, |
| 664 |
'name': 'fourth-ether', |
| 665 |
'running': True, |
| 666 |
'rx-byte': 1234, |
| 667 |
'rx-drop': 1234, |
| 668 |
'rx-error': 1234, |
| 669 |
'rx-packet': 1234, |
| 670 |
'tx-byte': 1234, |
| 671 |
'tx-drop': 1234, |
| 672 |
'tx-error': 1234, |
| 673 |
'tx-packet': 1234, |
| 674 |
'tx-queue-drop': 1234, |
| 675 |
'type': 'ether' |
| 676 |
}, |
| 677 |
'fifth-ether': { |
| 678 |
'actual-mtu': 1500, |
| 679 |
'default-name': 'ether5', |
| 680 |
'disabled': False, |
| 681 |
'fp-rx-byte': 1234, |
| 682 |
'fp-rx-packet': 1234, |
| 683 |
'fp-tx-byte': 1234, |
| 684 |
'fp-tx-packet': 1234, |
| 685 |
'l2mtu': 1598, |
| 686 |
'last-link-down-time': 'may/02/2022 18:12:32', |
| 687 |
'last-link-up-time': 'may/02/2022 18:08:01', |
| 688 |
'link-downs': 14, |
| 689 |
'mac-address': '00:11:22:33:44:99', |
| 690 |
'max-l2mtu': 4074, |
| 691 |
'mtu': 1500, |
| 692 |
'name': 'fifth-ether', |
| 693 |
'running': False, |
| 694 |
'rx-byte': 1234, |
| 695 |
'rx-drop': 1234, |
| 696 |
'rx-error': 1234, |
| 697 |
'rx-packet': 1234, |
| 698 |
'slave': True, |
| 699 |
'tx-byte': 1234, |
| 700 |
'tx-drop': 1234, |
| 701 |
'tx-error': 1234, |
| 702 |
'tx-packet': 1234, |
| 703 |
'tx-queue-drop': 1234, |
| 704 |
'type': 'ether' |
| 705 |
} |
| 706 |
}) |
| 707 |
self.assertEqual(result['ansible_facts']['ansible_net_memfree_mb'], 12345678 / 1048576.0) |
| 708 |
self.assertEqual(result['ansible_facts']['ansible_net_memtotal_mb'], 23456789 / 1048576.0) |
| 709 |
self.assertEqual(result['ansible_facts']['ansible_net_model'], '750GL') |
| 710 |
self.assertEqual(result['ansible_facts']['ansible_net_neighbors'], []) |
| 711 |
self.assertEqual(result['ansible_facts']['ansible_net_ospf_instance'], { |
| 712 |
'default': { |
| 713 |
'default': True, |
| 714 |
'disabled': False, |
| 715 |
'distribute-default': 'never', |
| 716 |
'in-filter': 'ospf-in', |
| 717 |
'metric-bgp': 'auto', |
| 718 |
'metric-connected': 20, |
| 719 |
'metric-default': 1, |
| 720 |
'metric-other-ospf': 'auto', |
| 721 |
'metric-rip': 20, |
| 722 |
'metric-static': 20, |
| 723 |
'name': 'default', |
| 724 |
'out-filter': 'ospf-out', |
| 725 |
'redistribute-bgp': False, |
| 726 |
'redistribute-connected': False, |
| 727 |
'redistribute-other-ospf': False, |
| 728 |
'redistribute-rip': False, |
| 729 |
'redistribute-static': False, |
| 730 |
'router-id': '0.0.0.0', |
| 731 |
'state': 'down' |
| 732 |
} |
| 733 |
}) |
| 734 |
self.assertEqual(result['ansible_facts']['ansible_net_ospf_neighbor'], {}) |
| 735 |
self.assertEqual(result['ansible_facts']['ansible_net_route'], { |
| 736 |
'main': { |
| 737 |
'active': True, |
| 738 |
'connect': True, |
| 739 |
'disabled': False, |
| 740 |
'distance': 0, |
| 741 |
'dst-address': '192.168.1.0/24', |
| 742 |
'dynamic': True, |
| 743 |
'gateway': 'my-bridge', |
| 744 |
'gateway-status': 'my-bridge reachable', |
| 745 |
'pref-src': '192.168.1.1', |
| 746 |
'scope': 10 |
| 747 |
} |
| 748 |
}) |
| 749 |
self.assertEqual(result['ansible_facts']['ansible_net_serialnum'], '0123456789AB') |
| 750 |
self.assertEqual(result['ansible_facts']['ansible_net_spacefree_mb'], 123456789 / 1048576.0) |
| 751 |
self.assertEqual(result['ansible_facts']['ansible_net_spacetotal_mb'], 234567890 / 1048576.0) |
| 752 |
self.assertEqual(result['ansible_facts']['ansible_net_uptime'], '2w3d4h5m6s') |
| 753 |
self.assertEqual(result['ansible_facts']['ansible_net_version'], '6.49.6 (stable)') |