foreman_maintain 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0f6837492a59470b98bbbf7d98963f98c0324326ed7beca8d682a2a04df38d6b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b84626fc17039356e4ab10b77a2b2a54fda21c6438850e7558b63617a0556073
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: dc8146e0110fd7334b28d56a45b84f7d10936e3e72e56ceaaf0ccc33e8ff16c256fdb1ca73961b3833306b488d471c545b7d8f3967ebab1c2a8653ebde12a594
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: bbad46d7af9797cf1dcfba28c734dc2494e3258d34f784642460d94d852f70e23a9e49aca2c57bb8fab579bb29ca5c89fdf7438fa2e63a982d58684393cf39b2
         
     | 
| 
         @@ -3,21 +3,34 @@ class Features::SyncPlans < ForemanMaintain::Feature 
     | 
|
| 
       3 
3 
     | 
    
         
             
                label :sync_plans
         
     | 
| 
       4 
4 
     | 
    
         
             
              end
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              def  
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
              def required_new_implementation
         
     | 
| 
      
 7 
     | 
    
         
            +
                @required_new_implementation ||=
         
     | 
| 
      
 8 
     | 
    
         
            +
                  feature(:foreman_database).query(
         
     | 
| 
      
 9 
     | 
    
         
            +
                    <<-SQL
         
     | 
| 
      
 10 
     | 
    
         
            +
                      SELECT COUNT(1) FROM information_schema.table_constraints
         
     | 
| 
      
 11 
     | 
    
         
            +
                      WHERE constraint_name='katello_sync_plan_foreman_tasks_recurring_logic_fk' AND table_name='katello_sync_plans'
         
     | 
| 
      
 12 
     | 
    
         
            +
                    SQL
         
     | 
| 
      
 13 
     | 
    
         
            +
                  ).first['count'].to_i > 0
         
     | 
| 
       12 
14 
     | 
    
         
             
              end
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              def  
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
              def sync_plan_ids_by_status(enabled = true, filter_ids = nil)
         
     | 
| 
      
 17 
     | 
    
         
            +
                if filter_ids
         
     | 
| 
      
 18 
     | 
    
         
            +
                  return [] if filter_ids.empty?
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  ids_condition = filter_ids.map { |id| "'#{id}'" }.join(',')
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                if required_new_implementation
         
     | 
| 
      
 24 
     | 
    
         
            +
                  query = <<-SQL
         
     | 
| 
      
 25 
     | 
    
         
            +
                    select sp.id as id from katello_sync_plans sp inner join foreman_tasks_recurring_logics rl on sp.foreman_tasks_recurring_logic_id = rl.id
         
     | 
| 
      
 26 
     | 
    
         
            +
                    where rl.state='#{enabled ? 'active' : 'disabled'}' #{ids_condition ? " AND sp.id IN (#{ids_condition})" : ''}
         
     | 
| 
      
 27 
     | 
    
         
            +
                  SQL
         
     | 
| 
      
 28 
     | 
    
         
            +
                else
         
     | 
| 
      
 29 
     | 
    
         
            +
                  query = <<-SQL
         
     | 
| 
      
 30 
     | 
    
         
            +
                    SELECT id FROM katello_sync_plans WHERE enabled ='#{enabled ? 't' : 'f'}' #{ids_condition ? " AND id IN (#{ids_condition})" : ''}
         
     | 
| 
       19 
31 
     | 
    
         
             
                  SQL
         
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
                feature(:foreman_database).query(query).map { |r| r['id'].to_i }
         
     | 
| 
       21 
34 
     | 
    
         
             
              end
         
     | 
| 
       22 
35 
     | 
    
         | 
| 
       23 
36 
     | 
    
         
             
              def make_disable(ids)
         
     | 
| 
         @@ -39,8 +52,11 @@ class Features::SyncPlans < ForemanMaintain::Feature 
     | 
|
| 
       39 
52 
     | 
    
         
             
              private
         
     | 
| 
       40 
53 
     | 
    
         | 
| 
       41 
54 
     | 
    
         
             
              def update_records(ids, enabled)
         
     | 
| 
      
 55 
     | 
    
         
            +
                ids_not_required_update = sync_plan_ids_by_status(enabled, ids)
         
     | 
| 
      
 56 
     | 
    
         
            +
                ids_required_update = ids - ids_not_required_update
         
     | 
