Project

General

Profile

Revision 9fb80abe

Added by Ondřej Pražák over 7 years ago

making promoting decisions more robust

View differences:

test/unit/job_test.rb
5 5
  def setup
6 6
    @organization = get_organization
7 7
    @compute_resource = FactoryGirl.create(:compute_resource, :libvirt)
8
    @hostgroup = FactoryGirl.create(:pipeline_hostgroup, :compute_profile => @compute_profile)
8
    @hostgroup = FactoryGirl.create(:pipeline_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)
......
23 23
    assert job.is_valid?
24 24
  end
25 25

  
26
  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))
30

  
31
    job = ForemanPipeline::Job.create(:name => "test job",
32
                                      :organization => @organization,
33
                                      :hostgroup => @hostgroup,
34
                                      :compute_resource => @compute_resource,
35
                                      :content_view => cv,
36
                                      :jenkins_instance => @jenkins_instance,
37
                                      :environment => env,
38
                                      :to_environments => [to_env])
39
    target_v = cv.content_view_versions.select { |v| v.environments.include?(env) && !v.environments.include?(to_env) }.first
40
    assert_equal target_v, job.target_cv_version
41
  end
42

  
43
  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))
46

  
47
    job = ForemanPipeline::Job.create(:name => "test job",
48
                                      :organization => @organization,
49
                                      :hostgroup => @hostgroup,
50
                                      :compute_resource => @compute_resource,
51
                                      :content_view => cv,
52
                                      :jenkins_instance => @jenkins_instance,
53
                                      :environment => env)
54

  
55
    assert_equal nil, job.target_cv_version
56
  end
57

  
58
  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))
63

  
64
    job = ForemanPipeline::Job.create(:name => "test job",
65
                                      :organization => @organization,
66
                                      :hostgroup => @hostgroup,
67
                                      :compute_resource => @compute_resource,
68
                                      :content_view => cv,
69
                                      :jenkins_instance => @jenkins_instance,
70
                                      :environment => env,
71
                                      :to_environments => [to_env, to_env2])
72
    assert_equal [to_env, to_env2], job.envs_for_promotion
73
  end
74

  
75
  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))
80

  
81
    job = ForemanPipeline::Job.create(:name => "test job",
82
                                      :organization => @organization,
83
                                      :hostgroup => @hostgroup,
84
                                      :compute_resource => @compute_resource,
85
                                      :content_view => cv,
86
                                      :jenkins_instance => @jenkins_instance,
87
                                      :environment => env,
88
                                      :to_environments => [to_env, to_env2])
89
    assert_equal [to_env2], job.envs_for_promotion
90
  end
91

  
92
  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))
97

  
98
    job = ForemanPipeline::Job.create(:name => "test job",
99
                                      :organization => @organization,
100
                                      :hostgroup => @hostgroup,
101
                                      :compute_resource => @compute_resource,
102
                                      :content_view => cv,
103
                                      :jenkins_instance => @jenkins_instance,
104
                                      :environment => env,
105
                                      :to_environments => [to_env, to_env2])
106
    assert job.can_be_promoted?
107
  end
108

  
109
  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))
113

  
114
    job = ForemanPipeline::Job.create(:name => "test job",
115
                                      :organization => @organization,
116
                                      :hostgroup => @hostgroup,
117
                                      :compute_resource => @compute_resource,
118
                                      :content_view => cv,
119
                                      :jenkins_instance => @jenkins_instance,
120
                                      :environment => env,
121
                                      :to_environments => [to_env])
122
    refute job.can_be_promoted?
123
  end
124

  
125
  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))
130

  
131
    job = ForemanPipeline::Job.create(:name => "test job",
132
                                      :organization => @organization,
133
                                      :hostgroup => @hostgroup,
134
                                      :compute_resource => @compute_resource,
135
                                      :content_view => cv,
136
                                      :jenkins_instance => @jenkins_instance,
137
                                      :environment => env,
138
                                      :to_environments => [to_env, to_env2])
139
    assert job.promotion_safe?
140
  end
141

  
142
  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))
145

  
146
    job = ForemanPipeline::Job.create(:name => "test job",
147
                                      :organization => @organization,
148
                                      :hostgroup => @hostgroup,
149
                                      :compute_resource => @compute_resource,
150
                                      :content_view => cv,
151
                                      :jenkins_instance => @jenkins_instance,
152
                                      :environment => env)
153
    refute job.promotion_safe?
154
  end
155

  
156
  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))
160

  
161
    job = ForemanPipeline::Job.create(:name => "test job",
162
                                      :organization => @organization,
163
                                      :hostgroup => @hostgroup,
164
                                      :compute_resource => @compute_resource,
165
                                      :content_view => cv,
166
                                      :jenkins_instance => @jenkins_instance,
167
                                      :environment => env,
168
                                      :to_environments => [to_env])
169
    refute job.promotion_safe?
170
  end
171

  
172
  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))
176

  
177
    job = ForemanPipeline::Job.new(:name => "test job",
178
                                      :organization => @organization,
179
                                      :hostgroup => @hostgroup,
180
                                      :compute_resource => @compute_resource,
181
                                      :content_view => cv,
182
                                      :jenkins_instance => @jenkins_instance,
183
                                      :environment => env,
184
                                      :to_environments => [to_env])
185
    job.save
186
    assert_equal "Environment succession violation: #{to_env.name}", job.errors[:base].first
187
  end
26 188
end

Also available in: Unified diff