foreman_pipeline 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +2 -1
  4. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/jenkins-instance-details-info.controller.js +23 -2
  5. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/jenkins-instance-details.controller.js +1 -23
  6. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details-info.html +31 -0
  7. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details-users.html +17 -14
  8. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details.html +3 -10
  9. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/jenkins-instances.module.js +4 -1
  10. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/new/new-jenkins-instance.controller.js +4 -7
  11. data/app/assets/javascripts/foreman_pipeline/jenkins-instances/new/views/new-jenkins-instance-form.html +18 -3
  12. data/app/assets/javascripts/foreman_pipeline/jenkins-users/new/new-jenkins-user.controller.js +5 -5
  13. data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-content-views.controller.js +3 -3
  14. data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-hostgroups.controller.js +3 -5
  15. data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-jenkins-projects.controller.js +2 -2
  16. data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/job-projects-discovery.controller.js +10 -1
  17. data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/views/job-projects-discovery.html +20 -12
  18. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-content-views.html +12 -8
  19. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-environments.html +10 -6
  20. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-hostgroups.html +6 -2
  21. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-jenkins-projects.html +7 -6
  22. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-jenkins.html +15 -11
  23. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-resources.html +16 -12
  24. data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-to-environments.html +11 -7
  25. data/app/assets/javascripts/foreman_pipeline/jobs/jobs.module.js +4 -1
  26. data/app/assets/stylesheets/foreman_pipeline/foreman_pipeline.css +4 -0
  27. data/app/controllers/foreman_pipeline/api/jenkins_instances_controller.rb +10 -3
  28. data/app/controllers/foreman_pipeline/api/jenkins_projects_controller.rb +1 -1
  29. data/app/controllers/foreman_pipeline/api/jenkins_users_controller.rb +1 -1
  30. data/app/controllers/foreman_pipeline/api/jobs_controller.rb +44 -48
  31. data/app/lib/actions/foreman_pipeline/jenkins/build.rb +9 -3
  32. data/app/lib/actions/foreman_pipeline/jenkins/build_project.rb +2 -0
  33. data/app/lib/actions/foreman_pipeline/jenkins/bulk_build.rb +4 -0
  34. data/app/lib/actions/foreman_pipeline/jenkins/list.rb +4 -0
  35. data/app/lib/actions/foreman_pipeline/jenkins_instance/create_jenkins_instance_keys.rb +1 -1
  36. data/app/lib/actions/foreman_pipeline/job/create_host.rb +2 -2
  37. data/app/lib/actions/foreman_pipeline/job/cv_promote_job_hook.rb +1 -3
  38. data/app/lib/actions/foreman_pipeline/job/cv_publish_job_hook.rb +1 -3
  39. data/app/lib/actions/foreman_pipeline/job/job_hook.rb +4 -3
  40. data/app/lib/actions/foreman_pipeline/job/repo_sync_job_hook.rb +4 -17
  41. data/app/lib/actions/foreman_pipeline/job/run_job_manually.rb +2 -11
  42. data/app/lib/actions/foreman_pipeline/job/wait_until_provisioned.rb +4 -1
  43. data/app/lib/actions/foreman_pipeline/mixins/uri_extension.rb +1 -1
  44. data/app/models/foreman_pipeline/jenkins_instance.rb +8 -6
  45. data/app/models/foreman_pipeline/jenkins_project.rb +2 -4
  46. data/app/models/foreman_pipeline/jenkins_project_param.rb +0 -1
  47. data/app/models/foreman_pipeline/jenkins_user.rb +0 -2
  48. data/app/models/foreman_pipeline/job.rb +24 -8
  49. data/app/models/foreman_pipeline/job_to_environment.rb +0 -2
  50. data/app/services/foreman_pipeline/job_filter.rb +34 -0
  51. data/app/views/foreman/unattended/snippets/_jenkins_instance_pubkey.erb +3 -3
  52. data/app/views/foreman_pipeline/api/jenkins_instances/show.json.rabl +1 -1
  53. data/config/routes.rb +2 -7
  54. data/db/migrate/20150209160604_add_jenkins_home_to_jenkins_instance_table.rb +1 -1
  55. data/db/migrate/20150213095447_add_cert_path_to_jenkins_instances.rb +1 -1
  56. data/db/migrate/20150223142315_change_jenkins_instance_cert_path_column.rb +1 -1
  57. data/db/migrate/20150224090100_create_jenkins_projects_table.rb +4 -4
  58. data/db/migrate/20160404102405_update_projects_table.rb +9 -0
  59. data/db/migrate/20160404133012_drop_job_jenkins_project.rb +30 -0
  60. data/db/migrate/20160629085119_add_timeout_to_jenkins_instance.rb +9 -0
  61. data/db/seeds.d/location.rb +9 -0
  62. data/db/seeds.d/snippets.rb +11 -0
  63. data/lib/foreman_pipeline/engine.rb +1 -2
  64. data/lib/foreman_pipeline/plugin.rb +1 -1
  65. data/lib/foreman_pipeline/roles.rb +3 -3
  66. data/lib/foreman_pipeline/skip_tests.rb +22 -6
  67. data/lib/foreman_pipeline/tasks/{foreman_pipeline_test.rake → test.rake} +3 -2
  68. data/lib/foreman_pipeline/version.rb +1 -1
  69. data/test/fixtures/jenkins_instances.yml +8 -0
  70. data/test/fixtures/jenkins_projects.yml +9 -0
  71. data/test/fixtures/jenkins_users.yml +4 -0
  72. data/test/fixtures/jobs.yml +47 -0
  73. data/test/fixtures/pipeline_compute_attributes.yml +20 -0
  74. data/test/fixtures/pipeline_compute_profiles.yml +5 -0
  75. data/test/fixtures/pipeline_hostgroups.yml +25 -0
  76. data/test/fixtures_support.rb +17 -0
  77. data/test/{foreman_pipeline_plugin_test_helper.rb → foreman_pipeline_test_helper.rb} +17 -8
  78. data/test/functional/foreman_pipeline/api/jenkins_users_controller_test.rb +47 -0
  79. data/test/functional/foreman_pipeline/api/jobs_controller_test.rb +186 -0
  80. data/test/{unit → models}/jenkins_instance_test.rb +1 -1
  81. data/test/{unit → models}/job_test.rb +111 -55
  82. data/test/services/job_filter_test.rb +59 -0
  83. metadata +37 -16
  84. data/app/models/foreman_pipeline/job_jenkins_project.rb +0 -27
  85. data/lib/foreman_pipeline/tasks/foreman_pipeline_seed.rake +0 -28
  86. data/test/factories/hostgroup_factory.rb +0 -5
  87. data/test/unit/sanity_test.rb +0 -12
