AMBARI-3657. User: Enable modifiyng existing group, fix groups attr. not set stack trace (Andrew Onischuk via dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/61d3ee9d Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/61d3ee9d Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/61d3ee9d Branch: refs/heads/trunk Commit: 61d3ee9d6d884130b2f7bb27ce34e97f41274fb1 Parents: cefc54a Author: Lisnichenko Dmitro <[email protected]> Authored: Fri Nov 1 17:14:18 2013 +0200 Committer: Lisnichenko Dmitro <[email protected]> Committed: Fri Nov 1 17:14:18 2013 +0200 ---------------------------------------------------------------------- .../resource_management/providers/accounts.py | 45 +++++++++++--------- .../resource_management/resources/accounts.py | 5 +-- 2 files changed, 26 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/61d3ee9d/ambari-agent/src/main/python/resource_management/providers/accounts.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/providers/accounts.py b/ambari-agent/src/main/python/resource_management/providers/accounts.py index 1ff43f3..e164eb2 100644 --- a/ambari-agent/src/main/python/resource_management/providers/accounts.py +++ b/ambari-agent/src/main/python/resource_management/providers/accounts.py @@ -10,32 +10,35 @@ class UserProvider(Provider): def action_create(self): if not self.user: command = ['useradd', "-m"] + self.log.info("Adding user %s" % self.resource) + else: + command = ['usermod'] + self.log.info("Modifying user %s" % (self.resource.username)) - useradd_options = dict( - comment="-c", - gid="-g", - uid="-u", - shell="-s", - password="-p", - home="-d", - ) + options = dict( + comment="-c", + gid="-g", + uid="-u", + shell="-s", + password="-p", + home="-d", + ) - if self.resource.system: - command.append("--system") + if self.resource.system and not self.user: + command.append("--system") - if self.resource.groups: - command += ["-G", ",".join(self.resource.groups)] + if self.resource.groups: + command += ["-G", ",".join(self.resource.groups)] - for option_name, option_flag in useradd_options.items(): - option_value = getattr(self.resource, option_name) - if option_flag and option_value: - command += [option_flag, str(option_value)] + for option_name, option_flag in options.items(): + option_value = getattr(self.resource, option_name) + if option_flag and option_value: + command += [option_flag, str(option_value)] - command.append(self.resource.username) + command.append(self.resource.username) - shell.checked_call(command) - self.resource.updated() - self.log.info("Added user %s" % self.resource) + shell.checked_call(command) + self.resource.updated() def action_remove(self): if self.user: @@ -60,7 +63,7 @@ class GroupProvider(Provider): self.log.info("Adding group %s" % self.resource) else: command = ['groupmod'] - self.log.info("Modifying group %s to %s" % (self.resource.group_name, self.resource)) + self.log.info("Modifying group %s" % (self.resource.group_name)) options = dict( gid="-g", http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/61d3ee9d/ambari-agent/src/main/python/resource_management/resources/accounts.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/resources/accounts.py b/ambari-agent/src/main/python/resource_management/resources/accounts.py index b149cdd..c087ac9 100644 --- a/ambari-agent/src/main/python/resource_management/resources/accounts.py +++ b/ambari-agent/src/main/python/resource_management/resources/accounts.py @@ -18,11 +18,10 @@ class User(Resource): comment = ResourceArgument() uid = ResourceArgument() gid = ResourceArgument() - groups = ForcedListArgument() # supplementary groups + groups = ForcedListArgument(default=[]) # supplementary groups home = ResourceArgument() shell = ResourceArgument(default="/bin/bash") password = ResourceArgument() system = BooleanArgument(default=False) - actions = Resource.actions + ["create", "remove", "modify", "manage", "lock", - "unlock"] + actions = Resource.actions + ["create", "remove"]
