|
| 1 | +#Email_git.py: to make boot of the repo and test it through exit code |
| 2 | + |
| 3 | +#!/usr/bin/env python3 |
| 4 | +# OpenPOWER Automated Test Project |
| 5 | +# |
| 6 | +# Contributors Listed Below - COPYRIGHT 2024 |
| 7 | +# [+] International Business Machines Corp. |
| 8 | +# |
| 9 | +# |
| 10 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +# you may not use this file except in compliance with the License. |
| 12 | +# You may obtain a copy of the License at |
| 13 | +# |
| 14 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +# |
| 16 | +# Unless required by applicable law or agreed to in writing, software |
| 17 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 19 | +# implied. See the License for the specific language governing |
| 20 | +# permissions and limitations under the License. |
| 21 | +import json |
| 22 | +# import requests |
| 23 | +import os |
| 24 | +import uuid |
| 25 | +from datetime import datetime |
| 26 | +import re |
| 27 | +import unittest |
| 28 | +import os |
| 29 | +from urllib.parse import urlparse |
| 30 | +from enum import Enum |
| 31 | +import subprocess |
| 32 | +import OpTestConfiguration |
| 33 | +import OpTestLogger |
| 34 | +import configparser |
| 35 | +import sys |
| 36 | +from testcases import BisectKernel |
| 37 | +from testcases import Test_build |
| 38 | +from common.OpTestSystem import OpSystemState |
| 39 | +from common.OpTestSOL import OpSOLMonitorThread |
| 40 | +from common.OpTestInstallUtil import InstallUtil |
| 41 | +from common.Exceptions import CommandFailed |
| 42 | +# from testcases import Boot |
| 43 | +log = OpTestLogger.optest_logger_glob.get_logger(__name__) |
| 44 | +class Email_git(unittest.TestCase): |
| 45 | + """ |
| 46 | + Test case for bisecting the Linux kernel using Git Bisect. |
| 47 | + This test downloads the Linux kernel from a specified repository, |
| 48 | + configures and compiles it, and then uses Git Bisect to find the |
| 49 | + commit that introduced a specific issue. |
| 50 | + """ |
| 51 | + def setUp(self): |
| 52 | + """ |
| 53 | + Set up the test environment. |
| 54 | + Initializes test parameters and checks required configurations. |
| 55 | + """ |
| 56 | + self.conf = OpTestConfiguration.conf |
| 57 | + self.cv_HOST = self.conf.host() |
| 58 | + self.cv_SYSTEM = self.conf.system() |
| 59 | + self.connection = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 60 | + self.console_thread = OpSOLMonitorThread(1, "console") |
| 61 | + self.host_cmd_timeout = self.conf.args.host_cmd_timeout |
| 62 | + self.repo = self.conf.args.git_repo |
| 63 | + self.repo_reference = self.conf.args.git_repo_reference |
| 64 | + self.branch = self.conf.args.git_branch |
| 65 | + self.home = self.conf.args.git_home |
| 66 | + # self.config_path = self.conf.args.git_repoconfigpatih |
| 67 | + self.config = self.conf.args.git_repoconfig |
| 68 | + self.good_commit = self.conf.args.good_commit |
| 69 | + self.bad_commit = self.conf.args.bad_commit |
| 70 | + self.bisect_script = self.conf.args.bisect_script |
| 71 | + self.bisect_category = self.conf.args.bisect_category |
| 72 | + self.append_kernel_cmdline = self.conf.args.append_kernel_cmdline |
| 73 | + self.linux_path = os.path.join(self.home, "linux") |
| 74 | + if not self.repo: |
| 75 | + self.fail("Provide git repo of kernel to install") |
| 76 | + if not (self.conf.args.host_ip and self.conf.args.host_user and self.conf.args.host_password): |
| 77 | + self.fail( |
| 78 | + "Provide host ip user details refer, --host-{ip,user,password}") |
| 79 | + def get_commit_message(self,commit_sha): |
| 80 | + try: |
| 81 | + self.connection.run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(self.linux_path,self.linux_path)) |
| 82 | + |
| 83 | + commit_message = self.connection.run_command("git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha)) |
| 84 | + print(commit_message) |
| 85 | + except subprocess.CalledProcessError: |
| 86 | + commit_message = None |
| 87 | + print(commit_message[0].strip()) |
| 88 | + return commit_message[0].strip() |
| 89 | + def runTest(self): |
| 90 | + # def generate_email_template(machine_type, gcc_version, commit, error_message): |
| 91 | + machine_type = self.connection.run_command("uname -m") |
| 92 | + gcc_version = self.connection.run_command("gcc --version")[0] |
| 93 | + try: |
| 94 | + with open("output.json", "r") as file: |
| 95 | + data = json.load(file) |
| 96 | + error_message = data.get("error", "") |
| 97 | + commit = data.get("commit", "") |
| 98 | + except FileNotFoundError: |
| 99 | + print("Error: output.json not found.") |
| 100 | + error_message = "" |
| 101 | + commit = "" |
| 102 | + |
| 103 | + fix_description = self.get_commit_message(commit) |
| 104 | + linux = re.split(r'[/.]', self.repo)[-2] |
| 105 | + subject = "[{}][bisected {}][gcc {}] build fail with error: {}".format(linux,commit, gcc_version, error_message) |
| 106 | + |
| 107 | + body = """ |
| 108 | + Greetings, |
| 109 | +
|
| 110 | + Today's next kernel fails to build with gcc {} on {} machine. |
| 111 | +
|
| 112 | + {} |
| 113 | +
|
| 114 | + Machine Type: {} |
| 115 | + gcc: {} |
| 116 | + Commit: {} |
| 117 | +
|
| 118 | + Builds fine when below patch is reverted |
| 119 | + {} - {} |
| 120 | +
|
| 121 | + -- |
| 122 | + Regards |
| 123 | + Linux CI |
| 124 | + """.format(gcc_version, machine_type, error_message, machine_type, gcc_version, commit, commit, fix_description) |
| 125 | + print(subject) |
| 126 | + print(body) |
| 127 | + |
| 128 | + with open("email.json","w") as email: |
| 129 | + json.dump({"subject":subject,"body":body},email) |
| 130 | + # return subject, body |
| 131 | + |
0 commit comments