2
from curtin import block
3
from curtin import config
4
from curtin import futil
5
from curtin import util
7
from curtin.commands import curthooks
8
from .helpers import CiTestCase
11
class TestPublicAPI(CiTestCase):
12
"""Test entry points known to be used externally.
14
Curtin's only known external library user is the curthooks
15
that are present in the MAAS images. This will test for presense
16
of the modules and entry points that are used there.
18
This unit test is present to just test entry points. Function
19
behavior should be present elsewhere."""
21
def assert_has_callables(self, module, expected):
22
self.assertEqual(expected, _module_has(module, expected, callable))
25
"""Verify expected attributes in curtin.block."""
26
self.assert_has_callables(
28
['get_devices_for_mp', 'get_blockdev_for_partition', '_lsblock'])
30
def test_config(self):
31
"""Verify exported attributes in curtin.config."""
32
self.assert_has_callables(config, ['load_config'])
35
"""Verify exported attributes in curtin.util."""
36
self.assert_has_callables(
37
util, ['RunInChroot', 'load_command_environment'])
39
def test_centos_apply_network_config(self):
40
"""MAAS images use centos_apply_network_config from cmd.curthooks."""
41
self.assert_has_callables(curthooks, ['centos_apply_network_config'])
44
"""Verify exported attributes in curtin.futil."""
45
self.assert_has_callables(futil, ['write_files'])
48
def _module_has(module, names, nfilter=None):
49
found = [(name, getattr(module, name))
50
for name in names if hasattr(module, name)]
51
if nfilter is not None:
52
found = [(name, attr) for name, attr in found if nfilter(attr)]
54
return [name for name, _ in found]