Example #1
0
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()
Example #2
0
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()
Example #3
0
def main(argv=sys.argv):
    
    conf = argv[1]
    
    sqlFile = "%s/.d2c_test/main_test_stub.sqlite" % os.path.expanduser('~') 
    if os.path.exists(sqlFile):
        print "Deleting existing DB"
        os.unlink(sqlFile)
        
    mockBoto = mock(boto)
    
    def mock_connect_ec2(*args, **kwargs):
        return DummyConn()
    
    mockBoto.connect_ec2 = mock_connect_ec2
   
    mockRemoteFactory = mock(RemoteShellExecutorFactory)
    when(mockRemoteFactory).executor(any(), any(), 
                any(), any(), any()).thenReturn(mock(RemoteShellExecutor))
    when(mockRemoteFactory).executor(any(), any(), 
                any()).thenReturn(mock(RemoteShellExecutor))
                
    mockExecFactory = mock(ShellExecutorFactory)
    when(mockExecFactory).executor(any(), any()).thenReturn(mock(ShellExecutor))
   
    dao = DAO(sqlFile, mockBoto, mockRemoteFactory, mockExecFactory)
    
    test_initor.init_db(dao, conf)
    
    mockAMIFactory = mock(AMIToolsFactory)
    mockAMITools = mock(AMITools)
    when(mockAMIFactory).getAMITools(any()).thenReturn(mockAMITools)
    when(mockAMITools).getArch(any()).thenReturn("x86_64")
    when(mockAMITools).registerAMI(any(), any(), any()).thenReturn("foobarami")
    
    print dao.getAMIs()
    
    app = Application(dao, mockAMIFactory)
    app.MainLoop()
Example #4
0
import sys
import os

from d2c.Application import Application
from d2c.data.DAO import DAO
from d2c.AMITools import AMIToolsFactory

import test_initor

SQLITE_FILE = "%s/.d2c_test/d2c_db.sqlite" % os.path.expanduser('~') 
if os.path.exists(SQLITE_FILE):
    print "Deleting existing DB"
    os.unlink(SQLITE_FILE)
        
dao = DAO(SQLITE_FILE)

test_initor.init_db(dao, "/home/willmore/scicloud.conf")

deployment = dao.getDeployments()[0]
deployment.state = "FOOBAR"
uploadAction = deployment.roles[0].uploadActions[0]
uploadAction.logger = True
dao.saveDeployment(deployment)

assert uploadAction.logger
assert uploadAction is deployment.roles[0].uploadActions[0]
Example #5
0
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)
Example #6
0
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"))