-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lvm: Add a function to disable and enable LVM auto-activation
- Loading branch information
1 parent
d1357ef
commit b1109bd
Showing
3 changed files
with
91 additions
and
0 deletions.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .disk_test import * | ||
from .edd_test import * | ||
from .lvm_test import * | ||
from .mdraid_test import * | ||
from .raid_test import * |
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,41 @@ | ||
import unittest | ||
from unittest.mock import patch, mock_open | ||
|
||
import blivet.devicelibs.lvm as lvm | ||
|
||
|
||
class LVMTestCase(unittest.TestCase): | ||
|
||
def test_lvm_autoactivation(self): | ||
localconf = "global { event_activation = 0 }" | ||
|
||
with patch("builtins.open", mock_open(read_data=localconf)): | ||
# already disabled | ||
with self.assertRaises(RuntimeError): | ||
lvm.disable_lvm_autoactivation() | ||
|
||
localconf = "" | ||
with patch("builtins.open", mock_open(read_data=localconf)) as m: | ||
lvm.disable_lvm_autoactivation() | ||
m.assert_called_with("/etc/lvm/lvmlocal.conf", "a") | ||
handle = m() | ||
handle.write.assert_called_once_with("global { event_activation = 0 }") | ||
|
||
localconf = "test\ntest" | ||
with patch("builtins.open", mock_open(read_data=localconf)) as m: | ||
# not disabled | ||
with self.assertRaises(RuntimeError): | ||
lvm.reenable_lvm_autoactivation() | ||
|
||
localconf = "# global { event_activation = 0 }" | ||
with patch("builtins.open", mock_open(read_data=localconf)) as m: | ||
# not disabled | ||
with self.assertRaises(RuntimeError): | ||
lvm.reenable_lvm_autoactivation() | ||
|
||
localconf = "test\nglobal { event_activation = 0 }" | ||
with patch("builtins.open", mock_open(read_data=localconf)) as m: | ||
lvm.reenable_lvm_autoactivation() | ||
m.assert_called_with("/etc/lvm/lvmlocal.conf", "w+") | ||
handle = m() | ||
handle.write.assert_called_once_with("test\n") |