Ejemplo n.º 1
0
 def test_machine_without_role3(self):
     mds = MachineDiscoveryRepository(sess_maker=self.sess_maker)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = MachineScheduleRepository(sess_maker=self.sess_maker)
     ret = ms.get_roles_by_mac_selector(posts.M01["boot-info"]["mac"])
     self.assertEqual(0, len(ret))
Ejemplo n.º 2
0
 def test_two_machine_discovery(self):
     mds = MachineDiscoveryRepository(sess_maker=self.sess_maker)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = MachineScheduleRepository(sess_maker=self.sess_maker)
     ret = ms.get_available_machines()
     self.assertEqual(2, len(ret))
Ejemplo n.º 3
0
 def test_machine_without_role2(self):
     mds = MachineDiscoveryRepository(sess_maker=self.sess_maker)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = MachineScheduleRepository(sess_maker=self.sess_maker)
     ret = ms.get_all_schedules()
     self.assertEqual(0, len(ret))
Ejemplo n.º 4
0
 def test_machine_without_role4(self):
     mds = MachineDiscoveryRepository(sess_maker=self.sess_maker)
     mds.upsert(posts.M01)
     mds.upsert(posts.M02)
     ms = MachineScheduleRepository(sess_maker=self.sess_maker)
     for role in ScheduleRoles.roles:
         ret = ms.get_role_ip_list(role)
         self.assertEqual(0, len(ret))
Ejemplo n.º 5
0
    def test_no_machine(self):
        mdr = MachineDiscoveryRepository(self.sess_maker)
        mdr.upsert(posts.M01)

        with session_commit(sess_maker=self.sess_maker) 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())
Ejemplo n.º 6
0
    def test_fetch_one_machine(self):
        mdr = MachineDiscoveryRepository(self.sess_maker)
        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"])
Ejemplo n.º 7
0
    def test_no_machine_remove_disks(self):
        mdr = MachineDiscoveryRepository(self.sess_maker)
        mdr.upsert(posts.M01)

        with session_commit(sess_maker=self.sess_maker) 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 session_commit(sess_maker=self.sess_maker) 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())
Ejemplo n.º 8
0
    def test_no_machine_readd_disk_diff(self):
        mdr = MachineDiscoveryRepository(self.sess_maker)
        mdr.upsert(posts.M01)

        with session_commit(sess_maker=self.sess_maker) 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 session_commit(sess_maker=self.sess_maker) 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())
Ejemplo n.º 9
0
 def __init__(self, sess_maker: sessionmaker):
     self.discovery = MachineDiscoveryRepository(sess_maker)
     self.machine_state = MachineStateRepository(sess_maker)
     self.user_interface = UserInterfaceRepository(sess_maker)
     self.machine_schedule = MachineScheduleRepository(sess_maker)
Ejemplo n.º 10
0
 def test_bad_content(self):
     mdr = MachineDiscoveryRepository(self.sess_maker)
     with self.assertRaises(TypeError):
         mdr.upsert(dict())
     with self.assertRaises(TypeError):
         mdr.upsert({"lldp": ""})