Example #1
0
def notify_failure(config, log_path):
    if config["DEBUG"] or config["CDIMAGE_NOLOG"]:
        return

    project = config.project
    if config["UBUNTU_DEFAULTS_LOCALE"] == "zh_CN":
        project = "ubuntu-chinese-edition"
    series = config.full_series
    image_type = config.image_type
    date = config["CDIMAGE_DATE"]

    recipients = get_notify_addresses(config, project)
    if not recipients:
        return

    try:
        if log_path is None:
            body = ""
        else:
            body = open(log_path)
        send_mail(
            "CD image %s%s/%s/%s failed to build on %s" % (
                ("(built by %s) " % config["SUDO_USER"]
                 if config["SUDO_USER"] else ""),
                project, series, image_type, date),
            "build-image-set", recipients, body)
    finally:
        if log_path is not None:
            body.close()
Example #2
0
 def test_send_mail_from_string(self, mock_popen):
     send_mail("Test subject", "test_notify",
               ["*****@*****.**", "*****@*****.**"], "Body\nText\n")
     expected_command = [
         "mail",
         "-s",
         "Test subject",
         "-a",
         "X-Generated-By: test_notify",
         "*****@*****.**",
         "*****@*****.**",
     ]
     mock_popen.assert_called_once_with(expected_command,
                                        stdin=subprocess.PIPE)
     mock_popen.return_value.stdin.write.assert_called_once_with(
         b"Body\nText\n")
Example #3
0
 def test_send_mail_from_file(self, mock_popen):
     path = os.path.join(self.temp_dir, "body")
     with mkfile(path) as body:
         print("Body", file=body)
         print("Text", file=body)
     with open(path) as body:
         send_mail("Test subject", "test_notify", ["*****@*****.**"], body)
         expected_command = [
             "mail",
             "-s",
             "Test subject",
             "-a",
             "X-Generated-By: test_notify",
             "*****@*****.**",
         ]
         mock_popen.assert_called_once_with(expected_command, stdin=body)
Example #4
0
 def test_send_mail_dry_run_from_string(self):
     self.capture_logging()
     send_mail("Test subject",
               "test_notify", ["*****@*****.**", "*****@*****.**"],
               "Body\nText\n",
               dry_run=True)
     self.assertLogEqual([
         "Would send mail to: [email protected], [email protected]",
         "",
         "Subject: Test subject",
         "X-Generated-By: test_notify",
         "",
         "Body",
         "Text",
         "",
     ])
Example #5
0
    def update_tasks(self, date):
        tasks_dir = self.tasks_output_dir(self.config.project)
        previous_tasks_dir = "%s-previous" % tasks_dir
        debian_cd_tasks_dir = os.path.join(self.config.root, "debian-cd",
                                           "tasks", "auto",
                                           self.config.image_type,
                                           self.config.project,
                                           self.config.full_series)

        task_recipients = []
        task_mail_path = os.path.join(self.config.root, "etc", "task-mail")
        if os.path.exists(task_mail_path):
            with open(task_mail_path) as task_mail:
                task_recipients = task_mail.read().split()
        if task_recipients:
            read, write = os.pipe()
            pid = os.fork()
            if pid == 0:  # child
                try:
                    os.close(read)
                    with os.fdopen(write, "w", 1) as write_file:
                        self.diff_tasks(output=write_file)
                    os._exit(0)
                except Exception:
                    traceback.print_exc()
                finally:
                    os._exit(1)
            else:  # parent
                os.close(write)
                with os.fdopen(read) as read_file:
                    send_mail(
                        "Task changes for %s %s/%s on %s" %
                        (self.config.capproject, self.config.image_type,
                         self.config.full_series, date), "update-tasks",
                        task_recipients, read_file)
                os.waitpid(pid, 0)

        self.diff_tasks()

        osextras.mkemptydir(debian_cd_tasks_dir)
        osextras.mkemptydir(previous_tasks_dir)
        for entry in os.listdir(tasks_dir):
            shutil.copy2(os.path.join(tasks_dir, entry),
                         os.path.join(debian_cd_tasks_dir, entry))
            shutil.copy2(os.path.join(tasks_dir, entry),
                         os.path.join(previous_tasks_dir, entry))
Example #6
0
 def test_send_mail_dry_run_from_file(self):
     path = os.path.join(self.temp_dir, "body")
     with mkfile(path) as body:
         print("Body", file=body)
         print("Text", file=body)
     self.capture_logging()
     with open(path) as body:
         send_mail("Test subject",
                   "test_notify", ["*****@*****.**"],
                   body,
                   dry_run=True)
     self.assertLogEqual([
         "Would send mail to: [email protected]",
         "",
         "Subject: Test subject",
         "X-Generated-By: test_notify",
         "",
         "Body",
         "Text",
         "",
     ])
Example #7
0
def live_build_notify_failure(config, arch, lp_build=None):
    if config["DEBUG"]:
        return

    project = config.project
    recipients = get_notify_addresses(config, project)
    if not recipients:
        return

    livefs_id_bits = [project]
    if config.subproject:
        livefs_id_bits.append(config.subproject)
    cpuarch, subarch = split_arch(arch)
    if subarch:
        livefs_id_bits.append(subarch)
    if config["UBUNTU_DEFAULTS_LOCALE"]:
        livefs_id_bits.append(config["UBUNTU_DEFAULTS_LOCALE"])
    livefs_id = "-".join(livefs_id_bits)

    datestamp = time.strftime("%Y%m%d")
    try:
        if lp_build is not None:
            if lp_build.build_log_url is None:
                raise URLError(
                    "Failed build %s has no build_log_url" % lp_build.web_link)
            with closing(urlopen(lp_build.build_log_url, timeout=30)) as comp:
                with closing(io.BytesIO(comp.read())) as comp_bytes:
                    with closing(GzipFile(fileobj=comp_bytes)) as f:
                        body = f.read()
        else:
            log_url = "http://%s/~buildd/LiveCD/%s/%s/latest/livecd-%s.out" % (
                live_builder(config, arch), config.series, livefs_id, cpuarch)
            with closing(urlopen(log_url, timeout=30)) as f:
                body = f.read()
    except URLError:
        body = b""
    subject = "LiveFS %s%s/%s/%s failed to build on %s" % (
        "(built by %s) " % config["SUDO_USER"] if config["SUDO_USER"] else "",
        livefs_id, config.full_series, arch, datestamp)
    send_mail(subject, "buildlive", recipients, body)