Пример #1
0
    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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        self.cdb.commit()

        cdb2 = CloudMiner("sqlite:///:memory:")
        cdb2.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        cdb2.commit()
Пример #2
0
    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.commit()

        cdb2 = CloudMiner('sqlite:///:memory:')
        cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
        cdb2.commit()
Пример #3
0
class CloudIaaSTestCase(unittest.TestCase):
    
    def setUp(self):
        self.cdb = CloudMiner('sqlite:///:memory:')
        self.runname = "run1"
        self.iaasid = "iceicebaby"
        self.nodeid = "toocold"
        self.service_type = "iaasid1"
        self.parent = None
        self.hostname = "localhost"
        self.runlogdir = ""
        self.vmlogdir = ""


    def tearDown(self):
        pass
    
    def test_iaas_query(self):
        extras = {}
        extras['hi'] = 'there'
        runname = str(uuid.uuid1())
        iaasid = str(uuid.uuid1())
        nodeid = str(uuid.uuid1())
        source = "src"
        event_count = 10

        # create and add events
        for i in range(0, event_count):
            name = str(uuid.uuid1())
            cye = CYvent(source, name, 'key%d' % (i), datetime.datetime.now(), extras)
            self.cdb.add_cloudyvent(runname, iaasid, nodeid, self.hostname, self.service_type, self.parent, self.runlogdir, self.vmlogdir, cye)
        self.cdb.commit()

        # now get an IaaS object
        cyvm = self.cdb.get_by_iaasid(iaasid)
        self.assertEqual(len(cyvm.events), event_count)
        
    def test_many_iaas_1_runname(self):
        runname = str(uuid.uuid1())
        source = "src"
        key = "key"
        name = "name"
        vm_count = 10

        for i in range(0, vm_count):
            iaasid = str(uuid.uuid1())
            nodeid = str(uuid.uuid1())
            cye = CYvent(source, name, 'key%d' % (i), datetime.datetime.now(), None)
            self.cdb.add_cloudyvent(runname, iaasid, nodeid, self.hostname, self.service_type, self.parent, self.runlogdir, self.vmlogdir, cye)
            self.cdb.commit()

        cyvm_a = self.cdb.get_events_by_runname(runname)
        self.assertEqual(len(cyvm_a), vm_count, "%d should equal %d" % (len(cyvm_a), vm_count))
Пример #4
0
    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.commit()

        cdb2 = CloudMiner("sqlite:///" + self.filename)
        cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
        cdb2.commit()

        rc = self.cdb.get_events_by_runname(self.runname)
        self.assertEqual(len(rc), 2)
        self.assertEqual(rc[0].source, "src1")
        self.assertEqual(rc[0].key, "key")
        self.assertEqual(rc[0].name, "name1")
Пример #5
0
    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.commit()

        cdb2 = CloudMiner('sqlite:///:memory:')
        cdb2.add_cloudyvent(self.runname, self.iaasid, 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].name, 'name1')
Пример #6
0
    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, self.nodeid, self.hostname, self.service_type, self.parent, 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, self.nodeid, self.hostname, self.service_type, self.parent, self.runlogdir, self.vmlogdir, cye)
        cdb2.commit()

        rc = self.cdb.get_events_by_runname(self.runname)
        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].unique_event_key, 'key')
        self.assertEqual(rc[0].name, 'name1')
Пример #7
0
class CloudIaaSTestCase(unittest.TestCase):
    def setUp(self):
        self.cdb = CloudMiner("sqlite:///:memory:")
        self.runname = "run1"

    def tearDown(self):
        pass

    def test_iaas_query(self):
        extras = {}
        extras["hi"] = "there"
        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)
        self.cdb.commit()

        # now get an IaaS object
        cyvm = self.cdb.get_by_iaasid(iaasid)
        self.assertEqual(len(cyvm.events), event_count)

    def test_many_iaas_1_runname(self):
        runname = str(uuid.uuid1())
        source = "src"
        key = "key"
        name = "name"
        vm_count = 10

        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()

        cyvm_a = self.cdb.get_events_by_runname(runname)
        self.assertEqual(len(cyvm_a), vm_count)
Пример #8
0
class CloudMinerRealFileTestCase(unittest.TestCase):
    def setUp(self):
        (osf, self.filename) = tempfile.mkstemp()
        os.close(osf)
        print self.filename
        self.cdb = CloudMiner("sqlite:///" + self.filename)
        self.runname = "runitk"
        self.iaasid = "iceicebaby"

    def tearDown(self):
        os.remove(self.filename)
        pass

    def test_file_db(self):
        extras = {}
        key = "key1"
        source = "src1"
        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.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.commit()

        cdb2 = CloudMiner("sqlite:///" + self.filename)
        cdb2.add_cloudyvent(self.runname, self.iaasid, cye)
        cdb2.commit()

        rc = self.cdb.get_events_by_runname(self.runname)
        self.assertEqual(len(rc), 2)
        self.assertEqual(rc[0].source, "src1")
        self.assertEqual(rc[0].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)

        cdb2 = CloudMiner("sqlite:///" + self.filename)

        rc = cdb2.get_events_by_runname(self.runname)
        self.assertEqual(len(rc), 0)

        self.cdb.commit()
        cdb2.commit()
        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].name, "name1")
