Пример #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
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))
Пример #4
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))
Пример #5
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))
Пример #6
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)
Пример #7
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))
Пример #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, 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))
Пример #9
0
def config(netconf_dir):
    config = Config(netconf_dir)
    yield config
    config.delete()
    assert not os.path.exists(netconf_dir)