lib/beaker/dsl/install_utils/foss_utils.rb
# Install development repository on the given host. This method pushes all
# repository information including package files for the specified
# package_name to the host and modifies the repository configuration file
# to point at the new repository. This is particularly useful for
# installing development packages on hosts that can't access the builds
# server.
#
# @param [Host] host An object implementing {Beaker::Hosts}'s
#                    interface.
# @param [String] package_name The name of the package whose repository is
#                              being installed.
# @param [String] build_version A string identifying the output of a
#                               packaging job for use in looking up
#                               repository directory information
# @param [String] repo_configs_dir A local directory where repository files will be
#                                  stored as an intermediate step before
#                                  pushing them to the given host.
# @param [Hash{Symbol=>String}] opts Options to alter execution.
# @option opts [String] :dev_builds_url The URL to look for dev builds.
# @option opts [String, Array<String>] :dev_builds_repos The repo(s)
#                                       to check for dev builds in.
#
# @note This method only works on redhat-like and debian-like hosts.
#
Install development repository on the given host. This method pushes all
repository information including package files for the specified
package_name to the host and modifies the repository configuration file
to point at the new repository. This is particularly useful for
installing development packages on hosts that can't access the builds
server.
Install development repository on the given host . This method pushes all repository information including package files for the specified package_name to the host and modifies the repository configuration file to point at the new repository . This is particularly useful for installing development packages on hosts that can ' t access the builds server .
def install_puppetlabs_dev_repo ( host, package_name, build_version,
                                  repo_configs_dir = 'tmp/repo_configs',
                                  opts = options )
          variant, version, arch, codename = host['platform'].to_array
          platform_configs_dir = File.join(repo_configs_dir, variant)
          opts = FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts)
          _, protocol, hostname = opts[:dev_builds_url].partition /.*:\/\//
          dev_builds_url = protocol + hostname
          on host, "mkdir -p /root/#{package_name}"
          case variant
          when /^(fedora|el|centos)$/
            variant = (($1 == 'centos') ? 'el' : $1)
            fedora_prefix = ((variant == 'fedora') ? 'f' : '')
            if host.is_pe?
              pattern = "pl-%s-%s-repos-pe-%s-%s%s-%s.repo"
            else
              pattern = "pl-%s-%s-%s-%s%s-%s.repo"
            end
            repo_filename = pattern % [
              package_name,
              build_version,
              variant,
              fedora_prefix,
              version,
              arch
            ]
            repo = fetch_http_file( "%s/%s/%s/repo_configs/rpm/" %
                         [ dev_builds_url, package_name, build_version ],
                          repo_filename,
                          platform_configs_dir)
            link = nil
            package_repos = opts[:dev_builds_repos].nil? ? [] : [opts[:dev_builds_repos]]
            package_repos.push(['products', 'devel']).flatten!
            package_repos.each do |repo|
              link =  "%s/%s/%s/repos/%s/%s%s/%s/%s/" %
                [ dev_builds_url, package_name, build_version, variant,
                  fedora_prefix, version, repo, arch ]
              unless link_exists?( link )
                logger.debug("couldn't find link at '#{repo}', falling back to next option...")
              else
                logger.debug("found link at '#{repo}'")
                break
              end
            end
            raise "Unable to reach a repo directory at #{link}" unless link_exists?( link )
            repo_dir = fetch_http_dir( link, platform_configs_dir )
            config_dir = '/etc/yum.repos.d/'
            scp_to host, repo, config_dir
            scp_to host, repo_dir, "/root/#{package_name}"
            search = "baseurl\\s*=\\s*http:\\/\\/#{hostname}.*$"
            replace = "baseurl=file:\\/\\/\\/root\\/#{package_name}\\/#{arch}"
            sed_command = "sed -i 's/#{search}/#{replace}/'"
            find_and_sed = "find #{config_dir} -name \"*.repo\" -exec #{sed_command} {} \\;"
            on host, find_and_sed
          when /^(debian|ubuntu|cumulus)$/
            list = fetch_http_file( "%s/%s/%s/repo_configs/deb/" %
                           [ dev_builds_url, package_name, build_version ],
                          "pl-%s-%s-%s.list" %
                           [ package_name, build_version, codename ],
                          platform_configs_dir )
            repo_dir = fetch_http_dir( "%s/%s/%s/repos/apt/%s" %
                                        [ dev_builds_url, package_name,
                                          build_version, codename ],
                                         platform_configs_dir )
            config_dir = '/etc/apt/sources.list.d'
            scp_to host, list, config_dir
            scp_to host, repo_dir, "/root/#{package_name}"
            repo_name = nil
            package_repos = opts[:dev_builds_repos].nil? ? [] : [opts[:dev_builds_repos]]
            package_repos.flatten!
            package_repos.each do |repo|
              repo_path = "/root/#{package_name}/#{codename}/#{repo}"
              repo_check = on(host, "[[ -d #{repo_path} ]]", :acceptable_exit_codes => [0,1])
              if repo_check.exit_code == 0
                logger.debug("found repo at '#{repo_path}'")
                repo_name = repo
                break
              else
                logger.debug("couldn't find repo at '#{repo_path}', falling back to next option...")
              end
            end
            if repo_name.nil?
              repo_name = 'main'
              logger.debug("using default repo '#{repo_name}'")
            end
            search = "deb\\s\\+http:\\/\\/#{hostname}.*$"
            replace = "deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} #{repo_name}"
            sed_command = "sed -i 's/#{search}/#{replace}/'"
            find_and_sed = "find #{config_dir} -name \"*.list\" -exec #{sed_command} {} \\;"
            on host, find_and_sed
            on host, "apt-get update"
            configure_type_defaults_on( host )
          else
            raise "No repository installation step for #{variant} yet..."
          end
        end
