Merge ~peter-sabaini/charm-sudo-pair:fix-tmpfiles into ~sudo-pair-charmers/charm-sudo-pair:master

Proposed by Peter Sabaini
Status: Merged
Approved by: Jeremy Lounder
Approved revision: bb6843ce629b2ff5ae333e88c706eef8fbe5e828
Merged at revision: bb6843ce629b2ff5ae333e88c706eef8fbe5e828
Proposed branch: ~peter-sabaini/charm-sudo-pair:fix-tmpfiles
Merge into: ~sudo-pair-charmers/charm-sudo-pair:master
Diff against target: 76 lines (+18/-0)
4 files modified
lib/libsudopair.py (+5/-0)
reactive/sudo_pair.py (+2/-0)
tests/unit/conftest.py (+4/-0)
tests/unit/test_libsudopair.py (+7/-0)
Reviewer Review Type Date Requested Status
Jeremy Lounder (community) Approve
Drew Freiberger (community) Approve
Review via email: mp+377518@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Drew Freiberger (afreiberger) wrote :

I've run unit tests with my suggestion on testing the content below. Content fine as is, but would recommend the additional test.

Thanks for the commit!

review: Approve
Revision history for this message
Peter Sabaini (peter-sabaini) wrote :

LOL, indeed I meant to really compare something in the test. Thanks for the catch -- please take a look?

On 13.01.20 19:29, Drew Freiberger wrote:
> Review: Approve
>
> I've run unit tests with my suggestion on testing the content below. Content fine as is, but would recommend the additional test.
>
> Thanks for the commit!
>
> Diff comments:
>
>> diff --git a/tests/unit/test_libsudopair.py b/tests/unit/test_libsudopair.py
>> index ecd1e41..d983900 100644
>> --- a/tests/unit/test_libsudopair.py
>> +++ b/tests/unit/test_libsudopair.py
>> @@ -147,6 +147,13 @@ class TestSudoPairHelper():
>> sph.create_socket_dir()
>> assert os.path.exists(tmpdir.join('/var/run/sudo_pair'))
>>
>> + def test_create_tmpfiles_conf(self, sph, tmpdir):
>> + sph.create_tmpfiles_conf()
>> + expected_content = ''
>
> I'd really like to see this check some amount of the content of the return to make sure the function is still able to be properly mocked out with the read/write.
>
> expected_content = "d {} 0755 - - -\n".format(sph.socket_dir)
>
>> + with open(tmpdir.join('/usr/lib/tmpfiles.d/sudo_pair.conf')) as f:
>> + content = f.read()
>> + assert expected_content in content
>
> assert expected_content == content
>
>> +
>> def test_install_sudo_pair_so(self, sph, tmpdir):
>> sph.install_sudo_pair_so()
>> assert filecmp.cmp('./files/sudo_pair.so', tmpdir.join('/usr/lib/sudo/sudo_pair.so'))
>
>

Revision history for this message
Drew Freiberger (afreiberger) wrote :

+1 lgtm

review: Approve
Revision history for this message
Jeremy Lounder (jldev) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/libsudopair.py b/lib/libsudopair.py
2index 3422521..d3b96a7 100644
3--- a/lib/libsudopair.py
4+++ b/lib/libsudopair.py
5@@ -47,6 +47,7 @@ class SudoPairHelper(object):
6 self.user_prompt_path = '/etc/sudo_pair.prompt.user'
7 self.pair_prompt_path = '/etc/sudo_pair.prompt.pair'
8 self.socket_dir = '/var/run/sudo_pair'
9+ self.tmpfiles_conf = '/usr/lib/tmpfiles.d/sudo_pair.conf'
10 self.owner = 'root'
11 self.group = 'root'
12 self.socket_dir_perms = 0o644
13@@ -79,6 +80,10 @@ class SudoPairHelper(object):
14 def create_socket_dir(self):
15 host.mkdir(self.socket_dir, perms=self.socket_dir_perms, owner=self.owner, group=self.group)
16
17+ def create_tmpfiles_conf(self):
18+ with open(self.tmpfiles_conf, "w") as f:
19+ f.write("d {} 0755 - - -\n".format(self.socket_dir))
20+
21 def install_sudo_pair_so(self):
22 sudo_pair_lib = os.path.join(hookenv.charm_dir(), 'files', 'sudo_pair.so')
23 copy_file(sudo_pair_lib, self.sudo_lib_path, self.owner, self.group, self.sudo_pair_so_perms)
24diff --git a/reactive/sudo_pair.py b/reactive/sudo_pair.py
25index 13db3d9..be557f8 100644
26--- a/reactive/sudo_pair.py
27+++ b/reactive/sudo_pair.py
28@@ -15,6 +15,8 @@ def install_sudo_pair():
29
30 sph.create_socket_dir()
31
32+ sph.create_tmpfiles_conf()
33+
34 sph.copy_user_prompt()
35
36 sph.copy_pair_prompt()
37diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
38index 38db222..0e2c034 100644
39--- a/tests/unit/conftest.py
40+++ b/tests/unit/conftest.py
41@@ -4,6 +4,7 @@ import pytest
42 import pwd
43 import grp
44 import os
45+from pathlib import Path
46
47
48 @pytest.fixture
49@@ -36,6 +37,9 @@ def sph(mock_hookenv_config, mock_charm_dir, tmpdir):
50 sph.group = grp.getgrgid(os.getgid()).gr_name
51 sph.sudo_conf_path = tmpdir.join(sph.sudo_conf_path)
52 sph.socket_dir = tmpdir.join(sph.socket_dir)
53+ td = Path(tmpdir.join(sph.tmpfiles_conf).strpath).parent
54+ td.mkdir(parents=True, exist_ok=True, mode=0o755)
55+ sph.tmpfiles_conf = tmpdir.join(sph.tmpfiles_conf)
56 sph.sudo_lib_path = tmpdir.join(sph.sudo_lib_path)
57 sph.user_prompt_path = tmpdir.join(sph.user_prompt_path)
58 sph.pair_prompt_path = tmpdir.join(sph.pair_prompt_path)
59diff --git a/tests/unit/test_libsudopair.py b/tests/unit/test_libsudopair.py
60index ecd1e41..fea4985 100644
61--- a/tests/unit/test_libsudopair.py
62+++ b/tests/unit/test_libsudopair.py
63@@ -147,6 +147,13 @@ class TestSudoPairHelper():
64 sph.create_socket_dir()
65 assert os.path.exists(tmpdir.join('/var/run/sudo_pair'))
66
67+ def test_create_tmpfiles_conf(self, sph, tmpdir):
68+ sph.create_tmpfiles_conf()
69+ expected_content = 'd {} 0755 - - -\n'.format(sph.socket_dir)
70+ with open(tmpdir.join('/usr/lib/tmpfiles.d/sudo_pair.conf')) as f:
71+ content = f.read()
72+ assert expected_content in content
73+
74 def test_install_sudo_pair_so(self, sph, tmpdir):
75 sph.install_sudo_pair_so()
76 assert filecmp.cmp('./files/sudo_pair.so', tmpdir.join('/usr/lib/sudo/sudo_pair.so'))

Subscribers

People subscribed via source and target branches