def main(argv=None): DAO._SQLITE_FILE = "%s/.d2c_test/startAction_test.sqlite" % os.path.expanduser('~') if os.path.exists(DAO._SQLITE_FILE): print "Deleting existing DB" os.unlink(DAO._SQLITE_FILE) dao = DAO() settings = {} for l in open("/home/willmore/test.conf", "r"): (k, v) = string.split(l.strip(), "=") settings[k] = v print str(settings) ec2Cred = EC2Cred(settings['ec2CredId'], settings['cert'], settings['privateKey']) awsCred = AWSCred(settings['accessKey'], settings['secretKey']) conf = Configuration(ec2ToolHome='/opt/EC2_TOOLS', awsUserId=settings['userid'], ec2Cred=ec2Cred, awsCred=awsCred) dao.saveConfiguration(conf) ec2ConnFactory = EC2ConnectionFactory(settings['accessKey'], settings['secretKey'], StdOutLogger()) role = Role("dummyDep", "loner", AMI('dummy'), 1, reservationId='r-f3639a85', startActions = [Action('echo howdy > /tmp/howdy.txt')], logger=StdOutLogger(), ec2ConnFactory=ec2ConnFactory, dao=dao) role.executeStartCommands()
def main(argv=None): ''' End-to-End integration test of deployment lifecycle. Uses one micro, EBS-backed instance, ''' SQLITE_FILE = "%s/.d2c_test/deploy_test.sqlite" % os.path.expanduser('~') if os.path.exists(SQLITE_FILE): print "Deleting existing DB" os.unlink(SQLITE_FILE) dao = DAO(SQLITE_FILE) conf = TestConfig("/home/willmore/test.conf") dao.saveConfiguration(conf) ec2ConnFactory = EC2ConnectionFactory(conf.awsCred.access_key_id, conf.awsCred.secret_access_key, StdOutLogger()) #credStore = CredStore(dao) testDir = "/tmp/d2c/%s/" % random.randint(0, 1000) sshCred = SSHCred('dirac', '/home/willmore/dirac.id_rsa') deployment = Deployment("dummyDep", ec2ConnFactory, roles=[ Role("dummyDep", "loner", ami=AMI(amiId="ami-1396a167"), count=1, instanceType=InstanceType.M1_LARGE, startActions=[Action(command="echo howdy > /tmp/howdy.txt", sshCred=sshCred)], finishedChecks=[FileExistsFinishedCheck(fileName="/tmp/howdy.txt", sshCred=sshCred)], #stopActions=[Action(command="sudo service collectd stop", # sshCred=sshCred)], dataCollectors=[DataCollector(source="/tmp/howdy.txt", destination=testDir + "howdy.txt", sshCred=sshCred), DataCollector(source="/opt/collectd/var/lib/collectd", destination=testDir + "collectd_stats", sshCred=sshCred)])]) class Listener: def notify(self, event): print "Deployment state changed to: " + event.newState deployment.addAnyStateChangeListener(Listener()) thread = Thread(target=deployment.run) thread.start() thread.join()
from d2c.data.CredStore import CredStore from TestConfig import TestConfig from d2c.data.DAO import DAO from d2c.CloudWatchConnectionFactory import CloudWatchConnectionFactory from d2c.data.CloudWatchClient import CloudWatchClient import datetime import os from mockito import * DAO._SQLITE_FILE = "%s/.d2c_test/metrics_test.sqlite" % os.path.expanduser('~') if os.path.exists(DAO._SQLITE_FILE): print "Deleting existing DB" os.unlink(DAO._SQLITE_FILE) dao = DAO() conf = TestConfig("/home/willmore/test.conf") dao.saveConfiguration(conf) client = CloudWatchClient(CloudWatchConnectionFactory(CredStore(dao)), dao) start = datetime.datetime(2011, 4, 13, 0, 0, 0) end = datetime.datetime(2011, 4, 13, 21, 35, 0) iid = 'i-0351ff75' dao.getMetrics() metrics = client.getInstanceMetrics(iid, start, end) dao.saveInstanceMetrics(metrics) print dao.getInstanceMetrics(iid)
def main(argv=None): ''' End-to-End integration test of deployment lifecycle. Uses one micro, EBS-backed instance, ''' SQLITE_FILE = "%s/.d2c_test/deploy_test.sqlite" % os.path.expanduser('~') if os.path.exists(SQLITE_FILE): print "Deleting existing DB" os.unlink(SQLITE_FILE) dao = DAO(SQLITE_FILE) conf = TestConfig("/home/willmore/test.conf") dao.saveConfiguration(conf) ec2ConnFactory = EC2ConnectionFactory(conf.awsCred.access_key_id, conf.awsCred.secret_access_key, StdOutLogger()) credStore = CredStore(dao) ec2Cred = credStore.getDefaultEC2Cred() testDir = "/tmp/d2c/%s" % random.randint(0, 1000) sshCred = SSHCred('ec2-user', '/home/willmore/cert/cloudeco.pem') deployment = Deployment("dummyDep", ec2ConnFactory, roles=[ Role("dummyDep", "loner", ami=AMI(amiId="ami-47cefa33"), count=1, launchCred=ec2Cred, instanceType=InstanceType.T1_MICRO, startActions=[Action(command="echo howdy > /tmp/howdy.txt", sshCred=sshCred)], finishedChecks=[FileExistsFinishedCheck(fileName="/tmp/howdy.txt", sshCred=sshCred)], stopActions=[Action(command="echo adios > /tmp/adios.txt", sshCred=sshCred)], dataCollectors=[DataCollector(source="/tmp/howdy.txt", destination=testDir, sshCred=sshCred), DataCollector(source="/tmp/adios.txt", destination=testDir, sshCred=sshCred), DataCollector(source="/tmp/d2c.context", destination=testDir, sshCred=sshCred)])]) class Listener: def notify(self, event): print "Deployment state changed to: " + event.newState deployment.addAnyStateChangeListener(Listener()) thread = Thread(target=deployment.run) thread.start() thread.join() print "howdy.txt fetch = %s" % str(os.path.exists(testDir + "/howdy.txt")) print "adios.txt fetch = %s" % str(os.path.exists(testDir + "/adios.txt")) print "d2c.context fetch = %s" % str(os.path.exists(testDir + "/d2c.context"))