@@ -0,0 +1,47 @@
1
+ valid:
2
+ name: "valid job"
3
+ organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
4
+ hostgroup_id: <%= ActiveRecord::FixtureSet.identify(:basic) %>
5
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
6
+ content_view_id: <%= ActiveRecord::FixtureSet.identify(:library_view) %>
7
+ jenkins_instance_id: <%= ActiveRecord::FixtureSet.identify(:one) %>
8
+ environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
9
+ manual_trigger: true
10
+ sync_trigger: false
11
+ levelup_trigger: false
12
+
13
+ runs_on_sync:
14
+ name: "runs on sync"
15
+ organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
16
+ hostgroup_id: <%= ActiveRecord::FixtureSet.identify(:basic) %>
17
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
18
+ content_view_id: <%= ActiveRecord::FixtureSet.identify(:library_view) %>
19
+ jenkins_instance_id: <%= ActiveRecord::FixtureSet.identify(:one) %>
20
+ environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
21
+ manual_trigger: false
22
+ sync_trigger: true
23
+ levelup_trigger: false
24
+
25
+ runs_on_levelup:
26
+ name: "runs on publish/promote"
27
+ organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
28
+ hostgroup_id: <%= ActiveRecord::FixtureSet.identify(:basic) %>
29
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
30
+ content_view_id: <%= ActiveRecord::FixtureSet.identify(:library_view) %>
31
+ jenkins_instance_id: <%= ActiveRecord::FixtureSet.identify(:one) %>
32
+ environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
33
+ manual_trigger: false
34
+ sync_trigger: false
35
+ levelup_trigger: true
36
+
37
+ runs_on_first_publish:
38
+ name: "runs on publish/promote"
39
+ organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
40
+ hostgroup_id: <%= ActiveRecord::FixtureSet.identify(:basic) %>
41
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
42
+ content_view_id: <%= ActiveRecord::FixtureSet.identify(:no_environment_view) %>
43
+ jenkins_instance_id: <%= ActiveRecord::FixtureSet.identify(:one) %>
44
+ environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
45
+ manual_trigger: false
46
+ sync_trigger: false
47
+ levelup_trigger: true
@@ -0,0 +1,20 @@
1
+ simple:
2
+ compute_profile_id: <%= ActiveRecord::FixtureSet.identify(:small) %>
3
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
4
+ vm_attrs:
5
+ flavor_id: m1.small
6
+ availability_zone: eu-west-1a
7
+
8
+ intermediate:
9
+ compute_profile_id: <%= ActiveRecord::FixtureSet.identify(:big) %>
10
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:ec2) %>
11
+ vm_attrs:
12
+ cpus: 2
13
+ memory: 536870912
14
+
15
+ advanced:
16
+ compute_profile_id: <%= ActiveRecord::FixtureSet.identify(:big) %>
17
+ compute_resource_id: <%= ActiveRecord::FixtureSet.identify(:one) %>
18
+ vm_attrs:
19
+ cpus: 2
20
+ memory: 536870912
@@ -0,0 +1,5 @@
1
+ small:
2
+ name: small
3
+
4
+ big:
5
+ name: big
@@ -0,0 +1,25 @@
1
+ basic:
2
+ name: Basic
3
+ architecture: x86_64
4
+ environment: production
5
+ operatingsystem: centos5_3
6
+ medium: one
7
+ puppet_proxy: puppetmaster
8
+ domain: mydomain
9
+ title: Basic
10
+ root_pass: $1$foreman$NW1XVtbk4/XkJqmKNrFWV0
11
+ compute_profile_id: <%= ActiveRecord::FixtureSet.identify(:small) %>
12
+ lookup_value_matcher: hostgroup=Basic
13
+
14
+ advanced:
15
+ name: Advanced
16
+ architecture: x86_64
17
+ environment: production
18
+ operatingsystem: centos5_3
19
+ medium: one
20
+ puppet_proxy: puppetmaster
21
+ domain: mydomain
22
+ title: advanced
23
+ root_pass: $1$foreman$NW1XVtbk4/XkJqmKNrFWV0
24
+ compute_profile_id: <%= ActiveRecord::FixtureSet.identify(:big) %>
25
+ lookup_value_matcher: hostgroup=Advanced
@@ -0,0 +1,17 @@
1
+ module ForemanPipeline
2
+ module FixturesSupport
3
+ FIXTURE_CLASSES = {
4
+ :jobs => ForemanPipeline::Job,
5
+ :jenkins_instances => ForemanPipeline::JenkinsInstance,
6
+ :jenkins_users => ForemanPipeline::JenkinsUser,
7
+ :jenkins_projects => ForemanPipeline::JenkinsProject,
8
+ :pipeline_hostgroups => Hostgroup,
9
+ :pipeline_compute_profiles => ComputeProfile,
10
+ :pipeline_compute_attributes => ComputeAttribute,
11
+ }
12
+
13
+ def self.set_fixture_classes(test_class)
14
+ FIXTURE_CLASSES.each { |k, v| test_class.set_fixture_class(k => v) }
15
+ end
16
+ end
17
+ end
@@ -5,6 +5,11 @@ FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factorie
5
5
  FactoryGirl.reload
