def test_link_builder(self): """Create a link from a Link object.""" BRICKNAME = "new_brick" factory = stubs.FactoryStub() brick = factory.new_brick("vm", BRICKNAME) brick.add_sock() self.assertEqual(len(brick.plugs), 0) NICKNAME = "{0}_sock_eth0".format(BRICKNAME) link = configparser.Link("link", BRICKNAME, NICKNAME, "model", "mac") configfile.LinkBuilder().load_from(factory, link) self.assertEqual(len(brick.plugs), 1)
def test_link_builder_brick_not_found(self): """ The sock builder does not find the sock owner, no exception is raised and a warning is emitted. """ BRICKNAME = "new_brick" observer = self._add_observer(configfile.brick_not_found) link = configparser.Link("link", BRICKNAME, "name", "model", "mac") configfile.LinkBuilder().load_from(stubs.FactoryStub(), link) self.assertEqual(len(observer), 1) self.assertEqual(observer[0]["brick"], BRICKNAME)
def test_link_builder_sock_not_found(self): """ The link builder does not find the sock, no exception is raised and a warning is emitted. """ BRICKNAME = "new_brick" SOCKNAME = "nonexistent_sock" factory = stubs.FactoryStub() observer = self._add_observer(configfile.sock_not_found) brick = factory.new_brick("vm", BRICKNAME) self.assertEqual(len(brick.plugs), 0) link = configparser.Link("link", BRICKNAME, SOCKNAME, "model", "mac") configfile.LinkBuilder().load_from(factory, link) self.assertEqual(len(brick.plugs), 0) self.assertEqual(len(observer), 1) self.assertEqual(observer[0]["sockname"], SOCKNAME)