mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
Check-pr creates and uses SP. (#1504)
* Check-pr creates and uses SP. * flake8. * flake8. * Fixing var name. * Fixing deploy.py * Looking for client_secret * Change to check_output. * mypy fix. * Fixing check-pr * working version. * lint * Updating arg text. * Removing redundant functionality. * Changing register codepath and adding flag. * Removing pycache file. * Fixing unattended flag. * Adding space. * Fixing a few calls. * Removing file. * Removing python3. * Removing old file. * Adding wait into registration.py * Formatting registration.py. * Removing space. * Adding retry logic to check-pr. * Formatting. * Retriggering. * Retriggering. * Calling sp_create and adding retry to authorize. * Fixing syntax. * Removing comments. * Adding another retry. * Retriggering. * Retriggering. * Retriggering. * Trying to find error. * Adding retry logic. * Increasing sleep. * Fixing formatting. * Retriggering. * Removing bad file. * Trying out retry for logger. * typevar issue? * Re-adding. * Retriggering. * retriggering. * Retriggering. Co-authored-by: nharper285 <nharper285@gmail.com> Co-authored-by: Cheick Keita <kcheick@gmail.com>
This commit is contained in:
committed by
GitHub
parent
bb972c22f4
commit
1de2cc841d
@ -22,9 +22,10 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from enum import Enum
|
||||
from shutil import which
|
||||
from typing import Dict, List, Optional, Set, Tuple
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypeVar
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import requests
|
||||
@ -220,6 +221,35 @@ TARGETS: Dict[str, Integration] = {
|
||||
),
|
||||
}
|
||||
|
||||
OperationResult = TypeVar("OperationResult")
|
||||
|
||||
def retry(
|
||||
operation: Callable[[Any], OperationResult],
|
||||
description: str,
|
||||
tries: int = 10,
|
||||
wait_duration: int = 10,
|
||||
data: Any = None,
|
||||
) -> OperationResult:
|
||||
logger = logging.Logger
|
||||
count = 0
|
||||
while True:
|
||||
try:
|
||||
return operation(data)
|
||||
except Exception as exc:
|
||||
exception = exc
|
||||
logger.error(f"failed '{description}'. logging stack trace.")
|
||||
logger.error(exc)
|
||||
count += 1
|
||||
if count >= tries:
|
||||
if exception:
|
||||
raise exception
|
||||
else:
|
||||
raise Exception(f"failed '{description}'")
|
||||
else:
|
||||
logger.info(
|
||||
f"waiting {wait_duration} seconds before retrying '{description}'"
|
||||
)
|
||||
time.sleep(wait_duration)
|
||||
|
||||
class TestOnefuzz:
|
||||
def __init__(self, onefuzz: Onefuzz, logger: logging.Logger, test_id: UUID) -> None:
|
||||
@ -836,10 +866,14 @@ class Run(Command):
|
||||
test_id: UUID,
|
||||
*,
|
||||
endpoint: Optional[str],
|
||||
client_id: Optional[str],
|
||||
client_secret: Optional[str],
|
||||
poll: bool = False,
|
||||
stop_on_complete_check: bool = False,
|
||||
) -> None:
|
||||
self.onefuzz.__setup__(endpoint=endpoint)
|
||||
self.onefuzz.__setup__(
|
||||
endpoint=endpoint, client_id=client_id, client_secret=client_secret
|
||||
)
|
||||
tester = TestOnefuzz(self.onefuzz, self.logger, test_id)
|
||||
result = tester.check_jobs(
|
||||
poll=poll, stop_on_complete_check=stop_on_complete_check
|
||||
@ -847,8 +881,17 @@ class Run(Command):
|
||||
if not result:
|
||||
raise Exception("jobs failed")
|
||||
|
||||
def check_repros(self, test_id: UUID, *, endpoint: Optional[str]) -> None:
|
||||
self.onefuzz.__setup__(endpoint=endpoint)
|
||||
def check_repros(
|
||||
self,
|
||||
test_id: UUID,
|
||||
*,
|
||||
endpoint: Optional[str],
|
||||
client_id: Optional[str],
|
||||
client_secret: Optional[str],
|
||||
) -> None:
|
||||
self.onefuzz.__setup__(
|
||||
endpoint=endpoint, client_id=client_id, client_secret=client_secret
|
||||
)
|
||||
tester = TestOnefuzz(self.onefuzz, self.logger, test_id)
|
||||
launch_result, repros = tester.launch_repro()
|
||||
result = tester.check_repro(repros)
|
||||
@ -860,6 +903,8 @@ class Run(Command):
|
||||
samples: Directory,
|
||||
*,
|
||||
endpoint: Optional[str] = None,
|
||||
client_id: Optional[str] = None,
|
||||
client_secret: Optional[str] = None,
|
||||
pool_size: int = 10,
|
||||
region: Optional[Region] = None,
|
||||
os_list: List[OS] = [OS.linux, OS.windows],
|
||||
@ -870,20 +915,44 @@ class Run(Command):
|
||||
if test_id is None:
|
||||
test_id = uuid4()
|
||||
self.logger.info("launching test_id: %s", test_id)
|
||||
|
||||
def try_setup(data: Any) -> None:
|
||||
self.onefuzz.__setup__(
|
||||
endpoint=endpoint, client_id=client_id, client_secret=client_secret
|
||||
)
|
||||
|
||||
retry(try_setup, "trying to configure")
|
||||
|
||||
self.onefuzz.__setup__(endpoint=endpoint)
|
||||
tester = TestOnefuzz(self.onefuzz, self.logger, test_id)
|
||||
tester.setup(region=region, pool_size=pool_size, os_list=os_list)
|
||||
tester.launch(samples, os_list=os_list, targets=targets, duration=duration)
|
||||
return test_id
|
||||
|
||||
def cleanup(self, test_id: UUID, *, endpoint: Optional[str]) -> None:
|
||||
self.onefuzz.__setup__(endpoint=endpoint)
|
||||
def cleanup(
|
||||
self,
|
||||
test_id: UUID,
|
||||
*,
|
||||
endpoint: Optional[str],
|
||||
client_id: Optional[str],
|
||||
client_secret: Optional[str],
|
||||
) -> None:
|
||||
self.onefuzz.__setup__(
|
||||
endpoint=endpoint, client_id=client_id, client_secret=client_secret
|
||||
)
|
||||
tester = TestOnefuzz(self.onefuzz, self.logger, test_id=test_id)
|
||||
tester.cleanup()
|
||||
|
||||
def check_logs(self, test_id: UUID, *, endpoint: Optional[str]) -> None:
|
||||
self.onefuzz.__setup__(endpoint=endpoint)
|
||||
def check_logs(
|
||||
self,
|
||||
test_id: UUID,
|
||||
*,
|
||||
endpoint: Optional[str],
|
||||
client_id: Optional[str],
|
||||
client_secret: Optional[str],
|
||||
) -> None:
|
||||
self.onefuzz.__setup__(
|
||||
endpoint=endpoint, client_id=client_id, client_secret=client_secret
|
||||
)
|
||||
tester = TestOnefuzz(self.onefuzz, self.logger, test_id=test_id)
|
||||
tester.check_logs_for_errors()
|
||||
|
||||
@ -892,6 +961,8 @@ class Run(Command):
|
||||
samples: Directory,
|
||||
*,
|
||||
endpoint: Optional[str] = None,
|
||||
client_id: Optional[str] = None,
|
||||
client_secret: Optional[str] = None,
|
||||
pool_size: int = 15,
|
||||
region: Optional[Region] = None,
|
||||
os_list: List[OS] = [OS.linux, OS.windows],
|
||||
@ -907,6 +978,8 @@ class Run(Command):
|
||||
self.launch(
|
||||
samples,
|
||||
endpoint=endpoint,
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
pool_size=pool_size,
|
||||
region=region,
|
||||
os_list=os_list,
|
||||
@ -915,15 +988,30 @@ class Run(Command):
|
||||
duration=duration,
|
||||
)
|
||||
self.check_jobs(
|
||||
test_id, endpoint=endpoint, poll=True, stop_on_complete_check=True
|
||||
test_id,
|
||||
endpoint=endpoint,
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
poll=True,
|
||||
stop_on_complete_check=True,
|
||||
)
|
||||
|
||||
if skip_repro:
|
||||
self.logger.warning("not testing crash repro")
|
||||
else:
|
||||
self.check_repros(test_id, endpoint=endpoint)
|
||||
self.check_repros(
|
||||
test_id,
|
||||
endpoint=endpoint,
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
)
|
||||
|
||||
self.check_logs(test_id, endpoint=endpoint)
|
||||
self.check_logs(
|
||||
test_id,
|
||||
endpoint=endpoint,
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error("testing failed: %s", repr(e))
|
||||
@ -934,7 +1022,12 @@ class Run(Command):
|
||||
success = False
|
||||
|
||||
try:
|
||||
self.cleanup(test_id, endpoint=endpoint)
|
||||
self.cleanup(
|
||||
test_id,
|
||||
endpoint=endpoint,
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
)
|
||||
except Exception as e:
|
||||
self.logger.error("testing failed: %s", repr(e))
|
||||
error = e
|
||||
|
Reference in New Issue
Block a user