示例#1
0
 def testSaveAndDelete(self):
     persistence = Config(self.tempdir)
     persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
     filePath = os.path.join(self.tempdir, 'nets', NETWORK)
     self.assertFalse(os.path.exists(filePath))
     persistence.save()
     self.assertTrue(os.path.exists(filePath))
     persistence.delete()
     self.assertFalse(os.path.exists(filePath))
示例#2
0
 def testSaveAndDelete(self):
     persistence = Config(self.tempdir)
     persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
     filePath = os.path.join(self.tempdir, 'nets', NETWORK)
     self.assertFalse(os.path.exists(filePath))
     persistence.save()
     self.assertTrue(os.path.exists(filePath))
     persistence.delete()
     self.assertFalse(os.path.exists(filePath))
示例#3
0
    def testDiff(self):
        configA = Config(self.tempdir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)

        configB = Config(self.tempdir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks, {})
        self.assertEqual(diff.bonds, {})

        EVIL_NETWORK = 'jarjar'
        EVIL_BONDING_ATTRIBUTES = {'options': 'mode=3', 'nics': ['eth3']}
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks[EVIL_NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], BONDING_ATTRIBUTES)

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        self.assertIn(NETWORK, diff.networks)
示例#4
0
    def testDiff(self):
        configA = Config(self.tempdir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)
        configA.set_device(DEVICE, DEVICE_ATTRIBUTES)

        configB = Config(self.tempdir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)
        configB.set_device(DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks, {})
        self.assertEqual(diff.bonds, {})
        self.assertEqual(diff.devices, {})

        EVIL_NETWORK = 'jarjar'
        EVIL_BONDING_ATTRIBUTES = {'options': 'mode=3', 'nics': ['eth3']}
        EVIL_DEVICE = 'devdev'
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)
        configB.set_device(EVIL_DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks[EVIL_NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], BONDING_ATTRIBUTES)
        # Devices diff is not yet supported.
        self.assertEqual(diff.devices, {})

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        self.assertIn(NETWORK, diff.networks)
示例#5
0
    def testDiff(self):
        configA = Config(self.tempdir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)

        configB = Config(self.tempdir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks, {})
        self.assertEqual(diff.bonds, {})

        EVIL_NETWORK = 'jarjar'
        EVIL_BONDING_ATTRIBUTES = {'options': 'mode=3', 'nics': ['eth3']}
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks[EVIL_NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], BONDING_ATTRIBUTES)

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        self.assertIn(NETWORK, diff.networks)
示例#6
0
    def testDiff(self):
        configA = Config(self.tempdir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)

        configB = Config(self.tempdir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks, {})
        self.assertEqual(diff.bonds, {})

        EVIL_NETWORK = "jarjar"
        EVIL_BONDING_ATTRIBUTES = {"options": "mode=3", "nics": ["eth3"]}
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks[EVIL_NETWORK], {"remove": True})
        self.assertEqual(diff.bonds[BONDING], BONDING_ATTRIBUTES)

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        self.assertIn(NETWORK, diff.networks)
示例#7
0
    def testDiff(self):
        configA = Config(self.tempdir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)
        configA.set_device(DEVICE, DEVICE_ATTRIBUTES)

        configB = Config(self.tempdir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)
        configB.set_device(DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks, {})
        self.assertEqual(diff.bonds, {})
        self.assertEqual(diff.devices, {})

        EVIL_NETWORK = 'jarjar'
        EVIL_BONDING_ATTRIBUTES = {'options': 'mode=3', 'nics': ['eth3']}
        EVIL_DEVICE = 'devdev'
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)
        configB.set_device(EVIL_DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        self.assertEqual(diff.networks[EVIL_NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], BONDING_ATTRIBUTES)
        # Devices diff is not yet supported.
        self.assertEqual(diff.devices, {})

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        self.assertIn(NETWORK, diff.networks)
示例#8
0
    def testDiff(self, netconf_dir):
        configA = Config(netconf_dir)
        configA.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configA.setBonding(BONDING, BONDING_ATTRIBUTES)
        configA.set_device(DEVICE, DEVICE_ATTRIBUTES)

        configB = Config(netconf_dir)
        configB.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, BONDING_ATTRIBUTES)
        configB.set_device(DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        assert diff.networks == {}
        assert diff.bonds == {}
        assert diff.devices == {}

        EVIL_NETWORK = 'jarjar'
        EVIL_BONDING_ATTRIBUTES = {'options': 'mode=3', 'nics': ['eth3']}
        EVIL_DEVICE = 'devdev'
        configB.setNetwork(EVIL_NETWORK, NETWORK_ATTRIBUTES)
        configB.setBonding(BONDING, EVIL_BONDING_ATTRIBUTES)
        configB.set_device(EVIL_DEVICE, DEVICE_ATTRIBUTES)

        diff = configA.diffFrom(configB)
        assert diff.networks[EVIL_NETWORK] == {'remove': True}
        assert diff.bonds[BONDING] == BONDING_ATTRIBUTES
        # Devices diff is not yet supported.
        assert diff.devices == {}

        configB.removeNetwork(NETWORK)
        diff = configA.diffFrom(configB)
        assert NETWORK in diff.networks
示例#9
0
    def testSaveAndDelete(self):
        persistence = Config(self.tempdir)
        persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
        persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)

        net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
        bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
        device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)
        self.assertFalse(os.path.exists(net_path))
        self.assertFalse(os.path.exists(bond_path))
        self.assertFalse(os.path.exists(device_path))

        persistence.save()
        self.assertTrue(os.path.exists(net_path))
        self.assertTrue(os.path.exists(bond_path))
        self.assertTrue(os.path.exists(device_path))

        persistence.delete()
        self.assertFalse(os.path.exists(net_path))
        self.assertFalse(os.path.exists(bond_path))
        self.assertFalse(os.path.exists(device_path))
