예제 #1
0
 def test_config_init_cfg_overrides(self, goodConfigPath):
     url = "http://1.1.1.1:11"
     gpgkey =  "111111"
     c = Config(goodConfigPath, 0, ["url=%s" % url, "signing.gpgkey=%s" % gpgkey])
     assert c.url == url
     assert c.get_signing_config().gpgkey == gpgkey
     assert c.name == "profile0"
예제 #2
0
 def test_init_no_cfg_only_overrides(self):
     url = "http://1.1.1.1:11"
     gpgkey =  "111111"
     passphrase_file = "/etc/passphrase"
     cfg_overrides = [
             "url=%s" % url,
             "signing.gpgkey=%s" % gpgkey,
             "signing.passphrase_file=%s" % passphrase_file
             ]
     c = Config(False, cfg_overrides=cfg_overrides)
     assert c.url == url
     assert c.get_signing_config().gpgkey == gpgkey
     assert c.get_signing_config().passphrase_file == passphrase_file
     assert hasattr(c, "name") is False
예제 #3
0
 def test_config_init_invalid_yaml(self, tmpdir):
     path = tmpdir.join("invalid.yaml")
     with open(path, 'w') as f:
         f.write("%invalid yaml!")
     with pytest.raises(AptlyCtlError) as e:
         c = Config(path)
     assert "invalid yaml" in e.value.args[0].lower()
예제 #4
0
 def test_config_init_without_profiles(self, tmpdir):
     path = tmpdir.join("empty.conf")
     with open(path, 'w'):
         pass
     with pytest.raises(AptlyCtlError) as e:
         c = Config(path)
     assert "config file must contain 'profiles' list" in e.value.args[0].lower()
예제 #5
0
 def test_config_init_no_permissions(self, tmpdir):
     path = tmpdir.join("not_readable.conf")
     with open(path, 'w') as f:
         os.chmod(f.fileno(), 0)
     with pytest.raises(AptlyCtlError) as e:
         c = Config(path)
     assert "permission denied" in e.value.args[0].lower()
예제 #6
0
 def test_cfg_no_url(self, tmpdir):
     wrong_cfg = {}
     wrong_cfg["profiles"] = [ self._goodConfig["profiles"][0].copy() ]
     del wrong_cfg["profiles"][0]["url"]
     path_to_wrong_cfg = tmpdir.join("aptly-ctl-wrong.conf")
     with open(path_to_wrong_cfg, 'a') as f:
         yaml.dump(wrong_cfg, f)
     with pytest.raises(AptlyCtlError) as e:
         c = Config(path_to_wrong_cfg)
     assert "specify url of api to connect to" in e.value.args[0].lower()
예제 #7
0
def main():
    parser, subparsers = config_parser()
    for subcommand in aptly_ctl.subcommands.__all__:
        eval("aptly_ctl.subcommands.%s.config_subparser(subparsers)" %
             subcommand)

    args = parser.parse_args()

    if not args.subcommand:
        parser.print_help()
        sys.exit(2)

    log_level = VERBOSITY[min(args.verbose, len(VERBOSITY) - 1)]
    try:
        _init_logging(log_level, args.subcommand)
    except ValueError as e:
        print(e)
        sys.exit(2)
    logger = logging.getLogger(__name__)

    try:
        config = Config(args.config, args.profile, args.config_keys)
    except AptlyCtlError as e:
        logger.error(e)
        logger.debug("", exc_info=True)
        sys.exit(2)

    if not system_ver_compare:
        logger.debug("Cannot import apt.apt_pkg module from python3-apt" +
                     " package. Using python substitute that is much slower.")

    logger.info("Running %s subcommand." % args.subcommand)
    try:
        sys.exit(args.func(config, args))
    except AptlyAPIException as e:
        if e.status_code == 404 and "page not found" in e.args[0].lower():
            logger.error(
                "API reponded with '%s'. Check configured API url and run command with -vv to see failed request details."
                % e.args[0])
            logger.debug("", exc_info=True)
            sys.exit(1)
        else:
            raise
    except (AptlyCtlError, requests.exceptions.RequestException) as e:
        logger.error(e)
        logger.debug("", exc_info=True)
        sys.exit(1)
예제 #8
0
 def test_config_init_from_directory(self, tmpdir):
     with pytest.raises(AptlyCtlError) as e:
         c = Config(tmpdir)
     assert "is a directory" in e.value.args[0].lower()
예제 #9
0
 def test_config_init_set_profile_wrong_name(self, goodConfigPath):
     with pytest.raises(AptlyCtlError) as e:
         c = Config(goodConfigPath, "nonexistent")
     assert "cannot find configuration profile" in e.value.args[0].lower()
예제 #10
0
 def test_get_overrided_signing_config_if_there_are_no_signing_overrides(self, goodConfigPath):
     c = Config(goodConfigPath, 0)
     assert c.get_signing_config().gpgkey == "aba45rts"
     assert c.get_signing_config(PubSpec("./stretch")).gpgkey == "aba45rts"
예제 #11
0
 def test_config_init_nonexistent_path(self, tmpdir):
     with pytest.raises(AptlyCtlError) as e:
         c = Config(tmpdir.join("nonexistent.conf"))
     assert "no such file or directory" in e.value.args[0].lower()
예제 #12
0
 def test_config_init_existent_path(self, goodConfigPath):
     assert Config(goodConfigPath).name == "profile0"
예제 #13
0
 def test_get_overrided_signing_config(self, goodConfigPath):
     c = Config(goodConfigPath, "with_sign")
     assert c.get_signing_config().gpgkey == "default"
     assert c.get_signing_config(PubSpec("./stretch")).gpgkey == "stretch"
     assert c.get_signing_config(PubSpec("debian/jessie")).gpgkey == "jessie"
     assert c.get_signing_config(PubSpec("none/none")).gpgkey == "default"
예제 #14
0
 def test_config_init_cfg_overrides_wrong_key(self, goodConfigPath):
     url = "url http://localhost:9090/api"
     with pytest.raises(AptlyCtlError) as e:
         c = Config(goodConfigPath, 0, [url])
     assert "incorrect configuration key in command line arguments" in e.value.args[0].lower()
예제 #15
0
 def test_config_init_set_profile_by_int(self, goodConfigPath):
     assert Config(goodConfigPath, 1).name == "profile1"
예제 #16
0
 def test_config_init_set_profile_by_name(self, goodConfigPath):
     c = Config(goodConfigPath, "profile1")
     assert c.name == "profile1"
     assert c.url == self._goodConfig["profiles"][1]["url"]
예제 #17
0
 def test_config_init_set_profile_by_partial_name(self, goodConfigPath):
     c = Config(goodConfigPath, "my")
     assert c.name == "my_profile"
     assert c.url == self._goodConfig["profiles"][2]["url"]
예제 #18
0
 def test_config_init_set_profile_ambiguous_name_but_matches_fully(self, goodConfigPath):
     c = Config(goodConfigPath, "prefix")
     assert c.name == "prefix"
     assert c.url == self._goodConfig["profiles"][3]["url"]
예제 #19
0
 def test_config_init_set_profile_ambiguous_name(self, goodConfigPath):
     with pytest.raises(AptlyCtlError) as e:
         c = Config(goodConfigPath, "profile")
     assert "ambiguously matches" in e.value.args[0].lower()
예제 #20
0
 def test_config_init_set_profile_wrong_num(self, goodConfigPath):
     with pytest.raises(AptlyCtlError) as e:
         c = Config(goodConfigPath, 55)
     assert "there is no profile numbered" in e.value.args[0].lower()