Пример #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))
Пример #2
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))
Пример #3
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))
Пример #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))
Пример #5
0
    def test_one_machine_boot_interface_is_not_first(self):
        mac = "aa:bb:cc:dd:ee:0{}"
        with session_commit(sess_maker=self.sess_maker) as session:
            uuid = "b7f5f93a-b029-475f-b3a4-479ba198cb8a"
            machine = Machine(uuid=uuid)
            session.add(machine)
            session.flush()

            # add 3 non-boot interfaces
            for i in range(3):
                session.add(
                    MachineInterface(machine_id=machine.id,
                                     mac=mac.format(i),
                                     netmask=1,
                                     ipv4="10.10.10.10",
                                     cidrv4="127.0.0.1/8",
                                     as_boot=False,
                                     gateway="1.1.1.1",
                                     name="foo"))

            # and a 4th one, with as_boot = True
            session.add(
                MachineInterface(machine_id=machine.id,
                                 mac=mac.format(3),
                                 netmask=1,
                                 ipv4="10.10.10.10",
                                 cidrv4="127.0.0.1/8",
                                 as_boot=True,
                                 gateway="1.1.1.1",
                                 name="foo"))
            session.commit()

        ms = MachineScheduleRepository(sess_maker=self.sess_maker)
        data = {
            "roles": ["kubernetes-control-plane", "etcd-member"],
            "selector": {
                "mac": mac.format(0)
            }
        }
        # schedule using the first but non-boot interface
        ms.create_schedule(data)

        s = ms.get_all_schedules()
        self.assertEqual(len(s), 1)

        # verify the scheduled machine is indexed by its boot-interface, the 3rd one in this case
        self.assertIn(mac.format(3), s)
Пример #6
0
    def test_one_machine(self):
        mac = "00:00:00:00:00:00"
        with session_commit(sess_maker=self.sess_maker) as session:
            uuid = "b7f5f93a-b029-475f-b3a4-479ba198cb8a"
            machine = Machine(uuid=uuid)
            session.add(machine)
            machine_id = session.query(Machine).filter(
                Machine.uuid == uuid).first().id
            session.add(
                MachineInterface(machine_id=machine_id,
                                 mac=mac,
                                 netmask=1,
                                 ipv4="10.10.10.10",
                                 cidrv4="127.0.0.1/8",
                                 as_boot=True,
                                 gateway="1.1.1.1",
                                 name="lol"))
            session.commit()

        ms = MachineScheduleRepository(sess_maker=self.sess_maker)
        ret = ms.get_available_machines()
        self.assertEqual(1, len(ret))
Пример #7
0
    def test_one_machine_scheduled_cp(self):
        mac = "00:00:00:00:00:00"
        with session_commit(sess_maker=self.sess_maker) as session:
            uuid = "b7f5f93a-b029-475f-b3a4-479ba198cb8a"
            machine = Machine(uuid=uuid)
            session.add(machine)
            machine_id = session.query(Machine).filter(
                Machine.uuid == uuid).first().id
            session.add(
                MachineInterface(machine_id=machine_id,
                                 mac=mac,
                                 netmask=1,
                                 ipv4="10.10.10.10",
                                 cidrv4="127.0.0.1/8",
                                 as_boot=True,
                                 gateway="1.1.1.1",
                                 name="lol"))
            session.add(
                Schedule(machine_id=machine_id,
                         role=ScheduleRoles.etcd_member))
            session.add(
                Schedule(machine_id=machine_id,
                         role=ScheduleRoles.kubernetes_control_plane))
            session.commit()

        ms = MachineScheduleRepository(sess_maker=self.sess_maker)
        ret = ms.get_available_machines()
        self.assertEqual(0, len(ret))

        ret = ms.get_roles_by_mac_selector(mac)
        self.assertEqual([
            ScheduleRoles.etcd_member, ScheduleRoles.kubernetes_control_plane
        ], ret)

        ret = ms.get_machines_by_roles(ScheduleRoles.etcd_member,
                                       ScheduleRoles.kubernetes_control_plane)
        self.assertEqual(1, len(ret))

        ret = ms.get_machines_by_roles(ScheduleRoles.kubernetes_node)
        self.assertEqual(0, len(ret))

        ret = ms.get_machines_by_roles(ScheduleRoles.etcd_member)
        self.assertEqual(1, len(ret))

        ret = ms.get_machines_by_roles(ScheduleRoles.kubernetes_control_plane)
        self.assertEqual(1, len(ret))
Пример #8
0
    def test_one_machine_to_schedule(self):
        mac = "00:00:00:00:00:00"
        with session_commit(sess_maker=self.sess_maker) as session:
            uuid = "b7f5f93a-b029-475f-b3a4-479ba198cb8a"
            machine = Machine(uuid=uuid)
            session.add(machine)
            machine_id = session.query(Machine).filter(
                Machine.uuid == uuid).first().id
            session.add(
                MachineInterface(machine_id=machine_id,
                                 mac=mac,
                                 netmask=1,
                                 ipv4="10.10.10.10",
                                 cidrv4="127.0.0.1/8",
                                 as_boot=True,
                                 gateway="1.1.1.1",
                                 name="lol"))

            session.commit()

        ms = MachineScheduleRepository(sess_maker=self.sess_maker)
        data = {
            "roles": ["kubernetes-control-plane", "etcd-member"],
            "selector": {
                "mac": mac
            }
        }
        s = ms.get_all_schedules()
        self.assertEqual(0, len(s))

        ms.create_schedule(data)
        ms.create_schedule(data)
        s = ms.get_all_schedules()
        self.assertEqual(1, len(s))

        s = ms.get_machines_by_roles(
            *["kubernetes-control-plane", "etcd-member"])
        self.assertEqual(1, len(s))

        s = ms.get_machines_by_roles("kubernetes-control-plane")
        self.assertEqual(1, len(s))
Пример #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)