Example #1
0
def reboot(options, args):
    """
    Reboot an already booted plan.  You must supply the run name of the booted plan.
    """
    if len(args) < 2:
        print "The reboot command requires a run name.  See --help"
        return 1
    dbname = args[1]
    cb = CloudInitD(options.database, db_name=dbname, log_level=options.loglevel, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, terminate=True, boot=False, ready=False, continue_on_error=True)
    print_chars(1, "Rebooting %s\n" % (cb.run_name))
    cb.shutdown()
    try:
        try:
            print_chars(1, "Terminating all services %s\n" % (cb.run_name))
            options.logger.info("Terminating all services")
            cb.block_until_complete(poll_period=0.1)
            options.logger.info("Starting services back up")
            cb = CloudInitD(options.database, db_name=dbname, log_level=options.loglevel, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, terminate=False, boot=True, ready=True, continue_on_error=False)
            print_chars(1, "Booting all services %s\n" % (cb.run_name))
            cb.start()
            cb.block_until_complete(poll_period=0.1)
            return 0
        except CloudServiceException, svcex:
            print svcex
        except MultilevelException, mex:
            print mex
Example #2
0
    def test_validateiaas(self):
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/iaastypevalidate/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()

        cb.block_until_complete(poll_period=1.0)

        # check the log for a warning
        fname = os.path.expanduser("~/.cloudinitd/%s/badsvc.log" % (cb.run_name))
        print fname
        self.assertTrue(os.path.exists(fname), "The path %s should exist" % (fname))
        f = open(fname, "r")
        found = False
        for l in f.readlines():
            print l
            ndx = l.find("WARN")
            if ndx >= 0:
                ndx = l.find("2.7")
                if ndx >= 0:
                    found = True
        self.assertTrue(found, "a warning with the key 2.7 should be in the logfile %s" %(fname))
        f.close()

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
        fname = cb.get_db_file()
        os.remove(fname)
Example #3
0
 def test_manyservices_one_vm_simple(self):
     self.plan_basedir = cloudinitd.nosetests.g_plans_dir
     dir = tempfile.mkdtemp()
     conf_file = self.plan_basedir + "/singlevmmanyservice/top.conf"
     cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
     cb.start()
     cb.block_until_complete(poll_period=1.0)
     cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
     cb.shutdown()
     cb.block_until_complete(poll_period=1.0)
Example #4
0
    def _start_one(self, conf_file):
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/" + conf_file + "/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()
        cb.block_until_complete(poll_period=1.0)

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
        fname = cb.get_db_file()
        os.remove(fname)
Example #5
0
    def get_status_test(self):
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/oneservice/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()
        cb.block_until_complete(poll_period=1.0)

        svc = cb.get_service("sampleservice")
        status = svc.get_iaas_status()
        self.assertEqual("running", status, "status is %s" % (status))

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
        fname = cb.get_db_file()
        os.remove(fname)
Example #6
0
    def dep_keys_test(self):
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/oneservice/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()
        cb.block_until_complete(poll_period=1.0)

        svc = cb.get_service("sampleservice")
        attr_keys = svc.get_keys_from_bag()
        # until we figure out how to get __dict__ values from the sqlalchemy objects this will be in complete
        expectations = [
            "hostname",
            "instance_id",
#            "name",
#            "level_id",
#            "image",
#            "iaas",
#            "allocation",
#            "keyname",
#            "localkey",
#            "username",
#            "scp_username",
#            "readypgm",
#            "hostname",
#            "bootconf",
#            "bootpgm",
#            "instance_id",
#            "iaas_url",
#            "iaas_key",
#            "iaas_secret",
#            "contextualized",
#            "securitygroups",
            "webmessage"
            ]
        for e in expectations:
            self.assertTrue(e in attr_keys, "The key %s should exist in %s" % (e, str(attr_keys)))

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
        fname = cb.get_db_file()
        os.remove(fname)
