diff --git a/script/server/sysom_hotfix/requirements.txt b/script/server/sysom_hotfix/requirements.txt index 433c06cee07b45b05a69d7e40b72ddb618e4c524..3d1fc63996bd0fe5552966fe5a464e0775aa6d7e 100644 --- a/script/server/sysom_hotfix/requirements.txt +++ b/script/server/sysom_hotfix/requirements.txt @@ -20,4 +20,6 @@ gunicorn==20.1.0 xlwt==1.3.0 xlrd==2.0.1 beautifulsoup4==4.12.2 -openpyxl==3.1.2 \ No newline at end of file +openpyxl==3.1.2 +oss2==2.12.1 +python-jenkins==1.8.2 \ No newline at end of file diff --git a/sysom_server/sysom_hotfix/apps/hotfix/apps.py b/sysom_server/sysom_hotfix/apps/hotfix/apps.py index 1542c43576d95fdc9cb738c91aab557f65fba8c4..51dc724f9c9c72a22adfc8dea8471c15b1cdc656 100644 --- a/sysom_server/sysom_hotfix/apps/hotfix/apps.py +++ b/sysom_server/sysom_hotfix/apps/hotfix/apps.py @@ -32,7 +32,7 @@ class HotfixConfig(AppConfig): ceclistener = CECListener(settings.YAML_CONFIG.get_service_config(), settings.SYSOM_CEC_URL, settings.SYSOM_CEC_HOTFIX_SERVER_MSG_TOPIC) if ceclistener is None: logger.error("INIT CECListener Failed...") - ceclistener.run() + ceclistener.start() else: # nothing to do when execute database migrations pass diff --git a/sysom_server/sysom_hotfix/apps/hotfix/migrations/0008_auto_20240411_1604.py b/sysom_server/sysom_hotfix/apps/hotfix/migrations/0008_auto_20240411_1604.py new file mode 100644 index 0000000000000000000000000000000000000000..d11c12ceeb4ae643215d5f725d1b5d234ba1c021 --- /dev/null +++ b/sysom_server/sysom_hotfix/apps/hotfix/migrations/0008_auto_20240411_1604.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2.16 on 2024-04-11 08:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hotfix', '0007_alter_releasedhotfixlistmodule_released_kernel_version'), + ] + + operations = [ + migrations.AddField( + model_name='hotfixmodel', + name='can_formal', + field=models.BooleanField(default=0, verbose_name='能否设置为正式包'), + ), + migrations.AddField( + model_name='hotfixmodel', + name='extern_build_id', + field=models.CharField(default='0', max_length=10, verbose_name='外部构建id'), + ), + migrations.AddField( + model_name='hotfixmodel', + name='hotfix_id', + field=models.CharField(default='0', max_length=10, verbose_name='热补丁id'), + ), + migrations.AddField( + model_name='hotfixmodel', + name='test_state', + field=models.IntegerField(default=0, verbose_name='测试状态'), + ), + migrations.AddField( + model_name='hotfixmodel', + name='test_url', + field=models.CharField(default='', max_length=300, verbose_name='测试链接'), + ), + ] diff --git a/sysom_server/sysom_hotfix/apps/hotfix/models.py b/sysom_server/sysom_hotfix/apps/hotfix/models.py index 9faaef0a7080fb0552c1891ea5d40712045c7afe..6bc4b1db14f6b6ae322b20147479962cabeb2c8a 100644 --- a/sysom_server/sysom_hotfix/apps/hotfix/models.py +++ b/sysom_server/sysom_hotfix/apps/hotfix/models.py @@ -23,6 +23,11 @@ class HotfixModel(BaseModel): creator = models.CharField(max_length=20, default="admin", verbose_name="创建者") formal = models.BooleanField(default=0, verbose_name="正式包") rpm_package = models.CharField(max_length=255, verbose_name="rpm包名") + extern_build_id = models.CharField(max_length=10, default="0", verbose_name="外部构建id") + hotfix_id = models.CharField(max_length=10, default="0", verbose_name="热补丁id") + can_formal = models.BooleanField(default=0, verbose_name="能否设置为正式包") + test_url = models.CharField(max_length=300,default="", verbose_name="测试链接") + test_state = models.IntegerField(default=0, verbose_name="测试状态") class Meta: db_table = 'sys_hotfix' diff --git a/sysom_server/sysom_hotfix/apps/hotfix/views.py b/sysom_server/sysom_hotfix/apps/hotfix/views.py index 268d81cec4a1579dde75809cd55886ac7b69322a..180eb475fdeff53f17b67ee6d411172b21949b09 100644 --- a/sysom_server/sysom_hotfix/apps/hotfix/views.py +++ b/sysom_server/sysom_hotfix/apps/hotfix/views.py @@ -38,9 +38,25 @@ from cec_base.event import Event from django.http import HttpResponse, FileResponse from lib.function import FunctionClass from sysom_utils import SysomFramework +from lib.authentications import TokenAuthentication +from conf.settings import YAML_CONFIG + +import oss2 +import urllib.parse +from requests.auth import HTTPBasicAuth +import requests class SaveUploadFile(APIView): - authentication_classes = [] + authentication_classes = [TokenAuthentication] + + def __init__(self, **kwargs: Any) -> None: + super().__init__(**kwargs) + self.use_oss = bool(YAML_CONFIG.get_service_config().oss.use_oss) + if self.use_oss: + self.oss_id = YAML_CONFIG.get_service_config().oss.oss_access_key_id + self.oss_key = YAML_CONFIG.get_service_config().oss.oss_access_key_secret + self.oss_end_point = YAML_CONFIG.get_service_config().oss.oss_end_point + self.oss_bucketname = YAML_CONFIG.get_service_config().oss.oss_bucket_name @swagger_auto_schema(operation_description="上传文件", request_body=openapi.Schema( @@ -85,6 +101,7 @@ class SaveUploadFile(APIView): os.makedirs(patch_file_repo) patch_file_name = patch_file.name.rstrip("."+file_upload_type) + "-" + datetime.now().strftime('%Y%m%d%H%M%S') + "." + file_upload_type file_path = os.path.join(patch_file_repo, patch_file_name) + try: with open(file_path, 'wb') as f: for chunk in patch_file.chunks(): @@ -92,6 +109,30 @@ class SaveUploadFile(APIView): except Exception as e: logger.error(e) raise APIException(message=f"Upload Failed: {e}") + + # if use oss for file storage + if self.use_oss: + auth = oss2.Auth(YAML_CONFIG.get_service_config().oss.oss_access_key_id, YAML_CONFIG.get_service_config().oss.oss_access_key_secret) + bucket = oss2.Bucket(auth, YAML_CONFIG.get_service_config().oss.oss_end_point, YAML_CONFIG.get_service_config().oss.oss_bucket_name) + bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ) + try: + with open(file_path, 'r') as up_file: + result = bucket.put_object(patch_file_name, up_file.read()) + except Exception as e: + logger.error("oss bucket put object failed!") + raise APIException(message=f"Upload OSS Bucket Failed: {e}") + + if result.status != 200: + return Response({"message": "上传异常", "errorCode": 3, "data": {}}) + + url = bucket.sign_url('GET', patch_file_name, 60) + url = url.replace("http", "https", 1) + oss_patch_file_url = urllib.parse.unquote(url.split('?')[0]) + patch_file_name = oss_patch_file_url + + # upload file to oss success, remove the local file + os.remove(file_path) + return success(result={"patch_name":patch_file_name}, message="Upload success") class HotfixAPIView(GenericViewSet, @@ -103,6 +144,7 @@ class HotfixAPIView(GenericViewSet, ): queryset = HotfixModel.objects.filter(deleted_at=None) serializer_class = serializer.HotfixSerializer + authentication_classes = [TokenAuthentication] filter_backends = [DjangoFilterBackend] filterset_fields = ['created_at', 'creator', 'building_status', 'arch'] http_method_names = ['get', 'post', 'patch', 'delete'] @@ -145,12 +187,15 @@ class HotfixAPIView(GenericViewSet, hotfix_necessary = 0 hotfix_risk = 2 try: - res = self.function.create_hotfix_object_to_database(os_type, kernel_version, hotfix_name, patch_file, patch_path, - hotfix_necessary, hotfix_risk, log_file, arch) + res = self.function.create_hotfix_object_to_database( + os_type=os_type, kernel_version=kernel_version, hotfix_name=hotfix_name, patch_file=patch_file, patch_path=patch_path, + hotfix_necessary=hotfix_necessary, hotfix_risk=hotfix_risk, log_file=log_file, arch=arch + ) status = self.function.create_message_to_cec(customize=False, cec_topic=settings.SYSOM_CEC_HOTFIX_TOPIC, os_type=os_type, - hotfix_id=res.id, kernel_version=res.kernel_version, hotfix_name=res.hotfix_name, patch_file=res.patch_file, patch_path=res.patch_path, - arch=res.arch, log_file=res.log_file) + hotfix_id=res.id, kernel_version=res.kernel_version, hotfix_name=res.hotfix_name, patch_file=res.patch_file, + patch_path=res.patch_path, arch=res.arch, log_file=res.log_file + ) except Exception as e: return other_response(msg=str(e), code=400) else: @@ -169,14 +214,19 @@ class HotfixAPIView(GenericViewSet, hotfix_necessary = 0 hotfix_risk = 2 try: - res = self.function.create_hotfix_object_to_database(os_type, kernel_version, hotfix_name, patch_file, patch_path, - hotfix_necessary, hotfix_risk, log_file, arch) + res = self.function.create_hotfix_object_to_database( + os_type=os_type, kernel_version=kernel_version, hotfix_name=hotfix_name, + patch_file=patch_file, patch_path=patch_path, hotfix_necessary=hotfix_necessary, hotfix_risk=hotfix_risk, + log_file=log_file, arch=arch + ) # if this is customize kernel, it should provide the git repo and the branch of this version # with devel-package and debuginfo-package status = self.function.create_message_to_cec(customize=True, cec_topic=settings.SYSOM_CEC_HOTFIX_TOPIC, os_type=res.os_type, - hotfix_id=res.id, kernel_version=res.kernel_version, hotfix_name=res.hotfix_name, patch_file=res.patch_file, patch_path=res.patch_path, arch=res.arch, - log_file=res.log_file, source_repo=source_repo, source=source, devel_link=devel_link,debuginfo_link=debuginfo_link,image=image,is_src_package=is_src_package) + hotfix_id=res.id, kernel_version=res.kernel_version, hotfix_name=res.hotfix_name, patch_file=res.patch_file, + patch_path=res.patch_path, arch=res.arch, log_file=res.log_file, source_repo=source_repo, + source=source, devel_link=devel_link,debuginfo_link=debuginfo_link,image=image,is_src_package=is_src_package + ) except Exception as e: return other_response(msg=str(e), code=400) return success(result={"msg":"success","id":res.id,"event_id":self.event_id}, message="create hotfix job success") @@ -614,6 +664,7 @@ class ReleaseHotfixListAPIView(GenericViewSet, queryset = ReleasedHotfixListModule.objects.all() pagination_class = Pagination serializer_class = serializer.ReleasedHotfixSerializer + authentication_classes = [TokenAuthentication] filter_class = HotfixReleasedFilter filter_backends = [DjangoFilterBackend] http_method_names = ['get', 'post', 'patch', 'put', 'delete'] diff --git a/sysom_server/sysom_hotfix/conf/settings.py b/sysom_server/sysom_hotfix/conf/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..50189053334351370d36a224e7b8e30caaa5c107 --- /dev/null +++ b/sysom_server/sysom_hotfix/conf/settings.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- # +""" +Time 2023/08/24 15:41 +Author: mingfeng (SunnyQjm) +Email mfeng@linux.alibaba.com +File settings.py +Description: +""" +import os + +env = os.environ.get("env", "product") + + +if env == "develop": + from .develop import * +elif env == "testing": + from .testing import * +elif env == "product": + from .product import * \ No newline at end of file diff --git a/sysom_server/sysom_hotfix/config.yml b/sysom_server/sysom_hotfix/config.yml index 54a1e1549985b8af1a24ecb7d807797328ebb58f..747fe1f21c956c4acb3cd786a496afd5bdaae405 100644 --- a/sysom_server/sysom_hotfix/config.yml +++ b/sysom_server/sysom_hotfix/config.yml @@ -38,4 +38,19 @@ sysom_service: tls_skip_verify: false cec: max_retry_time: 10 # max retry the recovery of listener - sleep_time: 5 # second \ No newline at end of file + sleep_time: 5 # second + + oss: + use_oss: 0 + oss_access_key_id: "" + oss_access_key_secret: "" + oss_end_point: "" + oss_bucket_name: "" + + # extern builder can be a jenkins-like hotfix job + # seperate platform + extern_builder: + use_extern_builder: 0 + extern_builder_location: "" + extern_builder_username: "" + extern_builder_passwd: "" \ No newline at end of file diff --git a/sysom_server/sysom_hotfix/lib/authentications.py b/sysom_server/sysom_hotfix/lib/authentications.py index e93a4e7b582358b7a444c5388a7bc39a248773ed..05ad19e2c389b0447af1c50f80c3b0dfbb9e2bf5 100644 --- a/sysom_server/sysom_hotfix/lib/authentications.py +++ b/sysom_server/sysom_hotfix/lib/authentications.py @@ -6,6 +6,7 @@ from django.conf import settings from rest_framework.exceptions import AuthenticationFailed from rest_framework.request import Request from rest_framework.authentication import BaseAuthentication +from sysom_utils import SysomFramework from .utils import import_module @@ -20,7 +21,7 @@ def get_jwt_decode_classes() -> List[BaseAuthentication]: m = getattr(module, 'JWTTokenDecode') jwt_decode_classes.append(m) except Exception as exc: - logger.warn(exc) + logger.warning(exc) return jwt_decode_classes @@ -37,11 +38,26 @@ def decode_token(token: str) -> dict: return result -class TaskAuthentication(BaseAuthentication): +class TokenAuthentication(BaseAuthentication): def authenticate(self, request: Request): token = request.META.get('HTTP_AUTHORIZATION') - payload = decode_token(token) + is_local = request.META.get("REMOTE_HOST", "") in ["localhost", "127.0.0.1"] + try: + payload = decode_token(token) + except Exception as exc: + if is_local: + return {"id": 1, "token": "local"}, None + else: + raise exc + # 判断用户是否已经手动注销登录 + if SysomFramework.gcache("JWT_TOKEN").load(token) is None: + if not is_local: + raise AuthenticationFailed('用户已退出登录!') + payload['token'] = token - if 'sub' in payload: + if "user_id" in payload: + payload['id'] = payload['user_id'] + elif 'sub' in payload: payload['id'] = int(payload['sub']) - return payload, _ + return payload, None + diff --git a/sysom_server/sysom_hotfix/lib/function.py b/sysom_server/sysom_hotfix/lib/function.py index 4ab2867937f99252653a270443f5adf3b4f48cd9..a6044bf7fa8c0cfb746f1bcccd8d352f8b916da9 100644 --- a/sysom_server/sysom_hotfix/lib/function.py +++ b/sysom_server/sysom_hotfix/lib/function.py @@ -19,6 +19,9 @@ from bs4 import BeautifulSoup from lib.utils import human_datetime from sysom_utils import SysomFramework from channel_job import default_channel_job_executor +from cec_base.event import Event +from cec_base.cec_client import MultiConsumer, CecAsyncConsumeTask +from requests.auth import HTTPBasicAuth """ Function class @@ -109,73 +112,59 @@ class FunctionClass(): return None # building status and formal is set to be 0 when creating a hotfix - def create_hotfix_object_to_database(self, os_type, kernel_version, hotfix_name, patch_file, patch_path, hotfix_necessary, hotfix_risk, - log_file, arch): + def create_hotfix_object_to_database(self, **kwargs): res = HotfixModel.objects.create( - kernel_version = kernel_version, - os_type=os_type, - patch_file = patch_file, - hotfix_name = hotfix_name, - patch_path = patch_path, + hotfix_id = kwargs.get("hotfix_id", ""), + kernel_version = kwargs.get("kernel_version", ""), + os_type = kwargs.get("os_type", ""), + patch_file = kwargs.get("patch_file", ""), + hotfix_name = kwargs.get("hotfix_name", ""), + patch_path = kwargs.get("patch_path", ""), building_status = 0, hotfix_necessary = 0, hotfix_risk = 2, formal = 0, - log_file = log_file, - arch = arch + log_file = kwargs.get("log_file", ""), + arch = kwargs.get("arch", "x86_64"), + can_formal = kwargs.get("can_formal", False) ) return res def create_message_to_cec(self, **kwargs): - customize = kwargs['customize'] - cec_topic = kwargs['cec_topic'] - os_type = kwargs['os_type'] - hotfix_id = kwargs['hotfix_id'] - kernel_version= kwargs['kernel_version'] - patch_file = kwargs['patch_file'] - hotfix_name = kwargs['hotfix_name'] - patch_path = kwargs['patch_path'] - arch = kwargs['arch'] - log_file = kwargs['log_file'] try: - if not customize: + cec_topic = kwargs.get("cec_topic", "hotfix_job") + if not kwargs.get('customize', False): if re.search('anolis', os_type): self.producer.produce(cec_topic, { - "hotfix_id" : hotfix_id, - "kernel_version" : kernel_version, - "patch_name" : patch_file, - "hotfix_name" : hotfix_name, - "patch_path" : patch_path, - "arch": arch, - "log_file" : log_file, - "os_type" : os_type, + "hotfix_id" : kwargs.get("hotfix_id", None), + "kernel_version" : kwargs.get("kernel_version", ""), + "patch_name" : kwargs.get("patch_file", ""), + "hotfix_name" : kwargs.get("hotfix_name", ""), + "patch_path" : kwargs.get("patch_path", ""), + "arch": kwargs.get("arch", "x86_64"), + "log_file" : kwargs.get("log_file", ""), + "os_type" : kwargs.get("os_type", ""), "git_repo": "git@gitee.com:anolis/cloud-kernel.git", "customize": 0 }) else: # this is customize kernel - source_repo = kwargs['source_repo'] - source = kwargs['source'] - devel_link = kwargs['devel_link'] - debuginfo_link = kwargs['debuginfo_link'] - image = kwargs['image'] - is_src_package = kwargs["is_src_package"] self.producer.produce(cec_topic, { - "hotfix_id" : hotfix_id, - "kernel_version" : kernel_version, - "hotfix_name" : hotfix_name, - "patch_name" : patch_file, - "patch_path" : patch_path, - "arch": arch, - "log_file" : log_file, - "os_type" : os_type, + "hotfix_id" : kwargs.get("hotfix_id", None), + "kernel_version" : kwargs.get("kernel_version", ""), + "hotfix_name" : kwargs.get("hotfix_name", ""), + "patch_name" : kwargs.get("patch_file", ""), + "patch_path" : kwargs.get("patch_path", ""), + "arch": kwargs.get("arch", "x86_64"), + "log_file" : kwargs.get("log_file", ""), + "os_type" : kwargs.get("os_type", ""), "customize": 1, - "src_repo": source_repo, - "src_origin": source, - "devel_link": devel_link, - "debuginfo_link": debuginfo_link, - "image": image, - "is_src_package": is_src_package + "src_repo": kwargs.get("source_repo", ""), + "src_origin": kwargs.get("source", ""), + "devel_link": kwargs.get("devel_link", ""), + "debuginfo_link": kwargs.get("debuginfo_link", ""), + "image": kwargs.get("image", ""), + "is_src_package": kwargs.get("is_src_package", False), }) self.producer.flush() return True @@ -451,68 +440,50 @@ class FunctionClass(): """ CECListener listen topic of hotfix_msg, which is send by builder """ -class CECListener(): +class CECListener(MultiConsumer): def __init__(self, con, cec_url, listen_topic) -> None: + super().__init__( + YAML_CONFIG.get_cec_url(CecTarget.PRODUCER), + custom_callback=self.on_receive_event, + ) + self.append_group_consume_task( + listen_topic, + "sysom_hotfix", + Consumer.generate_consumer_id(), + ensure_topic_exist=True, + ) try: logger.info("Server CECListener init ...") self.parameters = con self.cec_url = cec_url self.listen_topic = listen_topic - self.sync_key = "sync" # this key is to tag this message for sync job - self.rpm_key = "rpm_name" # this key is to tag this message for sync rpm name - self.log_key = "log" # this key is to tag this message for sync log self.thread_runner = threading.Thread(target=self.listener, name="hotfix_server_listener") + self.op_key = { + "status": self.update_hotfix_job_status, + "rpm_name" : self.sync_hotfix_job_rpm_name, + "log": self.sync_hotfix_log, + "extern_build_id": self.sync_extern_build_id, + "build_log_finished": self.sync_building_log_cec_finish + } + self.use_extern_builder = bool(YAML_CONFIG.get_service_config().extern_builder.use_extern_builder) + if self.use_extern_builder: + self.extern_builder_location = YAML_CONFIG.get_service_config().extern_builder.extern_builder_location + self.extern_builder_username = YAML_CONFIG.get_service_config().extern_builder.extern_builder_username + self.extern_builder_passwd = YAML_CONFIG.get_service_config().extern_builder.extern_builder_passwd except Exception as e: return None - def run(self): - logger.info("Server CEC Listener start...") - self.thread_runner.start() - - def listener(self): - with dispatch_admin(self.cec_url) as admin: - if not admin.is_topic_exist(self.listen_topic): - admin.create_topic(self.listen_topic) - - consumer_id = Consumer.generate_consumer_id() - # one server just need one group id and one consumer is enough - self.consumer = dispatch_consumer(self.cec_url, self.listen_topic, - consumer_id=consumer_id, - group_id="server_listener") - - logger.info("Server CECListener init finished...") - - retry_time = 0 + def on_receive_event(self, event: Event, task: CecAsyncConsumeTask): try: - while retry_time < self.parameters.cec.max_retry_time: - """ - for each event in hotfix_msg topic, use the key inside to decide the message type - """ - for event in self.consumer: - time.sleep(1) - logger.info("processing one msg...") - try: - cec_values = event.value - hotfix_id = cec_values["hotfix_id"] - if self.sync_key in cec_values: - if self.rpm_key in cec_values: - self.sync_hotfix_job_rpm_name(hotfix_id, cec_values[self.rpm_key]) - if self.log_key in cec_values: - self.sync_hotfix_log(hotfix_id) - else: - self.update_hotfix_job_status(hotfix_id, cec_values["status"]) - except Exception as e: - logger.error(str(e)) - finally: - logger.info("ack one msg from builder...") - self.consumer.ack(event=event) - time.sleep(0.5) - time.sleep(self.parameters.cec.sleep_time) - retry_time += 1 + cec_values = event.value + db_id = cec_values["hotfix_id"] + logger.error(cec_values) + self.op_key[cec_values['op']](db_id,cec_values['value']) except Exception as e: logger.error(str(e)) - logger.error("Hotfix Server CEC Listener exit ...") + finally: + task.ack(event) def update_hotfix_job_status(self, hotfix_id, status): hotfix = HotfixModel.objects.get(id=hotfix_id) @@ -533,27 +504,51 @@ class CECListener(): hotfix.save() return hotfix_id - def sync_hotfix_job_rpm_name(self, hotfix_id, rpm_name): + def sync_hotfix_job_rpm_name(self, hotfix_id, rpm_package): try: logger.info("get rpm_name of %s from builder..." % rpm_name) hotfix = HotfixModel.objects.get(id=hotfix_id) - hotfix.rpm_package = rpm_name + hotfix.rpm_package = rpm_package hotfix.save() except Exception as e: logger.error("%s : Exception raised..." % sys._getframe().f_code.co_name) return hotfix_id - def sync_hotfix_log(self, hotfix_id): + def sync_hotfix_log(self, hotfix_id, msg): hotfix = HotfixModel.objects.get(id=hotfix_id) try: - log = "" - for line in open(os.path.join(settings.HOTFIX_FILE_STORAGE_REPO, "log", hotfix.log_file)): - log = log + str(line) - hotfix.log = log + hotfix.log = msg hotfix.save() except Exception as e: logger.error(str(e)) + def sync_extern_build_id(self, hotfix_id, extern_build_id): + try: + hotfix = HotfixModel.objects.get(id=hotfix_id) + hotfix.extern_build_id = extern_build_id + hotfix.save() + except Exception as e: + logger.error("%s : Exception raised..." % sys._getframe().f_code.co_name) + return hotfix_id + + def sync_building_log_cec_finish(self, hotfix_id, log_location): + try: + hotfix = HotfixModel.objects.get(id=hotfix_id) + if re.search("http", log_location): + # this log location is a url + res = requests.get( + request_url, + auth=HTTPBasicAuth(self.extern_builder_username, self.extern_builder_passwd) + ) + else: + # this is a local file location + log = "" + for line in open(log_location, "r"): + log = log + str(line) + hotfix.log = log + hotfix.save() + except Exception as e: + logger.error(str(e)) """ Hotfix Server Exception diff --git a/sysom_server/sysom_hotfix_builder/app/builder.py b/sysom_server/sysom_hotfix_builder/app/builder.py index 8b40553e6c48a32c5e52922b18855c861b628433..febdcecd514c8e63c761ed37cd1e231d8f608c66 100644 --- a/sysom_server/sysom_hotfix_builder/app/builder.py +++ b/sysom_server/sysom_hotfix_builder/app/builder.py @@ -39,27 +39,49 @@ class ServerConnector(): # but more, we can send : sync to server for log and hotfix name sync def update_hotfix_building_status(self, id, status): self.cec.produce(self.cec_msg_topic, { - "hotfix_id" : id, - "status" : status + "db_id" : id, + "op": "status", + "value" : status }) + self.cec.flush() def sync_rpm_name_cec(self, hotfix_id, rpm_name): logger.info("produce rpm_name ") self.cec.produce(self.cec_msg_topic, { - "hotfix_id" : hotfix_id, - "type": "rpm", - "sync" : True, - "rpm_name" : rpm_name + "db_id" : hotfix_id, + "op": "rpm", + "value" : rpm_name }) + self.cec.flush() def sync_building_log_cec(self, hotfix_id): logger.info("sync hotfix build log") self.cec.produce(self.cec_msg_topic, { - "hotfix_id": hotfix_id, - "type": "log", - "sync": True + "db_id": hotfix_id, + "op": "log", + "value": msg }) + self.cec.flush() + + def sync_extern_build_id(self, hotfix_id, extern_build_id): + logger.info("sync jenkins build id") + self.cec.produce(self.cec_msg_topic, { + "db_id": hotfix_id, + "op": "extern_build_id", + "value": extern_build_id + }) + self.cec.flush() + + # this function used to call server get the build log when build finished + def sync_building_log_cec_finish(self, hotfix_id, log_location): + logger.info("sync hotfix log when finished") + self.cec.produce(self.cec_msg_topic, { + "db_id": hotfix_id, + "op": "build_log_finished", + "value": log_location + }) + self.cec.flush() class HotfixBuilder():