Exemple #1
0
    def __init__(self, retries=3, log_obj=None, force=False):
        self.queues = {}
        with cfg_component("server.satellite") as CFG:
            try:
                self.threads = int(CFG.REPOSYNC_DOWNLOAD_THREADS)
            except ValueError:
                raise ValueError("Number of threads expected, found: '%s'" %
                                 CFG.REPOSYNC_DOWNLOAD_THREADS)
            try:
                self.timeout = int(CFG.REPOSYNC_TIMEOUT)
            except ValueError:
                raise ValueError("Timeout in seconds expected, found: '%s'" %
                                 CFG.REPOSYNC_TIMEOUT)
            try:
                self.minrate = int(CFG.REPOSYNC_MINRATE)
            except ValueError:
                raise ValueError(
                    "Minimal transfer rate in bytes pre second expected, found: '%s'"
                    % CFG.REPOSYNC_MINRATE)

        if self.threads < 1:
            raise ValueError("Invalid number of threads: %d" % self.threads)

        self.retries = retries
        self.log_obj = log_obj
        self.force = force
        self.lock = Lock()
        self.exception = None
        # WORKAROUND - BZ #1439758 - ensure first item in queue is performed alone to properly setup NSS
        self.first_in_queue_done = False
        self.first_in_queue_lock = Lock()
Exemple #2
0
import grp
import io
import os
import os.path
import pwd
import shutil
import yaml
import hashlib

from contextlib import redirect_stderr
from uyuni.common.context_managers import cfg_component

uyuni_roster_config = {}

with cfg_component("java") as CFG:
    thread_pool_size = CFG.salt_event_thread_pool_size
    try:
        uyuni_roster_config.update({
            "ssh_connect_timeout":
            CFG.SALT_SSH_CONNECT_TIMEOUT,
        })
    except (AttributeError, ValueError):
        pass

# To be moved into a config file in future
cert_location = "/etc/pki/trust/anchors"
if not os.path.isdir(cert_location):
    cert_location = "/etc/pki/ca-trust/source/anchors"

with cfg_component(None) as CFG:
Exemple #3
0
    def __init__(self,
                 url,
                 name,
                 insecure=False,
                 interactive=True,
                 yumsrc_conf=None,
                 org="1",
                 channel_label="",
                 no_mirrors=False,
                 ca_cert_file=None,
                 client_cert_file=None,
                 client_key_file=None,
                 channel_arch="",
                 http_headers=None):
        # pylint: disable=W0613
        self.url = url
        self.name = name
        if org:
            self.org = org
        else:
            self.org = "NULL"

        # read the proxy configuration in /etc/rhn/rhn.conf
        with cfg_component('server.satellite') as CFG:
            self.proxy_addr, self.proxy_user, self.proxy_pass = get_proxy(
                self.url)
            self.authtoken = None

            # Replace non-valid characters from reponame (only alphanumeric chars allowed)
            self.reponame = "".join(
                [x if x.isalnum() else "_" for x in self.name])
            self.channel_label = channel_label

            # SUSE vendor repositories belongs to org = NULL
            # The repository cache root will be "/var/cache/rhn/reposync/REPOSITORY_LABEL/"
            root = os.path.join(CACHE_DIR, str(org or "NULL"), self.reponame)
            self.repo = DebRepo(url,
                                root,
                                os.path.join(CFG.MOUNT_POINT,
                                             CFG.PREPENDED_DIR, self.org,
                                             'stage'),
                                self.proxy_addr,
                                self.proxy_user,
                                self.proxy_pass,
                                gpg_verify=not (insecure),
                                channel_label=channel_label)
            self.repo.verify()

            self.num_packages = 0
            self.num_excluded = 0

            # keep authtokens for mirroring
            (_scheme, _netloc, _path, query, _fragid) = urlparse.urlsplit(url)
            if query:
                self.authtoken = query

            # configure network connection
            try:
                # bytes per second
                self.minrate = int(CFG.REPOSYNC_MINRATE)
            except ValueError:
                self.minrate = 1000
            try:
                # seconds
                self.timeout = int(CFG.REPOSYNC_TIMEOUT)
            except ValueError:
                self.timeout = 300
