diff --git a/src/cli/one_helper/oneflowtemplate_helper.rb b/src/cli/one_helper/oneflowtemplate_helper.rb index 718b2c112a..281a286b44 100644 --- a/src/cli/one_helper/oneflowtemplate_helper.rb +++ b/src/cli/one_helper/oneflowtemplate_helper.rb @@ -161,7 +161,7 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper # @return [Hash] Custom attributes values def custom_attrs(custom_attrs) # rubocop:disable Layout/LineLength - return unless custom_attrs + return if custom_attrs.nil? || custom_attrs.empty? ret = {} ret['custom_attrs_values'] = OpenNebulaHelper.parse_user_inputs(custom_attrs) diff --git a/src/flow/lib/LifeCycleManager.rb b/src/flow/lib/LifeCycleManager.rb index e331d08ef5..a6a7ad7b41 100644 --- a/src/flow/lib/LifeCycleManager.rb +++ b/src/flow/lib/LifeCycleManager.rb @@ -326,6 +326,11 @@ class ServiceLCM set_cardinality(role, cardinality, force) if cardinality_diff > 0 + # change client to have right ownership + client = @cloud_auth.client("#{service.uname}:#{service.gid}") + + service.replace_client(client) + role.scale_way('UP') rc = deploy_roles(client, @@ -378,7 +383,13 @@ class ServiceLCM elsif service.can_recover_undeploy? recover_undeploy(client, service) elsif service.can_recover_scale? + # change client to have right ownership + client = @cloud_auth.client("#{service.uname}:#{service.gid}") + + service.replace_client(client) recover_scale(client, service) + elsif Service::STATE['COOLDOWN'] == service.state + service.set_state(Service::STATE['RUNNING']) else break OpenNebula::Error.new( 'Service cannot be recovered in state: ' \ @@ -679,7 +690,7 @@ class ServiceLCM def catch_up(client) Log.error LOG_COMP, 'Catching up...' - @srv_pool.info + @srv_pool.info_all @srv_pool.each do |service| recover_action(client, service.id) if service.transient_state? diff --git a/src/flow/lib/models/service.rb b/src/flow/lib/models/service.rb index a34f10b2b1..8d68c3b772 100644 --- a/src/flow/lib/models/service.rb +++ b/src/flow/lib/models/service.rb @@ -55,6 +55,7 @@ module OpenNebula DEPLOYING UNDEPLOYING SCALING + COOLDOWN ] FAILED_STATES = %w[ @@ -140,6 +141,20 @@ module OpenNebula @body['ready_status_gate'] end + def uname + self['UNAME'] + end + + def gid + self['GID'].to_i + end + + # Replaces this object's client with a new one + # @param [OpenNebula::Client] owner_client the new client + def replace_client(owner_client) + @client = owner_client + end + # Sets a new state # @param [Integer] the new state # @return [true, false] true if the value was changed diff --git a/src/flow/lib/models/service_pool.rb b/src/flow/lib/models/service_pool.rb index 820c13104f..eb83824fef 100644 --- a/src/flow/lib/models/service_pool.rb +++ b/src/flow/lib/models/service_pool.rb @@ -72,6 +72,15 @@ module OpenNebula rc end + def info_all + osp = OpenNebulaServicePool.new(client) + rc = osp.info_all + + @one_pool = osp + + rc + end + # rubocop:disable Lint/ToJSON def to_json # rubocop:enable Lint/ToJSON diff --git a/src/flow/oneflow-server.rb b/src/flow/oneflow-server.rb index 44f9dea823..33d25f596e 100644 --- a/src/flow/oneflow-server.rb +++ b/src/flow/oneflow-server.rb @@ -491,14 +491,15 @@ post '/service_template/:id/action' do VALIDATION_EC) end - if custom_attrs && !custom_attrs_values + if custom_attrs && !custom_attrs.empty? && !custom_attrs_values return internal_error('No custom_attrs_values found', VALIDATION_EC) end if custom_attrs && - custom_attrs_values && - !(custom_attrs.keys - custom_attrs_values.keys).empty? + !custom_attrs.empty? + custom_attrs_values && + !(custom_attrs.keys - custom_attrs_values.keys).empty? return internal_error('Every custom_attrs key must have its ' \ 'value defined at custom_attrs_value', VALIDATION_EC)