foreman-katello-engine 0.0.3 → 0.0.4

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.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  Gemfile.lock
2
+ test/foreman_app
3
+ .bundle
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.3"
5
+ before_install: rake test:foreman_prepare
6
+ script: rake test
data/Gemfile CHANGED
@@ -1,3 +1,18 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ FOREMAN_GEMFILE=File.expand_path('../test/foreman_app/Gemfile', __FILE__)
6
+ unless File.exist?(FOREMAN_GEMFILE)
7
+ puts <<MESSAGE
8
+ Foreman source code is not present. To get the latest version, run:
9
+
10
+ rake test:foreman_prepare
11
+
12
+ and try again.
13
+ MESSAGE
14
+
15
+ else
16
+ self.instance_eval(Bundler.read_file(FOREMAN_GEMFILE))
17
+ end
18
+
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  Foreman Katello Rails Engine
2
2
  ============================
3
+ [![Build Status](https://travis-ci.org/Katello/foreman-katello-engine.png?branch=master)](https://travis-ci.org/Katello/foreman-katello-engine)
3
4
 
4
5
  Bringing Katello specific code into Foreman.
5
6
 
@@ -9,7 +10,6 @@ Installation
9
10
  Create `bundler.d/katello.rb` in your Foreman installation:
10
11
 
11
12
  ```ruby
12
- gem 'deface', '~> 0.7.2'
13
13
  gem 'foreman-katello-engine'
14
14
  ```
15
15
 
@@ -72,13 +72,28 @@ and reference it from the kickstart template:
72
72
  <%= snippets "katello" %>
73
73
  ```
74
74
 
75
- Current status
76
- --------------
75
+ Testing
76
+ -------
77
+
78
+ Since this is a Rails engine, it needs a host app to test the
79
+ functionality properly. Therefore to run the tests, you need to get
80
+ the source for the Foreman, as well as setting the development
81
+ environment.
82
+
83
+ The easiest way to do it is running this rake task:
84
+
85
+ rake test:foreman_prepare
86
+
87
+ This downloads the latest Foreman develop code, as well as installs
88
+ required dependencies.
89
+
90
+ To run the whole suite use:
91
+
92
+ rake test
77
93
 
78
- Highly experimental.
94
+ To execute a single test file run:
79
95
 
80
- The values for activation keys are not synced from actual Katello
81
- instance, just some test values.
96
+ ruby -Itest:lib path/to/your_test.rb
82
97
 
83
98
  Licence
84
99
  -------
data/Rakefile ADDED
@@ -0,0 +1,104 @@
1
+ ENGINE_DIR = File.expand_path('..', __FILE__)
2
+ FOREMAN_DIR = 'test/foreman_app'
3
+ require 'fileutils'
4
+
5
+ namespace :test do
6
+ desc "Download latest foreman devel source and install dependencies"
7
+ task :foreman_prepare do
8
+ foreman_repo = 'https://github.com/theforeman/foreman.git'
9
+ foreman_gemfile = File.join(FOREMAN_DIR, "Gemfile")
10
+ unless File.exists?(foreman_gemfile)
11
+ puts "Foreman source code is not present at #{FOREMAN_DIR}"
12
+ puts "Downloading latest Foreman development branch into #{FOREMAN_DIR}..."
13
+ FileUtils.mkdir_p(FOREMAN_DIR)
14
+
15
+ unless system("git clone #{foreman_repo} #{FOREMAN_DIR}")
16
+ puts "Error while getting latest Foreman code from #{foreman_repo} into #{FOREMAN_DIR}"
17
+ fail
18
+ end
19
+ end
20
+
21
+ gemfile_content = File.read(foreman_gemfile)
22
+ unless gemfile_content.include?('FOREMAN_GEMFILE')
23
+ puts 'Preparing Gemfile'
24
+ gemfile_content.gsub!('__FILE__', 'FOREMAN_GEMFILE')
25
+ gemfile_content.insert(0, "FOREMAN_GEMFILE = __FILE__ unless defined? FOREMAN_GEMFILE\n")
26
+ File.open(foreman_gemfile, 'w') { |f| f << gemfile_content }
27
+ end
28
+
29
+ settings_file = "#{FOREMAN_DIR}/config/settings.yaml"
30
+ unless File.exists?(settings_file)
31
+ puts 'Preparing settings file'
32
+ FileUtils.copy("#{settings_file}.example", settings_file)
33
+ settings_content = File.read(settings_file)
34
+ settings_content.sub!('organizations_enabled: false', 'organizations_enabled: true')
35
+ settings_content << ":puppetgem: true\n"
36
+ File.open(settings_file, 'w') { |f| f << settings_content }
37
+ end
38
+
39
+ db_file = "#{FOREMAN_DIR}/config/database.yml"
40
+ unless File.exists?(db_file)
41
+ puts 'Preparing database file'
42
+ FileUtils.copy("#{db_file}.example", db_file)
43
+ end
44
+
45
+ ["#{ENGINE_DIR}/.bundle/config", "#{FOREMAN_DIR}/.bundle/config"].each do |bundle_file|
46
+ unless File.exists?(bundle_file)
47
+ FileUtils.mkdir_p(File.dirname(bundle_file))
48
+ puts 'Preparing bundler configuration'
49
+ File.open(bundle_file, 'w') { |f| f << <<FILE }
50
+ ---
51
+ BUNDLE_WITHOUT: console:development:fog:jsonp:libvirt:mysql:mysql2:ovirt:postgresql:vmware
52
+ FILE
53
+ end
54
+ end
55
+
56
+ local_gemfile = "#{FOREMAN_DIR}/bundler.d/Gemfile.local.rb"
57
+ unless File.exist?(local_gemfile)
58
+ File.open(local_gemfile, 'w') { |f| f << <<GEMFILE }
59
+ gem "puppet"
60
+ gem "facter"
61
+ GEMFILE
62
+ end
63
+
64
+ puts 'Installing dependencies...'
65
+ unless system('bundle install')
66
+ fail
67
+ end
68
+ end
69
+
70
+ task :db_prepare do
71
+ unless File.exists?(FOREMAN_DIR)
72
+ puts <<MESSAGE
73
+ Foreman source code not prepared. Run
74
+
75
+ rake test:foreman_prepare
76
+
77
+ to download foreman source and its dependencies
78
+ MESSAGE
79
+ fail
80
+ end
81
+
82
+ # once we are Ruby19 only, switch to block variant of cd
83
+ pwd = FileUtils.pwd
84
+ FileUtils.cd(FOREMAN_DIR)
85
+ unless system('rake db:test:prepare RAILS_ENV=test')
86
+ puts "Migrating database first"
87
+ system('rake db:migrate db:schema:dump db:test:prepare RAILS_ENV=test') || fail
88
+ end
89
+ FileUtils.cd(pwd)
90
+ end
91
+
92
+ task :set_loadpath do
93
+ %w[lib test].each do |dir|
94
+ $:.unshift(File.expand_path(dir, ENGINE_DIR))
95
+ end
96
+ end
97
+
98
+ task :all => [:db_prepare, :set_loadpath] do
99
+ Dir.glob('test/**/*_test.rb') { |f| require f.sub('test/','') unless f.include? '/foreman_app/' }
100
+ end
101
+
102
+ end
103
+
104
+ task :test => 'test:all'
@@ -1,15 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "foreman-katello-engine"
3
- s.version = "0.0.3"
3
+ s.version = "0.0.4"
4
4
 
5
5
  s.authors = ["Katello"]
6
6
  s.date = "2013-03-04"
7
7
  s.description = "Katello specific parts of Foreman"
8
8
  s.email = "katello-devel@redhat.com"
9
9
  s.files = `git ls-files`.split("\n")
10
- s.homepage = "http://katello.org"
10
+ s.homepage = "http://github.com/katello/foreman-katello-engine"
11
11
  s.licenses = ["GPL-2"]
12
12
  s.require_paths = ["lib"]
13
13
  s.add_dependency "katello_api"
14
+ s.add_dependency "deface", "~> 0.7.2"
14
15
  s.summary = "Katello specific parts of Foreman"
15
16
  end
@@ -1 +1,2 @@
1
+ require 'deface'
1
2
  require 'foreman_katello_engine'
@@ -5,14 +5,6 @@ module ForemanKatelloEngine
5
5
 
6
6
  class << self
7
7
 
8
- def initialize_settings
9
- # proceed only if db set up correctly
10
- Setting.first rescue return
11
- [
12
- Foreman::DefaultSettings::Loader.set('katello_url', 'url of a Katello instance', 'https://localhost/katello')
13
- ].each { |s| Foreman::DefaultSettings::Loader.create(s.update(:category => "General")) }
14
- end
15
-
16
8
  def client_config
17
9
  {
18
10
  :base_url => Setting['katello_url'],
@@ -33,11 +25,11 @@ module ForemanKatelloEngine
33
25
  end
34
26
 
35
27
  def activation_keys_to_subscriptions(org_name, env_name)
36
- environments, _ = self.environment.index('organization_id' => org_name, :name => env_name)
28
+ environments, _ = self.environment.index('organization_id' => org_name, 'name' => env_name)
37
29
  if environment = environments.first
38
30
  activation_keys, _ = self.activation_key.index('environment_id' => environment['id'])
39
31
  return activation_keys.reduce({}) do |h, ak|
40
- h.update(ak['name'] => ak['pools'].map { |pool| pool['subscription'] })
32
+ h.update(ak['name'] => ak['pools'].map { |pool| pool['productName'] })
41
33
  end
42
34
  else
43
35
  return nil
@@ -3,9 +3,13 @@ module ForemanKatelloEngine
3
3
  #Thus, inhereits from ::Rails::Engine and not from Rails::Engine
4
4
  class Engine < ::Rails::Engine
5
5
 
6
- initializer 'foreman_katello_engine.helper' do |app|
6
+ config.after_initialize do
7
7
  require 'foreman_katello_engine/bindings'
8
- ForemanKatelloEngine::Bindings.initialize_settings
8
+ require 'foreman_katello_engine/settings'
9
+ ForemanKatelloEngine::Settings.initialize_settings
10
+ end
11
+
12
+ initializer 'foreman_katello_engine.helper' do |app|
9
13
  ActionView::Base.send :include, ForemanKatelloEngine::HostsAndHostgroupsHelper
10
14
  end
11
15
 
@@ -0,0 +1,13 @@
1
+ module ForemanKatelloEngine
2
+ class Settings
3
+
4
+ def self.initialize_settings
5
+ # proceed only if db set up correctly
6
+ Setting.first rescue return
7
+ [
8
+ Foreman::DefaultSettings::Loader.set('katello_url', 'url of a Katello instance', 'https://localhost/katello')
9
+ ].each { |s| Foreman::DefaultSettings::Loader.create(s.update(:category => "General")) }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+ require 'mocha/setup'
3
+
4
+ class ActivationKeysControllerTest < ActionController::TestCase
5
+
6
+ def aks_to_subscriptions_data
7
+ {"ak1" => ["prod1", "prod2"], "ak2" => ["prod3", "prod4"]}
8
+ end
9
+
10
+ def test_index
11
+ ForemanKatelloEngine::Bindings.stubs(:activation_keys_to_subscriptions).returns(aks_to_subscriptions_data)
12
+ get :index, {}, set_session_user
13
+ assert_response :success
14
+ assert_equal aks_to_subscriptions_data, JSON.parse(response.body)
15
+ end
16
+
17
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ require 'mocha/setup'
3
+
4
+ class BindingsTest < ActiveSupport::TestCase
5
+
6
+ def setup
7
+ Foreman::DefaultSettings::Loader.load
8
+ ForemanKatelloEngine::Settings.initialize_settings
9
+ end
10
+
11
+ test 'client lib setting' do
12
+ Setting['katello_url'] = 'https://example.com/katello'
13
+ Setting['oauth_consumer_key'] = 'key'
14
+ Setting['oauth_consumer_secret'] = 'secret'
15
+ config = ForemanKatelloEngine::Bindings.environment.config
16
+ assert_equal 'https://example.com/katello', config[:base_url]
17
+ assert_equal 'key', config[:oauth][:consumer_key]
18
+ assert_equal 'secret', config[:oauth][:consumer_secret]
19
+ end
20
+
21
+ test 'activation keys to subscriptions mapping' do
22
+ KatelloApi::Resources::Environment.any_instance.
23
+ expects(:index).
24
+ with('organization_id' => 'ACME_Corporation', 'name' => 'Dev').
25
+ returns([environments_data, environments_data.to_json])
26
+
27
+ KatelloApi::Resources::ActivationKey.any_instance.
28
+ expects(:index).
29
+ with('environment_id' => 2).
30
+ returns([activation_keys_data, activation_keys_data.to_json])
31
+
32
+ expected_mapping = {"katello-and-friends-dev" => ["Katello", "Candlepin", "Pulp", "Foreman"]}
33
+ mapping = ForemanKatelloEngine::Bindings.activation_keys_to_subscriptions('ACME_Corporation', 'Dev')
34
+ assert_equal(expected_mapping, mapping)
35
+ end
36
+
37
+ def environments_data
38
+ [
39
+ {"updated_at"=>"2013-03-08T13:26:56Z",
40
+ "created_at"=>"2013-03-08T13:26:56Z",
41
+ "name"=>"Dev",
42
+ "prior"=>"Library",
43
+ "prior_id"=>1,
44
+ "library"=>false,
45
+ "organization_id"=>1,
46
+ "description"=>"",
47
+ "id"=>2,
48
+ "organization"=>"ACME_Corporation",
49
+ "label"=>"Dev"},
50
+ ]
51
+ end
52
+
53
+ def activation_keys_data
54
+ [
55
+ {"name"=>"katello-and-friends-dev",
56
+ "description"=>"",
57
+ "user_id"=>1,
58
+ "created_at"=>"2013-03-08T14:23:06Z",
59
+ "system_template_id"=>nil,
60
+ "updated_at"=>"2013-03-13T13:59:38Z",
61
+ "id"=>1,
62
+ "organization_id"=>1,
63
+ "usage_limit"=>-1,
64
+ "pools"=>
65
+ [{"cp_id" => "8a90c4ae3d49de9b013d5dab8019004a", "productName" => "Katello"},
66
+ {"cp_id" => "8a90c4ae3d49de9b013d5dabc862004d", "productName" => "Candlepin"},
67
+ {"cp_id" => "8a90c4ae3d49de9b013d62d38e340071", "productName" => "Pulp"},
68
+ {"cp_id" => "8a90c4ae3d49de9b013d62d163e9006d", "productName" => "Foreman"}],
69
+ "content_view_id"=>nil,
70
+ "environment_id"=>2,
71
+ "usage_count"=>2},
72
+ ]
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class SettingsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ #Setting.where(:name => 'katello_url').delete_all
7
+ end
8
+
9
+ test "katello specific settings" do
10
+ ForemanKatelloEngine::Settings.initialize_settings
11
+ assert_equal 'https://localhost/katello', Setting['katello_url']
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+ require File.join("foreman_app/config/environment.rb")
6
+
7
+ require 'test/unit'
8
+ require 'foreman-katello-engine'
9
+ require 'rails/test_help'
10
+
11
+ Rails.backtrace_cleaner.remove_silencers!
12
+
13
+ class ActiveSupport::TestCase
14
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
15
+ #
16
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
17
+ # -- they do not yet inherit this setting
18
+
19
+ foreman_dir = File.expand_path("../foreman_app", File.join(Dir.pwd, __FILE__))
20
+ fixture_path=File.join(foreman_dir, "test/fixtures")
21
+ fixtures :all
22
+
23
+ set_fixture_class({ :hosts => Host::Base })
24
+ end
25
+
26
+ def set_session_user
27
+ SETTINGS[:login] ? {:user => User.admin.id, :expires_at => 5.minutes.from_now} : {}
28
+ end
metadata CHANGED
@@ -1,49 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: foreman-katello-engine
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Katello
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-03-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: katello_api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: deface
32
+ requirement: !ruby/object:Gem::Requirement
24
33
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.7.2
32
38
  type: :runtime
33
- version_requirements: *id001
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.7.2
34
46
  description: Katello specific parts of Foreman
35
47
  email: katello-devel@redhat.com
36
48
  executables: []
37
-
38
49
  extensions: []
39
-
40
50
  extra_rdoc_files: []
41
-
42
- files:
51
+ files:
43
52
  - .gitignore
53
+ - .travis.yml
44
54
  - Gemfile
45
55
  - LICENSE
46
56
  - README.md
57
+ - Rakefile
47
58
  - app/controllers/activation_keys_controller.rb
48
59
  - app/helpers/foreman_katello_engine/hosts_and_hostgroups_helper.rb
49
60
  - app/models/activation_key.rb
@@ -56,38 +67,34 @@ files:
56
67
  - lib/foreman_katello_engine.rb
57
68
  - lib/foreman_katello_engine/bindings.rb
58
69
  - lib/foreman_katello_engine/engine.rb
59
- homepage: http://katello.org
60
- licenses:
70
+ - lib/foreman_katello_engine/settings.rb
71
+ - test/functional/activation_keys_controller_test.rb
72
+ - test/lib/bindings_test.rb
73
+ - test/lib/settings_test.rb
74
+ - test/test_helper.rb
75
+ homepage: http://github.com/katello/foreman-katello-engine
76
+ licenses:
61
77
  - GPL-2
62
78
  post_install_message:
63
79
  rdoc_options: []
64
-
65
- require_paths:
80
+ require_paths:
66
81
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
82
+ required_ruby_version: !ruby/object:Gem::Requirement
68
83
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
89
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
85
94
  requirements: []
86
-
87
95
  rubyforge_project:
88
96
  rubygems_version: 1.8.25
89
97
  signing_key:
90
98
  specification_version: 3
91
99
  summary: Katello specific parts of Foreman
92
100
  test_files: []
93
-