Exemplo n.º 1
0
 def get_sub_repo_info(self, template_name):
     """
     返回一个数组,示例如下:
     """
     """
         [
             {
                 'addr': 'ssh://[email protected]:2222/paaslite/paaslite-cicd/FusionStage-Build.git',
                 'type': 'Git',
                 'codedir': 'FusionStage-Build',
                 'source_branch': 'br_FST21.0.0_730_forCenter', 'commit_id': ''
             },
             {
                 'type': 'Git',
                 'addr': 'ssh://[email protected]:2222/paasliteexplore/SecurityScan.git',
                 'source_branch': 'master',
                 'codedir': 'securityscan', 'commit_id': ''
             },
             ...        
         ]
     """
     chart_info = self.get_chart_info(template_name)
     if chart_info['meta']['number'] == 0:  # 获取失败
         logger.info(chart_info)
         return None
     buildSubRepo = chart_info['data'][0]['buildSubRepo']
     buildSubRepo = json.loads(buildSubRepo)
     sub_repo_info = buildSubRepo['sub_repo_info']
     return sub_repo_info
Exemplo n.º 2
0
 def _get(self, _url):
     logger.info(_url)
     response = self.session.get(_url, headers=self.headers, verify=False)
     if response.status_code == 200:
         res = json.loads(response.text)
         return res
     else:
         logger.info(f'访问失败: {_url}')
         return None
Exemplo n.º 3
0
 def open_first_pipeline(self):
     """ 打开搜索出的第一条记录 """
     is_not_available = self.is_visible('//*[@colspan="9"]', 1)
     if is_not_available:
         logger.info("不存在筛选出来的流水线")
         return False
     self.click_element_until(Xpather.PIPELINE_FIRST)
     self.switch_to_new(close_current=False)
     logger.info("打开筛选出来的流水线成功!")
     return True
Exemplo n.º 4
0
 def open_first_template(self):
     """ 打开搜索出的第一条记录 """
     is_not_available = self.is_visible('//*[@colspan="11"]', 1)
     if is_not_available:
         logger.info("不存在筛选出来的模板")
         return False
     self.click_element_until(Xpather.FIRST_TEMPLATE_A)
     self.switch_to_new(close_current=False)
     logger.info("打开筛选出来的模板成功!")
     return True
Exemplo n.º 5
0
 def _open():
     url = f'https://corecd.inhuawei.com/#/home/pipelineFactory?templateName={template_name}'
     if std_out:
         logger.info(url)
     self.open_url_in_new_window(url)
     open_success = self.is_visible('//*[text()="已获取Template信息!"]',
                                    timeout=15)
     if not open_success:
         self.switch_to_main(close_current=True)
         return False
     return True
Exemplo n.º 6
0
 def change_threshold_job_value(self,
                                check_item,
                                job_name,
                                value=None,
                                send_key=True,
                                open_or_not=False):
     """ 修改、打开、关闭门禁值 """
     if isinstance(value, float) or isinstance(value, int):
         value = str(value)
     if not self.click_element_until(
             Xpather.THRESHOLD_JOB_DETAIL % check_item):
         logger.info(f'没有{check_item}')
         return False
     if not self.is_visible(Xpather.THRESHOLD_JOB_VALUE % job_name, 1):
         logger.info(f'没有{job_name}')
         return False
     if send_key:
         self.send_new_keys(Xpather.THRESHOLD_JOB_VALUE % job_name, value)
         logger.info(f'正在输入门禁值: {value}')
     time.sleep(0.2)
     if open_or_not:
         self.click_elements(Xpather.THRESHOLD_JOB_ENABLE % job_name)
     else:
         self.click_elements(Xpather.THRESHOLD_JOB_DISABLE % job_name)
     self.click_element_until(Xpather.THRESHOLD_JOB_DETAIL % check_item)
     logger.info(f'修改门禁值 [{check_item}] [{job_name}] [{value}] 完成。')
Exemplo n.º 7
0
 def wrapper(*args, **kwargs):
     func_args = func.__code__.co_varnames
     has_template_name = True if 'template_name' in func_args else False
     names = self.pipeline_chooser(codequality_or_mr)
     for name in names:
         logger.info(name)
         if self.open_template_by_name(name):
             if has_template_name:
                 func(name, *args, **kwargs)  # 执行
             else:
                 func(*args, **kwargs)
             time.sleep(0.5)
         else:
             logger.error('ERROR: Open template failed!!!')
Exemplo n.º 8
0
 def get_chart_id_and_node_id(self, template_name, node):
     res = self.get_chart_info(template_name)
     if res is None:
         logger.info(f'{template_name}无此节点{node}')
         return None, None
     chart_id = res['data'][0]['chartId']
     chart_nodes = res['data'][0]['chartNode']
     node_id = ''
     for chart_node in chart_nodes:
         if chart_node['label'] == node:
             node_id = chart_node['id']
     if not node_id:
         logger.info(f'{template_name}无此节点{node}')
         return chart_id, None
     return chart_id, node_id
Exemplo n.º 9
0
 def post(self, _url, data=None, json=None):
     logger.info(_url)
     response = requests.post(_url,
                              data=data,
                              json=json,
                              headers=self.headers,
                              verify=False)
     logger.info(str(response))
     logger.info(response.text)
Exemplo n.º 10
0
 def wrapper(*args, **kwargs):
     if info is not None:
         logger.info(f'正在开始{info}...')
     for retry in range(1, retry_times+1):
         result = func(*args, **kwargs)
         if result:  # 执行
             if info is not None:
                 logger.info(f'{info}成功!')
             return result
         elif not result:
             if info is not None:
                 logger.info(f'{info}失败!重试第{retry}次...')
             if retry == retry_times:
                 return result
             continue
Exemplo n.º 11
0
 def get_sub_node_id(self,
                     template_name=None,
                     node=None,
                     sub_nodes: list = None,
                     chart_id=None,
                     node_id=None):
     res = self.get_sub_chart_info(template_name, node, chart_id, node_id)
     if res is None:
         logger.info(f'{template_name}无此节点{node}')
         return None
     chart_nodes = res['data']['chartNode']
     sub_node_id = ''
     for chart_node in chart_nodes:
         for sub_node in sub_nodes:
             print(sub_node, chart_node['label'])
             if chart_node['label'] == sub_node:
                 sub_node_id = chart_node['remark']
                 logger.info(f'访问节点{sub_node}成功!')
                 return sub_node_id
     if not sub_node_id:
         logger.info(f'无此类节点{sub_nodes}')
         return None
Exemplo n.º 12
0
 def check_threshold_item(check_item):
     """ 检查是否有该门禁值 """
     if check_item not in THRESHOLD_SET:
         logger.info('无此门禁检查项,请在settings.py配置THRESHOLD_SET变量')
         return False
     return True
Exemplo n.º 13
0
        logger.info(response.text)


if __name__ == '__main__':
    self = CoreCD_Driver()

    # Login
    self.login()
    """模板页测试"""
    # 打开模板页
    self.open_template_page()

    # 搜索关键字
    self.search_template(keyword="CTtTTTTT")
    self.open_first_template()
    self.search_template(keyword="CodeQuality")
    self.open_first_template()
    """流水线页测试"""
    # 打开流水线页
    self.open_pipeline_page()

    # 搜索关键字
    self.search_pipeline(keyword="AAAAAA")
    self.open_first_pipeline()

    self.search_pipeline(keyword="mr")
    self.open_first_pipeline()

    while self.next_template_page():
        logger.info("下一页")