Exemplo n.º 1
0
    def check(self):
        initial = 'duckiebot-not-configured'

        cmd = 'iwconfig'

        try:
            res = system_cmd_result(None,
                                    cmd,
                                    display_stdout=False,
                                    display_stderr=False,
                                    raise_on_error=True,
                                    capture_keyboard_interrupt=False,
                                    env=None)
        except CmdException as e:
            msg = 'The command failed\n'
            msg += '\n' + indent(e, ' >')
            raise CheckError(msg)

        if initial in res.stdout:
            msg = 'The robot is creating a network %r.' % initial
            l = 'According to iwconfig, you are creating a network %r.' % initial
            l += '\nThis means that you have failed to properly configure the robot.'
            l += '\nIt is likely the people around you are trying to connect to your robot.'

            l += '\n\nEntire output of iwconfig:\n\n' + indent(
                res.stdout, '  > ')
            raise CheckFailed(msg, l)
Exemplo n.º 2
0
    def check(self):
        expect = '4.4.38-v7+'
        cmd = ['uname', '-r']

        try:
            res = system_cmd_result(None,
                                    cmd,
                                    display_stdout=False,
                                    display_stderr=False,
                                    raise_on_error=True,
                                    capture_keyboard_interrupt=False,
                                    env=None)
        except CmdException as e:
            msg = 'The command failed\n'
            msg += '\n' + indent(e, ' >')
            raise CheckError(msg)

        found = res.stdout.strip()
        if found != expect:
            msg = 'You are running kernel %r instead of %r.' % (found, expect)
            l = 'The kernel version is important because otherwise the Edimax\n'
            l += 'driver will not work correctly and needs to be recompiled.\n'
            l += '\n'
            l += 'Please report this error because we thought that the kernel\n'
            l += 'was prevented to update.'
            raise CheckFailed(msg, l)
Exemplo n.º 3
0
 def check(self):
     if self.name not in os.environ:
         msg = 'Could not find environment variable %r.' % self.name
         raise CheckError(msg)
     
     value = os.environ[self.name]
     
     if value != self.expected:
         msg = 'Value of $%s is %r instead of %r.' % (self.name, value, self.expected)
         raise CheckFailed(msg)
Exemplo n.º 4
0
    def check(self): 
        try:
            contents = get_scuderia_contents()
        except ScuderiaException as e:
            msg  = 'Invalid scuderia file.'
            l = str(e)
            raise CheckError(msg, l)

        robot_name = socket.gethostname()
        if not robot_name in contents:
            msg = 'There is no entry "%s" in the scuderia file.' % robot_name
            raise CheckFailed(msg)
Exemplo n.º 5
0
    def check(self):
        try:
            path_machines = get_machines_files_path()
            path_scuderia = get_scuderia_path()
        except DTConfigException as e:
            msg = 'Could not get path to machines.'
            raise_wrapped(CheckError, e, msg)

        if not os.path.exists(path_machines):
            msg = 'Machines file does not exist.'
            raise CheckError(msg)

        if not os.path.exists(path_scuderia):
            msg = 'Scuderia file does not exist.'
            raise CheckError(msg)

        f1 = os.path.getmtime(path_machines)
        f2 = os.path.getmtime(path_scuderia)

        if f2 > f1:
            msg = 'The machines file is older than the scuderia file.'
            raise CheckFailed(msg)
Exemplo n.º 6
0
def get_active_groups(username):
    cmd = ['groups', username]
    try:
        res = system_cmd_result('.',
                                cmd,
                                display_stdout=False,
                                display_stderr=False,
                                raise_on_error=True,
                                capture_keyboard_interrupt=False,
                                env=None)
    except CmdException as e:
        raise CheckError(str(e))
    active_groups = res.stdout.split()  # XXX
    return active_groups
Exemplo n.º 7
0
    def check(self):
        fn = expand_all(self.filename)

        if not os.path.exists(fn):
            msg = 'File does not exist: %s' % fn
            raise CheckError(msg)

        contents = open(fn).read()

        l = 'Entire contents of %s:\n' % fn + indent(contents, '  > ')

        if not self.string in contents:
            msg = 'String %r not contained in %s' % (self.string, fn)
            raise CheckFailed(msg, l)
Exemplo n.º 8
0
    def check(self):
        fn = expand_all(self.filename)

        if not os.path.exists(fn):
            msg = 'Cannot check permissions if file or dir does not exist.'
            raise CheckError(msg)

        fstats = os.stat(fn)
        filemode = oct(stat.S_IMODE(fstats.st_mode))
        if len(filemode) > 4:
            filemode = filemode[-4:]
        if filemode != self.expected:
            msg = ('Expected mode %r, obtained %r.' %
                   (self.expected, filemode))
            raise CheckFailed(msg)
Exemplo n.º 9
0
def fail_if_stdout_contains(cwd, cmd, substring):
    try:
        res = system_cmd_result(cwd,
                                cmd,
                                display_stdout=False,
                                display_stderr=False,
                                raise_on_error=True,
                                capture_keyboard_interrupt=False,
                                env=None)
    except CmdException as e:
        msg = 'The command failed\n'
        msg += '\n' + indent(e, ' >')
        raise CheckError(msg)

    if substring in res.stdout:
        compact = ('I found the string "%s" in output of `%s`' %
                   (substring, " ".join(cmd)))
        long_explanation = 'Complete output is:\n\n' + indent(
            res.stdout.strip(), ' > ')
        raise CheckFailed(compact, long_explanation)
Exemplo n.º 10
0
def fail_if_stdout_does_not_contain(cwd, cmd, substring):
    try:
        res = dtu.system_cmd_result(cwd,
                                    cmd,
                                    display_stdout=False,
                                    display_stderr=False,
                                    raise_on_error=True,
                                    capture_keyboard_interrupt=False,
                                    env=None)
    except dtu.CmdException as e:
        msg = 'The command failed\n'
        msg += '\n' + dtu.indent(e, ' >')
        raise CheckError(msg)

    if not substring in res.stdout:
        compact = ('Could not find string "%s" in output of %s.' %
                   (substring, cmd))
        long_explanation = 'Complete output is:\n\n' + dtu.indent(
            res.stdout, ' > ')
        raise CheckFailed(compact, long_explanation)
Exemplo n.º 11
0
 def check(self):
     msg = 'Always fails'
     l = "(long error)" if self.has_long_error else None
     raise CheckError(msg, l)
Exemplo n.º 12
0
def raise_CheckError_from_CommandResult(res, msg = 'Command failed'):
    assert isinstance(res, dtu.CmdResult), res
    l = summary_of_cmdres(res)
    raise CheckError(msg, l)