347
349
self.assertThat(ip_link['ens11'], Not(Contains('inet')))
350
class TestGetInterfaceType(MAASTestCase):
352
class FakeSysProcTestCase(MAASTestCase):
353
super(TestGetInterfaceType, self).setUp()
354
356
self.tmp_sys_net = mkdtemp('maas-unit-tests.sys-class-net')
355
self.tmp_proc_net_vlan = mkdtemp('maas-unit-tests.proc-net-vlan')
357
self.tmp_proc_net = mkdtemp('maas-unit-tests.proc-net')
358
os.mkdir(os.path.join(self.tmp_proc_net, "vlan"))
359
os.mkdir(os.path.join(self.tmp_proc_net, "bonding"))
357
361
def tearDown(self):
358
super(TestGetInterfaceType, self).tearDown()
359
363
rmtree(self.tmp_sys_net)
360
rmtree(self.tmp_proc_net_vlan)
364
rmtree(self.tmp_proc_net)
362
366
def createInterfaceType(
363
367
self, ifname, iftype, is_bridge=False, is_vlan=False,
395
399
def createEthernetInterface(self, ifname, **kwargs):
396
400
self.createInterfaceType(ifname, 1, **kwargs)
403
class TestGetInterfaceType(FakeSysProcTestCase):
398
405
def test__identifies_missing_interface(self):
399
406
self.assertThat(get_interface_type(
400
407
'eth0', sys_class_net=self.tmp_sys_net),
405
412
self.createEthernetInterface('br0', is_bridge=True)
406
413
self.assertThat(get_interface_type(
407
414
'br0', sys_class_net=self.tmp_sys_net,
408
proc_net_vlan=self.tmp_proc_net_vlan),
415
proc_net=self.tmp_proc_net),
409
416
Equals('ethernet.bridge')
437
444
self.createEthernetInterface('eth0', is_physical=True)
438
445
self.assertThat(get_interface_type(
439
446
'eth0', sys_class_net=self.tmp_sys_net,
440
proc_net_vlan=self.tmp_proc_net_vlan),
447
proc_net=self.tmp_proc_net),
441
448
Equals('ethernet.physical')
445
452
self.createEthernetInterface('wlan0', is_wireless=True)
446
453
self.assertThat(get_interface_type(
447
454
'wlan0', sys_class_net=self.tmp_sys_net,
448
proc_net_vlan=self.tmp_proc_net_vlan),
455
proc_net=self.tmp_proc_net),
449
456
Equals('ethernet.wireless')
477
484
self.createInterfaceType('avian0', 1149)
478
485
self.assertThat(get_interface_type(
479
486
'avian0', sys_class_net=self.tmp_sys_net,
480
proc_net_vlan=self.tmp_proc_net_vlan),
487
proc_net=self.tmp_proc_net),
481
488
Equals('unknown-1149')
485
class TestAnnotateWithDriverInformation(MAASTestCase):
492
class TestAnnotateWithDriverInformation(FakeSysProcTestCase):
487
494
def test__populates_interface_type_for_each_interface(self):
488
495
# Note: this is more of an end-to-end test, since we call
489
# "/sbin/ip addr" on the host running the tests. This is necessary
490
# because we don't have dependency injection for the directory names
491
# all the way through.
496
# "/sbin/ip addr" on the host running the tests.
492
497
ip_addr_output = check_output(['/sbin/ip', 'addr'])
493
498
interfaces = parse_ip_addr(ip_addr_output)
494
499
interfaces_with_types = annotate_with_driver_information(interfaces)
502
507
elif iface['type'] == 'ethernet.bridge':
503
508
self.expectThat(iface, Contains('bridged_interfaces'))
510
def test__ignores_bond_interfaces_with_no_parents(self):
517
self.createEthernetInterface('eth0', is_physical=True)
518
self.createEthernetInterface('eth1', is_physical=True)
519
self.createEthernetInterface(
520
'bond0', is_bond=True, bonded_interfaces=['eth0, eth1'])
521
self.createEthernetInterface(
522
'bond1', is_bond=True, bonded_interfaces=[])
523
interfaces = annotate_with_driver_information(
524
interfaces, sys_class_net=self.tmp_sys_net,
525
proc_net=self.tmp_proc_net)
526
self.expectThat(interfaces, HasLength(3))
527
self.expectThat(interfaces, Contains('eth0'))
528
self.expectThat(interfaces, Contains('eth1'))
529
self.expectThat(interfaces, Contains('bond0'))
531
def test__finds_bond_members_original_mac_addresses(self):
532
testdata = dedent("""\
533
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
535
Bonding Mode: fault-tolerance (active-backup)
537
Currently Active Slave: ens11
539
MII Polling Interval (ms): 100
543
Slave Interface: ens11
547
Link Failure Count: 0
548
Permanent HW addr: 52:54:00:ea:1c:fc
551
Slave Interface: ens3
555
Link Failure Count: 0
556
Permanent HW addr: 52:54:00:13:0e:6f
559
proc_net_bonding_bond0 = os.path.join(
560
self.tmp_proc_net, "bonding", "bond0")
561
with open(proc_net_bonding_bond0, mode='w') as f:
564
"ens3": {"mac": "00:01:02:03:04:05"},
565
"ens11": {"mac": "01:02:03:04:05:06"},
567
annotate_with_proc_net_bonding_original_macs(
568
interfaces, proc_net=self.tmp_proc_net)
571
"ens3": {"mac": "52:54:00:13:0e:6f"},
572
"ens11": {"mac": "52:54:00:ea:1c:fc"},
577
def test__ignores_missing_proc_net_bonding(self):
578
os.rmdir(os.path.join(self.tmp_proc_net, "bonding"))
580
"ens3": {"mac": "00:01:02:03:04:05"},
581
"ens11": {"mac": "01:02:03:04:05:06"},
583
annotate_with_proc_net_bonding_original_macs(
584
interfaces, proc_net=self.tmp_proc_net)
587
"ens3": {"mac": "00:01:02:03:04:05"},
588
"ens11": {"mac": "01:02:03:04:05:06"},
506
594
class TestGetIPAddr(MAASTestCase):
507
595
"""Tests for `get_ip_addr`, `get_ip_addr_json`, `get_mac_addresses`."""