Example #1
0
class TransactionTests(TestCaseBase):
    def setUp(self):
        self.tempdir = _create_netconf()
        self.config = Config(self.tempdir)

    def tearDown(self):
        self.config.delete()
        self.assertFalse(os.path.exists(self.tempdir))

    def test_successful_setup(self):
        with Transaction(config=self.config) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)

        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertTrue(os.path.exists(file_path))

    def test_successful_non_persistent_setup(self):
        with Transaction(config=self.config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)

        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))

    def test_failed_setup(self):
        with self.assertRaises(ne.RollbackIncomplete) as roi:
            with Transaction(config=self.config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                raise TestException()

        diff, ex_type, _ = roi.exception.args
        self.assertEqual(diff.networks[NETWORK], {'remove': True})
        self.assertEqual(ex_type, TestException)
        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))

    def test_failed_setup_with_no_diff(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config):
                raise TestException()

    def test_failed_setup_in_rollback(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                raise TestException()

        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))
Example #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))
Example #3
0
    def testInit(self):
        filePath = os.path.join(self.tempdir, 'nets', NETWORK)
        try:
            with open(filePath, 'w') as networkFile:
                json.dump(NETWORK_ATTRIBUTES, networkFile)

            persistence = Config(self.tempdir)
            self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
        finally:
            rmFile(filePath)
Example #4
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))
Example #5
0
    def testInit(self):
        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)
        with open(net_path, 'w') as f:
            json.dump(NETWORK_ATTRIBUTES, f)
        with open(bond_path, 'w') as f:
            json.dump(BONDING_ATTRIBUTES, f)
        with open(device_path, 'w') as f:
            json.dump(DEVICE_ATTRIBUTES, f)

        persistence = Config(self.tempdir)
        self.assertEqual(persistence.networks[NETWORK], NETWORK_ATTRIBUTES)
        self.assertEqual(persistence.bonds[BONDING], BONDING_ATTRIBUTES)
        self.assertEqual(persistence.devices[DEVICE], DEVICE_ATTRIBUTES)
Example #6
0
    def testInit(self, netconf_dir):
        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)
        with open(net_path, 'w') as f:
            json.dump(NETWORK_ATTRIBUTES, f)
        with open(bond_path, 'w') as f:
            json.dump(BONDING_ATTRIBUTES, f)
        with open(device_path, 'w') as f:
            json.dump(DEVICE_ATTRIBUTES, f)

        persistence = Config(netconf_dir)
        assert persistence.networks[NETWORK] == NETWORK_ATTRIBUTES
        assert persistence.bonds[BONDING] == BONDING_ATTRIBUTES
        assert persistence.devices[DEVICE] == DEVICE_ATTRIBUTES
Example #7
0
 def setUp(self):
     self.tempdir = _create_netconf()
     self.config = Config(self.tempdir)
     self.net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
     self.bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
     self.device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)
Example #8
0
class TransactionTests(TestCaseBase):
    def setUp(self):
        self.tempdir = _create_netconf()
        self.config = Config(self.tempdir)
        self.net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
        self.bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
        self.device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)

    def tearDown(self):
        self.config.delete()
        self.assertFalse(os.path.exists(self.tempdir))

    def test_successful_setup(self):
        with Transaction(config=self.config) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

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

    def test_successful_non_persistent_setup(self):
        with Transaction(config=self.config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))

    def test_failed_setup(self):
        with self.assertRaises(ne.RollbackIncomplete) as roi:
            with Transaction(config=self.config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        diff = roi.exception.diff
        self.assertEqual(diff.networks[NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], {'remove': True})
        self.assertEqual(diff.devices, {})
        self.assertEqual(roi.exception.exc_type, TestException)
        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))

    def test_failed_setup_with_no_diff(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config):
                raise TestException()

    def test_failed_setup_in_rollback(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))
