Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cloudinit/config/cc_ssh_import_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
for user, user_cfg in users.items():
import_ids = []
if user_cfg["default"]:
import_ids = util.get_cfg_option_list(cfg, "ssh_import_id", [])
import_ids = util.uniq_merge(
util.get_cfg_option_list(cfg, "ssh_import_id", []),
user_cfg.get("ssh_import_id", []),
)
else:
try:
import_ids = user_cfg["ssh_import_id"]
Expand Down
41 changes: 41 additions & 0 deletions tests/unittests/config/test_cc_ssh_import_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,47 @@ def test_skip_inapplicable_configs(self, m_which, cfg, log, caplog):
cc_ssh_import_id.handle("name", cfg, cloud, [])
assert log in caplog.text

@pytest.mark.parametrize(
"cfg,expected",
(
pytest.param(
{"user": {"name": "dave", "ssh_import_id": ["lp:user"]}},
[mock.call(["lp:user"], "dave")],
id="default_user_config_is_honored",
),
pytest.param(
{"user": {"name": "dave"}, "ssh_import_id": ["lp:top"]},
[mock.call(["lp:top"], "dave")],
id="top_level_config_is_honored",
),
pytest.param(
{
"user": {"name": "dave", "ssh_import_id": ["lp:user"]},
"ssh_import_id": ["lp:top"],
},
[mock.call(["lp:top", "lp:user"], "dave")],
id="both_are_merged",
),
pytest.param(
{
"users": [
"default",
{"name": "bob", "ssh_import_id": ["lp:bob"]},
]
},
[mock.call(["lp:bob"], "bob")],
id="non_default_user_is_unaffected",
),
),
)
@mock.patch(MODPATH + "import_ssh_ids")
@mock.patch(MODPATH + "subp.which")
def test_ssh_import_id_sources(self, m_which, m_import, cfg, expected):
"""ssh_import_id on the default user is not ignored."""
m_which.return_value = "/usr/bin/ssh-import-id"
cc_ssh_import_id.handle("name", cfg, get_cloud("ubuntu"), [])
assert expected == m_import.call_args_list

@mock.patch(MODPATH + "pwd.getpwnam")
@mock.patch(MODPATH + "subp.subp")
@mock.patch(MODPATH + "subp.which")
Expand Down
Loading