예제 #1
0
    def test_basic_trackers(self):
        """Basic testing of all trackers; reset, and then retest."""
        sio_c = six.StringIO()
        sio_c2 = six.StringIO()
        sio_f = six.StringIO()
        sio_d = six.StringIO()

        tc = progress.CommandLineProgressTracker(output_file=sio_c)
        tc2 = progress.CommandLineProgressTracker(output_file=sio_c2,
                                                  term_delay=1)
        tf = progress.FunctionProgressTracker(output_file=sio_f)
        td = progress.DotProgressTracker(output_file=sio_d)
        tq = progress.QuietProgressTracker()

        mt = progress.MultiProgressTracker([tc, tc2, tf, tq, td])

        # run everything twice; this exercises that after a
        # reset(), everything still works correctly.
        for x in [1, 2]:
            progress.test_progress_tracker(mt, gofast=True)

            self.assertTrue(len(sio_c.getvalue()) > 100)
            self.assertTrue(len(sio_c2.getvalue()) > 100)
            self.assertTrue(len(sio_f.getvalue()) > 100)
            self.assertTrue(len(sio_d.getvalue()) > 1)
            # check that dot only printed dots
            self.assertTrue(len(sio_d.getvalue()) * "." == sio_d.getvalue())

            for f in [sio_c, sio_c2, sio_f, sio_d]:
                f.seek(0)
                f.truncate(0)

            # Reset them all, and go again, as a test of reset().
            mt.flush()
            mt.reset()
예제 #2
0
파일: test_ips.py 프로젝트: alhazred/caiman
 def test_prog_track_image_args(self):
     '''Test that setting progtrack in image args works'''
     self.tr_ips.image_args = {"progtrack": progress.QuietProgressTracker()}
     try:
         self.tr_ips.execute(dry_run=DRY_RUN)
     except Exception as err:
         self.fail(str(err))
예제 #3
0
파일: sysrepo.py 프로젝트: omniosorg/pkg5
def _get_image(image_dir):
        """Return a pkg.client.api.ImageInterface for the provided
        image directory."""

        cdir = os.getcwd()
        if not image_dir:
                image_dir = "/"
        api_inst = None
        tracker = progress.QuietProgressTracker()
        try:
                api_inst = pkg.client.api.ImageInterface(
                    image_dir, CLIENT_API_VERSION,
                    tracker, None, PKG_CLIENT_NAME)

                if api_inst.root != image_dir:
                        msg(_("Problem getting image at {0}").format(
                            image_dir))
        except Exception as err:
                raise SysrepoException(
                    _("Unable to get image at {dir}: {reason}").format(
                    dir=image_dir,
                    reason=str(err)))

        # restore the current directory, which ImageInterace had changed
        os.chdir(cdir)
        return api_inst
예제 #4
0
def get_tracker(quiet=False):
        if quiet:
                progresstracker = progress.QuietProgressTracker()
        else:
                try:
                        progresstracker = \
                            progress.FancyUNIXProgressTracker()
                except progress.ProgressTrackerException:
                        progresstracker = progress.CommandLineProgressTracker()
        return progresstracker