Example #9
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)
Example #10
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)
Example #11
0
 def testSetAndRemoveBonding(self):
     persistence = Config(self.tempdir)
     persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
     self.assertEqual(persistence.bonds[BONDING], BONDING_ATTRIBUTES)
     persistence.removeBonding(BONDING)
     self.assertTrue(persistence.bonds.get(BONDING) is None)
Example #12
0
class TransactionTests(TestCaseBase):
    def setUp(self):
        self.tempdir = _create_netconf()
        self.config = Config(self.tempdir)
        self.net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
        self.bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
        self.device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)

    def tearDown(self):
        self.config.delete()
        self.assertFalse(os.path.exists(self.tempdir))

    def test_successful_setup(self):
        with Transaction(config=self.config) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

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

    def test_successful_non_persistent_setup(self):
        with Transaction(config=self.config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))

    def test_failed_setup(self):
        with self.assertRaises(ne.RollbackIncomplete) as roi:
            with Transaction(config=self.config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        diff, ex_type, _ = roi.exception.args
        self.assertEqual(diff.networks[NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], {'remove': True})
        self.assertEqual(diff.devices, {})
        self.assertEqual(ex_type, TestException)
        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))

    def test_failed_setup_with_no_diff(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config):
                raise TestException()

    def test_failed_setup_in_rollback(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))
Example #13
0
 def setUp(self):
     self.tempdir = _create_netconf()
     self.config = Config(self.tempdir)
     self.net_path = os.path.join(self.tempdir, NETCONF_NETS, NETWORK)
     self.bond_path = os.path.join(self.tempdir, NETCONF_BONDS, BONDING)
     self.device_path = os.path.join(self.tempdir, NETCONF_DEVS, DEVICE)
Example #14
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))
Example #15
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)
Example #16
0
 def testSetAndRemoveDevice(self):
     persistence = Config(self.tempdir)
     persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)
     self.assertEqual(persistence.devices[DEVICE], DEVICE_ATTRIBUTES)
     persistence.remove_device(DEVICE)
     self.assertTrue(persistence.devices.get(DEVICE) is None)
Example #17
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
Example #18
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
Example #19
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)
Example #20
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)
Example #21
0
 def setUp(self):
     self.tempdir = _create_netconf()
     self.config = Config(self.tempdir)
Example #22
0
 def testSetAndRemoveBonding(self):
     persistence = Config(self.tempdir)
     persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
     self.assertEqual(persistence.bonds[BONDING], BONDING_ATTRIBUTES)
     persistence.removeBonding(BONDING)
     self.assertTrue(persistence.bonds.get(BONDING) is None)
Example #23
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)
Example #24
0
 def testSetAndRemoveDevice(self, netconf_dir):
     persistence = Config(netconf_dir)
     persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)
     assert persistence.devices[DEVICE] == DEVICE_ATTRIBUTES
     persistence.remove_device(DEVICE)
     assert persistence.devices.get(DEVICE) is None
Example #25
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)
Example #26
0
def config(netconf_dir):
    config = Config(netconf_dir)
    yield config
    config.delete()
    assert not os.path.exists(netconf_dir)
Example #27
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)
Example #28
0
 def testSetAndRemoveDevice(self):
     persistence = Config(self.tempdir)
     persistence.set_device(DEVICE, DEVICE_ATTRIBUTES)
     self.assertEqual(persistence.devices[DEVICE], DEVICE_ATTRIBUTES)
     persistence.remove_device(DEVICE)
     self.assertTrue(persistence.devices.get(DEVICE) is None)
Example #29
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))
Example #30
0
 def testSetAndRemoveBonding(self, netconf_dir):
     persistence = Config(netconf_dir)
     persistence.setBonding(BONDING, BONDING_ATTRIBUTES)
     assert persistence.bonds[BONDING] == BONDING_ATTRIBUTES
     persistence.removeBonding(BONDING)
     assert persistence.bonds.get(BONDING) is None