Skip to content

Commit

Permalink
Merge pull request #13785 from syncrou/service_without_service_template
Browse files Browse the repository at this point in the history
Power state for services that do not have an associated service_template
(cherry picked from commit 2de4087)

https://bugzilla.redhat.com/show_bug.cgi?id=1422650
  • Loading branch information
gmcculloug authored and simaishi committed Mar 3, 2017
1 parent ab2c703 commit f61a7f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Service < ApplicationRecord
delegate :custom_actions, :custom_action_buttons, :to => :service_template, :allow_nil => true
delegate :provision_dialog, :to => :miq_request, :allow_nil => true
delegate :user, :to => :miq_request, :allow_nil => true
delegate :atomic?, :to => :service_template
delegate :composite?, :to => :service_template

include ServiceMixin
include OwnershipMixin
Expand Down Expand Up @@ -213,6 +211,14 @@ def power_states_match?(action)
false
end

def composite?
service_template ? service_template.composite? : children.present?
end

def atomic?
service_template ? service_template.atomic? : children.empty?
end

def map_composite_power_states(action)
action_name = "#{action}_action"
service_actions = service_resources.map(&action_name.to_sym).uniq
Expand Down
10 changes: 10 additions & 0 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,19 @@
it "returns children" do
create_deep_tree
expect(@service.children).to match_array([@service_c1, @service_c2])
expect(@service.service_template).to be_nil
expect(@service.composite?).to be_truthy
expect(@service.atomic?).to be_falsey
expect(@service.services).to match_array([@service_c1, @service_c2]) # alias
expect(@service.direct_service_children).to match_array([@service_c1, @service_c2]) # alias
end

it "returns no children" do
@service = FactoryGirl.create(:service)
expect(@service.children).to be_empty
expect(@service.composite?).to be_falsey
expect(@service.atomic?).to be_truthy
end
end

describe "#indirect_service_children" do
Expand Down

0 comments on commit f61a7f1

Please sign in to comment.