Example #7
0
    def test_only_one_launched(self):
        if 'CLOUDINITD_CLEAN_ACCOUNT' not in os.environ:
            raise SkipTest()
        ilist_1 = self._get_running_vms()
        count1 = len(ilist_1)
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/singlevmmanyservice/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()
        cb.block_until_complete(poll_period=1.0)

        ilist_2 = self._get_running_vms()
        count2 = len(ilist_2)

        self.assertEqual(count1, count2 - 1, "there should be exactly 1 more VM in count 2: %d %d" % (count1, count2))

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
    def test_env_set(self):
        if cloudinitd.nosetests.is_a_test():
            raise SkipTest()
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/oneservice/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.start()
        cb.block_until_complete(poll_period=1.0)
        svc = cb.get_service("sampleservice")
        ssh_cmd = svc.get_ssh_command() + " ls -l %s" % (self.remote_dir)

        # form test directory command
        print ssh_cmd

        rc = os.system(ssh_cmd)
        self.assertEquals(rc, 0)

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
Example #9
0
def terminate(options, args):
    """
    Terminate an already booted plan.  You must supply the run name of the booted plan.
    """
    if len(args) < 2:
        print "The terminate command requires a run name.  See --help"
        return 1

    for dbname in args[1:]:
        options.name = dbname
        rc = 0
        try:
            cb = CloudInitD(options.database, log_level=options.loglevel, db_name=dbname, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, terminate=True, boot=False, ready=False, continue_on_error=True)
            print_chars(1, "Terminating %s\n" % (cb.run_name))
            cb.shutdown()

            cb.block_until_complete(poll_period=0.1)
            if not options.noclean:
                path = "%s/cloudinitd-%s.db" % (options.database, dbname)
                if not os.path.exists(path):
                    raise Exception("That DB does not seem to exist: %s" % (path))
                if not options.safeclean or (cb.get_exception() is None and not cb.get_all_exceptions()):
                    print_chars(1, "Deleting the db file %s\n" % (path))
                    os.remove(path)
                else:
                    print_chars(4, "There were errors when terminating %s, keeping db\n" % (cb.run_name))

            ex = cb.get_exception()
            if ex is None:
                ex_list = cb.get_all_exceptions()
                if ex_list:
                    ex = ex_list[-1]
            if ex is not None:
                print_chars(4, "An error occured %s" % (str(ex)))
                raise ex
        except CloudServiceException, svcex:
            print svcex
            rc = 1
        except Exception, mex:
            rc = 1
Example #10
0
    def test_prelaunch(self):

        key = None
        secret = None
        url = None
        try:
            key = os.environ['CLOUDINITD_IAAS_ACCESS_KEY']
            secret = os.environ['CLOUDINITD_IAAS_SECRET_KEY']
            url = os.environ['CLOUDINITD_IAAS_URL']
        except:
            pass

        # XXX this test may fail for nimbus
        con = cloudinitd.cb_iaas.iaas_get_con(None, key=key, secret=secret, iaasurl=url)
        i_list = con.get_all_instances()
        conf_file = "multilevelsimple"
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/" + conf_file + "/top.conf"
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        cb.pre_start_iaas()

        post_boot_list = con.get_all_instances()

        self.assertNotEqual(len(i_list), len(post_boot_list), "The list of instances should have grown")
        self.assertTrue(len(i_list)+3 < len(post_boot_list), "The list of instances should have grown by more than the number of services in the first level")

        cb.start()
        post_start_list = con.get_all_instances()
        self.assertEqual(len(post_boot_list), len(post_start_list), "The list should not have grown")
        cb.block_until_complete(poll_period=1.0)

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)
        fname = cb.get_db_file()
        os.remove(fname)
    def test_badlevel_creds(self):
        ilist_1 = self._get_running_vms()
        count1 = len(ilist_1)
        self.plan_basedir = cloudinitd.nosetests.g_plans_dir
        dir = tempfile.mkdtemp()
        conf_file = self.plan_basedir + "/badlevel2.2/top.conf"

        pass_ex = True
        cb = CloudInitD(dir, conf_file, terminate=False, boot=True, ready=True)
        try:
            cb.start()
            cb.block_until_complete(poll_period=1.0)
        except Exception, ex:
            pass_ex = True
        self.assertTrue(pass_ex, "An exception should have happened and didn't")

        cb = CloudInitD(dir, db_name=cb.run_name, terminate=True, boot=False, ready=False)
        cb.shutdown()
        cb.block_until_complete(poll_period=1.0)

        time.sleep(5)
        ilist_2 = self._get_running_vms()
        count2 = len(ilist_2)

        self.assertEqual(count1, count2, "the vm count before and after should be the same: %d %d" % (count1, count2))


if __name__ == '__main__':
    unittest.main()
 def _terminate(self, dir, run_name):
     cb = CloudInitD(dir, db_name=run_name, terminate=True, boot=False, ready=False, continue_on_error=True)
     cb.shutdown()
     cb.block_until_complete(poll_period=1.0)
     fname = cb.get_db_file()
     os.remove(fname)