6
6
 
7
7
  require "#{Katello::Engine.root}/test/support/fixtures_support"
8
+ require "fixtures_support"
9
+
10
+ require 'dynflow/testing'
11
+ Mocha::Mock.send :include, Dynflow::Testing::Mimic
12
+ require "#{Katello::Engine.root}/test/support/foreman_tasks/task"
8
13
 
9
14
  module FixtureTestCase
10
15
  extend ActiveSupport::Concern
@@ -17,16 +22,14 @@ module FixtureTestCase
17
22
  self.pre_loaded_fixtures = true
18
23
 
19
24
  Katello::FixturesSupport.set_fixture_classes(self)
25
+ ForemanPipeline::FixturesSupport.set_fixture_classes(self)
20
26
 
21
- self.fixture_path = Dir.mktmpdir("katello_fixtures")
27
+ self.fixture_path = Dir.mktmpdir("pipeline_and_katello_fixtures")
22
28
  FileUtils.cp(Dir.glob("#{Katello::Engine.root}/test/fixtures/models/*"), self.fixture_path)
29
+ FileUtils.cp(Dir.glob("#{ForemanPipeline::Engine.root}/test/fixtures/*"), self.fixture_path)
23
30
  FileUtils.cp(Dir.glob("#{Rails.root}/test/fixtures/*"), self.fixture_path)
