import base64
import datetime
+from time import sleep
from common.buildtrigger import trigger_info, trigger_next
from common.buildservice import BuildService
from common.prerelease import is_prerelease_project
status = content.get('status', '')
url = content.get('url', '')
build_id = content.get('build_id', '')
+ repo = content.get('repo', '')
# add image_created log for iris
pub_enabled = os.getenv("IRIS_PUB_ENABLED", "0") != "0"
if pub_enabled:
if is_prerelease_project(project):
build = BuildService(obs_api, obs_user, obs_passwd)
- saveinfo = build.get_info(project)
- if saveinfo.get('download_num', 0) != content.get('download_num', 1):
- print 'EXCEPTION* mismatch download_num current:%s, obs:%s' \
- % (content.get('download_num'), saveinfo.get('download_num'))
- print 'SKIP UPDATING BUILD INFO'
- return
+ # get env
+ if not os.getenv("POST_IMAGE_POLL_CNT") or not os.getenv("POST_IMAGE_POLL_SEC"):
+ print '[%s] POST_IMAGE_POLL_CNT or POLL_SEC does not exist!!\n' % (__file__)
+ poll_cnt = int(3)
+ poll_sec = int(10)
+ else:
+ poll_cnt = int(os.getenv("POST_IMAGE_POLL_CNT"))
+ poll_sec = int(os.getenv("POST_IMAGE_POLL_SEC"))
+ print '[%s] poll_cnt(%s), poll_sec(%s)\n' \
+ % (__file__, poll_cnt, poll_sec)
- info = {"images":
- [{"name": name,
- "status": status,
- "url": url}]
- }
- build.update_info(info, project)
-
- if buildmonitor_enabled:
+ # do polling
+ while poll_cnt > 0:
saveinfo = build.get_info(project)
- if len(saveinfo['images']) == saveinfo['images_count']:
- print '[%s] last image(%s)\n' \
- % (__file__, len(saveinfo['images']))
- #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
- # project)
- bm_stage = 'Post_Image'
- bm_data = {"bm_stage" : bm_stage,
- "bm_start_datetime" : str(bm_start_datetime),
- "project" : project,
- "bm_snapshot_name" : build_id,
- }
- trigger_next("BUILD-MONITOR", bm_data)
+ if saveinfo.get('download_num', 0) != content.get('download_num', 1):
+ print 'EXCEPTION* mismatch download_num current:%s, obs:%s' \
+ % (content.get('download_num'), saveinfo.get('download_num'))
+ print 'SKIP UPDATING BUILD INFO'
+ return
+
+ info = {"images":
+ [{"name": name,
+ "status": status,
+ "repo": repo,
+ "url": url}]
+ }
+
+ before_update_img_cnt = len(saveinfo['images'])
+ build.update_info(info, project)
+
+ # for check
+ checkinfo = build.get_info(project)
+ after_update_img_cnt = len(checkinfo['images'])
+ target_img_cnt = saveinfo['images_count']
+ print '[%s] before_update_img_cnt(%s), after_update_img_cnt(%s) / target_img_cnt(%s)\n' \
+ % (__file__, before_update_img_cnt, after_update_img_cnt, target_img_cnt)
+ poll_cnt -= 1
+
+ if after_update_img_cnt == target_img_cnt:
+ print '[%s] reached the target_img_cnt(%s)!! trigger BUILD-MONITOR(Post_Image)\n' \
+ % (__file__, target_img_cnt)
+ if buildmonitor_enabled:
+ #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
+ # project)
+ bm_stage = 'Post_Image'
+ bm_data = {"bm_stage" : bm_stage,
+ "bm_start_datetime" : str(bm_start_datetime),
+ "project" : project,
+ "bm_snapshot_name" : build_id,
+ }
+ trigger_next("BUILD-MONITOR", bm_data)
+ break
+ elif before_update_img_cnt == after_update_img_cnt:
+ print '[%s] update_info failed!! wait %s sec, remaining poll_cnt is (%s)\n' \
+ % (__file__, poll_sec, poll_cnt)
+ sleep(poll_sec)
+ continue
+ else:
+ print '[%s] update_info succeeded!! keep going\n' % (__file__)
+ break
if __name__ == "__main__":
sys.exit(main())