def test_device_classes_devices(self):
        """ Check devices under device classes are the same """
        failed_device_classes = []
        for dc in DEVICE_CLASSES:
            dc_object = dmd.unrestrictedTraverse(dc)

            # Devices under device class in global catalog
            global_catalog = ICatalogTool(dc_object)
            global_catalog_brains = global_catalog.search('Products.ZenModel.Device.Device')
            global_catalog_results = set([ brain.getPath() for brain in global_catalog_brains.results ])

            # Devices under device class in model catalog
            model_catalog = IModelCatalogTool(dc_object)
            model_catalog_brains = model_catalog.search('Products.ZenModel.Device.Device', limit=10000)
            model_catalog_results = set([ brain.getPath() for brain in model_catalog_brains.results ])

            result = "FAILED"
            if len(global_catalog_results - model_catalog_results) == 0 and  \
               len(model_catalog_results-global_catalog_results) ==0:
               result = "PASSED"
            else:
                failed_device_classes.append(dc)

        if not failed_device_classes:
            print "TEST PASSED: All devices found in the same device classes for both catalogs!!"
        else:
            print "TEST FAILED: The following device classes have different devices in the catalogs:"
            for failed in failed_device_classes:
                print "\t{0}".format(failed)

        return len(failed_device_classes) == 0
    def validate_templates(self):
        """ Check that both catalogs return same data for templates """
        global_catalog = ICatalogTool(dmd.Devices)
        model_catalog = IModelCatalogTool(dmd.Devices)

        # get template nodes from global catalog
        global_catalog_brains = global_catalog.search(types=('Products.ZenModel.RRDTemplate.RRDTemplate',))
        global_catalog_templates = set([ brain.getPath() for brain in global_catalog_brains ])

        # get template nodes from model catalog
        model_catalog_brains = global_catalog.search(types=('Products.ZenModel.RRDTemplate.RRDTemplate',))
        model_catalog_templates = set([ brain.getPath() for brain in model_catalog_brains ])

        # compare results
        if len(model_catalog_templates - global_catalog_templates) == 0 and \
            len(global_catalog_templates - model_catalog_templates) == 0:
            for template in global_catalog_templates:
                template_object = dmd.unrestrictedTraverse(template)
                query = Eq('id', template_object.id)
                
                gc_brains = global_catalog.search(types=('Products.ZenModel.RRDTemplate.RRDTemplate',), query=query)
                gc_templates = set([ brain.getPath() for brain in gc_brains ])

                mc_brains = model_catalog.search(types=('Products.ZenModel.RRDTemplate.RRDTemplate',), query=query)
                mc_templates = set([ brain.getPath() for brain in mc_brains ])

                failed_templates = []
                if not (len(mc_templates - gc_templates) == 0 and \
                   len(gc_templates - mc_templates) == 0):
                    failed_templates.append(template)

            if failed_templates:
                print "TEST FAILED: Inconsistent results from catalogs for templates:"
                for failure in failed_templates:
                    print "\t{0}".format(failure)
            else:
                print "TEST PASSED: Both catalogs returned same results!!"
                return True

        else:
            print "TEST FAILED: Inconsistent results from catalogs:"
            print "\t{0}".format("Templates found in global catalog and not in model catalog: {0}".format(global_catalog_templates - model_catalog_templates))
            print "\t{0}".format("Templates found in model catalog and not in global catalog: {0}".format(model_catalog_templates - global_catalog_templates))

        return False