示例#1
0
 def testAppend(self):
     dc = DeviceConfigurations()
     try:
         dc.append(self.config_one)
     except Exception, e:
         logging.error('FAILURE: append failed ' + str(dc.getContexts()) +
                       ': ' + str(e))
示例#2
0
 def testConfigInstantiate(self):
     dc = None
     dc = DeviceConfigurations()
     dc.setConfig(self.config_line)
     a = dc.getContexts()
     assert len(a) == 1 and a[
         0] == default_context, 'single config on intantiate doenst work'
示例#3
0
 def testDiffDifferent(self):
     dc1 = None
     dc2 = None
     dc1 = DeviceConfigurations()
     dc1.setConfig(self.config_line)
     dc2 = DeviceConfigurations()
     dc2.append(self.config_three)
     diff = dc1.diff(dc2)
     assert len(diff) > 0, 'diff() of different failed'
示例#4
0
 def testDiffSame(self):
     dc1 = None
     dc2 = None
     dc1 = DeviceConfigurations()
     dc1.setConfig(self.config_line)
     dc2 = DeviceConfigurations()
     dc2.setConfig(self.config_line)
     diff = dc1.diff(dc2)
     assert len(diff) == 0, 'diff() of same failed'
示例#5
0
 def testCmpSame(self):
     dc1 = None
     dc2 = None
     dc1 = DeviceConfigurations()
     dc1.setConfig(self.config_line)
     dc2 = DeviceConfigurations()
     dc2.setConfig(self.config_line)
     assert cmp(dc1, dc2) == 0, 'cmp() with same failed'
示例#6
0
 def testCmpDifferent(self):
     dc1 = None
     dc2 = None
     dc1 = DeviceConfigurations()
     dc1.setConfig(self.config_line)
     dc2 = DeviceConfigurations()
     dc2.append(self.config_two)
     c = cmp(dc1, dc2)
     assert not c == 0, 'cmp() with different failed (' + str(
         c) + '): \ndc1=' + str(dc1) + "\ndc2=" + str(dc2)
 def testDiffSame(self):
     store = ConfigurationStorage(dbhost=self._dbhost,
                                  dbname=self._dbname,
                                  user=self._dbuser,
                                  passwd=self._dbpasswd)
     config_one = DeviceConfigurations()
     config_one.setConfig(["hello there\n", "this is a test"])
     config_two = DeviceConfigurations()
     config_two.setConfig(["hello there\n", "this is a test"])
     ret = store.isChanged(config_one, config_two)
     #logging.warn( diff )
     assert ret == False, "same configs showed different diffs"
    def testBAppendDeviceConfigurations(self):
        """ add configurations to deviceconfigurations object """
        dc = DeviceConfigurations()
        conf = Configuration()
        conf.set(['hello there\n', 'this is a test'])
        #conf.setContext( 'context_one' )
        dc.append(conf)
        confResult = dc.getConfig('system')
        conf2 = Configuration()
        conf2.set(['hi there\n', 'this is also a test'])
        conf2.setContext('context_two')
        dc.append(conf2)
        confResult2 = dc.getConfig('context_two')

        #logging.warn( "confResult.get()[0]: " + confResult.get()[0] )

        assert confResult.get()[0] == 'hello there\n' \
            and confResult2.get()[0] == 'hi there\n'
    def testDetermineMergedContexts(self):
        store = ConfigurationStorage(dbhost=self._dbhost,
                                     dbname=self._dbname,
                                     user=self._dbuser,
                                     passwd=self._dbpasswd)

        # create a device configuration o bject from teh raw strings
        config_one = DeviceConfigurations()
        config_one.setConfig(["hello there\n", "this is a test"])

        # construct a device configuration ob ject from a configuration object
        config_two = DeviceConfigurations()
        conf = Configuration()
        conf.set(["hello there\n", "this is a test"])
        conf.setContext('something_else')
        config_two.append(conf)
        array = store.determineMergedContexts(config_one, config_two)
        assert array == ['something_else', 'system'
                         ], 'determining merged contexts failed: ' + str(array)
示例#10
0
 def testContext(self):
     dc = DeviceConfigurations()
     string = 'test_context'
     dc.setConfig(self.config_one, context=string)
     assert dc.getContexts()[0] == string, 'context names do not match'
示例#11
0
 def testDefaultContext(self):
     dc = DeviceConfigurations()
     assert dc.default_context == default_context, 'default context changed'
示例#12
0
 def testInit(self):
     dc = None
     try:
         dc = DeviceConfigurations()
     except Exception, e:
         pass