示例#1
0
    def test_06_uninstall_args_opts(self):
        """Test json args or opts for update command."""

        global_settings.client_output_quiet = True
        self.image_create(self.rurl1, prefix="test1")
        os.environ["PKG_IMAGE"] = self.img_path()
        # Test invalid pkg name.
        pkgs = [1, 2, 3]
        opts = {}
        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assertTrue("errors" in retjson)
        self.assertTrue(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        pkgs = [None]
        opts = {}
        os.environ["PKG_IMAGE"] = self.img_path()
        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assertTrue("errors" in retjson)
        self.assertTrue(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        # Test unknown option was reported.
        pkgs = ["[email protected]"]
        opts = {"unknown": "solaris"}
        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assertTrue("invalid option" in retjson["errors"][0]["reason"])

        # Test without pkg specified.
        pkgs = []
        opts = {"verbose": 3}
        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assertTrue(
            "at least one package" in retjson["errors"][0]["reason"])

        # Run through pkg uninstall.
        self.pkg("install pkg://test1/[email protected]")
        pkgs = ["foo"]
        opts = {"verbose": 3, "parsable_version": 0}

        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assertTrue("errors" not in retjson)
        self.assertTrue(retjson["status"] == 0)
        global_settings.client_output_quiet = False

        # Test input directly against schema.
        pargs = "pargs_json"
        uninstall_schema = cli_api._get_pkg_input_schema("uninstall")
        uninstall_input = {pargs: ["pkg"], "opts_json": {}}
        self.assertTrue(
            self.__schema_validation(uninstall_input, uninstall_schema))

        uninstall_input = {pargs: None, "opts_json": {}}
        self.assertTrue(
            not self.__schema_validation(uninstall_input, uninstall_schema))

        uninstall_input = {pargs: [], "opts_json": {"ignore_missing": True}}
        self.assertTrue(
            self.__schema_validation(uninstall_input, uninstall_schema))
示例#2
0
    def test_03_list_json_args_opts(self):
        """Test json args or opts for list command."""

        self.image_create(self.rurl1, prefix="test1")
        pkgs = [1, 2, 3]
        opts = {"list_installed_newest": True, "list_all": True}
        os.environ["PKG_IMAGE"] = self.img_path()
        retjson = self.__call_cmd("list", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        pkgs = [None]
        retjson = self.__call_cmd("list", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        pkgs = []
        opts = {"list_installed_newest": 1}
        retjson = self.__call_cmd("list", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'boolean'" in retjson["errors"][0]["reason"])

        opts = {"origins": 1}
        retjson = self.__call_cmd("list", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'array'" in retjson["errors"][0]["reason"])

        opts = {"random": 1}
        retjson = self.__call_cmd("list", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_("invalid option" in \
            retjson["errors"][0]["reason"])

        # Test args and opts directly against schema.
        pargs = "pargs_json"
        list_schema = cli_api._get_pkg_input_schema("list")
        list_input = {pargs: [], "opts_json": {}}
        self.assert_(self.__schema_validation(list_input, list_schema))

        list_input = {pargs: [12], "opts_json": {}}
        self.assert_(not self.__schema_validation(list_input, list_schema))

        list_input = {pargs: [], "opts_json": {"list_upgradable": "string"}}
        self.assert_(not self.__schema_validation(list_input, list_schema))

        list_input = {pargs: [], "opts_json": {"list_upgradable": False}}
        self.assert_(self.__schema_validation(list_input, list_schema))

        list_input = {pargs: [], "opts_json": {"origins": False}}
        self.assert_(not self.__schema_validation(list_input, list_schema))

        list_input = {pargs: [], "opts_json": {"origins": []}}
        self.assert_(self.__schema_validation(list_input, list_schema))
示例#3
0
def rad_get_input_schema(operation):
        """Get the input schema for RAD operation."""

        pkg_cmd = __correspond_pkg_cmd(operation)
        return entry._get_pkg_input_schema(pkg_cmd, opts_mapping)
示例#4
0
    def test_10_exact_install_json_args_opts(self):
        """Test json args or opts for exact-install command."""

        # Test invalid pkg name.
        self.image_create(self.rurl1, prefix="test1")
        os.environ["PKG_IMAGE"] = self.img_path()
        pkgs = [1, 2, 3]
        opts = {"backup_be": True}
        retjson = self.__call_cmd("exact-install", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        pkgs = [None]
        opts = {"backup_be": True}
        os.environ["PKG_IMAGE"] = self.img_path()
        retjson = self.__call_cmd("exact-install", pkgs, opts)
        self.assert_("errors" in retjson)
        self.assert_(
            "is not of type 'string'" in retjson["errors"][0]["reason"])

        # Test unknown option was reported.
        pkgs = ["[email protected]"]
        opts = {"unknown": "solaris"}
        retjson = self.__call_cmd("exact-install", pkgs, opts)
        self.assert_("invalid option" in retjson["errors"][0]["reason"])

        # Test without pkg specified.
        pkgs = []
        opts = {"verbose": 3}
        retjson = self.__call_cmd("exact-install", pkgs, opts)
        self.assert_("at least one package" in retjson["errors"][0]["reason"])

        # Run through pkg install.
        pkgs = ["[email protected]"]
        opts = {"verbose": 3, "parsable_version": 0}
        global_settings.client_output_quiet = True
        retjson = self.__call_cmd("exact-install", pkgs, opts)
        global_settings.client_output_quiet = False

        # Test input directly against schema.
        pargs = "pargs_json"
        einstall_schema = cli_api._get_pkg_input_schema("exact-install")
        einstall_input = {pargs: [], "opts_json": {}}
        self.assert_(self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: [12], "opts_json": {}}
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {}}
        self.assert_(self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {
            pargs: ["pkg"],
            "opts_json": {
                "parsable_version": "string"
            }
        }
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {"parsable_version": 3}}
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {
            pargs: ["pkg"],
            "opts_json": {
                "parsable_version": None
            }
        }
        self.assert_(self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {"reject_pats": False}}
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {"reject_pats": []}}
        self.assert_(self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {"accept": "str"}}
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: ["pkg"], "opts_json": {"accept": False}}
        self.assert_(self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {
            pargs: ["pkg"],
            "opts_json": {
                "reject_pats": [None, None]
            }
        }
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))

        einstall_input = {pargs: [None], "opts_json": {"reject_pats": []}}
        self.assert_(
            not self.__schema_validation(einstall_input, einstall_schema))
示例#5
0
    def test_07_set_publisher_args_opts(self):
        """Test json args or opts for update command."""

        global_settings.client_output_quiet = True
        self.rurl1 = self.dcs[1].get_repo_url()
        self.image_create(self.rurl1)
        os.environ["PKG_IMAGE"] = self.img_path()
        # Test invalid pkg name.
        pubs = ["test1"]
        opts = {"origin_uri": self.rurl1}
        retjson = self.__call_cmd("set-publisher", pubs, opts)
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        retjson = self.__call_cmd("unset-publisher", pubs, {})
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        opts = {"add_origins": [self.rurl1]}
        retjson = self.__call_cmd("set-publisher", pubs, opts)
        self.assert_("errors" not in retjson)

        pkgs = ["[email protected]"]
        opts = {"verbose": 3, "parsable_version": 0}
        retjson = self.__call_cmd("install", pkgs, opts)
        self.assert_("errors" not in retjson)
        self.assert_(retjson["status"] == 0)

        pkgs = ["newpkg"]
        opts = {"verbose": 3, "parsable_version": 0}
        retjson = self.__call_cmd("uninstall", pkgs, opts)
        self.assert_("errors" not in retjson)
        self.assert_(retjson["status"] == 0)

        self.pkg("set-publisher -O " + self.rurl2 + " test2")
        retjson = cli_api._pkg_invoke(subcommand="unset-publisher",
                                      pargs_json=json.dumps(["test2"]),
                                      opts_json=None)
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        retjson = self.__call_cmd("unset-publisher", pubs, {})
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        opts = {"repo_uri": self.rurl1}
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["data"]["added"] == ["test1"])
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["data"]["updated"] == ["test1"])
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        pkgs = ["pkg://test1/foo@1"]
        opts = {"verbose": 3, "parsable_version": 0}
        retjson = self.__call_cmd("install", pkgs, opts)
        self.assert_("errors" not in retjson)
        self.assert_(retjson["status"] == 0)

        opts = {
            "repo_uri": self.rurl2,
            "set_props": ["prop1=here", "prop2=there"]
        }
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        opts = {"repo_uri": self.rurl2, "unset_props": ["prop1", "prop2"]}
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 0)
        self.assert_("errors" not in retjson)

        opts = {
            "repo_uri": self.rurl2,
            "search_before": "a",
            "search_after": "b"
        }
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 2)
        self.assert_("errors" in retjson)

        opts = {"repo_uri": self.rurl2, "add_origins": ["a"]}
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 2)
        self.assert_("errors" in retjson)

        opts = {"repo_uri": self.rurl2, "refresh_allowed": False}
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 2)
        self.assert_("combined" in retjson["errors"][0]["reason"])

        opts = {"proxy_uri": self.rurl2}
        retjson = self.__call_cmd("set-publisher", [], opts)
        self.assert_(retjson["status"] == 2)
        self.assert_("only be used" in retjson["errors"][0]["reason"])
        global_settings.client_output_quiet = False

        # Test input directly against schema.
        pargs = "pargs_json"
        schema = cli_api._get_pkg_input_schema("set-publisher")

        test_input = {pargs: ["test1"], "opts_json": {"enable": True}}
        self.assert_(self.__schema_validation(test_input, schema))

        test_input = {pargs: None, "opts_json": {"enable": True}}
        self.assert_(not self.__schema_validation(test_input, schema))

        test_input = {pargs: [], "opts_json": {"repo_uri": "test"}}
        self.assert_(self.__schema_validation(test_input, schema))

        schema = cli_api._get_pkg_input_schema("unset-publisher")
        test_input = {pargs: [], "opts_json": {}}
        self.assert_(self.__schema_validation(test_input, schema))