Пример #9
0
    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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        self.cdb.commit()

        cdb2 = CloudMiner("sqlite:///:memory:")
        cdb2.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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].unique_event_key, "key")
        self.assertEqual(rc[0].name, "name1")
Пример #10
0
class CloudMinerTestCase(unittest.TestCase):
    def setUp(self):
        self.cdb = CloudMiner("sqlite:///:memory:")
        self.runname = "run1"
        self.iaasid = "iaasid1"
        self.nodeid = "nodeid1"
        self.service_type = "iaasid1"
        self.parent = None
        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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        self.cdb.commit()

    def test_simple_query(self):
        extras = {}
        key = "key1"
        source = "src1"
        name = "name1"
        extras["hi"] = "there"
        cye = CYvent(source, name, key, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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].unique_event_key, key)
        self.assertEqual(rc[0].name, name)

    def test_man_run_query(self):
        run2 = str(uuid.uuid1())

        extras = {}
        key = "key1"
        source = "src1"
        name = "name1"
        key2 = "key2"
        source2 = "src2"
        name2 = "name2"
        iaas2 = "iaas2"
        nodeid2 = "nodeid2"
        extras["hi"] = "there"
        cye = CYvent(source, name, key, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        cye = CYvent(source2, name2, key2, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(
            run2, iaas2, nodeid2, self.hostname, self.service_type, self.parent, 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].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].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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        self.cdb.commit()

        cdb2 = CloudMiner("sqlite:///:memory:")
        cdb2.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            self.runlogdir,
            self.vmlogdir,
            cye,
        )
        self.cdb.commit()

        cdb2 = CloudMiner("sqlite:///:memory:")
        cdb2.add_cloudyvent(
            self.runname,
            self.iaasid,
            self.nodeid,
            self.hostname,
            self.service_type,
            self.parent,
            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].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.nodeid,
                self.hostname,
                self.service_type,
                self.parent,
                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")
Пример #11
0
class Persistence:
    def __init__(self, params, common):
        self.p = params
        self.c = common
        self.lockfilepath = None
        
    def _find_db_conf(self):
        dbconf = self.p.get_conf_or_none("persistence", "persistencedb")
        if not dbconf:
            raise InvalidConfig("There is no persistence->persistencedb configuration")
        url = urlparse.urlparse(dbconf)
        
        # If it's some kind of URL, return verbatim
        if url.scheme:
            self.c.log.info("Database configuration (verbatim): %s" % dbconf)
            return dbconf
        
        # If it's an absolute path, assuming SQLite.
        # Relative paths are taken from the persistencedir setting.
        
        if not os.path.isabs(dbconf):
            pdir = self.p.get_conf_or_none("persistence", "persistencedir")
            if not pdir:
                raise InvalidConfig("There is no persistence->persistencedir configuration")
                
            if not os.path.isabs(pdir):
                pdir = self.c.resolve_var_dir(pdir)
                
            if not os.path.isdir(pdir):
                raise InvalidConfig("Not a directory: %s" % pdir)
        
            dbconf = os.path.join(pdir, dbconf)
        
        sqlitedbconf = "sqlite:///" + dbconf
        self.c.log.info("Database configuration (deduced): %s" % sqlitedbconf)
        
        if not os.path.exists(dbconf):
            raise InvalidConfig("File does not exist: %s" % dbconf)
            
        return sqlitedbconf
        
            
    def validate(self):
        self.cdb = CloudMiner(self._find_db_conf())
        
    def new_vm(self, run_name, vm):
        """Adds VM to a run_vms list if it exists for "run_name".  If list
        does not exist, it will be created.
        Return True if the VM has not been seen before.
        """
        # vm.events = CYvents
        # vm.instanceid = iaasid
        # runname
        newone = self.cdb.add_cloudyvent_vm(run_name, vm.instanceid, vm.nodeid, vm.hostname, vm.service_type, vm.parent, vm.runlogdir, vm.vmlogdir)
        for e in vm.events:
            self.cdb.add_cloudyvent(run_name, vm.instanceid, vm.nodeid, vm.hostname, vm.service_type, vm.parent, vm.runlogdir, vm.vmlogdir, e)
        self.cdb.commit()
        if newone:
            self.c.log.debug("New VM persisted: '%s'" % vm.instanceid)
        return newone
        
    def store_run_vms(self, run_name, run_vms):
        if not self.cdb:
            raise ProgrammingError("cannot persist anything without setup/validation")
        for vm in run_vms:
            # This will updates some fields if needed, it's not actually "add" but "add only if new"
            self.cdb.add_cloudyvent_vm(run_name, vm.instanceid, vm.nodeid, vm.hostname, vm.service_type, vm.parent, vm.runlogdir, vm.vmlogdir)
            for e in vm.events:
                self.cdb.add_cloudyvent(run_name, vm.instanceid, vm.nodeid, vm.hostname, vm.service_type, vm.parent, vm.runlogdir, vm.vmlogdir, e)
        self.cdb.commit()

    def find_instanceid_byservice(self, run_name, servicename):
        """Expects only zero or 1 result -- you cannot use the "piggybacking service" trick with a non-uniqe name
        """
        if not self.cdb:
            raise ProgrammingError("cannot persist anything without setup/validation")
        cyvm_a = self.cdb.get_vms_by_type(run_name, servicename)
        if len(cyvm_a) > 1:
            raise ProgrammingError("cannot handle non-unique service names here")
        if len(cyvm_a):
            return cyvm_a[0].iaasid
        return None

    def check_new_instanceid(self, instanceid):
        """Return True if the VM instanceid has been seen before.
        """
        cyvm = self.cdb.get_by_iaasid(instanceid)
        if cyvm:
            return True
        return False

    def get_run_vms_or_none(self, run_name):
        """Get list of VMs for a run name or return None"""

        if not self.cdb:
            raise ProgrammingError("cannot persist anything without setup/validation")
        cyvm_a = self.cdb.get_iaas_by_runname(run_name) 
        vm_a = []
        for cyvm in cyvm_a:
            rvm = RunVM()
            rvm.instanceid = cyvm.iaasid
            rvm.nodeid = cyvm.nodeid
            rvm.hostname = cyvm.hostname
            rvm.service_type = cyvm.service_type
            rvm.parent = cyvm.parent
            rvm.runlogdir = cyvm.runlogdir
            rvm.vmlogdir = cyvm.vmlogdir

            for e in cyvm.events:
                xtras = {}
                for x in e.extra:
                    xtras[x.key] = x.value
                c = CYvent(e.source, e.name, e.unique_event_key, e.timestamp, xtras)
                rvm.events.append(c)
            vm_a.append(rvm)

        return vm_a