24
31
  fixtures(:all)
25
- FIXTURES = load_fixtures
26
-
27
- # load_permissions
28
-
29
- Setting::Katello.load_defaults
32
+ FIXTURES = load_fixtures(ActiveRecord::Base)
30
33
  end
31
34
 
32
35
  module ClassMethods
@@ -42,9 +45,9 @@ class ActiveSupport::TestCase
42
45
 
43
46
  def get_organization(org = nil)
44
47
  saved_user = User.current
45
- User.current = User.find(users(:admin))
48
+ User.current = User.find(users(:admin).id)
46
49
  org = org.nil? ? :empty_organization : org
47
- organization = Organization.find(taxonomies(org.to_sym))
50
+ organization = Organization.find(taxonomies(org.to_sym).id)
48
51
  organization.stubs(:label_not_changed).returns(true)
49
52
  organization.setup_label_from_name
50
53
  organization.save!
@@ -52,3 +55,9 @@ class ActiveSupport::TestCase
52
55
  organization
53
56
  end
54
57
  end
58
+
59
+ class ActionController::TestCase
60
+ def setup_engine_routes
61
+ @routes = ForemanPipeline::Engine.routes
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ require "foreman_pipeline_test_helper"
2
+
3
+ class ForemanPipeline::Api::JenkinsUsersControllerTest < ActionController::TestCase
4
+ setup do
5
+ setup_engine_routes
6
+ @org = get_organization
7
+ @user = ForemanPipeline::JenkinsUser.find(jenkins_users(:jenkins_user_one).id)
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index, :organization_id => @org.id
12
+ assert_response :success
13
+ response = JSON.parse(@response.body)
14
+ assert_equal 1, response['total']
15
+ assert_equal @user.name, response['results'].first['name']
16
+ end
17
+
18
+ test "should get show" do
19
+ get :show, :organization_id => @org.id,
20
+ :id => @user.id
21
+ assert_response :success
22
+ resp = JSON.parse(@response.body)
23
+ assert_equal @user.name, resp['name']
24
+ end
25
+
26
+ test "should update jenkins user" do
27
+ put :update, :organization_id => @org.id,
28
+ :id => @user.id,
29
+ :jenkins_user => { :id => @user.id,
30
+ :name => "New username" }
31
+ assert_response :success
32
+ end
33
+
34
+ test "should create jenkins user" do
35
+ post :create, :organization_id => @org.id,
36
+ :jenkins_user => { :name => "Brand new user",
37
+ :organization_id => @org.id,
38
+ :token => "AndTheSilenceGaveNoToken" }
39
+ assert_response :success
40
+ end
41
+
42
+ test "should destroy jenkins user" do
43
+ delete :destroy, :organization_id => @org.id,
44
+ :id => @user.id
45
+ assert_response :success
46
+ end
47
+ end
@@ -0,0 +1,186 @@
1
+ require 'foreman_pipeline_test_helper'
2
+
3
+ class ForemanPipeline::Api::JobsControllerTest < ActionController::TestCase
4
+ include ::Support::ForemanTasks::Task
5
+
6
+ setup do
7
+ stub_tasks!
8
+ setup_engine_routes
9
+ @job = jobs(:valid)
10
+ @org = get_organization
11
+ end
12
+
13
+ test "should get index" do
14
+ get :index, { :organization_id => @org.id}
15
+ assert_response :success
16
+ response = ActiveSupport::JSON.decode(@response.body)
17
+ assert_equal 4, response['total']
18
+ assert response['results'].map { |item| item['name'] }.include?("valid job")
19
+ end
20
+
21
+ test 'should get show' do
22
+ job = ForemanPipeline::Job.find(jobs(:valid).id)
23
+ get :show, { :organization_id => @org.id, :id => job.id }
24
+ assert_response :success
25
+ response = ActiveSupport::JSON.decode(@response.body)
26
+ assert_equal job.name, response['name']
27
+ end
28
+
29
+ test 'should create new job' do
30
+ post :create, :organization_id => @org.id,
31
+ :job => { :name => "new job",
32
+ :manual_trigger => false,
33
+ :levelup_trigger => false,
34
+ :sync_trigger => false }
35
+ assert_response :success
36
+ end
37
+
38
+ test 'should not create new job without name' do
39
+ post :create, :organization_id => @org.id,
40
+ :job => { :manual_trigger => false,
41
+ :levelup_trigger => false,
42
+ :sync_trigger => false }
43
+ assert_response :unprocessable_entity
44
+ response = ActiveSupport::JSON.decode(@response.body)
45
+ assert_equal ["can't be blank"], response['errors']['name']
46
+ end
47
+
48
+ test 'should update job' do
49
+ put :update, :organization_id => @org.id,
50
+ :job => { :id => @job.id,
51
+ :name => "updated job",
52
+ :manual_trigger => true,
53
+ :levelup_trigger => false,
54
+ :sync_trigger => false },
55
+ :id => @job.id
56
+ assert_response :success
57
+ end
58
+
59
+ test 'should not update job with nil as a name' do
60
+ put :update, :organization_id => @org.id,
61
+ :job => { :id => @job.id,
62
+ :name => nil,
63
+ :manual_trigger => true,
64
+ :levelup_trigger => false,
65
+ :sync_trigger => false },
66
+ :id => @job.id
67
+ assert_response :unprocessable_entity
68
+ end
69
+
70
+ test 'should delete job' do
71
+ delete :destroy, :organization_id => @org.id,
72
+ :id => @job.id
73
+ assert_response :success
74
+ end
75
+
76
+ test 'should set content view' do
77
+ cv_id = katello_content_views(:acme_default).id
78
+ put :set_content_view, :organization_id => @org.id,
79
+ :id => @job.id,
80
+ :content_view_id => cv_id
81
+ assert_response :success
82
+ end
83
+
84
+ test 'should set hostgroup' do
85
+ hg_id = pipeline_hostgroups(:basic).id
86
+ put :set_hostgroup, :organization_id => @org.id,
87
+ :id => @job.id,
88
+ :hostgroup_id => hg_id
89
+ assert_response :success
90
+ end
91
+
92
+ test 'should set jenkins' do
93
+ jenkins_id = jenkins_instances(:one).id
94
+ put :set_jenkins, :organization_id => @org.id,
95
+ :id => @job.id,
96
+ :jenkins_instance_id => jenkins_id
97
+ assert_response :success
98
+ end
99
+
100
+ test 'should set environment' do
101
+ env_id = katello_environments(:library).id
102
+ put :set_environment, :organization_id => @org.id,
103
+ :id => @job.id,
104
+ :environment_id => env_id
105
+ assert_response :success
106
+ end
107
+
108
+ test "should set compute resource" do
109
+ compute_id = compute_resources(:ec2).id
110
+ put :set_resource, :organization_id => @org.id,
111
+ :id => @job.id,
112
+ :resource_id => compute_id
113
+ assert_response :success
114
+ end
115
+
116
+ test "should not set compute resource" do
117
+ compute_id = compute_resources(:mycompute).id
118
+ put :set_resource, :organization_id => @org.id,
119
+ :id => @job.id,
120
+ :resource_id => compute_id
121
+ assert_response :unprocessable_entity
122
+ message = "Cannot add a Compute resource that is not associated with assigned Hostgroup through a Compute profile"
123
+ assert_equal message, JSON.parse(@response.body)['errors']['base'].first
124
+ end
125
+
126
+ test "should set to_environments" do
127
+ ids = [katello_environments(:dev).id, katello_environments(:staging).id]
128
+ put :set_to_environments, :organization_id => @org.id,
129
+ :id => @job.id,
130
+ :to_environment_ids => ids
131
+ assert_response :success
132
+ end
133
+
134
+ test "should not set to_environments and detect env succession violation" do
135
+ ids = [katello_environments(:beta).id]
136
+ put :set_to_environments, :organization_id => @org.id,
137
+ :id => @job.id,
138
+ :to_environment_ids => ids
139
+ assert_response :unprocessable_entity
140
+ end
141
+
142
+ test "should set empty to_environments" do
143
+ put :set_to_environments, :organization_id => @org.id,
144
+ :id => @job.id,
145
+ :to_environment_ids => []
146
+ assert_response :success
147
+ end
148
+
149
+ test "should list available paths" do
150
+ get :available_paths, :organization_id => @org.id,
151
+ :id => @job.id
152
+ resp = JSON.parse(@response.body)
153
+ assert_equal "Dev", resp['results'].first['environments'][1]['name']
154
+ assert_equal 4, resp['results'].count
155
+ end
156
+
157
+ test "should list available resources" do
158
+ get :available_resources, :organization_id => @org.id,
159
+ :id => @job.id
160
+ resp = JSON.parse(@response.body)
161
+ assert_equal 1, resp.count
162
+ end
163
+
164
+ test "should run job" do
165
+ get :run_job, :organization_id => @org.id,
166
+ :id => @job.id
167
+ assert_equal "", @response.body
168
+ assert_response :success
169
+ end
170
+
171
+ test "should add jenkins projects" do
172
+ assert_sync_task(::Actions::ForemanPipeline::Jenkins::GetBuildParams, :job_id => @job.id, :name => "foo")
173
+ put :add_projects, :organization_id => @org.id,
174
+ :id => @job.id,
175
+ :projects => ["foo"]
176
+ assert_response :success
177
+ end
178
+
179
+ test "remove jenkins projects" do
180
+ ids = [jenkins_projects(:first).id, jenkins_projects(:second).id]
181
+ put :remove_projects, :organization_id => @org.id,
182
+ :id => @job.id,
183
+ :projects => ids
184
+ assert_response :success
185
+ end
186
+ end
@@ -1,4 +1,4 @@
1
- require 'foreman_pipeline_plugin_test_helper'
1
+ require 'foreman_pipeline_test_helper'
2
2
 
