def flare(cls, config, case_id): email = input('Please enter your contact email address: ').lower() case_id = int(case_id) if case_id else None myflare = Flare(version=AGENT_VERSION, case_id=case_id, email=email) myflare.add_path(config.get('conf_path')) myflare.add_path(config.get_loaded_config()) myflare.add_path(config.get('logging').get('agent_log_file')) myflare.add_path(config.get('logging').get('dogstatsd_log_file')) myflare.add_path(config.get('additional_checksd')) flarepath = myflare.create_archive( status=cls.status(config, to_screen=False)) print('The flare is going to be uploaded to Datadog') choice = input('Do you want to continue [Y/n]? ') if choice.strip().lower() not in ['yes', 'y', '']: print('Aborting (you can still use {0})'.format(flarepath)) sys.exit(0) success, case_id = myflare.submit() if success: if case_id: print( 'Your flare was uploaded successfully, this is your case id: {}' .format(case_id)) else: print( 'Your flare was uploaded successfully, but a case id could not be retrieved.' ) myflare.cleanup()
def test_flare_basic(zip_contents, requests_ok, requests_ok_no_case): my_flare = Flare(paths=[zip_contents]) expected_flare_path = "datadog-agent-{}.zip".format( datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")) assert os.path.basename(my_flare.get_archive_path()) == expected_flare_path flare_path = my_flare.create_archive() assert os.path.exists(flare_path) assert zipfile.is_zipfile(flare_path) with zipfile.ZipFile(flare_path, 'r') as flare_zip: archive_contents = flare_zip.infolist() for content in archive_contents: assert os.path.basename(content.filename) in CONTENTS assert content.compress_type == zipfile.ZIP_DEFLATED with mock.patch('requests.post', return_value=requests_ok): success, case = my_flare.submit() assert success assert case == CASE_NO with mock.patch('requests.post', return_value=requests_ok_no_case): success, case = my_flare.submit() assert success assert case is None my_flare.cleanup() assert not os.path.exists(flare_path)
def test_flare_400(zip_contents, requests_nok): my_flare = Flare(paths=[zip_contents]) my_flare.create_archive() with mock.patch('requests.post', return_value=requests_nok): assert not my_flare.submit() my_flare.cleanup() assert not os.path.exists(my_flare.get_archive_path())
def test_flare_too_large(zip_contents): my_flare = Flare(paths=[zip_contents]) my_flare.MAX_UPLOAD_SIZE = 1 my_flare.create_archive() assert not my_flare._validate_size() with mock.patch('requests.post', return_value=requests_ok): assert not my_flare.submit() my_flare.cleanup() assert not os.path.exists(my_flare.get_archive_path())
def test_flare_proxy_timeout(zip_contents): my_flare = Flare(paths=[zip_contents]) my_flare.create_archive() with mock.patch('requests.post') as requests_mock: requests_mock.side_effect = requests.exceptions.Timeout( 'fake proxy timeout') assert not my_flare.submit() my_flare.cleanup() assert not os.path.exists(my_flare.get_archive_path())
def flare(cls, case_id): email = input('Please enter your contact email address: ').lower() case_id = int(case_id) if case_id else None myflare = Flare(case_id=case_id, email=email) myflare.add_path(config.get('conf_path')) myflare.add_path(config.get_loaded_config()) myflare.add_path(config.get('logging').get('agent_log_file')) myflare.add_path(config.get('logging').get('dogstatsd_log_file')) myflare.add_path(config.get('additional_checksd')) flarepath = myflare.create_archive() print('The flare is going to be uploaded to Datadog') choice = input('Do you want to continue [Y/n]? ') if choice.strip().lower() not in ['yes', 'y', '']: print('Aborting (you can still use {0})'.format(flarepath)) sys.exit(0) if myflare.submit(): myflare.cleanup()