def test_locked_at_start(tmpdir): """ZYPP library is locked when auto-patch is started. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("locked_start", config=no_wait) caller.run() caller.check_report()
def test_patch_psreboot(tmpdir): """After applying patches, 'zypper ps' reports reboot is needed. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("patch_psreboot") caller.run() caller.check_report()
def test_sec_patches(tmpdir): """Some security patches available. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("sec_patches") caller.run() caller.check_report()
def test_locked_in_between(tmpdir): """The auto-patch workflow is interrupted by intermittent locks. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("locked_between", config=no_wait) caller.run() caller.check_report()
def test_patch_psproc(tmpdir): """After applying patches, 'zypper ps' reports processes needing restart. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("patch_psproc") caller.run() caller.check_report()
def test_zypp_patches(tmpdir): """A patches affects the package manager itself, restart patch required. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("zypp_patches") caller.run() caller.check_report()
def test_rec_patches(tmpdir): """Some recommended patches available, but no security patches. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("rec_patches") caller.run() caller.check_report()
def test_locked_final(tmpdir): """The auto-patch workflow is interrupted by a persistent lock, auto-patch eventually gives up waiting. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("locked_final", config=no_wait) caller.run() caller.check_report()
def test_no_patches(tmpdir): """No patches available. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("no_patches") caller.run() # assert that no mail report has been sent: with pytest.raises(FileNotFoundError): caller.check_report()
def test_config_mailreport_off(tmpdir, flag): """Explicitely switch off mail report in the configuration. Try out different representations of the negative value. """ with tmpdir.as_cwd(): cfg = {'mailreport': {'report': flag}} caller = AutoPatchCaller.get_caller("sec_patches", config=cfg) caller.run() # assert that no mail report has been sent: with pytest.raises(FileNotFoundError): caller.check_report()
def test_locked_complete(tmpdir): """A persistent lock blocks auto-patch completely, auto-patch eventually gives up waiting, not a single zypper succeeded. Note that no report is sent, because auto-patch couldn't even check the presence of available patches. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("locked_complete", config=no_wait) caller.run() # assert that no mail report has been sent: with pytest.raises(FileNotFoundError): caller.check_report()
def test_config_mailhost(tmpdir): """Configure mailhost. """ mailhost = "mailhub.example.com" with tmpdir.as_cwd(): cfg = {'mailreport': {'mailhost': mailhost}} caller = AutoPatchCaller.get_caller("sec_patches", config=cfg) caller.run() mailhost, msg = caller.check_report() assert mailhost == mailhost assert msg['from'] == default_mailfrom assert msg['to'] == default_mailto assert msg['subject'] == default_mailsubject
def test_config_mail_subject(tmpdir): """Configure mail subject. """ subject = "auto-patch report" with tmpdir.as_cwd(): cfg = {'mailreport': {'subject': subject}} caller = AutoPatchCaller.get_caller("sec_patches", config=cfg) caller.run() mailhost, msg = caller.check_report() assert mailhost == default_mailhost assert msg['from'] == default_mailfrom assert msg['to'] == default_mailto assert msg['subject'] == subject
def test_no_config(tmpdir): """No config file present. The script should take this gracefully and apply the built-in defaults. """ with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("sec_patches") os.unlink("auto-patch.cfg") caller.run() mailhost, msg = caller.check_report() assert mailhost == default_mailhost assert msg['from'] == default_mailfrom assert msg['to'] == default_mailto assert msg['subject'] == default_mailsubject
def test_config_mail_addresses(tmpdir): """Configure mail from and to. """ mailfrom = "*****@*****.**" mailto = "*****@*****.**" with tmpdir.as_cwd(): cfg = {'mailreport': {'mailfrom': mailfrom, 'mailto': mailto}} caller = AutoPatchCaller.get_caller("sec_patches", config=cfg) caller.run() mailhost, msg = caller.check_report() assert mailhost == default_mailhost assert msg['from'] == mailfrom assert msg['to'] == mailto assert msg['subject'] == default_mailsubject
def test_config_mailreport_on(tmpdir, flag): """Explicitely switch on mail report in the configuration. This is the default, so we won't get any different behavior. Try out different representations of the affirmative value. """ with tmpdir.as_cwd(): cfg = {'mailreport': {'report': flag}} caller = AutoPatchCaller.get_caller("sec_patches", config=cfg) caller.run() mailhost, msg = caller.check_report() assert mailhost == default_mailhost assert msg['from'] == default_mailfrom assert msg['to'] == default_mailto assert msg['subject'] == default_mailsubject
def test_default_config(tmpdir): """Default config file as installed with the package. The default file has all options commented out, so built-in defaults apply. """ cfg_path = Path(__file__).parent / ".." / "etc" / "auto-patch.cfg" with tmpdir.as_cwd(): caller = AutoPatchCaller.get_caller("sec_patches") shutil.copyfile(str(cfg_path), "auto-patch.cfg") caller.run() mailhost, msg = caller.check_report() assert mailhost == default_mailhost assert msg['from'] == default_mailfrom assert msg['to'] == default_mailto assert msg['subject'] == default_mailsubject