Пример #1
0
    def load_config(self):
        """Loads the next configuration for the plugin to test"""
        if hasattr(self.le_config, "apache_init_script"):
            try:
                self.check_call([self.le_config.apache_init_script, "stop"])
            except errors.Error:
                raise errors.Error(
                    "Failed to stop previous apache config from running")

        config = super(Proxy, self).load_config()
        self.modules = _get_modules(config)
        self.version = _get_version(config)
        self._all_names, self._test_names = _get_names(config)

        server_root = _get_server_root(config)
        with open(os.path.join(config, "config_file")) as f:
            config_file = os.path.join(server_root, f.readline().rstrip())
        self.test_conf = _create_test_conf(server_root, config_file)

        self.preprocess_config(server_root)
        self._prepare_configurator(server_root, config_file)

        try:
            self.check_call("apachectl -d {0} -f {1} -k start".format(
                server_root, config_file))
        except errors.Error:
            raise errors.Error(
                "Apache failed to load {0} before tests started".format(
                    config))

        return config
Пример #2
0
    def preprocess_config(self, server_root):
        """Prepares the configuration for use in the Docker"""
        super(Proxy, self).preprocess_config(server_root)
        if self.version[1] != 4:
            raise errors.Error("Apache version not 2.4")

        with open(self.test_conf, "a") as f:
            for module in self.modules:
                if module not in STATIC_MODULES:
                    if module in SHARED_MODULES:
                        f.write(
                            "LoadModule {0}_module /usr/local/apache2/modules/"
                            "mod_{0}.so\n".format(module))
                    else:
                        raise errors.Error(
                            "Unsupported module {0}".format(module))
Пример #3
0
def main():
    """Main test script execution."""
    args = get_args()
    setup_logging(args)

    if args.plugin not in PLUGINS:
        raise errors.Error("Unknown plugin {0}".format(args.plugin))

    temp_dir = tempfile.mkdtemp()
    plugin = PLUGINS[args.plugin](args)
    try:
        plugin.execute_in_docker("mkdir -p /var/log/apache2")
        while plugin.has_more_configs():
            success = True

            try:
                config = plugin.load_config()
                logger.info("Loaded configuration: %s", config)
                if args.auth:
                    success = test_authenticator(plugin, config, temp_dir)
                if success and args.install:
                    success = test_installer(args, plugin, config, temp_dir)
            except errors.Error as error:
                logger.error("Tests on %s raised:", config)
                logger.exception(error)
                success = False

            if success:
                logger.info("All tests on %s succeeded", config)
            else:
                logger.error("Tests on %s failed", config)
    finally:
        plugin.cleanup_from_tests()
Пример #4
0
    def check_call(self, command, *args, **kwargs):
        # pylint: disable=unused-argument
        """Simulates a call to check_call but executes the command in the
        running docker image

        """
        if self.popen(command).returncode:
            raise errors.Error(
                "{0} exited with a nonzero value".format(command))
Пример #5
0
def _get_server_root(config):
    """Returns the server root directory in config"""
    subdirs = [
        name for name in os.listdir(config)
        if os.path.isdir(os.path.join(config, name))]

    if len(subdirs) != 1:
        errors.Error("Malformed configuration directory {0}".format(config))

    return os.path.join(config, subdirs[0].rstrip())
Пример #6
0
def extract_configs(configs, parent_dir):
    """Extracts configs to a new dir under parent_dir and returns it"""
    config_dir = os.path.join(parent_dir, "configs")

    if os.path.isdir(configs):
        shutil.copytree(configs, config_dir, symlinks=True)
    elif tarfile.is_tarfile(configs):
        with tarfile.open(configs, "r") as tar:
            tar.extractall(config_dir)
    else:
        raise errors.Error("Unknown configurations file type")

    return config_dir
Пример #7
0
def _get_version(config):
    """Return version of Apache Server.

    Version is returned as tuple. (ie. 2.4.7 = (2, 4, 7)). Code taken from
    the Apache plugin.

    """
    with open(os.path.join(config, "version")) as f:
        # Should be on first line of input
        matches = APACHE_VERSION_REGEX.findall(f.readline())

    if len(matches) != 1:
        raise errors.Error("Unable to find Apache version")

    return tuple([int(i) for i in matches[0].split(".")])
Пример #8
0
    def load_config(self):
        """Loads the next configuration for the plugin to test"""
        config = super(Proxy, self).load_config()
        self._all_names, self._test_names = _get_names(config)

        server_root = _get_server_root(config)
        shutil.rmtree("/etc/apache2")
        shutil.copytree(server_root, "/etc/apache2", symlinks=True)

        self._prepare_configurator()

        try:
            subprocess.check_call("apachectl -k restart".split())
        except errors.Error:
            raise errors.Error(
                "Apache failed to load {0} before tests started".format(
                    config))

        return config
Пример #9
0
def main():
    """Main test script execution."""
    args = get_args()
    setup_logging(args)
    setup_display()

    if args.plugin not in PLUGINS:
        raise errors.Error("Unknown plugin {0}".format(args.plugin))

    temp_dir = tempfile.mkdtemp()
    plugin = PLUGINS[args.plugin](args)
    try:
        overall_success = True
        while plugin.has_more_configs():
            success = True

            try:
                config = plugin.load_config()
                logger.info("Loaded configuration: %s", config)
                if args.auth:
                    success = test_authenticator(plugin, config, temp_dir)
                if success and args.install:
                    success = test_installer(args, plugin, config, temp_dir)
            except errors.Error:
                logger.error("Tests on %s raised:", config, exc_info=True)
                success = False

            if success:
                logger.info("All tests on %s succeeded", config)
            else:
                overall_success = False
                logger.error("Tests on %s failed", config)
    finally:
        plugin.cleanup_from_tests()

    if overall_success:
        logger.warning("All compatibility tests succeeded")
        sys.exit(0)
    else:
        logger.warning("One or more compatibility tests failed")
        sys.exit(1)
Пример #10
0
    def load_config(self):
        """Loads the next configuration for the plugin to test"""
        config = super().load_config()
        self._all_names, self._test_names = _get_names(config)

        server_root = _get_server_root(config)

        # XXX: Deleting all of this is kind of scary unless the test
        #      instances really each have a complete configuration!
        shutil.rmtree("/etc/nginx")
        shutil.copytree(server_root, "/etc/nginx", symlinks=True)

        self._prepare_configurator()

        try:
            subprocess.check_call("service nginx reload".split())
        except errors.Error:
            raise errors.Error(
                "Nginx failed to load {0} before tests started".format(config))

        return config
Пример #11
0
 def get_all_names_answer(self):
     """Returns the set of domain names that the plugin should find"""
     if self._all_names:
         return self._all_names
     raise errors.Error("No configuration file loaded")