Updated Branches: refs/heads/trunk 19c00dbd9 -> cc8d9fec8
AMBARI-3571. Resource Management. Fix group Remove/Change gid/Change pwd. Refactor group (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/cc8d9fec Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/cc8d9fec Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/cc8d9fec Branch: refs/heads/trunk Commit: cc8d9fec8b47d47f1a32c435004316278eadd804 Parents: 19c00db Author: Lisnichenko Dmitro <[email protected]> Authored: Tue Oct 22 19:27:09 2013 +0300 Committer: Lisnichenko Dmitro <[email protected]> Committed: Tue Oct 22 19:27:09 2013 +0300 ---------------------------------------------------------------------- .../resource_management/providers/accounts.py | 37 +++++++++----------- .../resource_management/resources/accounts.py | 5 +-- .../main/python/resource_management/shell.py | 10 +++--- 3 files changed, 22 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/cc8d9fec/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 45673a7..1ff43f3 100644 --- a/ambari-agent/src/main/python/resource_management/providers/accounts.py +++ b/ambari-agent/src/main/python/resource_management/providers/accounts.py @@ -57,33 +57,30 @@ class GroupProvider(Provider): group = self.group if not group: command = ['groupadd'] - - groupadd_options = dict( + 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)) + + options = dict( gid="-g", password="-p", - ) + ) - for option_name, option_flag in groupadd_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.group_name) - command.append(self.resource.group_name) + shell.checked_call(command) + self.resource.updated() - shell.checked_call(command) - self.resource.updated() - self.log.info("Added group %s" % self.resource) - - group = self.group - - # if self.resource.members is not None: - # current_members = set(group.gr_mem) - # members = set(self.resource.members) - # for u in current_members - members: - # pass + group = self.group def action_remove(self): - if self.user: + if self.group: command = ['groupdel', self.resource.group_name] shell.checked_call(command) self.resource.updated() http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/cc8d9fec/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 fb07471..b149cdd 100644 --- a/ambari-agent/src/main/python/resource_management/resources/accounts.py +++ b/ambari-agent/src/main/python/resource_management/resources/accounts.py @@ -7,12 +7,9 @@ class Group(Resource): action = ForcedListArgument(default="create") group_name = ResourceArgument(default=lambda obj: obj.name) gid = ResourceArgument() - members = ForcedListArgument() password = ResourceArgument() - # append = BooleanArgument(default=False) # NOT SUPPORTED - actions = Resource.actions + ["create", "remove", "modify", "manage", "lock", - "unlock"] + actions = Resource.actions + ["create", "remove"] class User(Resource): http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/cc8d9fec/ambari-agent/src/main/python/resource_management/shell.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/shell.py b/ambari-agent/src/main/python/resource_management/shell.py index 8ca9306..13bb8a0 100644 --- a/ambari-agent/src/main/python/resource_management/shell.py +++ b/ambari-agent/src/main/python/resource_management/shell.py @@ -23,18 +23,16 @@ def _call(command, logoutput=False, throw_on_failure=True, @param logoutput: boolean, whether command output should be logged of not @param throw_on_failure: if true, when return code is not zero exception is thrown - @return: retrun_code, stdout, stderr + @return: retrun_code, stdout """ - if isinstance(command, (list, tuple)): - shell = False - else: - shell = True + shell = not isinstance(command, (list, tuple)) proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd, env=env, shell=shell, preexec_fn=preexec_fn) - out = proc.communicate()[0] + + out = proc.communicate()[0] if not proc.stdout.closed else "" code = proc.wait() if logoutput and out and out!="":
