Beispiel #1
0
    def create_working_dir(self, local_dir, config_dir):
        # make sure we are working with abspath however tempest init is called
        local_dir = os.path.abspath(local_dir)
        # Create local dir if missing
        if not os.path.isdir(local_dir):
            LOG.debug('Creating local working dir: %s' % local_dir)
            os.mkdir(local_dir)
        elif not os.listdir(local_dir) == []:
            raise OSError("Directory you are trying to initialize already "
                          "exists and is not empty: %s" % local_dir)

        etc_dir = os.path.join(local_dir, 'etc')
        log_dir = os.path.join(local_dir, 'logs')
        testr_dir = os.path.join(local_dir, '.testrepository')
        # Create log dir
        if not os.path.isdir(log_dir):
            LOG.debug('Creating log dir: %s' % log_dir)
            os.mkdir(log_dir)
        # Create and copy local etc dir
        self.copy_config(etc_dir, config_dir)
        # Generate the sample config file
        self.generate_sample_config(local_dir)
        # Generate a testr conf file
        self.generate_testr_conf(local_dir)
        # setup local testr working dir
        if not os.path.isdir(testr_dir):
            commands.run_argv(['testr', 'init', '-d', local_dir], sys.stdin,
                              sys.stdout, sys.stderr)
Beispiel #2
0
    def take_action(self, parsed_args):
        returncode = 0
        if parsed_args.config_file:
            self._set_env(parsed_args.config_file)
        else:
            self._set_env()
        # Workspace execution mode
        if parsed_args.workspace:
            workspace_mgr = workspace.WorkspaceManager(
                parsed_args.workspace_path)
            path = workspace_mgr.get_workspace(parsed_args.workspace)
            if not path:
                sys.exit("The %r workspace isn't registered in "
                         "%r. Use 'tempest init' to "
                         "register the workspace." %
                         (parsed_args.workspace, workspace_mgr.path))
            os.chdir(path)
            # NOTE(mtreinish): tempest init should create a .testrepository dir
            # but since workspaces can be imported let's sanity check and
            # ensure that one is created
            self._create_testrepository()
        # Local execution mode
        elif os.path.isfile('.testr.conf'):
            # If you're running in local execution mode and there is not a
            # testrepository dir create one
            self._create_testrepository()
        # local execution with config file mode
        elif parsed_args.config_file:
            self._create_testr_conf()
            self._create_testrepository()
        else:
            print("No .testr.conf file was found for local execution")
            sys.exit(2)
        if parsed_args.combine:
            temp_stream = tempfile.NamedTemporaryFile()
            return_code = run_argv(['tempest', 'last', '--subunit'], sys.stdin,
                                   temp_stream, sys.stderr)
            if return_code > 0:
                sys.exit(return_code)

        regex = self._build_regex(parsed_args)
        if parsed_args.list_tests:
            argv = ['tempest', 'list-tests', regex]
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            options = self._build_options(parsed_args)
            returncode = self._run(regex, options)
            if returncode > 0:
                sys.exit(returncode)

        if parsed_args.combine:
            return_code = run_argv(['tempest', 'last', '--subunit'], sys.stdin,
                                   temp_stream, sys.stderr)
            if return_code > 0:
                sys.exit(return_code)
            returncode = run_argv(['tempest', 'load', temp_stream.name],
                                  sys.stdin, sys.stdout, sys.stderr)
        sys.exit(returncode)
Beispiel #3
0
    def _run(self, regex, options):
        returncode = 0
        argv = ['tempest', 'run', regex] + options
        if '--subunit' in options:
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            argv.append('--subunit')
            stdin = io.StringIO()
            stdout_r, stdout_w = os.pipe()
            subunit_w = os.fdopen(stdout_w, 'wt')
            subunit_r = os.fdopen(stdout_r)
            returncodes = {}

            def run_argv_thread():
                returncodes['testr'] = run_argv(argv, stdin, subunit_w,
                                                sys.stderr)
                subunit_w.close()

            run_thread = threading.Thread(target=run_argv_thread)
            run_thread.start()
            returncodes['subunit-trace'] = subunit_trace.trace(subunit_r,
                                                               sys.stdout)
            run_thread.join()
            subunit_r.close()
            # python version of pipefail
            if returncodes['testr']:
                returncode = returncodes['testr']
            elif returncodes['subunit-trace']:
                returncode = returncodes['subunit-trace']
        return returncode
