Ejemplo n.º 1
0
    def fix(self, status):
        if status.info['exists']:
            if self.attributes['delete']:
                msg = _("{node}:{item}: deleting...")
            else:
                msg = _("{node}:{item}: updating...")
        else:
            msg = _("{node}:{item}: creating...")
        LOG.info(msg.format(item=self.id, node=self.node.name))

        if self.attributes['delete']:
            self.node.run("userdel {}".format(self.name))
        else:
            self.node.run("{command} "
                "-d {home} "
                "-g {gid} "
                "-G {groups} "
                "-p {password_hash} "
                "-s {shell} "
                "-u {uid} "
                "{username}".format(
                    command="useradd" if not status.info['exists'] else "usermod",
                    home=quote(self.attributes['home']),
                    gid=self.attributes['gid'],
                    groups=quote(",".join(self.attributes['groups'])),
                    password_hash=quote(self.attributes['password_hash']),
                    shell=quote(self.attributes['shell']),
                    uid=self.attributes['uid'],
                    username=self.name,
                )
            )
Ejemplo n.º 2
0
    def run(self, interactive=False):
        result = self.bundle.node.run(
            self.attributes['command'],
            may_fail=True,
        )

        if self.attributes['expected_return_code'] is not None and \
                not result.return_code == self.attributes['expected_return_code']:
            if not interactive:
                LOG.error("{}:{}: {}".format(
                    self.bundle.node.name,
                    self.id,
                    red(_("FAILED")),
                ))
            raise ActionFailure(_(
                "wrong return code for action '{action}' in bundle '{bundle}': "
                "expected {ecode}, but was {rcode}"
            ).format(
                action=self.name,
                bundle=self.bundle.name,
                ecode=self.attributes['expected_return_code'],
                rcode=result.return_code,
            ))

        if self.attributes['expected_stderr'] is not None and \
                result.stderr != self.attributes['expected_stderr']:
            LOG.error("{}:{}: {}".format(
                self.bundle.node.name,
                self.id,
                red(_("FAILED")),
            ))
            raise ActionFailure(_(
                "wrong stderr for action '{action}' in bundle '{bundle}'"
            ).format(
                action=self.name,
                bundle=self.bundle.name,
            ))

        if self.attributes['expected_stdout'] is not None and \
                result.stdout != self.attributes['expected_stdout']:
            LOG.error("{}:{}: {}".format(
                self.bundle.node.name,
                self.id,
                red(_("FAILED")),
            ))
            raise ActionFailure(_(
                "wrong stdout for action '{action}' in bundle '{bundle}'"
            ).format(
                action=self.name,
                bundle=self.bundle.name,
            ))

        LOG.info("{}:{}: {}".format(
            self.bundle.node.name,
            self.id,
            green(_("OK")),
        ))

        return result
Ejemplo n.º 3
0
    def fix(self, status):
        if not status.info['exists']:
            LOG.info(_("{}:{}: creating...").format(self.node.name, self.id))
        else:
            LOG.info(_("{}:{}: updating...").format(self.node.name, self.id))

        self.node.run("echo '{} {} {}' | debconf-set-selections".format(
            self.attributes['pkg_name'],
            self.name,
            self.attributes['value'],
        ))
        sleep(1)
    def fix(self, status):
        if not status.info['exists']:
            LOG.info(_("{}:{}: creating...").format(self.node.name, self.id))
        else:
            LOG.info(_("{}:{}: updating...").format(self.node.name, self.id))

        self.node.run("echo '{} {} {}' | debconf-set-selections".format(
            self.attributes['pkg_name'],
            self.name,  
            self.attributes['value'],
        ))
        sleep(1)
Ejemplo n.º 5
0
 def fix(self, status):
     if self.attributes['installed'] is False:
         LOG.info(_("{node}:{item}: removing...").format(
             item=self.id,
             node=self.node.name,
         ))
         pkg_remove(self.node, self.name)
     else:
         LOG.info(_("{node}:{item}: installing...").format(
             item=self.id,
             node=self.node.name,
         ))
         pkg_install(self.node, self.name)
Ejemplo n.º 6
0
 def fix(self, status):
     if self.attributes['running'] is False:
         LOG.info(_("{node}:{item}: stopping...").format(
             item=self.id,
             node=self.node.name,
         ))
         svc_stop(self.node, self.name)
     else:
         LOG.info(_("{node}:{item}: starting...").format(
             item=self.id,
             node=self.node.name,
         ))
         svc_start(self.node, self.name)
Ejemplo n.º 7
0
    def fix(self, status):
        if 'type' in status.info['needs_fixing']:
            # fixing the type fixes everything
            if status.info['path_info'].exists:
                LOG.info(_("{node}:{item}: fixing type...").format(
                    item=self.id,
                    node=self.node.name,
                ))
            else:
                LOG.info(_("{node}:{item}: creating...").format(
                    item=self.id,
                    node=self.node.name,
                ))
            self._fix_type(status)
            return

        for fix_type in ('owner', 'group'):
            if fix_type in status.info['needs_fixing']:
                if fix_type == 'group' and \
                        'owner' in status.info['needs_fixing']:
                    # owner and group are fixed with a single chown
                    continue
                LOG.info(_("{node}:{item}: fixing {type}...").format(
                    item=self.id,
                    node=self.node.name,
                    type=fix_type,
                ))
                getattr(self, "_fix_" + fix_type)(status)
Ejemplo n.º 8
0
 def fix(self, status):
     if not status.info['exists']:
         LOG.info(_("{node}:{item}: creating...").format(node=self.node.name, item=self.id))
         self.node.run("groupadd -g {gid} {groupname}".format(
             gid=self.attributes['gid'],
             groupname=self.name,
         ))
     elif self.attributes['delete']:
         LOG.info(_("{node}:{item}: deleting...").format(node=self.node.name, item=self.id))
         self.node.run("groupdel {}".format(self.name))
     else:
         LOG.info(_("{node}:{item}: updating...").format(node=self.node.name, item=self.id))
         self.node.run("groupmod -g {gid} {groupname}".format(
             gid=self.attributes['gid'],
             groupname=self.name,
         ))
Ejemplo n.º 9
0
 def fix(self, status):
     for fix_type in ('type', 'content', 'mode', 'owner', 'group'):
         if fix_type in status.info['needs_fixing']:
             if fix_type == 'group' and \
                     'owner' in status.info['needs_fixing']:
                 # owner and group are fixed with a single chown
                 continue
             if fix_type in ('mode', 'owner', 'group') and \
                     'content' in status.info['needs_fixing']:
                 # fixing content implies settings mode and owner/group
                 continue
             if status.info['path_info'].exists:
                 if self.attributes['delete']:
                     LOG.info(_("{node}:{item}: deleting...").format(
                         node=self.node.name, item=self.id))
                 else:
                     LOG.info(_("{node}:{item}: fixing {type}...").format(
                         node=self.node.name, item=self.id, type=fix_type))
             else:
                 LOG.info(_("{node}:{item}: creating...").format(
                     node=self.node.name, item=self.id))
             getattr(self, "_fix_" + fix_type)(status)