Esempio n. 1
0
    def test_replace_many(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        # Set a leaf, and commit.
        self.conn.set([(self.LEAF1, 111), (self.LEAF2, 222)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.SET, value=111),
            xrm2m.ChangeDetails(
                path=self.LEAF2, op=xrm2m.Change.SET, value=222)
        ])
        self.conn.commit()
        cfg = self.conn.get(self.COMMON_ANCESTOR)
        self.assertEqual(cfg, [(self.LEAF1, 111), (self.LEAF2, 222)])

        # Mark the whole sub-tree for replacement, set a single leaf, then
        # commit.
        self.conn.replace([self.COMMON_ANCESTOR])
        self.conn.set([(self.LEAF2, 333)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.DELETE, value=None),
            xrm2m.ChangeDetails(
                path=self.LEAF2, op=xrm2m.Change.SET, value=333)
        ])
        self.conn.commit()

        cfg = self.conn.get(self.COMMON_ANCESTOR)
        self.assertEqual(cfg, [(self.LEAF2, 333)])
Esempio n. 2
0
    def test_commit_replace(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        # Set a leaf, and commit.
        self.conn.set([(self.LEAF1, 111)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.SET, value=111)
        ])
        self.conn.commit()
        changes = self.conn.get_changes()
        self.assertEqual(changes, [])

        # Set another leaf, commit-replace the changes
        self.conn.set([(self.LEAF2, 222)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF2, op=xrm2m.Change.SET, value=222)
        ])
        self.conn.commit_replace()

        # Check only the second leaf is set.
        self.assertEqual(self.conn.get(self.LEAF1), [])
        self.assertEqual(self.conn.get_value(self.LEAF2), 222)
Esempio n. 3
0
    def test_set_many(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        # Set a leaf, and commit.
        self.conn.set([(self.LEAF1, 111), (self.LEAF2, 222)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.SET, value=111),
            xrm2m.ChangeDetails(
                path=self.LEAF2, op=xrm2m.Change.SET, value=222)
        ])
Esempio n. 4
0
    def test_delete_many(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        # Set a leaf, and commit.
        self.conn.set([(self.LEAF1, 111), (self.LEAF2, 222)])
        self.conn.commit()
        self.assertEqual(self.conn.get_value(self.LEAF1), 111)
        self.assertEqual(self.conn.get_value(self.LEAF2), 222)

        # Delete the leaf, then commit.
        self.conn.delete([self.LEAF1, self.LEAF2])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.DELETE, value=None),
            xrm2m.ChangeDetails(
                path=self.LEAF2, op=xrm2m.Change.DELETE, value=None)
        ])
        self.conn.commit()
Esempio n. 5
0
    def test_discard_changes(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        # Set a leaf, and discard the changes.
        self.conn.set([(self.LEAF1, 111)])
        changes = self.conn.get_changes()
        self.assertEqual(changes, [
            xrm2m.ChangeDetails(
                path=self.LEAF1, op=xrm2m.Change.SET, value=111)
        ])
        self.conn.discard_changes()
        changes = self.conn.get_changes()
        self.assertEqual(changes, [])
Esempio n. 6
0
    def test_single_cli_set(self):
        # Remove all existing config.
        self.conn.discard_changes()
        self.conn.commit_replace()

        self.conn.cli_set("int gig 0/0/0/0 ipv4 addr 10.0.0.1/24")
        path = xrm2m.RootCfg.\
                InterfaceConfiguration(collections.OrderedDict([
                    ("Active", "act"),
                    ("InterfaceName", "GigabitEthernet0/0/0/0")])).\
                IPV4Network.Addresses.Primary
        value = collections.OrderedDict([("Address", "10.0.0.1"),
                                         ("Netmask", "255.255.255.0"),
                                         ("RouteTag", None)])
        changes = self.conn.get_changes()
        self.assertEqual(
            changes,
            [xrm2m.ChangeDetails(path=path, op=xrm2m.Change.SET, value=value)])
        self.conn.discard_changes()