Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added fucntionality and polished up the test suite

  • Loading branch information...
commit 92a15ac77e5a641db1e1eced879d7b32fc4d5c53 1 parent 22b74b3
BuzzTroll authored
View
9 cloudminer/cloudminer.py
@@ -145,13 +145,16 @@ def get_events_by_runname(self, runname):
return e_a
- def get_events_by_name(self, cyvm, event_name):
- self.session.query(_CYvent
-
def get_by_iaasid(self, iaasid):
cyvm = self.session.query(_CYVM).filter(_CYVM.iaasid == iaasid).first()
return cyvm
+ def get_vms_by_type(self, runname, service_type):
+ cyvm_a = self.session.query(_CYVM).filter(and_(
+ _CYVM.runname == runname,
+ _CYVM.service_type == service_type)).all()
+ return cyvm_a
+
def commit(self):
self.session.commit()
View
20 cloudminer/tests/test_filedb_cm.py
@@ -26,6 +26,11 @@ def setUp(self):
self.cdb = CloudMiner('sqlite:///' + self.filename)
self.runname = "runitk"
self.iaasid = "iceicebaby"
+ self.service_type = "iaasid1"
+ self.hostname = "localhost"
+ self.runlogdir = ""
+ self.vmlogdir = ""
+
def tearDown(self):
os.remove(self.filename)
@@ -38,31 +43,32 @@ def test_file_db(self):
name = "name1"
extras['hi'] = 'there'
cye = CYvent(source, name, key, datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
def test_multiply_cms_simple(self):
extras = {}
extras['hi'] = 'there'
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
+ cye = CYvent('src1', 'name1', 'key2', datetime.datetime.now(), extras)
cdb2 = CloudMiner('sqlite:///' + self.filename)
- cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
+ cdb2.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
cdb2.commit()
rc = self.cdb.get_events_by_runname(self.runname)
- self.assertEqual(len(rc), 2)
+ self.assertEqual(len(rc), 2, "len is %d and should be %d" % (len(rc), 2))
self.assertEqual(rc[0].source, "src1")
- self.assertEqual(rc[0].key, 'key')
+ self.assertEqual(rc[0].unique_event_key, 'key')
self.assertEqual(rc[0].name, 'name1')
def test_multiple_cms_commit(self):
extras = {}
extras['hi'] = 'there'
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
cdb2 = CloudMiner('sqlite:///' + self.filename)
@@ -74,5 +80,5 @@ def test_multiple_cms_commit(self):
rc = cdb2.get_events_by_runname(self.runname)
self.assertEqual(len(rc), 1)
self.assertEqual(rc[0].source, "src1")
- self.assertEqual(rc[0].key, 'key')
+ self.assertEqual(rc[0].unique_event_key, 'key')
self.assertEqual(rc[0].name, 'name1')
View
19 cloudminer/tests/test_iaasid_cm.py
@@ -22,6 +22,12 @@ class CloudIaaSTestCase(unittest.TestCase):
def setUp(self):
self.cdb = CloudMiner('sqlite:///:memory:')
self.runname = "run1"
+ self.iaasid = "iceicebaby"
+ self.service_type = "iaasid1"
+ self.hostname = "localhost"
+ self.runlogdir = ""
+ self.vmlogdir = ""
+
def tearDown(self):
pass
@@ -32,14 +38,13 @@ def test_iaas_query(self):
runname = str(uuid.uuid1())
iaasid = str(uuid.uuid1())
source = "src"
- key = "key"
event_count = 10
# create and add events
for i in range(0, event_count):
name = str(uuid.uuid1())
- cye = CYvent(source, name, key, datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(runname, iaasid, cye)
+ cye = CYvent(source, name, 'key%d' % (i), datetime.datetime.now(), extras)
+ self.cdb.add_cloudyvent(runname, iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
# now get an IaaS object
@@ -55,10 +60,10 @@ def test_many_iaas_1_runname(self):
for i in range(0, vm_count):
iaasid = str(uuid.uuid1())
- cye = CYvent(source, name, key, datetime.datetime.now(), None)
- self.cdb.add_cloudyvent(runname, iaasid, cye)
- self.cdb.commit()
+ cye = CYvent(source, name, 'key%d' % (i), datetime.datetime.now(), None)
+ self.cdb.add_cloudyvent(runname, iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
+ self.cdb.commit()
cyvm_a = self.cdb.get_events_by_runname(runname)
- self.assertEqual(len(cyvm_a), vm_count)
+ self.assertEqual(len(cyvm_a), vm_count, "%d should equal %d" % (len(cyvm_a), vm_count))
View
50 cloudminer/tests/test_simple_cm.py
@@ -23,26 +23,30 @@ def setUp(self):
self.cdb = CloudMiner('sqlite:///:memory:')
self.runname = "run1"
self.iaasid = "iaasid1"
+ self.service_type = "iaasid1"
+ self.hostname = "localhost"
+ self.runlogdir = ""
+ self.vmlogdir = ""
def tearDown(self):
pass
def test_simple_insert_with_extra_none(self):
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), None)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
def test_simple_insert_with_extra(self):
extras = {}
extras['hi'] = 'there'
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
def test_simple_insert_with_extra_empty(self):
extras = {}
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
def test_simple_query(self):
@@ -52,13 +56,13 @@ def test_simple_query(self):
name = "name1"
extras['hi'] = 'there'
cye = CYvent(source, name, key, datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
rc = self.cdb.get_events_by_runname(self.runname)
self.assertEqual(len(rc), 1)
self.assertEqual(rc[0].source, source)
- self.assertEqual(rc[0].key, key)
+ self.assertEqual(rc[0].unique_event_key, key)
self.assertEqual(rc[0].name, name)
def test_man_run_query(self):
@@ -74,48 +78,66 @@ def test_man_run_query(self):
iaas2 = "iaas2"
extras['hi'] = 'there'
cye = CYvent(source, name, key, datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
cye = CYvent(source2, name2, key2, datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(run2, iaas2, cye)
+ self.cdb.add_cloudyvent(run2, iaas2, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
rc = self.cdb.get_events_by_runname(self.runname)
self.assertEqual(len(rc), 1, "len is %d should be 0" % (len(rc)))
self.assertEqual(rc[0].source, source)
- self.assertEqual(rc[0].key, key)
+ self.assertEqual(rc[0].unique_event_key, key)
self.assertEqual(rc[0].name, name)
rc = self.cdb.get_events_by_runname(run2)
self.assertEqual(len(rc), 1)
self.assertEqual(rc[0].source, source2)
- self.assertEqual(rc[0].key, key2)
+ self.assertEqual(rc[0].unique_event_key, key2)
self.assertEqual(rc[0].name, name2)
def test_multiply_cms_simple(self):
extras = {}
extras['hi'] = 'there'
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
cdb2 = CloudMiner('sqlite:///:memory:')
- cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
+ cdb2.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
cdb2.commit()
def test_multiply_cms_simple(self):
extras = {}
extras['hi'] = 'there'
cye = CYvent('src1', 'name1', 'key', datetime.datetime.now(), extras)
- self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
self.cdb.commit()
cdb2 = CloudMiner('sqlite:///:memory:')
- cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
+ cdb2.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
cdb2.commit()
rc = self.cdb.get_events_by_runname(self.runname)
self.assertEqual(len(rc), 1)
self.assertEqual(rc[0].source, "src1")
- self.assertEqual(rc[0].key, 'key')
+ self.assertEqual(rc[0].unique_event_key, 'key')
self.assertEqual(rc[0].name, 'name1')
+ def test_get_by_type(self):
+ extras = {}
+
+ e_count = 10
+ for i in range(0, e_count):
+ cye = CYvent('src1', 'name%d' % (i), 'key%d' % (i), datetime.datetime.now(), extras)
+ self.cdb.add_cloudyvent(self.runname, self.iaasid, self.hostname, self.service_type, self.runlogdir, self.vmlogdir, cye)
+
+ self.cdb.commit()
+
+ cyvm_a = self.cdb.get_vms_by_type(self.runname, self.service_type)
+ self.assertEqual(len(cyvm_a), 1)
+ vm = cyvm_a[0]
+ self.assertEqual(len(vm.events), e_count, "%d should equal %d" % (len(vm.events), e_count))
+ for e in vm.events:
+ self.assertEqual(e.name[:4], "name")
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.