def test_platform_upload(_legacy_upload, path_exists): ''' _legacy_upload not called when platform upload ''' config = InsightsConfig(legacy_upload=False) client = InsightsClient(config) client.upload('test.gar.gz', 'test.content.type') _legacy_upload.assert_not_called()
def test_legacy_upload(_legacy_upload, path_exists): ''' _legacy_upload called when legacy upload ''' config = InsightsConfig(legacy_upload=True) client = InsightsClient(config) client.upload('test.gar.gz', 'test.content.type') _legacy_upload.assert_called_once()
def test_platform_upload_systemd(_, path_exists, read_pidfile, systemd_notify): ''' Pidfile is read and systemd-notify is called for platform upload ''' config = InsightsConfig(legacy_upload=False) client = InsightsClient(config) client.upload('test.gar.gz', 'test.content.type') read_pidfile.assert_called_once() systemd_notify.assert_called_once_with(read_pidfile.return_value)
def test_legacy_upload_systemd(_, path_exists, read_pidfile, systemd_notify, op, wtd): ''' Pidfile is read and systemd-notify is called for legacy upload ''' config = InsightsConfig(legacy_upload=True) config.account_number = '' # legacy registration thing client = InsightsClient(config) client.upload('test.gar.gz', 'test.content.type') read_pidfile.assert_called_once() systemd_notify.assert_called_once_with(read_pidfile.return_value)
def test_upload_412_no_retry(upload_archive, handle_fail_rcs): # Hack to prevent client from parsing args to py.test tmp = sys.argv sys.argv = [] try: config = InsightsConfig(logging_file='/tmp/insights.log', retries=3) client = InsightsClient(config) client.upload('/tmp/insights.tar.gz') upload_archive.assert_called_once() finally: sys.argv = tmp
def test_upload_412_write_unregistered_file(upload_archive, write_unregistered_file): # Hack to prevent client from parsing args to py.test tmp = sys.argv sys.argv = [] try: config = InsightsConfig(logging_file='/tmp/insights.log', retries=3) client = InsightsClient(config) client.upload('/tmp/insights.tar.gz') unregistered_at = upload_archive.return_value.json()["unregistered_at"] write_unregistered_file.assert_called_once_with(unregistered_at) finally: sys.argv = tmp
def test_upload_500_retry(upload_archive): # Hack to prevent client from parsing args to py.test tmp = sys.argv sys.argv = [] try: retries = 3 config = InsightsConfig(logging_file='/tmp/insights.log', retries=retries) client = InsightsClient(config) client.upload('/tmp/insights.tar.gz') upload_archive.assert_called() assert upload_archive.call_count == retries finally: sys.argv = tmp
def test_platform_upload_with_no_log_path(_legacy_upload, _, path_exists): ''' testing logger when no path is given ''' config = InsightsConfig(legacy_upload=True, logging_file='tmp.log') client = InsightsClient(config) response = client.upload('test.gar.gz', 'test.content.type') _legacy_upload.assert_called_once() assert response is not None
def main(): compile_config() set_up_logging() v = handle_startup() if v is not None: if type(v) != bool: print(v) return else: client = InsightsClient() client.update_rules() tar = client.collect(check_timestamp=False, image_id=(config["image_id"] or config["only"]), tar_file=config["tar_file"], mountpoint=config["mountpoint"]) if not config['no_upload']: client.upload(tar) else: print('Archive saved to ' + tar)
def collect_and_output(): c = InsightsClient() tar_file = c.collect(analyze_image_id=config["analyze_image_id"], analyze_file=config["analyze_file"], analyze_mountpoint=config["analyze_mountpoint"]) if not tar_file: sys.exit(constants.sig_kill_bad) if config['to_stdout']: with open(tar_file, 'rb') as tar_content: shutil.copyfileobj(tar_content, sys.stdout) else: resp = None if not config['no_upload']: resp = c.upload(tar_file) else: logger.info('Archive saved at %s', tar_file) if resp and config["to_json"]: print(json.dumps(resp)) sys.exit()
from insights.client import InsightsClient client = InsightsClient() client.config.legacy_upload = False client.upload(payload='test.tar.gz', content_type='application/vnd.redhat.advisor.test+tgz')