Beispiel #4
0
    def take_action(self, parsed_args):
        returncode = 0
        if parsed_args.config_file:
            self._set_env(parsed_args.config_file)
        else:
            self._set_env()
        # Local execution mode
        if os.path.isfile('.testr.conf'):
            # If you're running in local execution mode and there is not a
            # testrepository dir create one
            self._create_testrepository()
        # local execution with config file mode
        elif parsed_args.config_file:
            self._create_testr_conf()
            self._create_testrepository()
        else:
            print("No .testr.conf file was found for local execution")
            sys.exit(2)

        regex = self._build_regex(parsed_args)
        if parsed_args.list_tests:
            argv = ['testcases', 'list-tests', regex]
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            options = self._build_options(parsed_args)
            returncode = self._run(regex, options)
        sys.exit(returncode)
Beispiel #5
0
    def _run(self, regex, options):
        returncode = 0
        argv = ['tempest', 'run', regex] + options
        if '--subunit' in options:
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            argv.append('--subunit')
            stdin = io.StringIO()
            stdout_r, stdout_w = os.pipe()
            subunit_w = os.fdopen(stdout_w, 'wt')
            subunit_r = os.fdopen(stdout_r)
            returncodes = {}

            def run_argv_thread():
                returncodes['testr'] = run_argv(argv, stdin, subunit_w,
                                                sys.stderr)
                subunit_w.close()

            run_thread = threading.Thread(target=run_argv_thread)
            run_thread.start()
            returncodes['subunit-trace'] = subunit_trace.trace(
                subunit_r, sys.stdout)
            run_thread.join()
            subunit_r.close()
            # python version of pipefail
            if returncodes['testr']:
                returncode = returncodes['testr']
            elif returncodes['subunit-trace']:
                returncode = returncodes['subunit-trace']
        return returncode
Beispiel #6
0
    def take_action(self, parsed_args):
        self._set_env()
        # Local exceution mode
        if os.path.isfile('.testr.conf'):
            # If you're running in local execution mode and there is not a
            # testrepository dir create one
            if not os.path.isdir('.testrepository'):
                returncode = run_argv(['testr', 'init'], sys.stdin, sys.stdout,
                                      sys.stderr)
            if returncode:
                sys.exit(returncode)
        else:
            print("No .testr.conf file was found for local exceution")
            sys.exit(2)

        regex = self._build_regex(parsed_args)
        if parsed_args.list_tests:
            argv = ['tempest', 'list-tests', regex]
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            options = self._build_options(parsed_args)
            returncode = self._run(regex, options)
        sys.exit(returncode)
Beispiel #7
0
    def create_working_dir(self, local_dir, config_dir):
        # make sure we are working with abspath however tempest init is called
        local_dir = os.path.abspath(local_dir)
        # Create local dir if missing
        if not os.path.isdir(local_dir):
            LOG.debug('Creating local working dir: %s' % local_dir)
            os.mkdir(local_dir)
        elif not os.listdir(local_dir) == []:
            raise OSError("Directory you are trying to initialize already "
                          "exists and is not empty: %s" % local_dir)

        lock_dir = os.path.join(local_dir, 'tempest_lock')
        etc_dir = os.path.join(local_dir, 'etc')
        config_path = os.path.join(etc_dir, 'tempest.conf')
        log_dir = os.path.join(local_dir, 'logs')
        testr_dir = os.path.join(local_dir, '.testrepository')
        # Create lock dir
        if not os.path.isdir(lock_dir):
            LOG.debug('Creating lock dir: %s' % lock_dir)
            os.mkdir(lock_dir)
        # Create log dir
        if not os.path.isdir(log_dir):
            LOG.debug('Creating log dir: %s' % log_dir)
            os.mkdir(log_dir)
        # Create and copy local etc dir
        self.copy_config(etc_dir, config_dir)
        # Generate the sample config file
        self.generate_sample_config(local_dir)
        # Update local confs to reflect local paths
        self.update_local_conf(config_path, lock_dir, log_dir)
        # Generate a testr conf file
        self.generate_testr_conf(local_dir)
        # setup local testr working dir
        if not os.path.isdir(testr_dir):
            commands.run_argv(['testr', 'init', '-d', local_dir], sys.stdin,
                              sys.stdout, sys.stderr)