예제 #5
0
파일: pkgdep.py 프로젝트: sunsparc64/pkg5
def resolve(args, img_dir):
    """Take a list of manifests and resolve any file dependencies, first
        against the other published manifests and then against what is installed
        on the machine."""
    out_dir = None
    echo_manifest = False
    output_to_screen = False
    suffix = None
    verbose = False
    use_system_to_resolve = True
    constraint_files = []
    extra_external_info = False
    try:
        opts, pargs = getopt.getopt(args, "d:e:Emos:Sv")
    except getopt.GetoptError as e:
        usage(_("illegal global option -- {0}").format(e.opt))
    for opt, arg in opts:
        if opt == "-d":
            out_dir = arg
        elif opt == "-e":
            constraint_files.append(arg)
        elif opt == "-E":
            extra_external_info = True
        elif opt == "-m":
            echo_manifest = True
        elif opt == "-o":
            output_to_screen = True
        elif opt == "-s":
            suffix = arg
        elif opt == "-S":
            use_system_to_resolve = False
        elif opt == "-v":
            verbose = True

    if (out_dir or suffix) and output_to_screen:
        usage(_("-o cannot be used with -d or -s"))

    manifest_paths = [os.path.abspath(fp) for fp in pargs]

    for manifest in manifest_paths:
        if not os.path.isfile(manifest):
            usage(_("The manifest file {0} could not be found.").format(
                manifest),
                  retcode=2)

    if out_dir:
        out_dir = os.path.abspath(out_dir)
        if not os.path.isdir(out_dir):
            usage(_("The output directory {0} is not a directory.").format(
                out_dir),
                  retcode=2)

    provided_image_dir = True
    pkg_image_used = False
    if img_dir == None:
        orig_cwd = None
        try:
            orig_cwd = os.getcwd()
        except OSError:
            # May be unreadable by user or have other problem.
            pass

        img_dir, provided_image_dir = api.get_default_image_root(
            orig_cwd=orig_cwd)
        if os.environ.get("PKG_IMAGE"):
            # It's assumed that this has been checked by the above
            # function call and hasn't been removed from the
            # environment.
            pkg_image_used = True

    if not img_dir:
        error(
            _("Could not find image.  Use the -R option or set "
              "$PKG_IMAGE to the\nlocation of an image."))
        return 1

    system_patterns = misc.EmptyI
    if constraint_files:
        system_patterns = []
        for f in constraint_files:
            try:
                with open(f, "rb") as fh:
                    for l in fh:
                        l = l.strip()
                        if l and not l.startswith("#"):
                            system_patterns.append(l)
            except EnvironmentError as e:
                if e.errno == errno.ENOENT:
                    error("{0}: '{1}'".format(e.args[1], e.filename),
                          cmd="resolve")
                    return 1
                raise api_errors._convert_error(e)
        if not system_patterns:
            error(
                _("External package list files were provided but "
                  "did not contain any fmri patterns."))
            return 1
    elif use_system_to_resolve:
        system_patterns = ["*"]

    # Becuase building an ImageInterface permanently changes the cwd for
    # python, it's necessary to do this step after resolving the paths to
    # the manifests.
    try:
        api_inst = api.ImageInterface(img_dir,
                                      CLIENT_API_VERSION,
                                      progress.QuietProgressTracker(),
                                      None,
                                      PKG_CLIENT_NAME,
                                      exact_match=provided_image_dir)
    except api_errors.ImageNotFoundException as e:
        if e.user_specified:
            if pkg_image_used:
                error(
                    _("No image rooted at '{0}' "
                      "(set by $PKG_IMAGE)").format(e.user_dir))
            else:
                error(_("No image rooted at '{0}'").format(e.user_dir))
        else:
            error(_("No image found."))
        return 1
    except api_errors.PermissionsException as e:
        error(e)
        return 1
    except api_errors.ImageFormatUpdateNeeded as e:
        # This should be a very rare error case.
        format_update_error(e)
        return 1

    try:
        pkg_deps, errs, unused_fmris, external_deps = \
            dependencies.resolve_deps(manifest_paths, api_inst,
                system_patterns, prune_attrs=not verbose)
    except (actions.MalformedActionError, actions.UnknownActionError) as e:
        error(
            _("Could not parse one or more manifests because of "
              "the following line:\n{0}").format(e.actionstr))
        return 1
    except dependencies.DependencyError as e:
        error(e)
        return 1
    except api_errors.ApiException as e:
        error(e)
        return 1
    ret_code = 0

    if output_to_screen:
        ret_code = pkgdeps_to_screen(pkg_deps, manifest_paths, echo_manifest)
    elif out_dir:
        ret_code = pkgdeps_to_dir(pkg_deps, manifest_paths, out_dir, suffix,
                                  echo_manifest)
    else:
        ret_code = pkgdeps_in_place(pkg_deps, manifest_paths, suffix,
                                    echo_manifest)

    if extra_external_info:
        if constraint_files and unused_fmris:
            msg(
                _("\nThe following fmris matched a pattern in a "
                  "constraint file but were not used in\ndependency "
                  "resolution:"))
            for pfmri in sorted(unused_fmris):
                msg("\t{0}".format(pfmri))
        if not constraint_files and external_deps:
            msg(_("\nThe following fmris had dependencies resolve "
                  "to them:"))
            for pfmri in sorted(external_deps):
                msg("\t{0}".format(pfmri))

    for e in errs:
        if ret_code == 0:
            ret_code = 1
        emsg(e)
    return ret_code
예제 #6
0
    def test_11_ClientInterface(self):
        """Test the clientInterface class."""
        pt = progress.QuietProgressTracker()
        cli_inst = cli_api.ClientInterface(
            pkg_image=self.img_path(),
            prog_tracker=pt,
            opts_mapping={"be_name": "boot_env"})
        opts = {"repo_uri": self.rurl1}
        retjson = cli_inst.publisher_set(json.dumps([]), json.dumps(opts))
        epset_schema_in = cli_inst.get_pkg_input_schema("set-publisher")
        epset_schema_out = cli_inst.get_pkg_output_schema("set-publisher")
        epset_input = {"pargs_json": [], "opts_json": opts}
        self.assert_(self.__schema_validation(epset_input, epset_schema_in))
        self.assert_(self.__schema_validation(retjson, epset_schema_out))

        # Test uninstalling an not installed pkg.
        opts = {}
        args = ["no_install"]
        retjson = cli_inst.uninstall(json.dumps(args), json.dumps(opts))
        self.assert_(retjson["status"] == 1)
        self.assert_("errors" in retjson)
        eunins_schema_in = cli_inst.get_pkg_input_schema("uninstall")
        # Test input schema was replaced by an mapped option name.
        self.assert_("boot_env" in json.dumps(eunins_schema_in))
        eunins_schema_out = cli_inst.get_pkg_output_schema("uninstall")
        eunins_input = {"pargs_json": args, "opts_json": opts}
        self.assert_(self.__schema_validation(eunins_input, eunins_schema_in))
        self.assert_(self.__schema_validation(retjson, eunins_schema_out))

        # Test be related exception does not crash the system.
        opts = {"boot_env": "s12"}
        args = ["no_install"]
        retjson = cli_inst.uninstall(json.dumps(args), json.dumps(opts))
        self.assert_(retjson["status"] == 1)
        self.assert_("errors" in retjson)
        self.assert_("boot_env" not in json.dumps(retjson))

        retjson = cli_inst.uninstall(json.dumps(["newpkg2"]), json.dumps({}))
        self.assert_(retjson["status"] == 1)
        self.assert_("errors" in retjson)

        opts = {"parsable_version": 0}
        args = ["[email protected]"]
        retjson = cli_inst.install(json.dumps(args), json.dumps(opts))
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)
        eins_schema_in = cli_inst.get_pkg_input_schema("install")
        eins_schema_out = cli_inst.get_pkg_output_schema("install")
        eins_input = {"pargs_json": args, "opts_json": opts}
        self.assert_(self.__schema_validation(eins_input, eins_schema_in))
        self.assert_(self.__schema_validation(retjson, eins_schema_out))

        retjson = cli_inst.list_inventory()
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)
        self.assert_("newpkg2" in json.dumps(retjson))

        retjson = cli_inst.uninstall(json.dumps(args), json.dumps(opts))
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        retjson = cli_inst.publisher_set(json.dumps(["test1"]))
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)