176
158
self.assertEqual([], self.mock_install_packages.call_args_list)
179
class TestSetupGrub(CurthooksBase):
161
class TestSetupZipl(CiTestCase):
164
super(TestSetupZipl, self).setUp()
165
self.target = self.tmp_dir()
167
@patch('curtin.block.get_devices_for_mp')
168
@patch('platform.machine')
169
def test_noop_non_s390x(self, m_machine, m_get_devices):
170
m_machine.return_value = 'non-s390x'
171
curthooks.setup_zipl(None, self.target)
172
self.assertEqual(0, m_get_devices.call_count)
174
@patch('curtin.block.get_devices_for_mp')
175
@patch('platform.machine')
176
def test_setup_zipl_writes_etc_zipl_conf(self, m_machine, m_get_devices):
177
m_machine.return_value = 's390x'
178
m_get_devices.return_value = ['/dev/mapper/ubuntu--vg-root']
179
curthooks.setup_zipl(None, self.target)
180
m_get_devices.assert_called_with(self.target)
181
with open(os.path.join(self.target, 'etc', 'zipl.conf')) as stream:
182
content = stream.read()
184
'# This has been modified by the MAAS curtin installer',
188
class TestSetupGrub(CiTestCase):
182
191
super(TestSetupGrub, self).setUp()
183
self.target = tempfile.mkdtemp()
192
self.target = self.tmp_dir()
184
193
self.add_patch('curtin.util.lsb_release', 'mock_lsb_release')
185
194
self.mock_lsb_release.return_value = {
186
195
'codename': 'xenial',
566
'path': '50-cloudconfig-file1.cfg',
567
'content': cloudconfig['file1']['content']},
569
'path': '50-cloudconfig-foobar.cfg',
570
'content': cloudconfig['foobar']['content']}
567
'path': '50-cloudconfig-file1.cfg',
568
'content': cloudconfig['file1']['content']},
570
'path': '50-cloudconfig-foobar.cfg',
571
'content': cloudconfig['foobar']['content']}
573
curthooks.handle_cloudconfig(cloudconfig, target=cc_target)
573
curthooks.handle_cloudconfig(cloudconfig, base_dir=cc_target)
574
574
mock_write_files.assert_called_with(expected_cfg, cc_target)
576
576
def test_handle_cloudconfig_bad_config(self):
577
577
with self.assertRaises(ValueError):
578
curthooks.handle_cloudconfig([], target="foobar")
578
curthooks.handle_cloudconfig([], base_dir="foobar")
581
class TestDetectRequiredPackages(CiTestCase):
586
'type': 'bcache', 'name': 'bcache0', 'id': 'cache0',
587
'backing_device': 'sda3', 'cache_device': 'sdb'},
589
'id': 'lvol1', 'name': 'lv1', 'volgroup': 'vg1',
590
'type': 'lvm_partition'},
592
'id': 'vol1', 'name': 'vg1', 'devices': ['sda', 'sdb'],
593
'type': 'lvm_volgroup'},
595
'id': 'mddevice', 'name': 'md0', 'type': 'raid',
596
'raidlevel': 5, 'devices': ['sda1', 'sdb1', 'sdc1']},
598
'id': 'format0', 'fstype': 'ext2', 'type': 'format'},
600
'id': 'format1', 'fstype': 'ext3', 'type': 'format'},
602
'id': 'format2', 'fstype': 'ext4', 'type': 'format'},
604
'id': 'format3', 'fstype': 'btrfs', 'type': 'format'},
606
'id': 'format4', 'fstype': 'xfs', 'type': 'format'}}
611
'name': 'bond0', 'type': 'bond',
612
'bond_interfaces': ['interface0', 'interface1'],
613
'params': {'bond-mode': 'active-backup'},
615
{'type': 'static', 'address': '10.23.23.2/24'},
616
{'type': 'static', 'address': '10.23.24.2/24'}]},
618
'id': 'interface1.2667', 'mtu': 1500, 'name':
619
'interface1.2667', 'type': 'vlan', 'vlan_id': 2667,
620
'vlan_link': 'interface1',
621
'subnets': [{'address': '10.245.184.2/24',
622
'dns_nameservers': [], 'type': 'static'}]},
624
'name': 'br0', 'bridge_interfaces': ['eth0', 'eth1'],
625
'type': 'bridge', 'params': {
626
'bridge_stp': 'off', 'bridge_fd': 0,
627
'bridge_maxwait': 0},
629
{'type': 'static', 'address': '192.168.14.2/24'},
630
{'type': 'static', 'address': '2001:1::1/64'}]}},
634
'en-intra': {'id': 1, 'link': 'eno1', 'dhcp4': 'yes'},
635
'en-vpn': {'id': 2, 'link': 'eno1'}}},
639
'interfaces': ['wlp1s0', 'switchports'],
644
def _fmt_config(self, config_items):
646
for item, item_confs in config_items.items():
647
version = item_confs['version']
648
res[item] = {'version': version}
650
res[item]['config'] = [self.test_config[item][version][i]
651
for i in item_confs['items']]
652
elif version == 2 and item == 'network':
653
for cfg_item in item_confs['items']:
654
res[item].update(self.test_config[item][version][cfg_item])
656
raise NotImplementedError
659
def _test_req_mappings(self, req_mappings):
660
for (config_items, expected_reqs) in req_mappings:
661
cfg = self._fmt_config(config_items)
662
actual_reqs = curthooks.detect_required_packages(cfg)
663
self.assertEqual(set(actual_reqs), set(expected_reqs),
664
'failed for config: {}'.format(config_items))
666
def test_storage_v1_detect(self):
667
self._test_req_mappings((
670
'items': ('lvm_partition', 'lvm_volgroup', 'btrfs', 'xfs')}},
671
('lvm2', 'xfsprogs', 'btrfs-tools')),
674
'items': ('raid', 'bcache', 'ext3', 'xfs')}},
675
('mdadm', 'bcache-tools', 'e2fsprogs', 'xfsprogs')),
678
'items': ('raid', 'lvm_volgroup', 'lvm_partition', 'ext3',
680
('lvm2', 'mdadm', 'e2fsprogs', 'btrfs-tools')),
683
'items': ('bcache', 'lvm_volgroup', 'lvm_partition', 'ext2')}},
684
('bcache-tools', 'lvm2', 'e2fsprogs')),
687
def test_network_v1_detect(self):
688
self._test_req_mappings((
691
'items': ('bridge',)}},
695
'items': ('vlan', 'bond')}},
696
('vlan', 'ifenslave')),
699
'items': ('bond', 'bridge')}},
700
('ifenslave', 'bridge-utils')),
703
'items': ('vlan', 'bridge', 'bond')}},
704
('ifenslave', 'bridge-utils', 'vlan')),
707
def test_mixed_v1_detect(self):
708
self._test_req_mappings((
711
'items': ('raid', 'bcache', 'ext4')},
714
'items': ('vlan',)}},
715
('mdadm', 'bcache-tools', 'e2fsprogs', 'vlan')),
718
'items': ('lvm_partition', 'lvm_volgroup', 'xfs')},
721
'items': ('bridge', 'bond')}},
722
('lvm2', 'xfsprogs', 'bridge-utils', 'ifenslave')),
725
'items': ('ext3', 'ext4', 'btrfs')},
728
'items': ('bond', 'vlan')}},
729
('e2fsprogs', 'btrfs-tools', 'vlan', 'ifenslave')),
732
def test_network_v2_detect(self):
733
self._test_req_mappings((
736
'items': ('bridge',)}},
740
'items': ('vlan',)}},
744
'items': ('vlan', 'bridge')}},
745
('vlan', 'bridge-utils')),
748
def test_mixed_storage_v1_network_v2_detect(self):
749
self._test_req_mappings((
752
'items': ('bridge', 'vlan')},
755
'items': ('raid', 'bcache', 'ext4')}},
756
('vlan', 'bridge-utils', 'mdadm', 'bcache-tools', 'e2fsprogs')),
759
def test_invalid_version_in_config(self):
760
with self.assertRaises(ValueError):
761
curthooks.detect_required_packages({'network': {'version': 3}})
580
764
# vi: ts=4 expandtab syntax=python