Beispiel #8
0
    def take_action(self, parsed_args):
        returncode = 0
        if parsed_args.config_file:
            self._set_env(parsed_args.config_file)
        else:
            self._set_env()
        # Workspace execution mode
        if parsed_args.workspace:
            workspace_mgr = workspace.WorkspaceManager(
                parsed_args.workspace_path)
            path = workspace_mgr.get_workspace(parsed_args.workspace)
            if not path:
                sys.exit(
                    "The %r workspace isn't registered in "
                    "%r. Use 'tempest init' to "
                    "register the workspace." %
                    (parsed_args.workspace, workspace_mgr.path))
            os.chdir(path)
            # NOTE(mtreinish): tempest init should create a .testrepository dir
            # but since workspaces can be imported let's sanity check and
            # ensure that one is created
            self._create_testrepository()
        # Local execution mode
        elif os.path.isfile('.testr.conf'):
            # If you're running in local execution mode and there is not a
            # testrepository dir create one
            self._create_testrepository()
        # local execution with config file mode
        elif parsed_args.config_file:
            self._create_testr_conf()
            self._create_testrepository()
        else:
            print("No .testr.conf file was found for local execution")
            sys.exit(2)

        regex = self._build_regex(parsed_args)
        if parsed_args.list_tests:
            argv = ['tempest', 'list-tests', regex]
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            options = self._build_options(parsed_args)
            returncode = self._run(regex, options)
        sys.exit(returncode)
Beispiel #9
0
    def take_action(self, parsed_args):
        returncode = 0
        if parsed_args.config_file:
            self._set_env(parsed_args.config_file)
        else:
            self._set_env()
        # Workspace execution mode
        if parsed_args.workspace:
            workspace_mgr = workspace.WorkspaceManager(
                parsed_args.workspace_path)
            path = workspace_mgr.get_workspace(parsed_args.workspace)
            os.chdir(path)
            # NOTE(mtreinish): tempest init should create a .testrepository dir
            # but since workspaces can be imported let's sanity check and
            # ensure that one is created
            self._create_testrepository()
        # Local execution mode
        elif os.path.isfile('.testr.conf'):
            # If you're running in local execution mode and there is not a
            # testrepository dir create one
            self._create_testrepository()
        # local execution with config file mode
        elif parsed_args.config_file:
            self._create_testr_conf()
            self._create_testrepository()
        else:
            print("No .testr.conf file was found for local execution")
            sys.exit(2)

        regex = self._build_regex(parsed_args)
        if parsed_args.list_tests:
            argv = ['tempest', 'list-tests', regex]
            returncode = run_argv(argv, sys.stdin, sys.stdout, sys.stderr)
        else:
            options = self._build_options(parsed_args)
            returncode = self._run(regex, options)
        sys.exit(returncode)
 def _run_testr(self, *args):
     logger.info("_run_testr called")
     return commands.run_argv([sys.argv[0]] + list(args),
                              sys.stdin, sys.stdout, sys.stderr)
Beispiel #11
0
 def _run_testr(self, *args):
     logger.debug("_run_testr called with args = %r", args)
     return commands.run_argv([sys.argv[0]] + list(args), sys.stdin,
                              sys.stdout, sys.stderr)
Beispiel #12
0
 def _run_testr(self, *args):
     return commands.run_argv([sys.argv[0]] + list(args),
                              sys.stdin, sys.stdout, sys.stderr)
