<s> import json <EOL> import socket <EOL> import httplib2 <EOL> from oslo_config import cfg <EOL> from solum . common import exception <EOL> from solum . openstack . common import log as logging <EOL> LOG = logging . getLogger ( __name__ ) <EOL> http_timeout_opt = [ <EOL> cfg . IntOpt ( '<STR_LIT>' , <EOL> default = <NUM_LIT:2> , <EOL> help = '<STR_LIT>' ) <EOL> ] <EOL> def list_opts ( ) : <EOL> yield '<STR_LIT>' , http_timeout_opt <EOL> CONF = cfg . CONF <EOL> CONF . register_opts ( http_timeout_opt , group = '<STR_LIT>' ) <EOL> CONF . import_opt ( '<STR_LIT>' , '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> http_req_timeout = CONF . api . http_request_timeout <EOL> def get_http_connection ( ) : <EOL> return httplib2 . Http ( timeout = http_req_timeout ) <EOL> def is_reachable ( url ) : <EOL> reachable = False <EOL> conn = get_http_connection ( ) <EOL> resp , _ = conn . request ( url , '<STR_LIT:GET>' ) <EOL> if resp is not None and resp [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> reachable = True <EOL> return reachable <EOL> def send_status ( test_result , status_url , repo_token , pending = False ) : <EOL> if status_url and repo_token : <EOL> commit_id = status_url . rstrip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> log_url = cfg . CONF . worker . log_url_prefix + commit_id <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' + repo_token , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } <EOL> if pending : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> elif test_result == <NUM_LIT:0> : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT:success>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> else : <EOL> data = { '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : log_url } <EOL> try : <EOL> conn = get_http_connection ( ) <EOL> resp , _ = conn . request ( status_url , '<STR_LIT:POST>' , headers = headers , <EOL> body = json . dumps ( data ) ) <EOL> if resp [ '<STR_LIT:status>' ] != '<STR_LIT>' : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( resp [ '<STR_LIT:status>' ] , status_url , repo_token ) ) <EOL> except ( httplib2 . HttpLib2Error , socket . error ) as ex : <EOL> LOG . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( status_url , repo_token , ex ) ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> def verify_artifact ( artifact , collab_url ) : <EOL> if collab_url is None : <EOL> return True <EOL> repo_token = artifact . get ( '<STR_LIT>' ) <EOL> if repo_token is None : <EOL> return False <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' + repo_token } <EOL> try : <EOL> conn = get_http_connection ( ) <EOL> resp , _ = conn . request ( collab_url , headers = headers ) <EOL> if resp [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> return True <EOL> elif resp [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> raise exception . RequestForbidden ( <EOL> reason = "<STR_LIT>" % <EOL> collab_url . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] ) <EOL> except ( httplib2 . HttpLib2Error , socket . error ) as ex : <EOL> LOG . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( collab_url , ex ) ) <EOL> return False </s>
