Example #1
0
def parseArgs():
    """Parse the arguments passed to the script."""
    logging.info("Parsing arguments")
    parser = argparse.ArgumentParser(description='Clean the QC database.')
    parser.add_argument('--config',
                        dest='config',
                        action='store',
                        default="config.yaml",
                        help='Path to the config file')
    parser.add_argument(
        '--config-git',
        action='store_true',
        help=
        'Check out the config file from git (branch repo_cleaner), ignore --config.'
    )
    parser.add_argument(
        '--config-consul',
        action='store',
        help=
        'Specify the consul url and port in the form of <url>:<port>, if specified'
        'ignore both --config and --config-git.')
    parser.add_argument(
        '--log-level',
        dest='log_level',
        action='store',
        default="20",
        help=
        'Log level (CRITICAL->50, ERROR->40, WARNING->30, INFO->20,DEBUG->10)')
    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='Dry run, no actual deletion nor modification to the CCDB.')
    parser.add_argument(
        '--only-path',
        dest='only_path',
        action='store',
        default="",
        help='Only work on given path (omit the initial slash).')
    args = parser.parse_args()
    dryable.set(args.dry_run)
    logging.info(args)
    return args
def parseArgs():
    """Parse the arguments passed to the script."""
    logging.info("Parsing arguments")
    parser = argparse.ArgumentParser(description='Clean the QC database.')
    parser.add_argument('--config',
                        dest='config',
                        action='store',
                        default="config.yaml",
                        help='Path to the config file')
    parser.add_argument(
        '--log-level',
        dest='log_level',
        action='store',
        default="20",
        help=
        'Log level (CRITICAL->50, ERROR->40, WARNING->30, INFO->20,DEBUG->10)')
    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='Dry run, no actual deletion nor modification to the CCDB.')
    args = parser.parse_args()
    dryable.set(args.dry_run)
    logging.debug(args)
    return args
Example #3
0
def test_labels_on_and_off():
    dryable.set( True, 'project1' )

    project1 = labelClass( 'project1' )()
    project2 = labelClass( 'project2' )()

    for x in range( 5 ):
        project1.callMe()
        project2.callMe()

    assert project1.calls == []
    assert project2.calls == [ 'project2' ] * 5

    dryable.set( False, 'project1' )
    dryable.set( True, 'project2' )
    for x in range( 5 ):
        project1.callMe()
        project2.callMe()

    assert project1.calls == [ 'project1' ] * 5
    assert project2.calls == [ 'project2' ] * 5
Example #4
0
def main():
    logging.getLogger().setLevel(int(10))
    dryable.set(True)
    ccdb = Ccdb('http://ccdb-test.cern.ch:8080')
    process(ccdb, "qc/testRunCleanup", 0)
Example #5
0
import dryable
import logging

logging.basicConfig(level=logging.INFO)

@dryable.Dryable( label = 'labelA' )
def functionA():
    print( "Hi, I am A" )

@dryable.Dryable( label = 'labelB' )
def functionB():
    print( "Hi, I am B" )

dryable.set( True, 'labelA' )
functionA() # this will be dried up
functionB() # this will run for real
Example #6
0
"""
Process some integers.

usage: 3_dryable.py [-h] [--dry-run] FILE [FILE ...] 

positional arguments:
  FILE           a path to a file you want to delete

optional arguments:
  -h, --help  show this help message and exit
  --dry-run   will not delete you file
"""
from docopt import docopt
import dryable

arguments = docopt(__doc__, version='Utility 20.0')
print(arguments)

dryable.set(arguments['--dry-run'])


@dryable.Dryable()
def deleteFiles(files: list):
    print('This will delete your files forever')


deleteFiles(arguments['FILE'])
Example #7
0
def test_decorator_with_return_value(subjectReturnsSomeValue):
    dryable.set(True)
    subject = subjectReturnsSomeValue
    assert subject.callMe(1) == 6666
    assert subject.callMe(2) == 6666
    assert subject.calls == []
Example #8
0
def test_decorator(subject):
    dryable.set(True)
    for x in range(10):
        subject.callMe(x, 1, 2, 3, x='x', y='y')

    assert subject.calls == []
Example #9
0
def test_nonDryRun(subject):
    dryable.set(False)
    for x in range(10):
        subject.callMe(x)

    assert subject.calls == list(range(10))
Example #10
0
def dryRun():
    dryable.set(True)
Example #11
0
def test_decorator(subject):
    dryable.set(True)
    for x in range(10):
        subject.callMe(x)

    assert subject.calls == []
Example #12
0
                image_ids.append((image_id, snapshot_id))
    return image_ids


@dryable.Dryable()
def delete_ami(region, image_id, snapshot_id):
    boto3.client('ec2', region_name=region).deregister_image(ImageId=image_id)
    boto3.client('ec2', region_name=region).delete_snapshot(SnapshotId=snapshot_id)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--confirm', action='store_true',
                        help='Deactivate dry-run mode')
    parser.add_argument('--version', type=str, required=True,
                        help='Final release to find release candidates versions. Example: v1.0.0')
    args = parser.parse_args()

    version = args.version
    if not '-rc' in version:
        dry_run = not args.confirm
        dryable.set(dry_run)
        for region in ["eu-central-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1"]:
            amis = get_release_candidate_ami_ids_for_version(region, version)
            for ami_id, snap_id in amis:
                print(f"{region} - Deleting AMI {ami_id} and its snapshot {snap_id}")
                delete_ami(region, ami_id, snap_id)
    else:
        print(
            f'Nothing to do with version {version} as it is not a final release')
Example #13
0
import dryable
import requests
import sys


def runCalculations():
    return ['some', 'results']


@dryable.Dryable()
def saveToRemoteDatabase(results):
    print('will now open an real world connection'
          'that requires a server and will make side effects')
    requests.post('http://url.to.some.server/results', data=str(results))


# the next line ensures that saveToRemoteDatabase
# will not run if --dry-run is specified on the command line
dryable.set('--dry-run' in sys.argv)
results = runCalculations()
print('got: {}'.format(results))
saveToRemoteDatabase(results)