Merge lp:~mbruzek/charm-helpers/add_uid_gid into lp:~jamesbeedy/charm-helpers/add_uid_gid

Proposed by Matt Bruzek on 2016-05-31
Status: Merged
Approved by: james beedy on 2016-05-31
Approved revision: 581
Merged at revision: 584
Proposed branch: lp:~mbruzek/charm-helpers/add_uid_gid
Merge into: lp:~jamesbeedy/charm-helpers/add_uid_gid
Diff against target: 86 lines (+52/-1) (has conflicts)
2 files modified
charmhelpers/core/host.py (+6/-1)
tests/core/test_host.py (+46/-0)
Text conflict in charmhelpers/core/host.py
To merge this branch: bzr merge lp:~mbruzek/charm-helpers/add_uid_gid
Reviewer Review Type Date Requested Status
james beedy 2016-05-31 Approve on 2016-05-31
Review via email: mp+296132@code.launchpad.net

Description of the Change

Hey James,

Instead of pointing out problems I fixed the problems that I found.

Please consider this merge proposal or if you already have the code fixed, please use/extend the tests that I wrote here.

To post a comment you must log in.
james beedy (jamesbeedy) wrote :

Nice work! Thanks for helping with the needed tests! My +1 doesn't really matter for the merge, but you've got it anyway!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2016-05-31 18:30:01 +0000
3+++ charmhelpers/core/host.py 2016-05-31 18:55:12 +0000
4@@ -175,19 +175,24 @@
5 return os.path.isdir(SYSTEMD_SYSTEM)
6
7
8+<<<<<<< TREE
9 def adduser(username, uid=None, password=None, shell='/bin/bash',
10 system_user=False, primary_group=None, secondary_groups=None):
11+=======
12+def adduser(username, password=None, shell='/bin/bash', system_user=False,
13+ primary_group=None, secondary_groups=None, uid=None):
14+>>>>>>> MERGE-SOURCE
15 """Add a user to the system.
16
17 Will log but otherwise succeed if the user already exists.
18
19 :param str username: Username to create
20- :param int uid: UID for user being created
21 :param str password: Password for user; if ``None``, create a system user
22 :param str shell: The default shell for the user
23 :param bool system_user: Whether to create a login or system user
24 :param str primary_group: Primary group for user; defaults to username
25 :param list secondary_groups: Optional list of additional groups
26+ :param int uid: UID for user being created
27
28 :returns: The password database entry struct, as returned by `pwd.getpwnam`
29 """
30
31=== modified file 'tests/core/test_host.py'
32--- tests/core/test_host.py 2016-05-31 18:30:01 +0000
33+++ tests/core/test_host.py 2016-05-31 18:55:12 +0000
34@@ -642,6 +642,52 @@
35 getpwnam.assert_called_with(username)
36
37 @patch('pwd.getpwnam')
38+ @patch('pwd.getpwuid')
39+ @patch('grp.getgrnam')
40+ @patch('subprocess.check_call')
41+ @patch.object(host, 'log')
42+ def test_add_user_uid(self, log, check_call, getgrnam, getpwuid, getpwnam):
43+ user_name = 'james'
44+ user_id = 1111
45+ uid_key_error = KeyError('user not found')
46+ getpwuid.side_effect = uid_key_error
47+ host.adduser(user_name, uid=user_id)
48+
49+ check_call.assert_called_with([
50+ 'useradd',
51+ '--uid',
52+ str(user_id),
53+ '--system',
54+ '-g',
55+ user_name,
56+ user_name
57+ ])
58+ getpwnam.assert_called_with(user_name)
59+ getpwuid.assert_called_with(user_id)
60+
61+ @patch('grp.getgrnam')
62+ @patch('grp.getgrgid')
63+ @patch('subprocess.check_call')
64+ @patch.object(host, 'log')
65+ def test_add_group_gid(self, log, check_call, getgrgid, getgrnam):
66+ group_name = 'darkhorse'
67+ group_id = 1005
68+ existing_group_gid = KeyError('group not found')
69+ new_group_gid = 1006
70+ getgrgid.side_effect = [existing_group_gid, new_group_gid]
71+
72+ host.add_group(group_name, gid=group_id)
73+ check_call.assert_called_with([
74+ 'addgroup',
75+ '--gid',
76+ str(group_id),
77+ '--group',
78+ group_name
79+ ])
80+ getgrgid.assert_called_with(group_id)
81+ getgrnam.assert_called_with(group_name)
82+
83+ @patch('pwd.getpwnam')
84 def test_user_exists_true(self, getpwnam):
85 getpwnam.side_effect = 'pw info'
86 self.assertTrue(host.user_exists('bob'))

Subscribers

People subscribed via source and target branches

to all changes: