Permalink
Browse files

patch to retain old behavior. We may actually want to modify this to …

…throw an acception when the wrong security group is specified
  • Loading branch information...
1 parent 9b31c8b commit 91805dfa13a35fc5a7041d9ef57689652726f9b5 @buzztroll buzztroll committed Oct 12, 2012
View
@@ -73,17 +73,17 @@ class IaaSBotoConn(object):
def __init__(self, svc, key, secret, iaasurl, iaas):
self._svc = svc
- if not iaas:
- iaas = "us-east-1"
-
if not iaasurl:
+ all_regions = boto.ec2.regions()
+ if iaas not in all_regions:
+ iaas = "us-east-1"
region = boto.ec2.get_region(iaas, aws_access_key_id=key, aws_secret_access_key=secret)
if not region:
raise ConfigException("The 'iaas' configuration '%s' does not specify a valid boto EC2 region." % iaas)
self._con = boto.connect_ec2(key, secret, region=region, validate_certs=False)
else:
(scheme, iaashost, iaasport, iaaspath) = cloudinitd.parse_url(iaasurl)
- region = RegionInfo(iaashost)
+ region = RegionInfo(endpoint=iaashost, name=iaas)
secure = scheme == "https"
@@ -124,9 +124,12 @@ def _run_instance(self):
sec_group = None
if security_groupname:
- sec_group_a = self._con.get_all_security_groups(groupnames=[security_groupname,])
- if sec_group_a:
- sec_group = sec_group_a
+ try:
+ sec_group_a = self._con.get_all_security_groups(groupnames=[security_groupname,])
+ if sec_group_a:
+ sec_group = sec_group_a
+ except Exception, boto_ex:
+ sec_group = None
reservation = self._con.run_instances(image, instance_type=instance_type, key_name=key_name, security_groups=sec_group)
instance = reservation.instances[0]
@@ -433,15 +436,13 @@ def iaas_get_con(svc, key=None, secret=None, iaasurl=None, iaas=None):
iaasurl = svc.get_dep("iaas_url")
if not iaas:
iaas = svc.get_dep("iaas")
- if not iaas:
- iaas = "us-east-1"
# pick the connection driver
ConDriver = IaaSBotoConn
- ndx = iaas.find("libcloud-")
- if ndx == 0:
- ConDriver = IaaSLibCloudConn
- pass
+ if iaas:
+ ndx = iaas.find("libcloud-")
+ if ndx == 0:
+ ConDriver = IaaSLibCloudConn
global g_lock
View
@@ -221,7 +221,7 @@ def reload_conf(options, args):
config_file = args[1]
print_chars(1, "Loading the launch plan for 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, fail_if_db_present=False, terminate=False, boot=False, ready=False, repair=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, fail_if_db_present=False, terminate=False, boot=False, ready=False)
if options.validate:
print_chars(1, "Validating the launch plan.\n")
errors = cb.boot_validate()
@@ -334,10 +334,13 @@ def _launch_new(options, args, cb):
fake_args = ["clean", options.name]
clean_ice(options, fake_args)
+ rc = 0
ex = cb.get_exception()
if ex is None:
- rc = 0
- else:
+ ex_list = cb.get_all_exceptions()
+ if ex_list:
+ ex = ex_list[-1]
+ if ex:
print_chars(4, "An error occured %s" % (str(ex)))
rc = 1
@@ -381,10 +384,16 @@ def _status(options, args):
fake_args = ["clean", dbname]
clean_ice(options, fake_args)
- ex = cb.get_exception()
- if ex is None:
- rc = 0
+ rc = 0
+ if g_repair:
+ ex = cb.get_last_exception()
else:
+ ex = cb.get_exception()
+ if ex is None:
+ ex_list = cb.get_all_exceptions()
+ if ex_list:
+ ex = ex_list[-1]
+ if ex:
print_chars(4, "An error occured %s" % (str(ex)))
rc = 1
@@ -399,7 +408,7 @@ def terminate(options, args):
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
@@ -416,7 +425,12 @@ def terminate(options, args):
raise Exception("That DB does not seem to exist: %s" % (path))
os.remove(path)
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
@@ -407,7 +407,11 @@ def check_status_error_test(self):
self.assertNotEqual(line, None)
rc = cloudinitd.cli.boot.main(["-O", outfile, "terminate", "%s" % (runname)])
- self.assertEqual(rc, 0)
+ if 'CLOUDINITD_TESTENV' in os.environ:
+ # in fake mode we cannot detect that an instance was killed
+ self.assertEqual(rc, 0)
+ else:
+ self.assertNotEqual(rc, 0)
def check_repair_error_test(self):
if 'CLOUDINITD_TESTENV' in os.environ:
@@ -25,7 +25,9 @@ def test_bad_opts1(self):
self.assertFalse(fail)
def test_service_poll(self):
- x = os.environ['CLOUDINITD_TESTENV']
+ x = None
+ if 'CLOUDINITD_TESTENV' in os.environ:
+ x = os.environ['CLOUDINITD_TESTENV']
os.environ['CLOUDINITD_TESTENV'] = "1"
h1 = str(uuid.uuid1())
@@ -3,9 +3,7 @@
from cloudinitd.user_api import CloudInitD
import tempfile
import logging
-
-
-
+from unittest.case import SkipTest
import unittest
import os
@@ -46,7 +44,11 @@ def test_manyservices_one_vm_simple(self):
cb.block_until_complete(poll_period=1.0)
+ # this test should be taken with a grain of salt. It will fail if you
+ # are doin anything else with you account
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
@@ -23,6 +23,7 @@ def test_validateiaas(self):
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
View
@@ -428,7 +428,7 @@ def get_scp_username(self):
@cloudinitd.LogEntryDecorator
def _get_ssh_command(self, host):
if not host:
- raise ConfigException("Trying to create and ssh command to a null hostname, something is not right.")
+ raise ConfigException("Trying to create an ssh command to a null hostname, something is not right.")
sshexec = "ssh"
try:
if os.environ['CLOUDINITD_SSH']:
@@ -762,7 +762,8 @@ def _get_readypgm_cmd(self):
readypgm = self._expand_attr(self._s.readypgm)
readypgm_args = self._expand_attr_list(self._s.readypgm_args)
- readypgm_args = urllib.quote(readypgm_args)
+ if readypgm_args:
+ readypgm_args = urllib.quote(readypgm_args)
cmd = self._get_fab_command() + " 'readypgm:hosts=%s,pgm=%s,args=%s,stagedir=%s,local_exe=%s'" % (host, readypgm, readypgm_args, self._stagedir, str(self._s.local_exe))
cloudinitd.log(self._log, logging.DEBUG, "Using ready pgm command %s" % (cmd))
@@ -774,8 +775,8 @@ def _get_boot_cmd(self):
bootpgm = self._expand_attr(self._s.bootpgm)
bootpgm_args = self._expand_attr_list(self._s.bootpgm_args)
-
- bootpgm_args = urllib.quote(bootpgm_args)
+ if bootpgm_args:
+ bootpgm_args = urllib.quote(bootpgm_args)
(osf, self._boot_output_file) = tempfile.mkstemp()
os.close(osf)
@@ -796,7 +797,8 @@ def _get_termpgm_cmd(self):
terminatepgm = self._expand_attr(self._s.terminatepgm)
terminatepgm_args = self._expand_attr_list(self._s.terminatepgm_args)
- terminatepgm_args = urllib.quote(terminatepgm_args)
+ if terminatepgm_args:
+ terminatepgm_args = urllib.quote(terminatepgm_args)
cmd = self._get_fab_command() + " readypgm:hosts=%s,pgm=%s,args=%s,stagedir=%s,local_exe=%s" % (host, terminatepgm, terminatepgm_args, self._stagedir, str(self._s.local_exe))
cloudinitd.log(self._log, logging.DEBUG, "Using terminate pgm command %s" % (cmd))
View
@@ -154,6 +154,8 @@ def func_name(cloudservice, action, msg)
self._boot_top.add_level(level_list)
self._levels.append(level_list)
self._exception = None
+ self._last_exception = None
+ self._exception_list = []
@cloudinitd.LogEntryDecorator
def find_dep(self, service_name, key):
@@ -173,11 +175,10 @@ def _mp_cb(self, mp, action, level_ndx):
@cloudinitd.LogEntryDecorator
def _svc_cb(self, svc, action, msg):
+ self._last_exception = svc.last_exception
rc = cloudinitd.callback_return_default
if action == cloudinitd.callback_action_error:
self._exception = svc.last_exception
- if self._exception is None and svc.exception_list:
- self._exception = svc.exception_list[-1]
if self._service_callback:
rc = self._service_callback(self, CloudService(self, svc), action, msg)
return rc
@@ -354,6 +355,14 @@ def get_exception(self):
return self._exception
@cloudinitd.LogEntryDecorator
+ def get_all_exceptions(self):
+ return self._exception_list
+
+ @cloudinitd.LogEntryDecorator
+ def get_last_exception(self):
+ return self._last_exception
+
+ @cloudinitd.LogEntryDecorator
def get_iaas_history(self):
ha = self._db.get_iaas_history()
@@ -17,12 +17,21 @@
print web_message
os.write(osf, web_message)
os.close(osf)
+
sudo = ""
if getpass.getuser() != "root":
sudo = "sudo"
-cmd = "%s cp %s /var/www/test.txt && %s chmod 644 /var/www/test.txt" % (sudo, fname, sudo)
-print cmd
-rc = os.system(cmd)
+
+commands = [
+ "%s apt-get update" % (sudo),
+ "%s apt-get -y install apache2" % (sudo),
+ "%s cp %s /var/www/test.txt && %s chmod 644 /var/www/test.txt" % (sudo, fname, sudo)
+ ]
+for cmd in commands:
+ print cmd
+ rc = os.system(cmd)
+ if rc != 0:
+ sys.exit(rc)
out_vals = {}
out_vals = {'testpgm' : 'hello' }

0 comments on commit 91805df

Please sign in to comment.