def install_puppetlabs_dev_repo ( host , package_name , build_version , repo_configs_dir = 'tmp/repo_configs' , opts = options ) variant , version , arch , codename = host [ 'platform' ] . to_array platform_configs_dir = File . join ( repo_configs_dir , variant ) opts = FOSS_DEFAULT_DOWNLOAD_URLS . merge ( opts ) _ , protocol , hostname = opts [ :dev_builds_url ] . partition / .*: \/ \/ / dev_builds_url = protocol + hostname on host , "mkdir -p /root/#{package_name}" case variant when / ^(fedora|el|centos)$ / variant = ( ( $1 == 'centos' ) ? 'el' : $1 ) fedora_prefix = ( ( variant == 'fedora' ) ? 'f' : '' ) if host . is_pe? pattern = "pl-%s-%s-repos-pe-%s-%s%s-%s.repo" else pattern = "pl-%s-%s-%s-%s%s-%s.repo" end repo_filename = pattern % [ package_name , build_version , variant , fedora_prefix , version , arch ] repo = fetch_http_file ( "%s/%s/%s/repo_configs/rpm/" % [ dev_builds_url , package_name , build_version ] , repo_filename , platform_configs_dir ) link = nil package_repos = opts [ :dev_builds_repos ] . nil? ? [ ] : [ opts [ :dev_builds_repos ] ] package_repos . push ( [ 'products' , 'devel' ] ) . flatten! package_repos . each do | repo | link = "%s/%s/%s/repos/%s/%s%s/%s/%s/" % [ dev_builds_url , package_name , build_version , variant , fedora_prefix , version , repo , arch ] unless link_exists? ( link ) logger . debug ( "couldn't find link at '#{repo}', falling back to next option..." ) else logger . debug ( "found link at '#{repo}'" ) break end end raise "Unable to reach a repo directory at #{link}" unless link_exists? ( link ) repo_dir = fetch_http_dir ( link , platform_configs_dir ) config_dir = '/etc/yum.repos.d/' scp_to host , repo , config_dir scp_to host , repo_dir , "/root/#{package_name}" search = "baseurl\\s*=\\s*http:\\/\\/#{hostname}.*$" replace = "baseurl=file:\\/\\/\\/root\\/#{package_name}\\/#{arch}" sed_command = "sed -i 's/#{search}/#{replace}/'" find_and_sed = "find #{config_dir} -name \"*.repo\" -exec #{sed_command} {} \\;" on host , find_and_sed when / ^(debian|ubuntu|cumulus)$ / list = fetch_http_file ( "%s/%s/%s/repo_configs/deb/" % [ dev_builds_url , package_name , build_version ] , "pl-%s-%s-%s.list" % [ package_name , build_version , codename ] , platform_configs_dir ) repo_dir = fetch_http_dir ( "%s/%s/%s/repos/apt/%s" % [ dev_builds_url , package_name , build_version , codename ] , platform_configs_dir ) config_dir = '/etc/apt/sources.list.d' scp_to host , list , config_dir scp_to host , repo_dir , "/root/#{package_name}" repo_name = nil package_repos = opts [ :dev_builds_repos ] . nil? ? [ ] : [ opts [ :dev_builds_repos ] ] package_repos . flatten! package_repos . each do | repo | repo_path = "/root/#{package_name}/#{codename}/#{repo}" repo_check = on ( host , "[[ -d #{repo_path} ]]" , :acceptable_exit_codes => [ 0 , 1 ] ) if repo_check . exit_code == 0 logger . debug ( "found repo at '#{repo_path}'" ) repo_name = repo break else logger . debug ( "couldn't find repo at '#{repo_path}', falling back to next option..." ) end end if repo_name . nil? repo_name = 'main' logger . debug ( "using default repo '#{repo_name}'" ) end search = "deb\\s\\+http:\\/\\/#{hostname}.*$" replace = "deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} #{repo_name}" sed_command = "sed -i 's/#{search}/#{replace}/'" find_and_sed = "find #{config_dir} -name \"*.list\" -exec #{sed_command} {} \\;" on host , find_and_sed on host , "apt-get update" configure_type_defaults_on ( host ) else raise "No repository installation step for #{variant} yet..." end end
Install development repository on the given host.
Install development repository on the given host .
# some of the uses of dev_builds_url below can't include protocol info, # plus this opens up possibility of switching the behavior on provided # url type
host
<not_specific>
package_name
<not_specific>
build_version
<not_specific>
repo_configs_dir
<not_specific>
opts
:dev_builds_repos The repo(s) to check for dev builds in.
: dev_builds_repos The repo ( s ) to check for dev builds in .
options
<not_specific>
<not_specific>
opts Options to alter execution.
opts Options to alter execution .
note
This method only works on redhat-like and debian-like hosts.
This method only works on redhat - like and debian - like hosts .