3
3
  class JenkinsInstanceTest < ActiveSupport::TestCase
4
4
 
@@ -1,32 +1,21 @@
1
- require 'foreman_pipeline_plugin_test_helper'
1
+ require 'foreman_pipeline_test_helper'
2
2
 
3
3
  class JobTest < ActiveSupport::TestCase
4
4
 
5
5
  def setup
6
6
  @organization = get_organization
7
7
  @compute_resource = FactoryGirl.create(:compute_resource, :libvirt)
8
- @hostgroup = FactoryGirl.create(:pipeline_hostgroup)
8
+ @hostgroup = FactoryGirl.create(:hostgroup)
9
9
  @content_view = FactoryGirl.create(:katello_content_view)
10
10
  @jenkins_user = FactoryGirl.create(:jenkins_user, :organization => get_organization)
11
11
  @jenkins_instance = FactoryGirl.create(:jenkins_instance, :jenkins_user => @jenkins_user, :organization => get_organization)
12
12
  @environment = FactoryGirl.create(:katello_environment, :library)
13
13
  end
14
14
 
15
- test "should validate host" do
16
- job = ForemanPipeline::Job.create(:name => "test job",
17
- :organization => @organization,
18
- :hostgroup => @hostgroup,
19
- :compute_resource => @compute_resource,
20
- :content_view => @content_view,
21
- :jenkins_instance => @jenkins_instance,
22
- :environment => @environment)
23
- assert job.is_valid?
24
- end
25
-
26
15
  test "should find target cv" do
