4
4
FIXME: revert to using ssh -q, stderr=STDOUT instead of 2>&1, stderr=PIPE once
5
5
lp:1281577 is addressed.
7
from subprocess import check_output, CalledProcessError, PIPE, STDOUT
7
from subprocess import check_output, PIPE
9
9
from helpers import IntegrationTest
10
10
from layers import OneLandscapeUnitLayer, OneLandscapeUnitNoCronLayer
140
140
layer = OneLandscapeUnitNoCronLayer
142
def _sanitize_ssh_output(self, output,
143
remove_text=["sudo: unable to resolve",
144
"Warning: Permanently added",
146
"""Strip some common warning messages from ssh output.
148
@param output: output to sanitize
149
@param remove_text: list of text that, if found at the beginning of
150
the a output line, will have that line removed
154
for line in output.split("\n"):
155
if any(line.startswith(remove) for remove in remove_text):
157
new_output.append(line)
158
return "\n".join(new_output)
160
def _run_cron(self, script):
162
cmd = ["juju", "ssh", self.layer.cron_unit, "sudo", "-u landscape",
165
# The sanitize is a workaround for lp:1328269
166
output = self._sanitize_ssh_output(
168
cmd, stderr=STDOUT, stdin=PIPE).decode("utf-8").strip())
169
except CalledProcessError as e:
170
output = e.output.decode("utf-8").strip()
171
status = e.returncode
172
# these jobs currently don't set their exit status to non-zero
173
# if they fail, they just print things to stdout/stderr
174
return (output, status)
176
142
def test_maintenance_cron(self):
177
143
"""Verify that the maintenance cron job runs without errors."""
178
144
script = "/opt/canonical/landscape/scripts/maintenance.sh"
179
output, status = self._run_cron(script)
145
output, status = self.environment.run_script_on_cron_unit(
180
147
self.assertEqual(output, "")
181
148
self.assertEqual(status, 0)
183
150
def test_update_security_db_cron(self):
184
151
"""Verify that the update_security_db cron job runs without errors."""
185
152
script = "/opt/canonical/landscape/scripts/update_security_db.sh"
186
output, status = self._run_cron(script)
153
output, status = self.environment.run_script_on_cron_unit(
187
155
self.assertEqual(output, "")
188
156
self.assertEqual(status, 0)
190
158
def test_update_alerts_cron(self):
191
159
"""Verify that the update_alerts cron job runs without errors."""
192
160
script = "/opt/canonical/landscape/scripts/update_alerts.sh"
193
output, status = self._run_cron(script)
161
output, status = self.environment.run_script_on_cron_unit(
194
163
self.assertEqual(output, "")
195
164
self.assertEqual(status, 0)
204
173
cmd = ["juju", "run", "--unit", self.layer.cron_unit, find_cmd]
205
174
script = check_output(cmd, stderr=PIPE).decode("utf-8").strip()
207
output, status = self._run_cron(script)
176
output, status = self.environment.run_script_on_cron_unit(
208
178
self.assertEqual(output, "")
209
179
self.assertEqual(status, 0)
211
181
def test_process_alerts_cron(self):
212
182
"""Verify that the process_alerts cron job runs without errors."""
213
183
script = "/opt/canonical/landscape/scripts/process_alerts.sh"
214
output, status = self._run_cron(script)
184
output, status = self.environment.run_script_on_cron_unit(
215
186
self.assertEqual(output, "")
216
187
self.assertEqual(status, 0)
218
189
def test_hash_id_databases_cron(self):
219
190
"""Verify that the hash_id_databases cron job runs without errors."""
220
191
script = "/opt/canonical/landscape/scripts/hash_id_databases.sh"
221
output, status = self._run_cron(script)
192
output, status = self.environment.run_script_on_cron_unit(
222
194
self.assertEqual(output, "")
223
195
self.assertEqual(status, 0)
225
197
def test_meta_releases_cron(self):
226
198
"""Verify that the meta_releases cron job runs without errors."""
227
199
script = "/opt/canonical/landscape/scripts/meta_releases.sh"
228
output, status = self._run_cron(script)
200
output, status = self.environment.run_script_on_cron_unit(
229
202
self.assertEqual(output, "")
230
203
self.assertEqual(status, 0)
232
205
def test_sync_lds_releases_cron(self):
233
206
"""Verify that the sync_lds_releases cron job runs without errors."""
234
207
script = "/opt/canonical/landscape/scripts/sync_lds_releases.sh"
235
output, status = self._run_cron(script)
208
output, status = self.environment.run_script_on_cron_unit(
236
210
self.assertEqual(output, "")
237
211
self.assertEqual(status, 0)