Esempio n. 1
0
def get_main_actor(dry):
    env_tokens = dict(os.environ)

    # Cannot specify a json file an an actor at the same time.
    if args.json and args.actor:
        kingpin_fail('You may only specify --actor or --json, not both!')

    if args.actor:
        ActorClass = actor_utils.get_actor_class(args.actor)
        parameters = dict([i.split('=') for i in args.params])
        options = dict([i.split('=') for i in args.options])

        return ActorClass(desc='Command Line',
                          options=options,
                          dry=dry,
                          **parameters)

    # Actor not specified. Process JSON file.
    try:
        json_file = args.json or sys.argv[1] if sys.argv else None
    except Exception as e:
        kingpin_fail(
            '%s You must specify --json or provide it as first argument.'
            % e)

    return Macro(desc='Kingpin',
                 options={'macro': json_file,
                          'tokens': env_tokens},
                 dry=dry)
Esempio n. 2
0
def get_main_actor(dry):
    env_tokens = dict(os.environ)

    # Cannot specify a script file an an actor at the same time.
    if args.script and args.actor:
        kingpin_fail('You may only specify --actor or --script, not both!')

    if args.actor:
        ActorClass = actor_utils.get_actor_class(args.actor)
        parameters = dict([i.split('=') for i in args.params])
        options = dict([i.split('=') for i in args.options])

        return ActorClass(options=options,
                          dry=dry,
                          init_tokens=env_tokens,
                          **parameters)

    # Actor not specified. Process JSON file.
    try:
        script = args.script or sys.argv[1] if sys.argv else None
    except Exception as e:
        kingpin_fail(
            '%s You must specify --script or provide it as first argument.' %
            e)

    return Macro(desc='Kingpin',
                 options={
                     'macro': script,
                     'tokens': env_tokens
                 },
                 dry=dry)
Esempio n. 3
0
def main():

    if args.actor and args.explain:
        ActorClass = actor_utils.get_actor_class(args.actor)
        print(ActorClass.__doc__)
        sys.exit(0)

    if args.build_only:
        try:
            actor = get_main_actor(dry=False)
        except Exception as e:
            log.critical(e)
            sys.exit(1)

        if args.orgchart:
            log.info('Creating organizational chart into %s' % args.orgchart)
            try:
                orgdata = actor.get_orgchart()
            except Exception as e:
                log.critical(e)
                sys.exit(2)

            with file(args.orgchart, 'w') as output:
                output.write(json.dumps(orgdata))

        sys.exit(0)

    # Begin doing real stuff!
    if os.environ.get('SKIP_DRY', False):
        log.warn('')
        log.warn('*** You have disabled the dry run.')
        log.warn('*** Execution will begin with no expectation of success.')
        log.warn('')
    elif not args.dry:
        log.info('Rehearsing... Break a leg!')

        try:
            dry_actor = get_main_actor(dry=True)
            yield dry_actor.execute()
        except actor_exceptions.ActorException as e:
            log.critical('Dry run failed. Reason:')
            log.critical(e)
            sys.exit(2)

        log.info('Rehearsal OK! Performing!')

    try:
        runner = get_main_actor(dry=args.dry)

        log.info('')
        log.warn('Lights, camera ... action!')
        log.info('')
        yield runner.execute()
    except actor_exceptions.ActorException as e:
        log.error('Kingpin encountered mistakes during the play.')
        log.error(e)
        sys.exit(2)
Esempio n. 4
0
def main():

    if args.actor and args.explain:
        ActorClass = actor_utils.get_actor_class(args.actor)
        print(ActorClass.__doc__)
        sys.exit(0)

    if args.build_only:
        try:
            actor = get_main_actor(dry=False)
        except Exception as e:
            log.critical(e)
            sys.exit(1)

        if args.orgchart:
            log.info('Creating organizational chart into %s' % args.orgchart)
            try:
                orgdata = actor.get_orgchart()
            except Exception as e:
                log.critical(e)
                sys.exit(2)

            with file(args.orgchart, 'w') as output:
                output.write(json.dumps(orgdata))

        sys.exit(0)

    # Begin doing real stuff!
    if os.environ.get('SKIP_DRY', False):
        log.warn('')
        log.warn('*** You have disabled the dry run.')
        log.warn('*** Execution will begin with no expectation of success.')
        log.warn('')
    elif not args.dry:
        log.info('Rehearsing... Break a leg!')

        try:
            dry_actor = get_main_actor(dry=True)
            yield dry_actor.execute()
        except actor_exceptions.ActorException as e:
            log.critical('Dry run failed. Reason:')
            log.critical(e)
            sys.exit(2)

        log.info('Rehearsal OK! Performing!')

    try:
        runner = get_main_actor(dry=args.dry)

        log.info('')
        log.warn('Lights, camera ... action!')
        log.info('')
        yield runner.execute()
    except actor_exceptions.ActorException as e:
        log.error('Kingpin encountered mistakes during the play.')
        log.error(e)
        sys.exit(2)
Esempio n. 5
0
def main():

    if args.actor and args.explain:
        ActorClass = actor_utils.get_actor_class(args.actor)
        print ActorClass.__doc__
        sys.exit(0)

    # Begin doing real stuff!
    if os.environ.get('SKIP_DRY', False):
        log.warn('')
        log.warn('*** You have disabled the dry run.')
        log.warn('*** Execution will begin with no expectation of success.')
        log.warn('')
    elif not args.dry:
        log.info('Rehearsing... Break a leg!')

        try:
            dry_actor = get_main_actor(dry=True)
            yield dry_actor.execute()
        except actor_exceptions.ActorException as e:
            log.critical('Dry run failed. Reason:')
            log.critical(e)
            sys.exit(2)

        log.info('Rehearsal OK! Performing!')

    try:
        runner = get_main_actor(dry=args.dry)

        log.info('')
        log.warn('Lights, camera ... action!')
        log.info('')
        yield runner.execute()
    except actor_exceptions.ActorException as e:
        log.error('Kingpin encountered mistakes during the play.')
        log.error(e)
        sys.exit(2)
Esempio n. 6
0
 def test_get_actor_class_bogus_actor(self):
     actor_string = 'bogus.actor'
     with self.assertRaises(exceptions.InvalidActor):
         utils.get_actor_class(actor_string)
Esempio n. 7
0
 def test_get_actor_class_direct(self):
     actor_string = 'kingpin.actors.test.test_utils.FakeActor'
     ret = utils.get_actor_class(actor_string)
     self.assertEqual(type(FakeActor), type(ret))
Esempio n. 8
0
 def test_get_actor_class(self):
     actor_string = 'misc.Sleep'
     ret = utils.get_actor_class(actor_string)
     self.assertEqual(type(misc.Sleep), type(ret))
Esempio n. 9
0
 def test_get_actor_class_bogus_actor(self):
     actor_string = 'bogus.actor'
     with self.assertRaises(exceptions.InvalidActor):
         utils.get_actor_class(actor_string)
Esempio n. 10
0
 def test_get_actor_class_direct(self):
     actor_string = 'kingpin.actors.test.test_utils.FakeActor'
     ret = utils.get_actor_class(actor_string)
     self.assertEquals(type(FakeActor), type(ret))
Esempio n. 11
0
 def test_get_actor_class(self):
     actor_string = 'misc.Sleep'
     ret = utils.get_actor_class(actor_string)
     self.assertEquals(type(misc.Sleep), type(ret))