27
- cv = Katello::ContentView.find(katello_content_views(:acme_default))
28
- env = Katello::KTEnvironment.find(katello_environments(:library))
29
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
16
+ cv = Katello::ContentView.find(katello_content_views(:acme_default).id)
17
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
18
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
30
19
 
31
20
  job = ForemanPipeline::Job.create(:name => "test job",
32
21
  :organization => @organization,
@@ -41,8 +30,8 @@ class JobTest < ActiveSupport::TestCase
41
30
  end
42
31
 
43
32
  test "should not find target cv" do
44
- cv = Katello::ContentView.find(katello_content_views(:acme_default))
45
- env = Katello::KTEnvironment.find(katello_environments(:test))
33
+ cv = Katello::ContentView.find(katello_content_views(:acme_default).id)
34
+ env = Katello::KTEnvironment.find(katello_environments(:test).id)
46
35
 
47
36
  job = ForemanPipeline::Job.create(:name => "test job",
48
37
  :organization => @organization,
@@ -56,10 +45,10 @@ class JobTest < ActiveSupport::TestCase
56
45
  end
57
46
 
58
47
  test "should find envs for promotion" do
59
- cv = Katello::ContentView.find(katello_content_views(:acme_default))
60
- env = Katello::KTEnvironment.find(katello_environments(:library))
61
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
62
- to_env2 = Katello::KTEnvironment.find(katello_environments(:staging))
48
+ cv = Katello::ContentView.find(katello_content_views(:acme_default).id)
49
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
50
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
51
+ to_env2 = Katello::KTEnvironment.find(katello_environments(:staging).id)
63
52
 
64
53
  job = ForemanPipeline::Job.create(:name => "test job",
65
54
  :organization => @organization,
@@ -73,10 +62,10 @@ class JobTest < ActiveSupport::TestCase
73
62
  end
74
63
 
75
64
  test "envs_for_promotion should exclude one env from promotions" do
76
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
77
- env = Katello::KTEnvironment.find(katello_environments(:library))
78
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
79
- to_env2 = Katello::KTEnvironment.find(katello_environments(:staging))
65
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
66
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
67
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
68
+ to_env2 = Katello::KTEnvironment.find(katello_environments(:staging).id)
80
69
 
81
70
  job = ForemanPipeline::Job.create(:name => "test job",
82
71
  :organization => @organization,
@@ -90,10 +79,10 @@ class JobTest < ActiveSupport::TestCase
90
79
  end
91
80
 
92
81
  test "job can be promoted" do
93
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
94
- env = Katello::KTEnvironment.find(katello_environments(:library))
95
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
96
- to_env2 = Katello::KTEnvironment.find(katello_environments(:staging))
82
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
83
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
84
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
85
+ to_env2 = Katello::KTEnvironment.find(katello_environments(:staging).id)
97
86
 
98
87
  job = ForemanPipeline::Job.create(:name => "test job",
99
88
  :organization => @organization,
@@ -107,9 +96,9 @@ class JobTest < ActiveSupport::TestCase
107
96
  end
108
97
 
109
98
  test "job cannot be promoted" do
110
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
111
- env = Katello::KTEnvironment.find(katello_environments(:library))
112
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
99
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
100
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
101
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
113
102
 
114
103
  job = ForemanPipeline::Job.create(:name => "test job",
115
104
  :organization => @organization,
@@ -123,10 +112,10 @@ class JobTest < ActiveSupport::TestCase
123
112
  end
124
113
 
125
114
  test "is promotion safe" do
126
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
127
- env = Katello::KTEnvironment.find(katello_environments(:library))
128
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
129
- to_env2 = Katello::KTEnvironment.find(katello_environments(:staging))
115
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
116
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
117
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
118
+ to_env2 = Katello::KTEnvironment.find(katello_environments(:staging).id)
130
119
 
131
120
  job = ForemanPipeline::Job.create(:name => "test job",
132
121
  :organization => @organization,
@@ -140,8 +129,8 @@ class JobTest < ActiveSupport::TestCase
140
129
  end
141
130
 
142
131
  test "is not promotion safe" do
143
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
144
- env = Katello::KTEnvironment.find(katello_environments(:library))
132
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
133
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
145
134
 
146
135
  job = ForemanPipeline::Job.create(:name => "test job",
147
136
  :organization => @organization,
@@ -154,9 +143,9 @@ class JobTest < ActiveSupport::TestCase
154
143
  end
155
144
 
156
145
  test "is not promotion safe again" do
157
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
158
- env = Katello::KTEnvironment.find(katello_environments(:library))
159
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
146
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
147
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
148
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
160
149
 
161
150
  job = ForemanPipeline::Job.create(:name => "test job",
162
151
  :organization => @organization,
@@ -170,9 +159,9 @@ class JobTest < ActiveSupport::TestCase
170
159
  end
171
160
 
172
161
  test "should detect env succession violation" do
173
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
174
- env = Katello::KTEnvironment.find(katello_environments(:library))
175
- to_env = Katello::KTEnvironment.find(katello_environments(:test))
162
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
163
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
164
+ to_env = Katello::KTEnvironment.find(katello_environments(:test).id)
176
165
 
177
166
  job = ForemanPipeline::Job.new(:name => "test job",
178
167
  :organization => @organization,
@@ -186,9 +175,9 @@ class JobTest < ActiveSupport::TestCase
186
175
  assert_equal "Environment succession violation: #{to_env.name}", job.errors[:base].first
187
176
  end
188
177
 
189
- test "was not yet promoted" do
190
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
191
- env = Katello::KTEnvironment.find(katello_environments(:library))
178
+ test "was not yet promoted to given envs" do
179
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
180
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
192
181
  job = ForemanPipeline::Job.create(:name => "test job",
193
182
  :organization => @organization,
194
183
  :hostgroup => @hostgroup,
@@ -200,10 +189,26 @@ class JobTest < ActiveSupport::TestCase
200
189
  assert job.not_yet_promoted?
201
190
  end
202
191
 
192
+ test "was already promoted to all to_environments" do
193
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
194
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
195
+ lib = Katello::KTEnvironment.find(katello_environments(:library).id)
196
+
197
+ job = ForemanPipeline::Job.create(:name => "test job",
198
+ :organization => @organization,
199
+ :hostgroup => @hostgroup,
200
+ :compute_resource => @compute_resource,
201
+ :content_view => cv,
202
+ :jenkins_instance => @jenkins_instance,
203
+ :environment => lib,
204
+ :to_environments => [to_env])
205
+ refute job.not_yet_promoted?
206
+ end
207
+
203
208
  test "there should be env for promotion" do
204
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
205
- env = Katello::KTEnvironment.find(katello_environments(:dev))
206
- to_env = Katello::KTEnvironment.find(katello_environments(:test))
209
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
210
+ env = Katello::KTEnvironment.find(katello_environments(:dev).id)
211
+ to_env = Katello::KTEnvironment.find(katello_environments(:test).id)
207
212
 
208
213
  job = ForemanPipeline::Job.create(:name => "test job",
209
214
  :organization => @organization,
@@ -217,10 +222,10 @@ class JobTest < ActiveSupport::TestCase
217
222
  assert_equal to_env, job.envs_for_promotion.first
218
223
  end
219
224
 
220
- test "there shloud not be env for promotion" do
221
- cv = Katello::ContentView.find(katello_content_views(:library_dev_view))
222
- env = Katello::KTEnvironment.find(katello_environments(:library))
223
- to_env = Katello::KTEnvironment.find(katello_environments(:dev))
225
+ test "there should not be env for promotion" do
226
+ cv = Katello::ContentView.find(katello_content_views(:library_dev_view).id)
227
+ env = Katello::KTEnvironment.find(katello_environments(:library).id)
228
+ to_env = Katello::KTEnvironment.find(katello_environments(:dev).id)
224
229
 
225
230
  job = ForemanPipeline::Job.create(:name => "test job",
226
231
  :organization => @organization,
@@ -232,4 +237,55 @@ class JobTest < ActiveSupport::TestCase
232
237
  :to_environments => [to_env])
233
238
  assert job.envs_for_promotion.empty?
234
239
  end
240
+
241
+ test "should not save job with composite view" do
242
+ composite = Katello::ContentView.find(katello_content_views(:composite_view).id)
243
+ job = ForemanPipeline::Job.new(:name => "test job",
244
+ :content_view => composite)
245
+ refute job.save
246
+ assert job.errors['base'].include? "Cannot add content view, only non-composites allowed."
247
+ end
248
+
249
+ test "should not save job where compute profile on hg is missing" do
250
+ job = ForemanPipeline::Job.create(:name => "test job",
251
+ :organization => @organization,
252
+ :hostgroup => @hostgroup,
253
+ :content_view => @content_view,
254
+ :jenkins_instance => @jenkins_instance,
255
+ :environment => @environment)
256
+ refute job.is_valid?
257
+ end
258
+
259
+ test "should not save job when compute resource is not available through hostgroup" do
260
+ job = ForemanPipeline::Job.create(:name => "test job",
261
+ :organization => @organization,
262
+ :hostgroup => Hostgroup.find(pipeline_hostgroups(:basic).id),
263
+ :compute_resource => @compute_resource,
264
+ :content_view => @content_view,
265
+ :jenkins_instance => @jenkins_instance,
266
+ :environment => @environment)
267
+ refute job.is_valid?
268
+ end
269
+
270
+ test "should find one compute resource available" do
271
+ job = ForemanPipeline::Job.create(:name => "test_job",
272
+ :organization => @organization,
273
+ :hostgroup => Hostgroup.find(pipeline_hostgroups(:basic).id))
274
+ assert_equal 1, job.available_compute_resources.count
275
+ end
276
+
277
+ test "should find two compute resources available" do
278
+ job = ForemanPipeline::Job.create(:name => "test_job",
279
+ :organization => @organization,
280
+ :hostgroup => Hostgroup.find(pipeline_hostgroups(:advanced).id))
281
+ assert_equal 2, job.available_compute_resources.count
282
+ end
283
+
284
+ test "should not save when hostgroup has no puppet env" do
285
+ job = ForemanPipeline::Job.new(:name => "test job",
286
+ :organization => @organization,
287
+ :hostgroup => @hostgroup)
288
+ refute job.save
289
+ assert job.errors.messages[:base].include? "Cannot add Hostgroup without Puppet environment"
290
+ end
235
291
  end