Ejemplo n.º 1
0
 def test06Defnode(self):
     "test defnode"
     a = augeas.Augeas(root=MYROOT)
     a.defnode("bighost", "/files/etc/hosts/50/ipaddr", "192.168.1.1")
     value = a.get("$bighost")
     self.assertEqual(value, "192.168.1.1")
     del a
Ejemplo n.º 2
0
 def test07Setm(self):
     "test setm"
     a = augeas.Augeas(root=MYROOT)
     matches = a.match("/files/etc/hosts/*/ipaddr")
     self.failUnless(matches)
     a.setm("/files/etc/hosts", "*/ipaddr", "192.168.1.1")
     for i in matches:
         self.assertEqual(a.get(i), "192.168.1.1")
     del a
Ejemplo n.º 3
0
 def test02Match(self):
     "test aug_match"
     a = augeas.Augeas(root=MYROOT)
     matches = a.match("/files/etc/hosts/*")
     self.failUnless(matches)
     for i in matches:
         for attr in a.match(i + "/*"):
             self.failUnless(a.get(attr) is not None)
     del a
Ejemplo n.º 4
0
 def test05Defvar(self):
     "test defvar"
     a = augeas.Augeas(root=MYROOT)
     a.defvar("hosts", "/files/etc/hosts")
     matches = a.match("$hosts/*")
     self.failUnless(matches)
     for i in matches:
         for attr in a.match(i + "/*"):
             self.failUnless(a.get(attr) is not None)
     del a
Ejemplo n.º 5
0
 def test03PrintAll(self):
     "print all tree elements"
     output = open("test03PrintAll.out", "w")
     a = augeas.Augeas(root=MYROOT)
     path = "/"
     matches = recurmatch(a, path)
     for (p, attr) in matches:
         print(p, attr, file=output)
         self.failUnless(p is not None and attr is not None)
     output.close()
Ejemplo n.º 6
0
    def test13AddTransform(self):
        a = augeas.Augeas(root=MYROOT)

        r = a.add_transform("Foo", "/tmp/bar")
        incl = a.get("/augeas/load/Foo/incl")
        self.assertEqual(incl, "/tmp/bar")

        r = a.add_transform("Foo", "/tmp/bar", "Faz", "/tmp/baz")
        excl = a.get("/augeas/load/Foo/excl")
        self.assertEqual(excl, "/tmp/baz")
Ejemplo n.º 7
0
    def test12Transform(self):
        a = augeas.Augeas(root=MYROOT)

        r = a.transform("Foo", "/tmp/bar")
        lens = a.get("/augeas/load/Foo/lens")
        self.assertEqual(lens, "Foo.lns")
        incl = a.get("/augeas/load/Foo/incl")
        self.assertEqual(incl, "/tmp/bar")

        r = a.transform("Foo", "/tmp/baz", True)
        excl = a.get("/augeas/load/Foo/excl")
        self.assertEqual(excl, "/tmp/baz")
Ejemplo n.º 8
0
    def test09TextStore(self):
        hosts = "192.168.0.1 rtr.example.com router\n"
        a = augeas.Augeas(root=MYROOT)
        r = a.set("/raw/hosts", hosts)
        r = a.text_store("Hosts.lns", "/raw/hosts", "/t1")

        # Test bad lens name
        try:
            r = a.text_store("Notthere.lns", "/raw/hosts", "/t2")
        except ValueError as e:
            error = e
        self.assertTrue(isinstance(error, ValueError))
Ejemplo n.º 9
0
 def test11Rename(self):
     a = augeas.Augeas(root=MYROOT)
     r = a.set("/a/b/c", "value")
     r = a.rename("/a/b/c", "d")
     self.assertEqual(r, 1)
     r = a.set("/a/e/d", "value2")
     r = a.rename("/a//d", "x")
     self.assertEqual(r, 2)
     try:
         r = a.rename("/a/e/x", "a/b")
     except ValueError as e:
         error = e
     self.assertTrue(isinstance(error, ValueError))
Ejemplo n.º 10
0
 def test04Grub(self):
     "test default setting of grub entry"
     a = augeas.Augeas(root=MYROOT)
     num = 0
     for entry in a.match("/files/etc/grub.conf/title"):
         num += 1
     self.assertEqual(num, 2)
     default = int(a.get("/files/etc/grub.conf/default"))
     self.assertEqual(default, 0)
     a.set("/files/etc/grub.conf/default", str(1))
     a.save()
     default = int(a.get("/files/etc/grub.conf/default"))
     self.assertEqual(default, 1)
     a.set("/files/etc/grub.conf/default", str(0))
     a.save()
Ejemplo n.º 11
0
 def test01Get(self):
     "test aug_get"
     a = augeas.Augeas(root=MYROOT)
     self.failUnless(a.get("/wrong/path") is None)
     del a
Ejemplo n.º 12
0
    def test14Label(self):
        a = augeas.Augeas(root=MYROOT)

        lbl = a.label("/augeas/version")
        self.assertEqual(lbl, "version")
Ejemplo n.º 13
0
    def test08Span(self):
        "test span"
        data = [
            {
                "expr": "/files/etc/hosts/1/ipaddr",
                "f": "hosts",
                "ls": 0,
                "le": 0,
                "vs": 104,
                "ve": 113,
                "ss": 104,
                "se": 113
            },
            {
                "expr": "/files/etc/hosts/1",
                "f": "hosts",
                "ls": 0,
                "le": 0,
                "vs": 0,
                "ve": 0,
                "ss": 104,
                "se": 155
            },
            {
                "expr": "/files/etc/hosts/*[last()]",
                "f": "hosts",
                "ls": 0,
                "le": 0,
                "vs": 0,
                "ve": 0,
                "ss": 155,
                "se": 202
            },
            {
                "expr": "/files/etc/hosts/#comment[2]",
                "f": "hosts",
                "ls": 0,
                "le": 0,
                "vs": 58,
                "ve": 103,
                "ss": 56,
                "se": 104
            },
            {
                "expr": "/files/etc/hosts",
                "f": "hosts",
                "ls": 0,
                "le": 0,
                "vs": 0,
                "ve": 0,
                "ss": 0,
                "se": 202
            },
        ]
        a = augeas.Augeas(root=MYROOT, flags=augeas.Augeas.ENABLE_SPAN)
        for d in data:
            r = a.span(d["expr"])
            self.assertEquals(os.path.basename(r[0]), d["f"])
            self.assertEquals(r[1], d["ls"])
            self.assertEquals(r[2], d["le"])
            self.assertEquals(r[3], d["vs"])
            self.assertEquals(r[4], d["ve"])
            self.assertEquals(r[5], d["ss"])
            self.assertEquals(r[6], d["se"])

        error = None
        try:
            r = a.span("/files")
        except ValueError as e:
            error = e
        self.assertTrue(isinstance(error, ValueError))

        error = None
        try:
            r = a.span("/random")
        except ValueError as e:
            error = e
        self.assertTrue(isinstance(error, ValueError))

        del a
Ejemplo n.º 14
0
 def __init__(self):
     # FIXME: avoid to cause exceptions when generating documents
     import opslib.icsutils.augeas as augeas
     self.aug = augeas.Augeas()