Exemple #4
0
    def __init__(self,
                 url,
                 name,
                 insecure=False,
                 interactive=False,
                 yumsrc_conf=YUMSRC_CONF,
                 org="1",
                 channel_label="",
                 no_mirrors=False,
                 ca_cert_file=None,
                 client_cert_file=None,
                 client_key_file=None,
                 channel_arch="",
                 http_headers=None):
        # insecure and interactive are not implemented for this module.
        """
        Plugin constructor.
        """

        name = re.sub('[^a-zA-Z0-9_.:-]+', '_', name)
        if urlsplit(url).scheme:
            self.url = url
        else:
            self.url = "file://%s" % url
        self.name = name
        self.insecure = insecure
        self.interactive = interactive
        self.org = org if org else "NULL"
        self.proxy_hostname = None
        self.proxy_url = None
        self.proxy_user = None
        self.proxy_pass = None
        self.authtoken = None
        self.sslcacert = ca_cert_file
        self.sslclientcert = client_cert_file
        self.sslclientkey = client_key_file
        self.http_headers = {}

        self.dnfbase = dnf.Base()
        self.dnfbase.conf.read(yumsrc_conf)
        if not os.path.exists(yumsrc_conf):
            self.dnfbase.conf.read('/dev/null')
        self.configparser = ConfigParser(
        )  # Reading config file directly as dnf only ready MAIN section.
        self.configparser.setSubstitutions(dnf.Base().conf.substitutions)
        self.configparser.read(yumsrc_conf)
        self.dnfbase.conf.cachedir = os.path.join(CACHE_DIR, self.org)

        # read the proxy configuration
        # /etc/rhn/rhn.conf has more priority than yum.conf
        with cfg_component('server.satellite') as CFG:
            # keep authtokens for mirroring
            (_scheme, _netloc, _path, query, _fragid) = urlsplit(url)
            if query:
                self.authtoken = query

            # load proxy configuration based on the url
            self._load_proxy_settings(self.url)

            # perform authentication if implemented
            self._authenticate(url)

            # Check for settings in yum configuration files (for custom repos/channels only)
            if org:
                repos = self.dnfbase.repos
            else:
                repos = None
            if repos and name in repos:
                repo = repos[name]
            elif repos and channel_label in repos:
                repo = repos[channel_label]
                # In case we are using Repo object based on channel config, override it's id to name of the repo
                # To not create channel directories in cache directory
                repo.id = name
            else:
                # Not using values from config files
                repo = dnf.repo.Repo(name, self.dnfbase.conf)
                repo.repofile = yumsrc_conf
                # pylint: disable=W0212
                repo._populate(self.configparser, name, yumsrc_conf)

            self.repo = repo

            self.yumbase = self.dnfbase  # for compatibility

            self.setup_repo(repo, no_mirrors, ca_cert_file, client_cert_file,
                            client_key_file)
            self.num_packages = 0
            self.num_excluded = 0
            self.groupsfile = None

            # configure network connection
            try:
                # bytes per second
                self.minrate = int(CFG.REPOSYNC_MINRATE)
            except ValueError:
                self.minrate = 1000
            try:
                # seconds
                self.timeout = int(CFG.REPOSYNC_TIMEOUT)
            except ValueError:
                self.timeout = 300

            self.repo = self.dnfbase.repos[self.repoid]
            self.get_metadata_paths()
Exemple #5
0
    def setup_repo(self, repo, no_mirrors, ca_cert_file, client_cert_file,
                   client_key_file):
        """
        Setup repository and fetch metadata
        """
        repo.metadata_expire = 0
        repo.mirrorlist = self.url
        repo.baseurl = [self.url]
        with cfg_component('server.satellite') as CFG:
            pkgdir = os.path.join(CFG.MOUNT_POINT, CFG.PREPENDED_DIR, self.org,
                                  'stage')
        if not os.path.isdir(pkgdir):
            fileutils.makedirs(pkgdir, user=APACHE_USER, group=APACHE_GROUP)
        repo.pkgdir = pkgdir
        repo.sslcacert = ca_cert_file
        repo.sslclientcert = client_cert_file
        repo.sslclientkey = client_key_file
        repo.proxy = None
        repo.proxy_username = None
        repo.proxy_password = None

        if self.proxy_url:
            repo.proxy = self.proxy_url if '://' in self.proxy_url else 'http://' + self.proxy_url
            repo.proxy_username = self.proxy_user
            repo.proxy_password = self.proxy_pass

        if no_mirrors:
            repo.mirrorlist = ""
        self.digest = hashlib.sha256(self.url.encode('utf8')).hexdigest()[:16]
        self.dnfbase.repos.add(repo)
        self.repoid = repo.id
        try:
            self.dnfbase.repos[self.repoid].load()
            # Don't use mirrors if there are none.
            if not self.clean_urls(
                    self.dnfbase.repos[self.repoid]._repo.getMirrors()):
                no_mirrors = True
                # Reload repo just in case.
                repo.mirrorlist = ""
                self.dnfbase.repos[self.repoid].load()
        except RepoError as exc:
            raise RepoMDError(exc)

        # Do not try to expand baseurl to other mirrors
        if no_mirrors:
            self.dnfbase.repos[self.repoid].urls = repo.baseurl
            # Make sure baseurl ends with / and urljoin will work correctly
            if self.dnfbase.repos[self.repoid].urls[0][-1] != '/':
                self.dnfbase.repos[self.repoid].urls[0] += '/'
        else:
            self.dnfbase.repos[self.repoid].urls = self.clean_urls(
                self.dnfbase.repos[self.repoid]._repo.getMirrors())  # pylint: disable=W0212
            self.dnfbase.repos[self.repoid].urls = [
                url for url in self.dnfbase.repos[self.repoid].urls
                if '?' not in url
            ]
        self.dnfbase.repos[self.repoid].basecachedir = os.path.join(
            CACHE_DIR, self.org)
        repoXML = type('', (), {})()
        repoXML.repoData = {}
        self.dnfbase.repos[self.repoid].repoXML = repoXML
Exemple #6
0
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
# this module implements the send mail support
#

import os
import smtplib

from rhn.connections import idn_puny_to_unicode
from uyuni.common.context_managers import cfg_component
from spacewalk.common.rhnConfig import PRODUCT_NAME
from typing import NamedTuple, Union

with cfg_component(None) as CFG:
    PRODUCT_NAME = CFG.PRODUCT_NAME
    FALLBACK_TRACEBACK_MAIL = CFG.TRACEBACK_MAIL


class HeadersRecipients(NamedTuple):
    headers: dict
    to_addresses: Union[tuple, list]


def __check_headers(headers: dict = None) -> HeadersRecipients:
    """Ensure that the headers have the minimum required fields."""
    if not isinstance(headers, dict):
        headers = {}
    if "Subject" not in headers:
        hostname = idn_puny_to_unicode(os.uname().nodename)