def runCommandAndCheck(logger, command, timeout=DEFAULT_TIMEOUT, **popen_args): # Return (process, stdout) where stdout is a list of unicode strings popen_args.update({'stdout': PIPE, 'stderr': STDOUT}) cmdstr = formatCommand(command) process = createProcess(logger, command, **popen_args) status, stdout, stderr = communicateProcess(logger, process, timeout) if status: output = u'\n'.join(stdout) raise RunCommandError(cmdstr, unicode(status), output) else: command_str = popen_args.get('cmdstr', command) logger.debug("Success : '%s'" % unicode(command_str)) return process, stdout
def joinAd(logger, user, realm, password, block_tcp_53): if user is None: user = '' if realm is None: realm = '' if password is None: password = '' if not isinstance(block_tcp_53, basestring): raise ValueError("block_tcp_53 must be a string: 'no' or anything") #./script admin password DOMAIN_FQDN block_tcp_53(no/other) cmd = (_NET_JOIN_SCRIPT, user, password, realm, block_tcp_53) cmdstr = formatCommand((_NET_JOIN_SCRIPT, user, '***', realm, block_tcp_53)) process = createProcess(logger, cmd, stdout=PIPE, stderr=STDOUT, env={}, cmdstr=cmdstr) # FIXME: use communicateProcess() with a timeout stdout, stderr = process.communicate() return_code = process.wait() if return_code == 0: logger.critical("Join successful to domain %s" % realm) return stdout = stdout.strip() stdout = '\n'.join(stdout.splitlines()[:50]) if return_code == 1: format = tr("Unable to create temp file:\n%s") elif return_code == 2: format = tr("There was an error while getting a ticket granting ticket:\n%s") #Not always critical. continue ? For instance: unreachable server raise NuauthException(MAYBE_TEMPORARY_ERROR, format, stdout) elif return_code == 4: format = tr("There was en error while trying to join the domain:\n%s") elif return_code == 10: format = tr("Abnormal program termination:\n%s") else: format = tr("Exit code %s:") % return_code + "\n%s" raise NuauthException(NUAUTH_INVALID_CONF, format, stdout)