Skip to content

Commit

Permalink
Allow power_state for services that do not have an associated service…
Browse files Browse the repository at this point in the history
…_template

For the cases in Automate where a service does not have an associated ServiceTemplate

1. If children exist we have a composite service
2. If no children exists we have an atomic service

https://bugzilla.redhat.com/show_bug.cgi?id=1419730
  • Loading branch information
syncrou committed Feb 7, 2017
1 parent 82b0db1 commit be71c6f
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 @@ -50,8 +50,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 @@ -211,6 +209,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 be71c6f

Please sign in to comment.