Revision 9fb80abe
Added by Ondřej Pražák over 7 years ago
app/models/foreman_pipeline/job.rb | ||
---|---|---|
26 | 26 |
|
27 | 27 |
validates :name, :presence => true |
28 | 28 |
validates :organization, :presence => true |
29 |
validate :no_composite_view |
|
29 |
validate :no_composite_view, :check_env_succession
|
|
30 | 30 |
|
31 | 31 |
def is_valid? |
32 | 32 |
!self.attributes.values.include?(nil) && !self.jenkins_instance.jenkins_user.nil? |
... | ... | |
39 | 39 |
def target_cv_version |
40 | 40 |
fail "Cannot fetch target version, no environment set" if environment.nil? |
41 | 41 |
fail "Cannot fetch target version, no content view set" if content_view.nil? |
42 |
fail "Content view has no versions!" if content_view.content_view_versions.empty? |
|
42 | 43 |
self.environment.content_view_versions.where(:content_view_id => self.content_view.id).first |
43 | 44 |
end |
44 | 45 |
|
... | ... | |
49 | 50 |
jenkins_instance.create_client(jenkins_instance.jenkins_user.name, jenkins_instance.jenkins_user.token) |
50 | 51 |
end |
51 | 52 |
|
52 |
def version_already_promoted? |
|
53 |
self.target_cv_version.environments.include?(self.environment.successor) |
|
53 |
#Is any to_env set? (Do we want to promote to any env?) |
|
54 |
def should_be_promoted? |
|
55 |
!to_environments.empty? |
|
54 | 56 |
end |
55 | 57 |
|
56 |
def environment_in_paths?(env_id) |
|
57 |
paths.map(&:full_path).flatten.uniq.map(&:id).include? env_id |
|
58 |
# this shlould make sure not to trigger cyclic runs in hook actions |
|
59 |
def not_yet_promoted? |
|
60 |
# no to_envs means we do not want to promote, no need to check further here |
|
61 |
return true if to_environments.empty? |
|
62 |
#we want to promote, but are any of to_envs safe to promote to? |
|
63 |
can_be_promoted? |
|
64 |
end |
|
65 |
|
|
66 |
#If we want to promote, is it safe (or could we get a cycle)? |
|
67 |
def promotion_safe? |
|
68 |
should_be_promoted? ? can_be_promoted? : false |
|
69 |
end |
|
70 |
|
|
71 |
#we have some to_envs set (== we want to promote), but cv version may already be in those envs |
|
72 |
def envs_for_promotion |
|
73 |
to_environments.reject { |env| target_cv_version.environments.include?(env) } |
|
74 |
end |
|
75 |
|
|
76 |
def can_be_promoted? |
|
77 |
!envs_for_promotion.empty? |
|
58 | 78 |
end |
59 | 79 |
|
60 | 80 |
def available_compute_resources |
... | ... | |
68 | 88 |
"Cannot add content view, only non-composites allowed.") if !content_view.nil? && content_view.composite? |
69 | 89 |
end |
70 | 90 |
|
91 |
def check_env_succession |
|
92 |
if environment && should_be_promoted? |
|
93 |
to_environments.each do |to_env| |
|
94 |
unless to_env.prior == environment |
|
95 |
errors.add(:base, "Environment succession violation: #{to_env.name}") |
|
96 |
end |
|
97 |
end |
|
98 |
end |
|
99 |
end |
|
71 | 100 |
end |
72 | 101 |
end |
Also available in: Unified diff
making promoting decisions more robust