simp-build-helpers 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Njg1Y2M5ZjZjMTUyMDE4ZjFkNGFhZDczNzJlOTlmNzkxOWIwYmMyYQ==
5
+ data.tar.gz: !binary |-
6
+ NDFlOTY0YTBkZWM5NzJmNWEyMTQ2MzViM2RhOGJmNzU4MGM5ZmEzNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDU0ZjQxZTU1NTc2NWNkM2I3YWNiNTViYjgyMTIwOGU4MWM1ZGUwZWE3MzBh
10
+ NjMxZGRlNWU3NTRjZDVhYmFmMWNlOWYzODMwOWM4NmVkYTg4MTVkMDgxZDli
11
+ NTRhZjBmYjU4ZTE3YTEyMTI3NzNmNjRjYTY5YzVlNTg1YWNiZmU=
12
+ data.tar.gz: !binary |-
13
+ ODBhMGJiZDcxMzEwYWNlMDBiZjY2YjgzY2YyOWY1NDNiMDExODQwMDAwODAz
14
+ YWU1NWVlYThiZTQyNzUzZGVkZDc5OWIyMDZmZTVhMjk4MmEwY2MxMWFjMzk0
15
+ MTNkNDk5YTRhNDVlNWY4YTcyZjQ1YzBkMzgyY2I0ZTQ0NzE1ZDE=
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ .*.sw?
3
+ .bundle/
4
+ /.bundle
5
+ /.rspec_system
6
+ /.vagrant
7
+ /.yardoc
8
+ /.yardoc/
9
+ /Gemfile.lock
10
+ /dist/
11
+ /doc/
12
+ /junit
13
+ /log
14
+ /pkg
15
+ /pkg/
16
+ /vendor
17
+ /vendor/cache/*.gem
18
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1,7 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - '1.9.3'
5
+ - 2.0
6
+ - 2.1
7
+ - 2.2
@@ -0,0 +1 @@
1
+ --markup markdown --title "simp-build-helpers Documentation" --protected
@@ -0,0 +1,7 @@
1
+ ### 0.1.0 / 2016-02-03
2
+
3
+ * Initial release:
4
+ - `autoscan_unpack_list( paths_string)` takes multiple paths that may be ISO
5
+ files or directories of ISO files and automatically detects the flavors and
6
+ ISO files appropriate for the target release
7
+
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'kramdown'
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-shell'
10
+ end
11
+
@@ -0,0 +1,98 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Make Guard exit when config is changed so it can be restarted
11
+ #
12
+ ## Note: if you want Guard to automatically start up again, run guard in a
13
+ ## shell loop, e.g.:
14
+ #
15
+ # $ while bundle exec guard; do echo "Restarting Guard..."; done
16
+ #
17
+ ## Note: if you are using the `directories` clause above and you are not
18
+ ## watching the project directory ('.'), the you will want to move the Guardfile
19
+ ## to a watched dir and symlink it back, e.g.
20
+ #
21
+ # $ mkdir config
22
+ # $ mv Guardfile config/
23
+ # $ ln -s config/Guardfile .
24
+ #
25
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
26
+ #
27
+ watch 'Guardfile' do
28
+ UI.info 'Exiting because Guard must be restarted for changes to take effect'
29
+ exit 0
30
+ end
31
+
32
+
33
+ # shell commands
34
+ guard :shell do
35
+ # test that the .gemspec still works
36
+ watch %r{^.*\.gemspec$} do |m|
37
+ cmd = "bundle exec gem build '#{m[0]}'"
38
+ p "== #{cmd}"
39
+ `#{cmd}`
40
+ end
41
+
42
+ ### watch /.*\.rb$/ do |m|
43
+ ### if !system("ruby -c #{m[0]} &> /dev/null")
44
+ ### #n "#{m[0]} is incorrect", 'Ruby Syntax', :failed
45
+ ### else
46
+ ### #n "#{m[0]} is correct", 'Ruby Syntax', :success
47
+ ### end
48
+ ### end
49
+ # environment variables:
50
+ # - SIMP_GUARD_SHELL_TESTS = when 1, run `simp config`
51
+ # - SIMP_NIC = when set, tack on "-i ${SIMP_NIC}"
52
+ # Run `simp config` when core files change
53
+ ### watch %r{^(bin/simp|lib/simp/(cli.rb|cli/(commands|config(/item)?)/.*\.rb))} do |m|
54
+ ### if ENV.fetch( 'SIMP_GUARD_SHELL_TESTS', false ) == '1'
55
+ ### m[0] + " has changed"
56
+ ### cmd = "bundle exec ruby bin/simp config -ffy"
57
+ ### cmd += " -i #{ENV['SIMP_NIC']}" if ENV.fetch( 'SIMP_NIC', false )
58
+ ### puts "== #{cmd}"
59
+ ### `#{cmd}`
60
+ ### end
61
+ ### end
62
+ end
63
+
64
+
65
+ # Run rspec tests when things change
66
+ guard :rspec, cmd: 'bundle exec rspec ' do
67
+ watch(%r{^spec/.+_spec\.rb$})
68
+
69
+ # when a file changes run the tests for that file
70
+ watch(%r{^lib/(.+)\.rb$}) do |m|
71
+ File.join( 'spec', "#{File.basename(m[1])}_spec.rb" )
72
+ end
73
+
74
+ watch('spec/spec_helper.rb') { "spec" }
75
+ end
76
+
77
+
78
+ # tmux 1.7+ can send rspec results to the TMUX status pane.
79
+ notification( :tmux, {
80
+ display_message: true,
81
+ timeout: 5, # in seconds
82
+ default_message_format: '%s >> %s',
83
+ # the first %s will show the title, the second the message
84
+ # Alternately you can also configure *success_message_format*,
85
+ # *pending_message_format*, *failed_message_format*
86
+ line_separator: ' > ', # since we are single line we need a separator
87
+ color_location: 'status-left-bg', # to customize which tmux element will change color
88
+
89
+ # Other options:
90
+ default_message_color: 'black',
91
+ success: 'colour150',
92
+ failure: 'colour174',
93
+ pending: 'colour179',
94
+ # Notify on all tmux clients
95
+
96
+ display_on_all_clients: false
97
+ }) if ( ENV.fetch( 'TMUX', false ) && (%x{tmux -V}.split(' ').last.split('.').last.to_i > 6 ))
98
+ # vim:set syntax=ruby:
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ simp-build-helpers - SIMP build helpers
2
+
3
+ --
4
+
5
+ Per Section 105 of the Copyright Act of 1976, these works are not entitled to
6
+ domestic copyright protection under US Federal law.
7
+
8
+ The US Government retains the right to pursue copyright protections outside of
9
+ the United States.
10
+
11
+ The United States Government has unlimited rights in this software and all
12
+ derivatives thereof, pursuant to the contracts under which it was developed and
13
+ the License under which it falls.
14
+
15
+ ---
16
+
17
+ Licensed under the Apache License, Version 2.0 (the "License");
18
+ you may not use this file except in compliance with the License.
19
+ You may obtain a copy of the License at
20
+
21
+ http://www.apache.org/licenses/LICENSE-2.0
22
+
23
+ Unless required by applicable law or agreed to in writing, software
24
+ distributed under the License is distributed on an "AS IS" BASIS,
25
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ See the License for the specific language governing permissions and
27
+ limitations under the License.
@@ -0,0 +1,41 @@
1
+ [![Build Status](https://secure.travis-ci.org/simp/rubygem-simp-build-helpers.svg?branch=master)](https://travis-ci.org/simp/rubygem-simp-build-helpers)
2
+ [![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
3
+ # simp-build-helpers
4
+
5
+ SIMP build helpers
6
+
7
+ #### Table of Contents
8
+ 1. [Overview](#overview)
9
+ 2. [Setup](#setup)
10
+ * [Beginning with simp-build-helpers](#beginning-with-simp-build-helpers)
11
+ 3. [Methods](#methods)
12
+ 4. [Environment variables](#environment-variables)
13
+ 5. [Examples](#examples)
14
+ 6. [License](#license)
15
+
16
+ ## Overview
17
+
18
+ Provides helper methods for building SIMP
19
+
20
+ ## Setup
21
+
22
+ ### Beginning with simp-build-helpers
23
+
24
+ Add this to your project's `Gemfile`:
25
+
26
+ ```ruby
27
+ gem 'simp-build-helpers'
28
+ ```
29
+
30
+ ## Methods
31
+
32
+
33
+
34
+ ## Environment variables
35
+
36
+
37
+ ## Examples
38
+
39
+
40
+ ## License
41
+ See [LICENSE](LICENSE)
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ abort e.message
9
+ end
10
+
11
+ require 'rake'
12
+
13
+
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new
16
+
17
+ task :test => :spec
18
+ task :default => :spec
19
+
20
+ require 'rubygems/package_task'
21
+ Gem::PackageTask.new(Gem::Specification.load('simp-build-helpers.gemspec')) do |pkg|
22
+ pkg.need_tar = true
23
+ pkg.need_zip = false
24
+ end
25
+
26
+ require 'yard'
27
+ YARD::Rake::YardocTask.new
28
+ task :doc => :yard
@@ -0,0 +1 @@
1
+ require 'simp/build/helpers/version'
@@ -0,0 +1,27 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Simp
21
+ module Build
22
+ module Helpers
23
+ # simp-build-helpers version
24
+ VERSION = "0.1.0"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,144 @@
1
+ require 'yaml'
2
+ require 'pry'
3
+
4
+
5
+ module Simp::Build
6
+ class SIMPBuildException < Exception; end
7
+ class ReleaseMapper
8
+ attr_accessor :do_checksums, :verbose
9
+
10
+ def initialize( target_release, mappings_file, do_checksums = false )
11
+ @target_release = target_release
12
+ @mappings_file = mappings_file
13
+ @release_mappings = YAML.load_file( mappings_file )
14
+ @target_data = get_release_mappings_for_target( @target_release, @release_mappings )
15
+ @do_checksums = do_checksums
16
+ @verbose = false
17
+ end
18
+
19
+
20
+ def get_release_mappings_for_target( target_release, release_mappings )
21
+ unless target_data = release_mappings
22
+ .fetch('simp_releases')
23
+ .fetch( target_release, false )
24
+
25
+ raise SIMPBuildException, "'#{target_release}' is not a recognized SIMP release." +
26
+ "\n\n## Recognized SIMP releases:\n" +
27
+ release_mappings.fetch('simp_releases')
28
+ .keys
29
+ .map{|x| " - #{x}\n"}
30
+ .join +
31
+ "\n\n"
32
+ end
33
+ target_data
34
+ end
35
+
36
+
37
+ # given a path string of files or directories, return a list of .iso files
38
+ # - if all paths are bad, the result is an empty arrays
39
+ # - directories are scanned for .iso files
40
+ def sanitize_iso_list( paths_string )
41
+ paths_string.split(':')
42
+ .map do |path|
43
+ if File.exists?( path )
44
+ if File.directory? path
45
+ Dir[File.join(path, '*.iso')]
46
+ elsif File.file? path
47
+ path
48
+ else
49
+ []
50
+ end
51
+ else
52
+ []
53
+ end
54
+ end
55
+ .flatten
56
+ .sort
57
+ .uniq
58
+ end
59
+
60
+ # Given a list of isos: see if any match the complete set of ISOs for one
61
+ # of the target_release's flavors. the target release. If it matches,
62
+ # return a Hash containing the flavor and the matched ISOs. If they didn't
63
+ # match any known distros, return nil
64
+ #
65
+ # Some of the `isos` lists might be superfluous
66
+ def get_flavor( isos )
67
+ iso_sizes = Hash[isos.map{|iso| [iso,File.size(iso)]}.sort]
68
+ result = false
69
+ result_isos = []
70
+ @target_data['flavors'].each do |flavor,data|
71
+ sizes = data['isos'].map{|x| x['size']}.sort
72
+ next unless sizes.uniq == sizes & iso_sizes.values
73
+ matched_isos = iso_sizes.select{|k,v| sizes.include?(v) }.keys
74
+ result_isos = matched_isos
75
+
76
+ if @do_checksums || (sizes.uniq.size != sizes.size)
77
+ result_isos = []
78
+ checksums = data['isos'].map{|x| x['checksum']}
79
+ iso_checksums = Hash[matched_isos.map do |iso|
80
+ puts "=== getting checksum of '#{iso}'" if @verbose
81
+ sum = `sha256sum "#{iso}"`.split(/ +/).first
82
+ [iso,sum]
83
+ end]
84
+
85
+ matched_isos = iso_checksums.select{|k,v| checksums.include?(v) }
86
+ if ( matched_isos.values.map{|sum| checksums.include? sum }
87
+ .all?{|x| x.class == TrueClass } ) &&
88
+ ( matched_isos.values.uniq.size == checksums.uniq.size )
89
+ result = flavor
90
+ result_isos = matched_isos.keys.dup
91
+ break
92
+ end
93
+ end
94
+ result = flavor
95
+ break
96
+ end
97
+
98
+ if result
99
+ @target_data['flavors'][result]
100
+ .merge({'flavor' => result})
101
+ .merge({'isos' =>result_isos})
102
+ else
103
+ nil
104
+ end
105
+ end
106
+
107
+ def autoscan_unpack_list( paths_string )
108
+ iso_paths = sanitize_iso_list( paths_string )
109
+
110
+ if iso_paths.empty?
111
+ raise SIMPBuildException,
112
+ 'ERROR: No suitable ISOs found for target release ' +
113
+ "'#{@target_release}' in '#{paths_string}'.\n\n" +
114
+
115
+ "## Recognized SIMP ISOs for '#{@target_release}:\n\n" +
116
+ @target_data.fetch('flavors')
117
+ .map{|flavor,data|
118
+ " ### #{flavor}\n\n" +
119
+ data['isos'].map{|x| " - #{x['name']}"}.join("\n") + "\n\n"
120
+ }.join + "\n\n"
121
+ end
122
+
123
+ unpack_files = get_flavor( iso_paths )
124
+
125
+ if unpack_files.nil?
126
+ max_iso_name_size = [@target_data['flavors'].map{|k,v| v['isos']}].flatten.map{|x| x['name'].size}.max
127
+ raise SIMPBuildException,
128
+ "ERROR: No flavors for target release '#{@target_release}' found in '#{paths_string}'.\n\n" +
129
+ "## Recognized SIMP ISOs for '#{@target_release}:\n\n" +
130
+ @target_data.fetch('flavors')
131
+ .map{|flavor,data|
132
+ " ### #{flavor}\n\n" +
133
+ data['isos'].map{|x|
134
+ " - #{x['name'].ljust(max_iso_name_size)}\n" +
135
+ " - size: #{x['size']}\n" +
136
+ " - checksum: #{x['checksum']}"}.join("\n") + "\n\n"
137
+ }.join + "\n\n"
138
+
139
+ end
140
+
141
+ unpack_files
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'simp/build/helpers/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "simp-build-helpers"
9
+ gem.version = Simp::Build::Helpers::VERSION
10
+ gem.summary = %q{SIMP build helpers}
11
+ gem.description = %q{Provides helper methods for building SIMP}
12
+ gem.license = "Apache-2.0"
13
+ gem.authors = ["Chris Tessmer"]
14
+ gem.email = "simp@simp-project.org"
15
+ gem.homepage = "https://github.com/simp/rubygem-simp-build-helpers"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+
19
+ `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule|
20
+ submodule.sub!("#{Dir.pwd}/",'')
21
+
22
+ Dir.chdir(submodule) do
23
+ `git ls-files`.split($/).map do |subpath|
24
+ gem.files << File.join(submodule,subpath)
25
+ end
26
+ end
27
+ end
28
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
29
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
30
+ gem.require_paths = ['lib']
31
+
32
+ gem.add_development_dependency 'bundler', '~> 1.0'
33
+ gem.add_development_dependency 'rake', '~> 10.0'
34
+ gem.add_development_dependency 'rspec', '~> 3.0'
35
+ gem.add_development_dependency 'yard', '~> 0.8'
36
+ end
@@ -0,0 +1 @@
1
+ matches byte size but not csum
@@ -0,0 +1 @@
1
+ CentOS-6.7-x86_64-bin-DVD1.iso
@@ -0,0 +1 @@
1
+ CentOS-6.7-x86_64-bin-DVD2.iso
@@ -0,0 +1 @@
1
+ CentOS-7-x86_64-DVD-1503-01.iso
@@ -0,0 +1 @@
1
+ CentOS-7-x86_64-DVD-1511.iso
@@ -0,0 +1 @@
1
+ RedHat-7.2-x86_64-DVD.iso
@@ -0,0 +1 @@
1
+ # placeholder text
@@ -0,0 +1,35 @@
1
+ ---
2
+ simp_releases:
3
+ 5.1.X:
4
+ flavors:
5
+ CentOS:
6
+ isos:
7
+ - name: 'CentOS-7-x86_64-DVD-1511.iso'
8
+ size: 29
9
+ checksum: 'a6525d9649326ff1d10958caa35b7e07cb454ee2419401a0e2ec03914a5c0e29'
10
+ RedHat:
11
+ isos:
12
+ - name: 'RedHat-7.2-x86_64-DVD.iso'
13
+ size: 26
14
+ checksum: '3ddcc08ba4cb90c1ef285aad2bce5bda2fd333fc0645e1db48a9c45b655c8a37'
15
+ build_command: 'bundle exec rake build:from_iso[RedHdat-7-x86_64-DVD-1511.iso]'
16
+ mock_cfg: 'epel-7-x86_64.cfg'
17
+ 5.1.0-2:
18
+ flavors:
19
+ CentOS:
20
+ isos:
21
+ - name: 'CentOS-7-x86_64-DVD-1503-01.iso'
22
+ size: 32
23
+ checksum: '698352c6b47a8a3cab47f2e1ee73722e25797511357787461a2b9e43dbb84ac2'
24
+ build_command: 'bundle exec rake <something-or-other>[CentOS-7-x86_64-DVD-1503-01.iso]'
25
+ mock_cfg: 'epel-7-x86_64.cfg'
26
+ 4.2.X:
27
+ flavors:
28
+ CentOS:
29
+ isos:
30
+ - name: 'CentOS-6.7-x86_64-bin-DVD1.iso'
31
+ size: 31
32
+ checksum: '1de19e772386fa08e82ddbcd00399159945a012ad1536dec76b260f9ef6036c3'
33
+ - name: 'CentOS-6.7-x86_64-bin-DVD1.iso'
34
+ size: 31
35
+ checksum: '8aa797a6d39f7496f1ef97e8b6a959941ee8e20e48bae545e5a96850fca98549'
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'simp/build/helpers'
3
+
4
+ describe Simp::Build::Helpers do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get('VERSION')).to_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+ require 'simp/build/release_mapper'
3
+
4
+ describe Simp::Build::ReleaseMapper do
5
+ before :each do
6
+ @mappings_path = File.expand_path( 'files/release_mappings.yaml', File.dirname(__FILE__) )
7
+ @mapper = Simp::Build::ReleaseMapper.new( '5.1.X', @mappings_path )
8
+ end
9
+
10
+ let :iso_paths do
11
+ pwd = File.expand_path( 'files/fake_isos', File.dirname(__FILE__) )
12
+ {
13
+ 'c7-64' => File.join(pwd, 'CentOS-7-x86_64-DVD-1511.iso'),
14
+ 'r7-64' => File.join(pwd, 'RedHat-7.2-x86_64-DVD.iso'),
15
+ 'c7-64-1503-1' => File.join(pwd, 'CentOS-7-x86_64-DVD-1503-01.iso'),
16
+ 'c67-64-1' => File.join(pwd, 'CentOS-6.7-x86_64-bin-DVD1.iso'),
17
+ 'c67-64-2' => File.join(pwd, 'CentOS-6.7-x86_64-bin-DVD2.iso'),
18
+ 'bad' => File.join(pwd, 'this', 'path', 'should', 'fail'),
19
+ 'c67-false-positive' => File.join(pwd, 'CentOS-6.7-false-positive.iso'),
20
+ }
21
+ end
22
+
23
+ describe '#initialize' do
24
+ it 'runs without errors' do
25
+ expect{ Simp::Build::ReleaseMapper.new( '5.1.X', @mappings_path ) }.to_not raise_error
26
+ end
27
+ end
28
+
29
+ describe '#sanitize_iso_list' do
30
+ it 'returns a 1-element list given a valid file' do
31
+ list = @mapper.sanitize_iso_list(iso_paths['c7-64'])
32
+ expect( list ).to be_a(Array)
33
+ expect( list.size ).to eq 1
34
+ end
35
+
36
+ it 'returns a 2-element list given two valid files (delimited by ":")' do
37
+ list = @mapper.sanitize_iso_list(
38
+ [iso_paths['c67-64-1'],iso_paths['c67-64-2']].join(':')
39
+ )
40
+ expect( list ).to be_a(Array)
41
+ expect( list.size ).to eq 2
42
+ end
43
+
44
+ it 'returns a list with one iso given the file' do
45
+ list = @mapper.sanitize_iso_list(iso_paths['c7-64'])
46
+ expect( list ).to be_a(Array)
47
+ expect( list.select{ |x| x =~ /.iso/ }.size ).to eq list.size
48
+ end
49
+
50
+ it 'returns a list of isos in a directory' do
51
+ list = @mapper.sanitize_iso_list( File.dirname iso_paths['c7-64'])
52
+ expect( list ).to be_a(Array)
53
+ expect( list.select{ |x| x =~ /.iso/ }.size ).to eq list.size
54
+ end
55
+
56
+ it 'returns an empty list for a non-existent path' do
57
+ list = @mapper.sanitize_iso_list( iso_paths['bad'] )
58
+ expect( list ).to be_a(Array)
59
+ expect( list ).to be_empty
60
+ end
61
+
62
+ it 'returns an empty list for an empty directory' do
63
+ list = @mapper.sanitize_iso_list(File.expand_path('files/fake_isos_empty',File.dirname(__FILE__)))
64
+ expect( list ).to be_a(Array)
65
+ expect( list ).to be_empty
66
+ end
67
+ end
68
+
69
+ describe '#get_flavor' do
70
+ it 'detects CentOS flavor for known file' do
71
+ list = [ iso_paths['c7-64'] ]
72
+ data = @mapper.get_flavor(list)
73
+ expect( data['flavor'] ).to eq('CentOS')
74
+ expect( data['isos'] ).to eq( list )
75
+ end
76
+
77
+ it 'detects RedHat flavor for known file' do
78
+ list = [ iso_paths['r7-64'] ]
79
+ data = @mapper.get_flavor(list)
80
+ expect( data['flavor'] ).to eq('RedHat')
81
+ expect( data['isos'] ).to eq( list )
82
+ end
83
+
84
+ it 'detects RedHat flavor and correct ISO from multiple files' do
85
+ list = [ iso_paths['c67-64-1'], iso_paths['c67-64-2'], iso_paths['r7-64'] ]
86
+ data = @mapper.get_flavor(list)
87
+ expect( data['flavor'] ).to eq('RedHat')
88
+ expect( data['isos'] ).to eq( [iso_paths['r7-64']] )
89
+ end
90
+
91
+ it 'detects CentOS flavor and correct ISOs from multiple files' do
92
+ mapper = Simp::Build::ReleaseMapper.new( '4.2.X', @mappings_path )
93
+ list = [ iso_paths['c67-64-1'], iso_paths['c67-64-2'], iso_paths['r7-64'] ]
94
+ data = mapper.get_flavor(list)
95
+ expect( data['flavor'] ).to eq('CentOS')
96
+ expect( data['isos'] ).to eq( [iso_paths['c67-64-1'], iso_paths['c67-64-2']] )
97
+ end
98
+
99
+ it 'returns nil when unable to detect a known flavor' do
100
+ list = [ iso_paths['c67-64-1'], iso_paths['c67-64-2'] ]
101
+ expect( @mapper.get_flavor(list) ).to be_nil
102
+ end
103
+
104
+ it 'detects CentOS flavor when checksums are enabled' do
105
+ mapper = Simp::Build::ReleaseMapper.new( '4.2.X', @mappings_path, true )
106
+ list = [ iso_paths['c67-64-1'], iso_paths['c67-64-2'], iso_paths['c67-false-positive'] ]
107
+ expect( mapper.get_flavor(list)['flavor'] ).to eq('CentOS')
108
+ end
109
+ end
110
+
111
+
112
+ describe '#autoscan_unpack_list' do
113
+ it 'autodetects 5.1.X unpack ISO from multiple directories' do
114
+ list = [ File.dirname(iso_paths['c7-64']),
115
+ File.expand_path('files/fake_isos_empty',File.dirname(__FILE__)) ]
116
+ path_string = list.join(':')
117
+ data = @mapper.autoscan_unpack_list(path_string)
118
+ expect( data ).to_not be_nil
119
+ expect( data['flavor'] ).to eq('CentOS')
120
+ expect( data['isos'] ).to eq [iso_paths['c7-64']]
121
+ end
122
+
123
+ it 'autodetects 4.2.X unpack ISOs from multiple directories' do
124
+ list = [ File.dirname(iso_paths['c67-64-1']),
125
+ File.expand_path('files/fake_isos_empty',File.dirname(__FILE__)) ]
126
+ path_string = list.join(':')
127
+ mapper = Simp::Build::ReleaseMapper.new( '4.2.X', @mappings_path, true )
128
+ data = mapper.autoscan_unpack_list(path_string)
129
+ expect( data ).to_not be_nil
130
+ expect( data['flavor'] ).to eq('CentOS')
131
+ expect( data['isos'].sort ).to eq [iso_paths['c67-64-1'],iso_paths['c67-64-2']]
132
+ end
133
+
134
+ it 'raises an error when no disks are found' do
135
+ path_string = iso_paths['bad']
136
+ expect{ @mapper.autoscan_unpack_list(path_string) }.to raise_error(Simp::Build::SIMPBuildException, /No suitable ISOs found/)
137
+ end
138
+ it "raises an error when no disks match the target's flavors" do
139
+ path_string = [iso_paths['c67-64-1'], iso_paths['c67-64-2']].join(':')
140
+ expect{ @mapper.autoscan_unpack_list(path_string) }.to raise_error(Simp::Build::SIMPBuildException, /No flavors for target release/)
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'simp/build/helpers/version'
3
+
4
+ include Simp::Build
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simp-build-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Tessmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ description: Provides helper methods for building SIMP
70
+ email: simp@simp-project.org
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - .yardopts
80
+ - ChangeLog.md
81
+ - Gemfile
82
+ - Guardfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - lib/simp/build/helpers.rb
87
+ - lib/simp/build/helpers/version.rb
88
+ - lib/simp/build/release_mapper.rb
89
+ - simp-build-helpers.gemspec
90
+ - spec/files/fake_isos/CentOS-6.7-false-positive.iso
91
+ - spec/files/fake_isos/CentOS-6.7-x86_64-bin-DVD1.iso
92
+ - spec/files/fake_isos/CentOS-6.7-x86_64-bin-DVD2.iso
93
+ - spec/files/fake_isos/CentOS-7-x86_64-DVD-1503-01.iso
94
+ - spec/files/fake_isos/CentOS-7-x86_64-DVD-1511.iso
95
+ - spec/files/fake_isos/RedHat-7.2-x86_64-DVD.iso
96
+ - spec/files/fake_isos_empty/.gitkeep
97
+ - spec/files/release_mappings.yaml
98
+ - spec/helpers_spec.rb
99
+ - spec/release_mapper_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/simp/rubygem-simp-build-helpers
102
+ licenses:
103
+ - Apache-2.0
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: SIMP build helpers
125
+ test_files:
126
+ - spec/files/fake_isos/CentOS-6.7-false-positive.iso
127
+ - spec/files/fake_isos/CentOS-6.7-x86_64-bin-DVD1.iso
128
+ - spec/files/fake_isos/CentOS-6.7-x86_64-bin-DVD2.iso
129
+ - spec/files/fake_isos/CentOS-7-x86_64-DVD-1503-01.iso
130
+ - spec/files/fake_isos/CentOS-7-x86_64-DVD-1511.iso
131
+ - spec/files/fake_isos/RedHat-7.2-x86_64-DVD.iso
132
+ - spec/files/fake_isos_empty/.gitkeep
133
+ - spec/files/release_mappings.yaml
134
+ - spec/helpers_spec.rb
135
+ - spec/release_mapper_spec.rb
136
+ - spec/spec_helper.rb