Пример #12
0
class CloudMinerTestCase(unittest.TestCase):
    
    def setUp(self):
        self.cdb = CloudMiner('sqlite:///:memory:')
        self.runname = "run1"
        self.iaasid = "iaasid1"

    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.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.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.commit()

    def test_simple_query(self):
        extras = {}
        key = "key1"
        source = "src1"
        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.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].name, name)

    def test_man_run_query(self):
        run2 = str(uuid.uuid1())

        extras = {}
        key = "key1"
        source = "src1"
        name = "name1"
        key2 = "key2"
        source2 = "src2"
        name2 = "name2"
        iaas2 = "iaas2"
        extras['hi'] = 'there'
        cye = CYvent(source, name, key, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(self.runname, self.iaasid, cye)
        cye = CYvent(source2, name2, key2, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(run2, iaas2, 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].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].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.commit()

        cdb2 = CloudMiner('sqlite:///:memory:')
        cdb2.add_cloudyvent(self.runname, self.iaasid, 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.commit()

        cdb2 = CloudMiner('sqlite:///:memory:')
        cdb2.add_cloudyvent(self.runname, self.iaasid, 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].name, 'name1')
Пример #13
0
class CloudMinerRealFileTestCase(unittest.TestCase):
    
    def setUp(self):
        (osf, self.filename) = tempfile.mkstemp()
        os.close(osf)
        print self.filename
        self.cdb = CloudMiner('sqlite:///' + self.filename)
        self.runname = "runitk"
        self.iaasid = "iceicebaby"
        self.nodeid = "toocold"
        self.parent = None
        self.service_type = "iaasid1"
        self.hostname = "localhost"
        self.runlogdir = ""
        self.vmlogdir = ""


    def tearDown(self):
        os.remove(self.filename)
        pass
   
    def test_file_db(self):
        extras = {}
        key = "key1"
        source = "src1"
        name = "name1"
        extras['hi'] = 'there'
        cye = CYvent(source, name, key, datetime.datetime.now(), extras)
        self.cdb.add_cloudyvent(self.runname, self.iaasid, self.nodeid, self.hostname, self.service_type, self.parent, 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, self.nodeid, self.hostname, self.service_type, self.parent, 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, self.nodeid, self.hostname, self.service_type, self.parent, self.runlogdir, self.vmlogdir, cye)
        cdb2.commit()

        rc = self.cdb.get_events_by_runname(self.runname)
        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].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, self.nodeid, self.hostname, self.service_type, self.parent, self.runlogdir, self.vmlogdir, cye)

        cdb2 = CloudMiner('sqlite:///' + self.filename)

        rc = cdb2.get_events_by_runname(self.runname)
        self.assertEqual(len(rc), 0)

        self.cdb.commit()
        cdb2.commit()
        rc = cdb2.get_events_by_runname(self.runname)
        self.assertEqual(len(rc), 1)
        self.assertEqual(rc[0].source, "src1")
        self.assertEqual(rc[0].unique_event_key, 'key')
        self.assertEqual(rc[0].name, 'name1')