示例#10
0
    def testSaveAndDelete(self):
        persistence = Config(self.tempdir)
        persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
        persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)

        net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
        bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
        device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)
        self.assertFalse(os.path.exists(net_path))
        self.assertFalse(os.path.exists(bond_path))
        self.assertFalse(os.path.exists(device_path))

        persistence.save()
        self.assertTrue(os.path.exists(net_path))
        self.assertTrue(os.path.exists(bond_path))
        self.assertTrue(os.path.exists(device_path))

        persistence.delete()
        self.assertFalse(os.path.exists(net_path))
        self.assertFalse(os.path.exists(bond_path))
        self.assertFalse(os.path.exists(device_path))
示例#11
0
    def testSaveAndDelete(self, netconf_dir):
        persistence = Config(netconf_dir)
        persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
        persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
        persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)

        net_path = os.path.join(netconf_dir, NETCONF_NETS, NETWORK)
        bond_path = os.path.join(netconf_dir, NETCONF_BONDS, BONDING)
        device_path = os.path.join(netconf_dir, NETCONF_DEVS, DEVICE)
        assert not os.path.exists(net_path)
        assert not os.path.exists(bond_path)
        assert not os.path.exists(device_path)

        persistence.save()
        assert os.path.exists(net_path)
        assert os.path.exists(bond_path)
        assert os.path.exists(device_path)

        persistence.delete()
        assert not os.path.exists(net_path)
        assert not os.path.exists(bond_path)
        assert not os.path.exists(device_path)
示例#12
0
 def testSetAndRemoveNetwork(self):
     persistence = Config(self.tempdir)
     persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
     self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
     persistence.removeNetwork(NETWORK)
     self.assertTrue(persistence.networks.get(NETWORK) is None)
示例#13
0
 def testSetAndRemoveNetwork(self):
     persistence = Config(self.tempdir)
     persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
     self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
     persistence.removeNetwork(NETWORK)
     self.assertTrue(persistence.networks.get(NETWORK) is None)
示例#14
0
 def testSetAndRemoveNetwork(self, netconf_dir):
     persistence = Config(netconf_dir)
     persistence.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
     assert persistence.networks[NETWORK] == NETWORK_ATTRIBUTES
     persistence.removeNetwork(NETWORK)
     assert persistence.networks.get(NETWORK) is None