def test_machine_without_role3(self):
     mds = DiscoveryRepository(self.smart)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = ScheduleRepository(self.smart)
     ret = ms.get_roles_by_mac_selector(posts.M01["boot-info"]["mac"])
     self.assertEqual(0, len(ret))
 def test_machine_without_role2(self):
     mds = DiscoveryRepository(self.smart)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = ScheduleRepository(self.smart)
     ret = ms.get_all_schedules()
     self.assertEqual(0, len(ret))
 def test_two_machine_discovery(self):
     mds = DiscoveryRepository(self.smart)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = ScheduleRepository(self.smart)
     ret = ms.get_available_machines()
     self.assertEqual(2, len(ret))
 def test_machine_without_role4(self):
     mds = DiscoveryRepository(self.smart)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = ScheduleRepository(self.smart)
     for role in model.ScheduleRoles.roles:
         ret = ms.get_role_ip_list(role)
         self.assertEqual(0, len(ret))
示例#5
0
    def test_no_machine(self):
        mdr = DiscoveryRepository(self.smart)
        mdr.upsert(posts.M01)

        with self.smart.new_session() as session:
            self.assertEqual(1, session.query(Machine).count())
            self.assertEqual(1, session.query(MachineInterface).count())
            self.assertEqual(1, session.query(MachineDisk).count())
            self.assertEqual(1, session.query(Chassis).count())
            self.assertEqual(1, session.query(ChassisPort).count())
示例#6
0
    def test_fetch_one_machine(self):
        mdr = DiscoveryRepository(self.smart)
        mdr.upsert(posts.M01)

        disco = mdr.fetch_all_discovery()
        self.assertEqual(1, len(disco))
        self.assertEqual(posts.M01["boot-info"]["mac"], disco[0]["boot-info"]["mac"])
        self.assertEqual(posts.M01["boot-info"]["uuid"], disco[0]["boot-info"]["uuid"])
        self.assertEqual(posts.M01["disks"], disco[0]["disks"])
        self.assertEqual(1, len(disco[0]["interfaces"]))
        self.assertEqual(posts.M01["boot-info"]["mac"], disco[0]["interfaces"][0]["mac"])
        self.assertTrue(disco[0]["interfaces"][0]["as_boot"])
示例#7
0
    def test_no_machine_remove_disks(self):
        mdr = DiscoveryRepository(self.smart)
        mdr.upsert(posts.M01)

        with self.smart.new_session() as session:
            self.assertEqual(1, session.query(Machine).count())
            self.assertEqual(1, session.query(MachineInterface).count())
            self.assertEqual(1, session.query(MachineDisk).count())
            self.assertEqual(1, session.query(Chassis).count())
            self.assertEqual(1, session.query(ChassisPort).count())

        without_disks = copy.deepcopy(posts.M01)
        without_disks["disks"] = None
        mdr.upsert(without_disks)

        with self.smart.new_session() as session:
            self.assertEqual(1, session.query(Machine).count())
            self.assertEqual(1, session.query(MachineInterface).count())
            self.assertEqual(0, session.query(MachineDisk).count())
            self.assertEqual(1, session.query(Chassis).count())
            self.assertEqual(1, session.query(ChassisPort).count())
示例#8
0
    def test_no_machine_readd_disk_diff(self):
        mdr = DiscoveryRepository(self.smart)
        mdr.upsert(posts.M01)

        with self.smart.new_session() as session:
            self.assertEqual(1, session.query(Machine).count())
            self.assertEqual(1, session.query(MachineInterface).count())
            self.assertEqual(1, session.query(MachineDisk).count())
            self.assertEqual(1, session.query(Chassis).count())
            self.assertEqual(1, session.query(ChassisPort).count())

        with_new_disk = copy.deepcopy(posts.M01)
        with_new_disk["disks"].append({'size-bytes': 21474836481, 'path': '/dev/sdb'})
        mdr.upsert(with_new_disk)

        with self.smart.new_session() as session:
            self.assertEqual(1, session.query(Machine).count())
            self.assertEqual(1, session.query(MachineInterface).count())
            self.assertEqual(2, session.query(MachineDisk).count())
            self.assertEqual(1, session.query(Chassis).count())
            self.assertEqual(1, session.query(ChassisPort).count())
示例#9
0
 def test_bad_content(self):
     mdr = DiscoveryRepository(self.smart)
     with self.assertRaises(TypeError):
         mdr.upsert(dict())
     with self.assertRaises(TypeError):
         mdr.upsert({"lldp": ""})
示例#10
0
 def __init__(self, smart: SmartDatabaseClient):
     self.discovery = DiscoveryRepository(smart)
     self.machine_state = MachineStateRepository(smart)
     self.user_interface = UserInterfaceRepository(smart)
     self.machine_schedule = ScheduleRepository(smart)