Ejemplo n.º 1
0
    def create_issues(self, scenario, data):

        for d in data:
            if d['status'] == 'passed':
                continue

            issue_hash = hashlib.sha256(
                f"{d['scope']} {d['name']} {d['aggregation']} {d['raw_result'].page_identifier}"
                .encode('utf-8')).hexdigest()

            if len(self.get_issues(issue_hash)) > 0:
                continue

            logger.info(f"=====> About to crate Azure DevOps issues")

            steps = []
            for i, locator in enumerate(d['raw_result'].locators, 1):
                command = locator['command']
                value = locator["value"]
                action = "to" if value != "" else "on"
                text = f"*{command}* {value} {action}  *{locator['target']}*"
                if command == "open":
                    text = f"*{command}* {action} {scenario['url']}{locator['target']}"

                steps.append(f"{i}. {text}")

            steps = "\n".join(steps)

            summary = f"{d['scope'].capitalize()} [{d['name']}] {d['aggregation']} value violates threshold rule for {scenario['name']}"

            description = f"""Value {d['actual']} violates threshold rule: {d['scope']} [{d['name']}] {d['aggregation']}
            {d['rule']} {d['expected']} for {scenario['name']}"

                                      Steps:\n {steps}

                                      *Issue Hash:* {issue_hash}  
                        """

            fields_mapping = {
                "/fields/System.Title": summary,
                "/fields/Microsoft.VSTS.Common.Priority":
                PRIORITY_MAPPING['High'],
                "/fields/System.Description": description,
                "/fields/System.AreaPath": self.team,
                "/fields/System.IterationPath": self.team
            }

            body = []
            for key, value in fields_mapping.items():
                if value:
                    _piece = {"op": "add", "path": key, "value": value}
                    body.append(_piece)

            res = post(self.url,
                       auth=self.auth,
                       json=body,
                       headers={'content-type': 'application/json-patch+json'})

            logger.info(
                f"Azure DevOps issue {res.json()['id']} has been created")
Ejemplo n.º 2
0
def execute_command(current_command, test_data_processor):
    logger.info(
        f"{current_command['comment']} [ {current_command['command']}({current_command['target']}) ] "
        f"{current_command['value']}".strip())

    current_target = current_command['target']
    current_value = test_data_processor.process(current_command['value'])
    current_cmd, current_is_actionable = get_command(current_command['command'])

    current_cmd(current_target, current_value)
Ejemplo n.º 3
0
    def create_issues(self, scenario, data):
        for d in data:
            if d['status'] == 'passed':
                continue

            issue_hash = hashlib.sha256(
                f"{d['scope']} {d['name']} {d['aggregation']} {d['raw_result'].page_identifier}"
                .encode('utf-8')).hexdigest()

            if len(self.get_issues(issue_hash)) > 0:
                continue

            logger.info(f"=====> About to crate JIRA issues")

            steps = []
            for i, locator in enumerate(d['raw_result'].locators, 1):
                command = locator['command']
                value = locator["value"]
                action = "to" if value != "" else "on"
                text = f"*{command}* {value} {action}  *{locator['target']}*"
                if command == "open":
                    text = f"*{command}* {action} {scenario['url']}{locator['target']}"

                steps.append(f"{i}. {text}")

            steps = "\n".join(steps)

            summary = f"{d['scope'].capitalize()} [{d['name']}] {d['aggregation']} value violates threshold rule for {scenario['name']}"

            description = f"""Value {d['actual']} violates threshold rule: {d['scope']} [{d['name']}] {d['aggregation']}
{d['rule']} {d['expected']} for {scenario['name']}"
                          
                          Steps:\n {steps}
                          
                          *Issue Hash:* {issue_hash}  
            """

            field_list = {
                'project': {
                    'key': self.project
                },
                'issuetype': 'Bug',
                'summary': summary,
                'description': description,
                'priority': {
                    'name': "High"
                },
                'labels': ['observer', 'ui_performance', scenario['name']]
            }

            issue = self.client.create_issue(field_list)
            self.add_attachment(issue, d['raw_result'].report)
            logger.info(f"JIRA {issue} has been created")
Ejemplo n.º 4
0
def execute(args):
    logger.info(f"Start with args {args}")
    scenario = get_scenario(args)

    config = SharedConfig()
    config.base_url = scenario['url']
    set_config(config)
    set_args(args)

    scenario_name = scenario['name']

    for i in range(0, args.loop):
        logger.info(f"Executing scenario {scenario_name} loop: {i + 1}")
        execute_scenario(scenario, args)

    close_driver()
Ejemplo n.º 5
0
def download_file(file_path):
    logger.info(f"Downloading data {file_path} from {TESTS_BUCKET} bucket")

    file_name = Path(file_path).name

    res = requests.get(
        f"{GALLOPER_URL}/api/v1/artifacts/{GALLOPER_PROJECT_ID}/{TESTS_BUCKET}/{file_name}",
        headers=get_headers(),
        stream=True)
    if res.status_code != 200 or 'html' in res.text:
        raise Exception(
            f"Unable to download file {file_name}. Reason {res.reason}")
    file_path = f"/tmp/data/{file_name}"
    os.makedirs("/tmp/data", exist_ok=True)
    with open(file_path, 'wb') as fd:
        for chunk in res.iter_content(chunk_size=128):
            fd.write(chunk)
    return file_path
Ejemplo n.º 6
0
def main():
    logger.info("Starting analysis...")
    logger.info(f"Time zone {TZ}")
    args = parse_args()
    execute(args)
Ejemplo n.º 7
0
def execute_scenario(scenario, args):
    for test in scenario['tests']:
        logger.info(f"Executing test: {test['name']}")
        _execute_test(test, args)