| 
      
 57 
     | 
    
         
            +
                make_data_key_empty(enabled) if !ids_not_required_update.empty? && ids_required_update.empty?
         
     | 
| 
       42 
58 
     | 
    
         
             
                updated_record_ids = []
         
     | 
| 
       43 
     | 
    
         
            -
                 
     | 
| 
      
 59 
     | 
    
         
            +
                ids_required_update.each do |sp_id|
         
     | 
| 
       44 
60 
     | 
    
         
             
                  result = feature(:hammer).run("sync-plan update --id #{sp_id} --enabled #{enabled}")
         
     | 
| 
       45 
61 
     | 
    
         
             
                  if result.include?('Sync plan updated')
         
     | 
| 
       46 
62 
     | 
    
         
             
                    updated_record_ids << sp_id
         
     | 
| 
         @@ -55,15 +71,23 @@ class Features::SyncPlans < ForemanMaintain::Feature 
     | 
|
| 
       55 
71 
     | 
    
         | 
| 
       56 
72 
     | 
    
         
             
              def data
         
     | 
| 
       57 
73 
     | 
    
         
             
                raise 'Use load_from_storage before accessing the data' unless defined? @data
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
       58 
75 
     | 
    
         
             
                @data
         
     | 
| 
       59 
76 
     | 
    
         
             
              end
         
     | 
| 
       60 
77 
     | 
    
         | 
| 
      
 78 
     | 
    
         
            +
              def make_data_key_empty(enabled)
         
     | 
| 
      
 79 
     | 
    
         
            +
                key_name = enabled ? 'disabled' : 'enabled'
         
     | 
| 
      
 80 
     | 
    
         
            +
                @data[:"#{key_name}"] = []
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       61 
83 
     | 
    
         
             
              def update_data(enabled, new_ids)
         
     | 
| 
       62 
84 
     | 
    
         
             
                if enabled
         
     | 
| 
       63 
85 
     | 
    
         
             
                  @data[:disabled] -= new_ids
         
     | 
| 
       64 
86 
     | 
    
         
             
                  @data[:enabled] = new_ids
         
     | 
| 
       65 
87 
     | 
    
         
             
                else
         
     | 
| 
       66 
     | 
    
         
            -
                  @data[:disabled] 
     | 
| 
      
 88 
     | 
    
         
            +
                  @data[:disabled] = [] unless @data[:disabled]
         
     | 
| 
      
 89 
     | 
    
         
            +
                  @data[:enabled] = [] if @data[:disabled].empty?
         
     | 
| 
      
 90 
     | 
    
         
            +
                  @data[:disabled].concat(new_ids).uniq!
         
     | 
| 
       67 
91 
     | 
    
         
             
                end
         
     | 
| 
       68 
92 
     | 
    
         
             
              end
         
     | 
| 
       69 
93 
     | 
    
         
             
            end
         
     | 
| 
         @@ -21,7 +21,7 @@ module Procedures::SyncPlans 
     | 
|
| 
       21 
21 
     | 
    
         
             
                  default_storage = ForemanMaintain.storage(:default)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  feature(:sync_plans).load_from_storage(default_storage)
         
     | 
| 
       23 
23 
     | 
    
         
             
                  with_spinner('disabling sync plans') do |spinner|
         
     | 
| 
       24 
     | 
    
         
            -
                    ids = feature(:sync_plans). 
     | 
| 
      
 24 
     | 
    
         
            +
                    ids = feature(:sync_plans).sync_plan_ids_by_status(true)
         
     | 
| 
       25 
25 
     | 
    
         
             
                    feature(:sync_plans).make_disable(ids)
         
     | 
| 
       26 
26 
     | 
    
         
             
                    spinner.update "Total #{ids.length} sync plans are now disabled."
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: foreman_maintain
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ivan Nečas
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-06-05 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: clamp
         
     | 
| 
         @@ -329,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       329 
329 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       330 
330 
     | 
    
         
             
            requirements: []
         
     | 
| 
       331 
331 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       332 
     | 
    
         
            -
            rubygems_version: 2.6 
     | 
| 
      
 332 
     | 
    
         
            +
            rubygems_version: 2.7.6
         
     | 
| 
       333 
333 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       334 
334 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       335 
335 
     | 
    
         
             
            summary: Foreman maintenance tool belt
         
     |