Пример #1
0
def test_run_this():
    # Arrange
    test_cmd = "echo %s"
    test_args = "Test"

    # Act
    utils.run_this(test_cmd, test_args)

    # Assert - If above method get's a zero exitcode it counts as successfully completed. Otherwise we die.
    assert True
Пример #2
0
    def import_tree(self, mirror_url, mirror_name, network_root=None, autoinstall_file=None, rsync_flags=None, arch=None, breed=None, os_version=None, logger=None):
        """
        Automatically import a directory tree full of distribution files.
        mirror_url can be a string that represents a path, a user@host
        syntax for SSH, or an rsync:// address.  If mirror_url is a
        filesystem path and mirroring is not desired, set network_root
        to something like "nfs://path/to/mirror_url/root"
        """
        self.log("import_tree", [mirror_url, mirror_name, network_root, autoinstall_file, rsync_flags])

        # both --path and --name are required arguments
        if mirror_url is None:
            self.log("import failed.  no --path specified")
            return False
        if mirror_name is None:
            self.log("import failed.  no --name specified")
            return False

        path = os.path.normpath("%s/distro_mirror/%s" % (self.settings().webdir, mirror_name))
        if arch is not None:
            arch = arch.lower()
            if arch == "x86":
                # be consistent
                arch = "i386"
            if path.split("-")[-1] != arch:
                path += ("-%s" % arch)

        # we need to mirror (copy) the files
        self.log("importing from a network location, running rsync to fetch the files first")

        utils.mkdir(path)

        # prevent rsync from creating the directory name twice
        # if we are copying via rsync

        if not mirror_url.endswith("/"):
            mirror_url = "%s/" % mirror_url

        if mirror_url.startswith("http://") or mirror_url.startswith("ftp://") or mirror_url.startswith("nfs://"):
            # http mirrors are kind of primative.  rsync is better.
            # that's why this isn't documented in the manpage and we don't support them.
            # TODO: how about adding recursive FTP as an option?
            self.log("unsupported protocol")
            return False
        else:
            # good, we're going to use rsync..
            # we don't use SSH for public mirrors and local files.
            # presence of user@host syntax means use SSH
            spacer = ""
            if not mirror_url.startswith("rsync://") and not mirror_url.startswith("/"):
                spacer = ' -e "ssh" '
            rsync_cmd = RSYNC_CMD
            if rsync_flags:
                rsync_cmd += " " + rsync_flags

            # if --available-as was specified, limit the files we
            # pull down via rsync to just those that are critical
            # to detecting what the distro is
            if network_root is not None:
                rsync_cmd += " --include-from=/etc/cobbler/import_rsync_whitelist"

            # kick off the rsync now
            utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)

        if network_root is not None:
            # in addition to mirroring, we're going to assume the path is available
            # over http, ftp, and nfs, perhaps on an external filer.  scanning still requires
            # --mirror is a filesystem path, but --available-as marks the network path.
            # this allows users to point the path at a directory containing just the network
            # boot files while the rest of the distro files are available somewhere else.

            # find the filesystem part of the path, after the server bits, as each distro
            # URL needs to be calculated relative to this.

            if not network_root.endswith("/"):
                network_root += "/"
            valid_roots = ["nfs://", "ftp://", "http://"]
            for valid_root in valid_roots:
                if network_root.startswith(valid_root):
                    break
            else:
                self.log("Network root given to --available-as must be nfs://, ftp://, or http://")
                return False

            if network_root.startswith("nfs://"):
                try:
                    (a, b, rest) = network_root.split(":", 3)
                except:
                    self.log("Network root given to --available-as is missing a colon, please see the manpage example.")
                    return False

        # importer_modules = self.get_modules_in_category("manage/import")
        # for importer_module in importer_modules:
        #    manager = importer_module.get_import_manager(self._collection_mgr,logger)
        #    try:
        #        (found,pkgdir) = manager.check_for_signature(path,breed)
        #        if found:
        #            self.log("running import manager: %s" % manager.what())
        #            return manager.run(pkgdir,mirror_name,path,network_root,autoinstall_file,rsync_flags,arch,breed,os_version)
        #    except:
        #        self.log("an exception occured while running the import manager")
        #        self.log("error was: %s" % sys.exc_info()[1])
        #        continue
        # self.log("No import managers found a valid signature at the location specified")
        # # FIXME: since we failed, we should probably remove the
        # # path tree we created above so we don't leave cruft around
        # return False
        import_module = self.get_module_by_name("manage_import_signatures").get_import_manager(self._collection_mgr, logger)
        import_module.run(path, mirror_name, network_root, autoinstall_file, arch, breed, os_version)
