-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(snapd): ubuntu do not snap refresh when snap absent
No longer call snap refresh when cloud-config user-data specifies upgade_packages:true and custom Ubuntu images do not have snapd package installed LP: #2064300
- Loading branch information
1 parent
aa357fa
commit 51c6569
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
import pytest | ||
|
||
from cloudinit.distros import fetch | ||
|
||
|
||
class TestPackageCommand: | ||
@pytest.mark.parametrize("snap_available", (True, False)) | ||
def test_package_command_only_refresh_snap_when_available( | ||
self, snap_available, mocker | ||
): | ||
"""Avoid calls to snap refresh when snap command not available.""" | ||
m_snap_available = mocker.patch( | ||
"cloudinit.distros.ubuntu.Snap.available", | ||
return_value=snap_available, | ||
) | ||
m_snap_upgrade_packges = mocker.patch( | ||
"cloudinit.distros.ubuntu.Snap.upgrade_packages", | ||
return_value=snap_available, | ||
) | ||
m_apt_run_package_command = mocker.patch( | ||
"cloudinit.distros.package_management.apt.Apt.run_package_command", | ||
) | ||
cls = fetch("ubuntu") | ||
distro = cls("ubuntu", {}, None) | ||
distro.package_command("upgrade") | ||
m_apt_run_package_command.assert_called_once_with("upgrade") | ||
m_snap_available.assert_called_once() | ||
if snap_available: | ||
m_snap_upgrade_packges.assert_called_once() | ||
else: | ||
m_snap_upgrade_packges.assert_not_called() |