def test_mail_on_error_with_warning_in_log(self): apt_pkg.config.set("Unattended-Upgrade::MailOnlyOnError", "true") pkgs, res, pkgs_kept_back, mem_log, logf_dpkg = self._return_mock_data( successful=True) mem_log.write("\nWARNING: some warning\n") send_summary_mail(pkgs, res, pkgs_kept_back, mem_log, logf_dpkg) self.assertTrue(os.path.exists("mail.txt"))
def test_summary_mail_no_reboot(self): send_summary_mail(*self._return_mock_data()) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertFalse("[reboot required]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue("Packages that were upgraded:\n 2vcard" in mail_txt)
def test_summary_mail_reboot(self): open("./reboot-required","w").write("") send_summary_mail(*self._return_mock_data()) os.unlink("./reboot-required") mail_txt = open("mail.txt").read() self.assertTrue("[reboot required]" in mail_txt) self._verify_common_mail_content(mail_txt)
def test_summary_mail_from_address(self): apt_pkg.config.set("Unattended-Upgrade::Sender", "rootolv") self.addCleanup(apt_pkg.config.set, "Unattended-Upgrade::Sender", "") send_summary_mail(*self._return_mock_data()) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue( "From: rootolv" in mail_txt, "missing From: in %s" % mail_txt)
def test_mail_quoted_printable(self): """Regression test for debian bug #700178""" send_summary_mail(*self._return_mock_data()) log_data = open("mail.txt").read() needle = "Allowed origins are: ['o=3DDebian,n=3Dwheezy', "\ "'o=3DDebian,n=3Dwheezy-updat=\n"\ "es', 'o=3DDebian,n=3Dwheezy,l=3DDebian-Security', "\ "'origin=3DDebian,archive=\n"\ "=3Dstable,label=3DDebian-Security']" self.assertTrue(needle in log_data)
def test_summary_mail_blacklisted(self): # Test that blacklisted packages are mentioned in the mail message. send_summary_mail(*self._return_mock_data()) self.assertTrue(os.path.exists(os.path.join(self.tmpdir, "mail.txt"))) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[package on hold]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue("Packages with upgradable origin but kept back:\n" " Debian wheezy-security:\n linux-image" in mail_txt)
def test_mail_quoted_printable(self): """Regression test for debian bug #700178""" send_summary_mail(*self._return_mock_data()) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: log_data = fp.read().decode("utf-8") needle = "Allowed origins are: ['o=3DDebian,n=3Dwheezy', "\ "'o=3DDebian,n=3Dwheezy-updat=\n"\ "es', 'o=3DDebian,n=3Dwheezy,l=3DDebian-Security', "\ "'origin=3DDebian,archive=\n"\ "=3Dstable,label=3DDebian-Security']" self.assertTrue(needle in log_data)
def test_summary_mail_reboot(self): with open(unattended_upgrade.REBOOT_REQUIRED_FILE, "w") as fp: fp.write("") send_summary_mail(*self._return_mock_data()) # this is used for py2 compat for py3 only we can do # remove the "rb" and the subsequent '.decode("utf-8")' with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[reboot required]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue("Packages that were upgraded:\n 2vcard" in mail_txt)
def test_summary_mail_reboot(self): with open("./reboot-required", "w") as fp: fp.write("") send_summary_mail(*self._return_mock_data()) os.unlink("./reboot-required") # this is used for py2 compat for py3 only we can do # remove the "rb" and the subsequent '.decode("utf-8")' with open("mail.txt", "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[reboot required]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue("Packages that were upgraded:\n 2vcard" in mail_txt)
def test_summary_mail_blacklisted(self): # Test that blacklisted packages are mentioned in the mail message. send_summary_mail(*self._return_mock_data()) self.assertTrue( os.path.exists(os.path.join(self.tmpdir, "mail.txt"))) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[package on hold]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue( "Packages with upgradable origin but kept back:\n" " Debian wheezy-security:\n linux-image" in mail_txt)
def test_summary_mail_only_on_error(self): # default is to always send mail, ensure this is correct # for both success and failure apt_pkg.config.set("Unattended-Upgrade::MailOnlyOnError", "false") send_summary_mail(*self._return_mock_data(successful=True)) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: self._verify_common_mail_content(fp.read().decode("utf-8")) os.remove(os.path.join(self.tmpdir, "mail.txt")) # now with a simulated failure send_summary_mail(*self._return_mock_data(successful=False)) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: self._verify_common_mail_content(fp.read().decode("utf-8")) os.remove(os.path.join(self.tmpdir, "mail.txt")) # now test with "MailOnlyOnError" apt_pkg.config.set("Unattended-Upgrade::MailOnlyOnError", "true") send_summary_mail(*self._return_mock_data(successful=True)) self.assertFalse( os.path.exists(os.path.join(self.tmpdir, "mail.txt"))) send_summary_mail(*self._return_mock_data(successful=False)) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self._verify_common_mail_content(mail_txt) self.assertTrue("Unattended upgrade result: Result String" in mail_txt) self.assertTrue( os.path.exists(os.path.join(self.tmpdir, "mail.txt"))) self.assertTrue( "Packages that attempted to upgrade:\n 2vcard" in mail_txt)
def test_summary_mail_blacklisted_only(self): # Test that when only blacklisted packages are available, they # are still mentioned in the mail message. pkgs, res, pkgs_kept_back, mem_log, logf_dpkg = self._return_mock_data( successful=True) pkgs = "" send_summary_mail(pkgs, res, pkgs_kept_back, mem_log, logf_dpkg) self.assertTrue(os.path.exists("mail.txt")) with open("mail.txt", "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[package on hold]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue( "Packages with upgradable origin but kept back:\n linux-image" in mail_txt) self.assertFalse( "Packages that attempted to upgrade:\n 2vcard" in mail_txt)
def test_summary_mail_blacklisted_only(self): # Test that when only blacklisted packages are available, they # are still mentioned in the mail message. pkgs, res, result_str, pkgs_kept_back, pkgs_removed, \ pkgs_kept_installed, mem_log, logf_dpkg = self._return_mock_data( successful=True) pkgs = [] send_summary_mail(pkgs, res, result_str, pkgs_kept_back, pkgs_removed, pkgs_kept_installed, mem_log, logf_dpkg) self.assertTrue( os.path.exists(os.path.join(self.tmpdir, "mail.txt"))) with open(os.path.join(self.tmpdir, "mail.txt"), "rb") as fp: mail_txt = fp.read().decode("utf-8") self.assertTrue("[package on hold]" in mail_txt) self._verify_common_mail_content(mail_txt) self.assertTrue( "Packages with upgradable origin but kept back:\n" " Debian wheezy-security:\n linux-image" in mail_txt) self.assertFalse( "Packages that attempted to upgrade:\n 2vcard" in mail_txt)
def test_summary_mail_only_on_error(self): # default is to always send mail, ensure this is correct # for both success and failure apt_pkg.config.set("Unattended-Upgrade::MailOnlyOnError", "false") send_summary_mail(*self._return_mock_data(successful=True)) self._verify_common_mail_content(open("mail.txt").read()) os.remove("mail.txt") # now with a simulated failure send_summary_mail(*self._return_mock_data(successful=False)) self._verify_common_mail_content(open("mail.txt").read()) os.remove("mail.txt") # now test with "MailOnlyOnError" apt_pkg.config.set("Unattended-Upgrade::MailOnlyOnError", "true") send_summary_mail(*self._return_mock_data(successful=True)) self.assertFalse(os.path.exists("mail.txt")) send_summary_mail(*self._return_mock_data(successful=False)) mail_txt = open("mail.txt").read() self._verify_common_mail_content(mail_txt) self.assertTrue("Unattended upgrade returned: False" in mail_txt) self.assertTrue(os.path.exists("mail.txt"))
def test_summary_mail_no_reboot(self): send_summary_mail(*self._return_mock_data()) mail_txt = open("mail.txt").read() self.assertFalse("[reboot required]" in mail_txt) self._verify_common_mail_content(mail_txt)