Пример #3
0
    def import_tree(self, mirror_url, mirror_name, network_root=None, autoinstall_file=None, rsync_flags=None, arch=None, breed=None, os_version=None, logger=None):
        """
        Automatically import a directory tree full of distribution files.
        mirror_url can be a string that represents a path, a user@host
        syntax for SSH, or an rsync:// address.  If mirror_url is a
        filesystem path and mirroring is not desired, set network_root
        to something like "nfs://path/to/mirror_url/root"
        """
        self.log("import_tree", [mirror_url, mirror_name, network_root, autoinstall_file, rsync_flags])

        # both --path and --name are required arguments
        if mirror_url is None or not mirror_url:
            self.log("import failed.  no --path specified")
            return False
        if mirror_name is None or not mirror_name:
            self.log("import failed.  no --name specified")
            return False

        path = os.path.normpath("%s/distro_mirror/%s" % (self.settings().webdir, mirror_name))
        if arch is not None:
            arch = arch.lower()
            if arch == "x86":
                # be consistent
                arch = "i386"
            if path.split("-")[-1] != arch:
                path += ("-%s" % arch)

        # we need to mirror (copy) the files
        self.log("importing from a network location, running rsync to fetch the files first")

        utils.mkdir(path)

        # prevent rsync from creating the directory name twice
        # if we are copying via rsync

        if not mirror_url.endswith("/"):
            mirror_url = "%s/" % mirror_url

        if mirror_url.startswith("http://") or mirror_url.startswith("https://") or mirror_url.startswith("ftp://") or mirror_url.startswith("nfs://"):
            # http mirrors are kind of primative.  rsync is better.
            # that's why this isn't documented in the manpage and we don't support them.
            # TODO: how about adding recursive FTP as an option?
            self.log("unsupported protocol")
            return False
        else:
            # good, we're going to use rsync..
            # we don't use SSH for public mirrors and local files.
            # presence of user@host syntax means use SSH
            spacer = ""
            if not mirror_url.startswith("rsync://") and not mirror_url.startswith("/"):
                spacer = ' -e "ssh" '
            rsync_cmd = RSYNC_CMD
            if rsync_flags:
                rsync_cmd += " " + rsync_flags

            # if --available-as was specified, limit the files we
            # pull down via rsync to just those that are critical
            # to detecting what the distro is
            if network_root is not None:
                rsync_cmd += " --include-from=/etc/cobbler/import_rsync_whitelist"

            # kick off the rsync now
            utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)

        if network_root is not None:
            # in addition to mirroring, we're going to assume the path is available
            # over http, ftp, and nfs, perhaps on an external filer.  scanning still requires
            # --mirror is a filesystem path, but --available-as marks the network path.
            # this allows users to point the path at a directory containing just the network
            # boot files while the rest of the distro files are available somewhere else.

            # find the filesystem part of the path, after the server bits, as each distro
            # URL needs to be calculated relative to this.

            if not network_root.endswith("/"):
                network_root += "/"
            valid_roots = ["nfs://", "ftp://", "http://", "https://"]
            for valid_root in valid_roots:
                if network_root.startswith(valid_root):
                    break
            else:
                self.log("Network root given to --available-as must be nfs://, ftp://, http://, or https://")
                return False

            if network_root.startswith("nfs://"):
                try:
                    (a, b, rest) = network_root.split(":", 3)
                except:
                    self.log("Network root given to --available-as is missing a colon, please see the manpage example.")
                    return False

        import_module = self.get_module_by_name("manage_import_signatures").get_import_manager(self._collection_mgr, logger)
        import_module.run(path, mirror_name, network_root, autoinstall_file, arch, breed, os_version)