Exemplo n.º 1
0
 def test_host_serialization(self):
     host = Host(name="pepito", os="linux")
     host.setDescription("Some description")
     host.setOwned(True)
     hserialized = self.hmapper.serialize(host)
     # if serialization fails, returns None
     self.assertNotEqual(
         hserialized,
         None,
         "Serialized host shouldn't be None")
     # we check the host attributes
     self.assertEquals(
         hserialized.get("_id"),
         host.getID(),
         "Serialized ID is not the same as Host ID")
     self.assertEquals(
         hserialized.get("name"),
         host.getName(),
         "Serialized name is not the same as Host name")
     self.assertEquals(
         hserialized.get("os"),
         host.getOS(),
         "Serialized OS is not the same as Host OS")
     self.assertEquals(
         hserialized.get("description"),
         host.getDescription(),
         "Serialized description is not the same as Host description")
     self.assertEquals(
         hserialized.get("owned"),
         host.isOwned(),
         "Serialized owned flag is not the same as Host owned flag")
Exemplo n.º 2
0
    def test_composite_host(self):
        # add host
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)
        # add inteface
        iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06")
        iface.setDescription("Some description")
        iface.setOwned(True)
        iface.addHostname("www.test.com")
        iface.setIPv4({
            "address": "192.168.10.168",
            "mask": "255.255.255.0",
            "gateway": "192.168.10.1",
            "DNS": "192.168.10.1"
        })
        iface.setPortsOpened(2)
        iface.setPortsClosed(3)
        iface.setPortsFiltered(4)
        host.addChild(iface)
        self.mapper_manager.save(iface)

        h = self.mapper_manager.find(host.getID())
        self.assertEquals(
            len(h.getAllInterfaces()), len(host.getAllInterfaces()),
            "Interfaces from original host should be equals to retrieved host's interfaces"
        )

        i = self.mapper_manager.find(h.getAllInterfaces()[0].getID())
        self.assertEquals(
            i.getID(), iface.getID(),
            "Interface's id' from original host should be equals to retrieved host's interface's id"
        )
Exemplo n.º 3
0
    def test_find_not_loaded_host(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        #create a set of mappers, so we have a clean map
        self.mapper_manager = MapperManager()
        self.mapper_manager.createMappers(self.connector)

        h = self.mapper_manager.find(host.getID())
        self.assertNotEquals(
            h,
            None,
            "Existent host shouldn't return None")

        self.assertEquals(
            h.getName(),
            "pepito",
            "Host name should be pepito")

        self.assertEquals(
            h.getOS(),
            "linux",
            "Host os should be linux")
Exemplo n.º 4
0
    def test_composite_host(self):
        # add host
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)
        # add inteface
        iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06")
        iface.setDescription("Some description")
        iface.setOwned(True)
        iface.addHostname("www.test.com")
        iface.setIPv4({
            "address": "192.168.10.168",
            "mask": "255.255.255.0",
            "gateway": "192.168.10.1",
            "DNS": "192.168.10.1"
        })
        iface.setPortsOpened(2)
        iface.setPortsClosed(3)
        iface.setPortsFiltered(4)
        host.addChild(iface)
        self.mapper_manager.save(iface)

        h = self.mapper_manager.find(host.getID())
        self.assertEquals(
            len(h.getAllInterfaces()),
            len(host.getAllInterfaces()),
            "Interfaces from original host should be equals to retrieved host's interfaces")

        i = self.mapper_manager.find(h.getAllInterfaces()[0].getID())
        self.assertEquals(
            i.getID(),
            iface.getID(),
            "Interface's id' from original host should be equals to retrieved host's interface's id")
Exemplo n.º 5
0
    def test_host_saving(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        self.assertNotEquals(self.connector.getDocument(host.getID()), None,
                             "Document shouldn't be None")

        self.assertEquals(
            self.connector.getDocument(host.getID()).get("name"),
            host.getName(), "Document should have the same host name")
Exemplo n.º 6
0
    def test_create_and_retrieve_host(self):
        self.mapper_manager.createMappers(NullPersistenceManager())
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        h = self.mapper_manager.find(host.getID())

        self.assertNotEquals(h, None, "Host retrieved shouldn't be None")

        self.assertEquals(host, h,
                          "Host created should be the same as host retrieved")
Exemplo n.º 7
0
    def test_host_saving(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        self.assertNotEquals(
            self.connector.getDocument(host.getID()),
            None,
            "Document shouldn't be None")

        self.assertEquals(
            self.connector.getDocument(host.getID()).get("name"),
            host.getName(),
            "Document should have the same host name")
Exemplo n.º 8
0
    def test_find_not_loaded_host(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        #create a set of mappers, so we have a clean map
        self.mapper_manager = MapperManager()
        self.mapper_manager.createMappers(self.connector)

        h = self.mapper_manager.find(host.getID())
        self.assertNotEquals(h, None, "Existent host shouldn't return None")

        self.assertEquals(h.getName(), "pepito", "Host name should be pepito")

        self.assertEquals(h.getOS(), "linux", "Host os should be linux")
Exemplo n.º 9
0
    def test_create_and_retrieve_host(self):
        self.mapper_manager.createMappers(NullPersistenceManager())
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        h = self.mapper_manager.find(host.getID())

        self.assertNotEquals(
            h,
            None,
            "Host retrieved shouldn't be None")

        self.assertEquals(
            host,
            h,
            "Host created should be the same as host retrieved")
Exemplo n.º 10
0
 def create_host(self):
     host = Host(name="pepito", os="linux")
     host.setDescription("Some description")
     host.setOwned(True)
     return host
Exemplo n.º 11
0
 def create_host(self):
     host = Host(name="pepito", os="linux")
     host.setDescription("Some description")
     host.setOwned(True)
     return host