Beispiel #13
0
 def test_looks_up_cmd_skips_options(self):
     self.stub__find_command(lambda x:0)
     commands.run_argv(['testr', '--version', 'foo'], 'in', 'out', 'err')
     self.assertEqual(['foo'], self.calls)
Beispiel #14
0
 def run_argv_thread():
     returncodes['testr'] = run_argv(argv, stdin, subunit_w,
                                     sys.stderr)
     subunit_w.close()
 def test_returns_execute_result(self):
     self.stub__find_command(lambda x: 1)
     self.assertEqual(
         1, commands.run_argv(['testr', 'foo'], 'in', 'out', 'err'))
Beispiel #16
0
 def _create_testrepository(self):
     if not os.path.isdir('.testrepository'):
         returncode = run_argv(['testr', 'init'], sys.stdin, sys.stdout,
                               sys.stderr)
         if returncode:
             sys.exit(returncode)
Beispiel #17
0
 def test_no_cmd_issues_help(self):
     self.stub__find_command(lambda x:0)
     commands.run_argv(['testr', '--version'], 'in', 'out', 'err')
     self.assertEqual(['help'], self.calls)
 def test_returns_0_when_None_returned_from_execute(self):
     self.stub__find_command(lambda x: None)
     self.assertEqual(
         0, commands.run_argv(['testr', 'foo'], 'in', 'out', 'err'))
Beispiel #19
0
 def test_runs_cmd_with_CLI_UI(self):
     self.stub__find_command(self.capture_ui)
     commands.run_argv(['testr', '--version', 'foo'], 'in', 'out', 'err')
     self.assertEqual(['foo'], self.calls)
     self.assertIsInstance(self.ui, cli.UI)
Beispiel #20
0
 def _create_testrepository(self):
     if not os.path.isdir('.testrepository'):
         returncode = run_argv(['testr', 'init'], sys.stdin, sys.stdout,
                               sys.stderr)
         if returncode:
             sys.exit(returncode)
 def _run_testr(self, *args):
     return commands.run_argv([sys.argv[0]] + list(args), sys.stdin,
                              sys.stdout, sys.stderr)
Beispiel #22
0
 def test_returns_execute_result(self):
     self.stub__find_command(lambda x:1)
     self.assertEqual(1, commands.run_argv(['testr', 'foo'], 'in', 'out',
         'err'))
Beispiel #23
0
 def test_returns_0_when_None_returned_from_execute(self):
     self.stub__find_command(lambda x:None)
     self.assertEqual(0, commands.run_argv(['testr', 'foo'], 'in', 'out',
         'err'))
Beispiel #24
0
 def _run_testr(self, *args):
     logger.debug("_run_testr called with args = %r", args)
     return commands.run_argv([sys.argv[0]] + list(args),
                              sys.stdin, sys.stdout, sys.stderr)
 def test_looks_up_cmd_skips_options(self):
     self.stub__find_command(lambda x: 0)
     commands.run_argv(['testr', '--version', 'foo'], 'in', 'out', 'err')
     self.assertEqual(['foo'], self.calls)
 def test_no_cmd_issues_help(self):
     self.stub__find_command(lambda x: 0)
     commands.run_argv(['testr', '--version'], 'in', 'out', 'err')
     self.assertEqual(['help'], self.calls)
 def test_runs_cmd_with_CLI_UI(self):
     self.stub__find_command(self.capture_ui)
     commands.run_argv(['testr', '--version', 'foo'], 'in', 'out', 'err')
     self.assertEqual(['foo'], self.calls)
     self.assertIsInstance(self.ui, cli.UI)
Beispiel #28
0
 def run_argv_thread():
     returncodes['testr'] = run_argv(argv, stdin, subunit_w,
                                     sys.stderr)
     subunit_w.close()
Beispiel #29
0
 def _run_testr(self, *args):
     logger.info("_run_testr called")
     return commands.run_argv([sys.argv[0]] + list(args), sys.stdin,
                              sys.stdout, sys.stderr)