smart_proxy_salt 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b25650758e39a88cb8683f8ebe295d343c0752d0fff229fbe21f86ee585848c6
4
- data.tar.gz: 9f26eb7258a77a426c1addf5e8ba949c432332f1b4b35897e193762cf1a60d3f
3
+ metadata.gz: 4ba18b31812c408bbbef40601e2f7279ee6f04d55a62b999b7b993f0158aede8
4
+ data.tar.gz: 82822b47407c7c5e66151627a7935d294566c6e5dc17c4bbf7c2674890653826
5
5
  SHA512:
6
- metadata.gz: bd79c67ac4733c9b1f19a7e5f6a62a6019e39209d37abd21d7a67f48aea4e24da875bbdaecd3c8db574e566cb451038904fd9e21d045db61896df0a96ccab51e
7
- data.tar.gz: 9c8640cc30f494fe2406b0a840643aacc2211c738fc25864c8c7e1024e4d2a6b6ad72e459eac947a2af9ac2b86ee14a87ba0cc84e27018742906d8a8ad50e18b
6
+ metadata.gz: d95ddd85199c088db57c6248d99d7a370e36c74191aeda0d74fd4f7fb7d573ee50a0b4a107092d2f8f6c3018c131e6127236cc5818f84c835eecabd0b21ef6bf
7
+ data.tar.gz: d9866d18feed738e03d0e47784ee75b41921b65bcbbd33e88aec5856cfd5160e4b0b5e5485d5c25c3a6c601d6c519bde984599b734f7f081b7adce9de53c3277
@@ -3,6 +3,6 @@
3
3
  module Proxy
4
4
  # Salt module
5
5
  module Salt
6
- VERSION = '5.0.0'.freeze
6
+ VERSION = '5.0.1'.freeze
7
7
  end
8
8
  end
@@ -1,10 +1,10 @@
1
1
  # Foreman Salt Report Upload
2
2
 
3
3
  Currently, there are two possibilites to upload the salt report to Foreman:
4
- 1. Use /usr/sbin/upload-salt-reports which is called by a cron job every 10 minutes by default
5
- 2. Upload the report immediately by using a Salt Reactor.
4
+ 1. Upload the report immediately by using a Salt Reactor (recommended).
5
+ 2. Use /usr/sbin/upload-salt-reports manually (or set up a cronjob, see `/cron/smart_proxy_salt`).
6
6
 
7
- This README, handles the second option and how to configure it
7
+ This README handles the first option and how to configure it
8
8
 
9
9
  ## Setup
10
10
  Add the content of 'master.snippet' to '/etc/salt/master' which configures a reactor.
@@ -4,13 +4,16 @@ Uploads reports from the Salt job cache to Foreman
4
4
  '''
5
5
  from __future__ import absolute_import, print_function, unicode_literals
6
6
 
7
+ LAST_UPLOADED = '/etc/salt/last_uploaded'
7
8
  FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
9
+ LOCK_FILE = '/var/lock/salt-report-upload.lock'
8
10
 
9
11
  try:
10
12
  from http.client import HTTPConnection, HTTPSConnection
11
13
  except ImportError:
12
14
  from httplib import HTTPSConnection, HTTPSConnection
13
15
 
16
+ import io
14
17
  import ssl
15
18
  import json
16
19
  import yaml
@@ -24,12 +27,21 @@ import logging
24
27
  log = logging.getLogger(__name__)
25
28
 
26
29
 
30
+ if sys.version_info.major == 3:
31
+ unicode = str
32
+
33
+
27
34
  def salt_config():
28
35
  with open(FOREMAN_CONFIG, 'r') as f:
29
36
  config = yaml.load(f.read())
30
37
  return config
31
38
 
32
39
 
40
+ def write_last_uploaded(last_uploaded):
41
+ with io.open(LAST_UPLOADED, 'w+') as f:
42
+ f.write(unicode(last_uploaded))
43
+
44
+
33
45
  def upload(report):
34
46
  config = salt_config()
35
47
  headers = {'Accept': 'application/json',
@@ -55,6 +67,7 @@ def upload(report):
55
67
  response = connection.getresponse()
56
68
 
57
69
  if response.status == 200:
70
+ write_last_uploaded(report['job']['job_id'])
58
71
  info_msg = 'Success {0}: {1}'.format(report['job']['job_id'], response.read())
59
72
  log.info(info_msg)
60
73
  else:
@@ -81,7 +94,7 @@ def create_report(json_str):
81
94
  return {'job':
82
95
  {
83
96
  'result': {
84
- msg['id']: entry['changes']['ret'],
97
+ msg['id']: next(iter(entry['changes'].values())),
85
98
  },
86
99
  'function': 'state.highstate',
87
100
  'job_id': msg['jid']
@@ -90,6 +103,18 @@ def create_report(json_str):
90
103
  raise Exception('No state.highstate found')
91
104
 
92
105
 
106
+ def get_lock():
107
+ if os.path.isfile(LOCK_FILE):
108
+ raise Exception("Unable to obtain lock.")
109
+ else:
110
+ io.open(LOCK_FILE, 'w+').close()
111
+
112
+
113
+ def release_lock():
114
+ if os.path.isfile(LOCK_FILE):
115
+ os.remove(LOCK_FILE)
116
+
117
+
93
118
  def now(highstate):
94
119
  '''
95
120
  Upload a highstate to Foreman
@@ -100,7 +125,10 @@ def now(highstate):
100
125
 
101
126
  try:
102
127
  report = create_report(base64.b64decode(highstate))
128
+ get_lock()
103
129
  upload(report)
104
130
  except Exception as exc:
105
131
  log.error('Exception encountered: %s', exc)
132
+ finally:
133
+ release_lock()
106
134
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Moll
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-14 00:00:00.000000000 Z
12
+ date: 2022-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
@@ -124,7 +124,6 @@ files:
124
124
  - bin/foreman-node
125
125
  - bin/salt_python_wrapper
126
126
  - bundler.d/salt.rb
127
- - cron/smart_proxy_salt
128
127
  - etc/foreman.conf.example
129
128
  - etc/foreman.yaml.example
130
129
  - lib/smart_proxy_salt.rb
@@ -1,5 +0,0 @@
1
- SHELL=/bin/sh
2
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
3
-
4
- # Check every 10 minutes for new Salt reports to upload to Foreman
5
- */10 * * * * root /usr/sbin/upload-salt-reports >>/var/log/foreman-proxy/salt-cron.log 2>&1