def test_hostonly_link(self):
        """Test a hostonly link."""

        line = "link|vm|_hostonly|rtl8139|00:11:22:33:44:55"
        parser = _configparser.Parser(six.StringIO(line))
        expected = tuple(line.split("|"))
        self.assertEqual(list(parser), [expected])
Example #2
0
 def from_fileobj(cls, fileobj):
     links = []
     sections = {}
     for item in _configparser.Parser(fileobj):
         if isinstance(item, tuple):
             links.append(item)
         else:
             sections[(item.type, item.name)] = dict(item)
     return cls(sections, links)
 def test_sections(self):
     parser = _configparser.Parser(self.fp)
     sections = [
         FakeSection("Project", "/home/user/.virtualbricks.vbl"),
         FakeSection("DiskImage", "vtatpa.qcow2"),
         FakeSection("Qemu", "test1"),
         FakeSection("SwitchWrapper", "sw1"),
     ]
     self.assertEqual([SectionCmp(s) for s in parser if is_section(s)],
                      sections)
    def test_link_ends_with_new_line(self):
        """
        Where links are parsed, a new line character can appears at the end of
        the line.
        """

        line = "link|vm|_hostonly|rtl8139|00:11:22:33:44:55\n"
        parser = _configparser.Parser(six.StringIO(line))
        expected = tuple(line[:-1].split("|"))
        self.assertEqual(list(parser), [expected])
    def test_link_with_minus(self):
        """
        Bricks' name can contains the following characters (in regex notation):
        [\w.-]. Check that the parser parse correctly the links.
        """

        line = "link|vm1-ng|switchwrapper_port|rtl8139|00:aa:1a:a2:b8:ec"
        parser = _configparser.Parser(six.StringIO(line))
        expected = tuple(line.split("|"))
        self.assertEqual(list(parser), [expected])
 def test_switch_wrapper(self):
     parser = _configparser.Parser(self.fp)
     sw = get_section(parser, "SwitchWrapper", "sw1")
     self.assertIsNot(sw, None)
     self.assertEqual(
         dict(sw), {
             "numports": "32",
             "pon_vbevent": "",
             "poff_vbevent": "",
             "path": "/var/run/switch/sck"
         })
Example #7
0
 def test_restore_from(self):
     sio = six.StringIO(DUMP)
     seek_end(sio)
     sio.write("# this is a comment")
     sio.seek(0)
     section = next(iter(_configparser.Parser(sio)))
     self.brick.load_from(section)
     for p, v in (("bool", False), ("float", 0.1), ("int", 43),
                  ("spinint", 31), ("str", "b")):
         self.assertEqual(self.brick.config[p], v)
     cur = sio.tell()
     sio.seek(0, os.SEEK_END)
     self.assertEqual(cur, sio.tell())
 def test_iter(self):
     sio = six.StringIO(CONFIG1)
     parser = _configparser.Parser(sio)
     itr = iter(parser)
     sec1 = next(itr)
     self.assertEqual(sec1.type, "Image")
     self.assertEqual(sec1.name, "martin")
     sec2 = next(itr)
     self.assertEqual(sec2.type, "Qemu")
     self.assertEqual(sec2.name, "sender")
     sec3 = next(itr)
     self.assertEqual(sec3.type, "Wirefilter")
     self.assertEqual(sec3.name, "wf")
     sec4 = next(itr)
     self.assertEqual(sec4.type, "Switch")
     self.assertEqual(sec4.name, "sw1")
     link = next(itr)
     self.assertEqual(
         link,
         ("link", "sender", "sw1_port", "rtl8139", "00:aa:79:71:be:61"))
 def test_disk_image(self):
     parser = _configparser.Parser(self.fp)
     diskimage = get_section(parser, "DiskImage", "vtatpa.qcow2")
     self.assertIsNot(diskimage, None)
     self.assertEqual(dict(diskimage), {"path": self.image})
    def test_name_does_not_start_with_letter(self):
        """Bricks' name must start with a letter."""

        line = "link|1-brick|switchwrapper_port|rtl8139|00:aa:1a:a2:b8:ec"
        parser = _configparser.Parser(six.StringIO(line))
        self.assertEqual(list(parser), [])
Example #11
0
 def restore_from(self, factory, fileobj):
     with freeze_notify(factory):
         for item in _configparser.Parser(fileobj):
             interfaces.IBuilder(item).load_from(factory, item)