Example #1
0
    def exportDevices(self, deviceClass='/', options={}):
        dumper = BatchDeviceDumper(noopts=True)
        output = StringIO()

        # Set command-line options
        dumper.options.root = deviceClass[1:]
        # Hidden 'option' in BatchDeviceDump
        dumper.options.pruneLSGO = True
        self._setOptions(dumper, options)

        # Export out custom list of properties
        def isPropExportable(propdict):
            id = propdict['id']
            if id == 'zDeviceTemplate':
                return True
            return propdict['islocal']
        dumper.isPropExportable = isPropExportable

        # Don't import out all getter/setter pairs either
        dumper.ignoreSetters += (
            'setLastChange', 'setHWProductKey', 'setHWSerialNumber',
            'setOSProductKey', 'setPriority',
        )

        dumpedCount = dumper.listDeviceTree(output)
        output.seek(0)
        data = output.readlines()
        output.close()

        # Dump the results in sorted order to make file
        # comparisons easier.
        data = '\n'.join(sorted(data))
        return data.lstrip('\n'), dumpedCount
Example #2
0
class Testzenbatchdumper(BaseTestCase):
    def afterSetUp(self):
        super(Testzenbatchdumper, self).afterSetUp()

        self.zdumper = BatchDeviceDumper(noopts=1)
        self.zdumper.options = FakeOptions()
        self.zdumper.options.regex = '.*'
        self.zdumper.options.prune = False
        self.zdumper.options.root = '/zport/dmd/Devices/TestZenBatchDumper'

        self.zloader = BatchDeviceLoader(noopts=1)
        self.zloader.options = FakeOptions()
        self.zloader.options.nomodel = True
        self.zloader.options.nocommit = False

        # Ensure that both commands get
        # a real database connection
        self.zdumper.dmd = self.zloader.dmd

        self.log = logging.getLogger("zen.BatchDeviceDumper")
        self.zdumper.log = self.log
        self.zloader.log = logging.getLogger("zen.BatchDeviceLoader")

        # Actually add the organizer we use in testing
        testRoot = self.zdumper.options.root.rsplit('/', 1)[1]
        self.zdumper.dmd.Devices.manage_addOrganizer(testRoot)

    def testDump(self):
        olympics = DateTime("2010/02/28")
        configs = [
            "/Devices/TestZenBatchDumper",
            "device1 cDateTest=%s" % repr(olympics)
        ]
        device_list, unparseable = self.zloader.parseDevices(configs)
        self.zloader.processDevices(device_list)

        outFile = StringIO()
        numDevs = self.zdumper.listDeviceTree(outFile)

        total = len([d for d in self.zdumper.root.getSubDevices()])
        self.assert_(total > 0, "Didn't load any devices")
        self.assert_(numDevs['Devices'] == total,
                     "Dumped %d of %d devices" % (numDevs['Devices'], total))
        outText = outFile.getvalue()
        outFile.close()

        self.log.info(outText)
        outConfigs = outText.split('\n')
        out_device_list, unparseable = self.zloader.parseDevices(outConfigs)
        self.assert_(numDevs['Devices'] == len(out_device_list))
        dev = self.zloader.dmd.Devices.findDevice('device1')
        self.assert_(dev.cDateTest == olympics)
class Testzenbatchdumper(BaseTestCase):

    def afterSetUp(self):
        super(Testzenbatchdumper, self).afterSetUp()

        self.zdumper = BatchDeviceDumper(noopts=1)
        self.zdumper.options = FakeOptions()
        self.zdumper.options.regex = '.*'
        self.zdumper.options.prune = False
        self.zdumper.options.root = '/zport/dmd/Devices/TestZenBatchDumper'

        self.zloader = BatchDeviceLoader(noopts=1)
        self.zloader.options = FakeOptions()
        self.zloader.options.nomodel = True
        self.zloader.options.nocommit = False

        # Ensure that both commands get
        # a real database connection
        self.zdumper.dmd = self.zloader.dmd

        self.log = logging.getLogger("zen.BatchDeviceDumper")
        self.zdumper.log = self.log
        self.zloader.log = logging.getLogger("zen.BatchDeviceLoader")

        # Actually add the organizer we use in testing
        testRoot = self.zdumper.options.root.rsplit('/', 1)[1]
        self.zdumper.dmd.Devices.manage_addOrganizer(testRoot)

    def testDump(self):
        olympics = DateTime("2010/02/28")
        configs = ["/Devices/TestZenBatchDumper", "device1 cDateTest=%s" % repr(olympics)]
        device_list, unparseable = self.zloader.parseDevices(configs)
        self.zloader.processDevices(device_list)

        outFile = StringIO()
        numDevs = self.zdumper.listDeviceTree(outFile)

        total = len([d for d in self.zdumper.root.getSubDevices() ])
        self.assert_(total > 0, "Didn't load any devices")
        self.assert_(numDevs['Devices'] == total,
            "Dumped %d of %d devices" % ( numDevs['Devices'], total))
        outText = outFile.getvalue()
        outFile.close()

        self.log.info(outText)
        outConfigs = outText.split('\n')
        out_device_list, unparseable = self.zloader.parseDevices(outConfigs)
        self.assert_(numDevs['Devices'] == len(out_device_list))
        dev = self.zloader.dmd.Devices.findDevice('device1')
        self.assert_(dev.cDateTest == olympics)