def launch_new(options, args): """ Boot a new launch plan. You must supply the path to a top level configuration file. A run name will be displayed in the output. See --help for more information. """ if len(args) < 2: print "The boot command requires a top level file. See --help" return 1 config_file = args[1] print_chars(1, "Starting up run ") print_chars(1, "%s\n" % (options.name), inverse=True, color="green", bold=True) cb = CloudInitD(options.database, log_level=options.loglevel, db_name=options.name, config_file=config_file, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, terminate=False, boot=True, ready=True, fail_if_db_present=True) print_chars(3, "Logging to: %s%s.log\n" % (options.logdir, options.name)) if options.validate: print_chars(1, "Validating the launch plan.\n") errors = cb.boot_validate() if len(errors) > 0: print_chars(0, "The boot plan is not valid.\n", color = "red") for (svc, ex) in errors: print_chars(1, "Service %s had the error:\n" % (svc.name)) print_chars(1, "\t%s" %(str(ex))) return 1 if options.dryrun: test_env = _getenv_or_none('CLOUDINITD_TESTENV') host_time_env = _getenv_or_none('CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME') fab_env = _getenv_or_none('CLOUDINITD_FAB') ssh_env = _getenv_or_none('CLOUDINITD_SSH') print_chars(1, "Performing a dry run...\n", bold=True) os.environ['CLOUDINITD_TESTENV'] = "2" os.environ['CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME'] = "0.0" os.environ['CLOUDINITD_FAB'] = cloudinitd.find_true() os.environ['CLOUDINITD_SSH'] = cloudinitd.find_true() try: (rc, cb) = _launch_new(options, args, cb) print_chars(1, "Dry run successful\n", bold=True, color="green") finally: _setenv_or_none('CLOUDINITD_TESTENV', test_env) _setenv_or_none('CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME', host_time_env) _setenv_or_none('CLOUDINITD_FAB', fab_env) _setenv_or_none('CLOUDINITD_SSH', ssh_env) if not options.noclean: path = "%s/cloudinitd-%s.db" % (options.database, cb.run_name) if not os.path.exists(path): raise Exception("That DB does not seem to exist: %s" % (path)) os.remove(path) return rc (rc, cb) = _launch_new(options, args, cb) return rc
def test_popen_true(self): cmd = cloudinitd.find_true() pexe = PopenExecutablePollable(cmd, allowed_errors=0) pexe.start() rc = pexe.poll() while not rc: rc = pexe.poll()
def test_multilevel_simple(self): cmd = cloudinitd.find_true() pexe1_1 = PopenExecutablePollable(cmd, allowed_errors=0) pexe1_2 = PopenExecutablePollable(cmd, allowed_errors=0) pexe2_1 = PopenExecutablePollable(cmd, allowed_errors=0) pexe2_2 = PopenExecutablePollable(cmd, allowed_errors=0) mcp = MultiLevelPollable() mcp.add_level([pexe1_1, pexe1_2]) mcp.add_level([pexe2_1, pexe2_2]) mcp.start() rc = False while not rc: rc = mcp.poll()
def test_multilevel_error(self): cmd = cloudinitd.find_true() pexe1_1 = PopenExecutablePollable(cmd, allowed_errors=0, timeout=60) pexe1_2 = PopenExecutablePollable(cmd, allowed_errors=0, timeout=60) pexe2_1 = PopenExecutablePollable(cmd, allowed_errors=0, timeout=60) pexe2_2 = PopenExecutablePollable("NotACommand", allowed_errors=0, timeout=5) mcp = MultiLevelPollable() mcp.add_level([pexe1_1, pexe1_2]) mcp.add_level([pexe2_1, pexe2_2]) mcp.start() rc = False try: failed = True while not rc: rc = mcp.poll() except: failed = False self.assertFalse(failed)
import cloudinitd import os dir = os.path.dirname(os.path.abspath(cloudinitd.__file__)) dir = os.path.dirname(dir) g_plans_dir = os.path.join(dir, "tests/plans/") if 'CLOUDINITD_IAAS_ACCESS_KEY' not in os.environ and 'CLOUDINITD_IAAS_SECRET_KEY' not in os.environ: os.environ['CLOUDINITD_TESTENV'] = "1" os.environ['CLOUDINITD_FAB'] = cloudinitd.find_true() os.environ['CLOUDINITD_SSH'] = cloudinitd.find_true() os.environ['CLOUDINITD_IAAS_ACCESS_KEY'] = "NOTHING" os.environ['CLOUDINITD_IAAS_SECRET_KEY'] = "NOTHING" os.environ['CLOUDINITD_IAAS_ACCESS_KEY'] = "notrealkey" os.environ['CLOUDINITD_IAAS_SECRET_KEY'] = "notrealkey" os.environ['CLOUDINITD_IAAS_URL'] = "NOTHING" os.environ['CLOUDINITD_IAAS_IMAGE'] = "NOTHING" #os.environ['CLOUDINITD_IAAS_TYPE'] = os.environ['CLOUDINITD_IAAS_ALLOCATION'] = "NOTHING" os.environ['CLOUDINITD_IAAS_SSHKEYNAME'] = "NOTHING" # keep this one if it is set. for localhost tests. os.environ['CLOUDINITD_IAAS_SSHKEY'] = os.environ.get('CLOUDINITD_IAAS_SSHKEY', "/etc/group") os.environ['CLOUDINITD_SSH_USERNAME'] = "******" def is_a_test(): return 'CLOUDINITD_TESTENV' in os.environ and os.environ['CLOUDINITD_TESTENV'] == "1"