Ejemplo n.º 1
0
def test_invalid():
    with pytest.raises(InvalidULID):  # invalid length (low-level)
        decode_ulid_base32('What is this')
    with pytest.raises(InvalidULID):  # invalid length (high-level)
        ulid_to_binary('What is this')
    with pytest.raises(InvalidULID):  # invalid characters
        ulid_to_binary('6' + '~' * 25)
    with pytest.raises(InvalidULID):  # invalid type
        ulid_to_binary(8.7)
    with pytest.raises(InvalidULID):  # out of range
        ulid_to_binary('8' + '0' * 25)
    with pytest.raises(InvalidULID):  # out of range
        ulid_to_binary('G' + '0' * 25)
    with pytest.raises(InvalidULID):  # out of range
        ulid_to_binary('R' + '0' * 25)
Ejemplo n.º 2
0
    def put_bootaction_status(self,
                              action_id,
                              action_status=hd_fields.ActionResult.Incomplete):
        """Update the status of a bootaction.

        :param action_id: string ULID ID of the boot action
        :param action_status: The string statu to set for the boot action
        """
        try:
            with self.db_engine.connect() as conn:
                query = self.ba_status_tbl.update().where(
                    self.ba_status_tbl.c.action_id == ulid2.decode_ulid_base32(
                        action_id)).values(action_status=action_status)
                conn.execute(query)
                return True
        except Exception as ex:
            self.logger.error("Error updating boot action %s status." %
                              action_id,
                              exc_info=ex)
            return False
Ejemplo n.º 3
0
    def get_boot_action(self, action_id):
        """Query for a single boot action by ID.

        :param action_id: string ULID bootaction id
        """
        try:
            with self.db_engine.connect() as conn:
                query = self.ba_status_tbl.select().where(
                    self.ba_status_tbl.c.action_id == ulid2.decode_ulid_base32(
                        action_id))
                rs = conn.execute(query)
                r = rs.fetchone()
                if r is not None:
                    ba_dict = dict(r)
                    ba_dict['action_id'] = bytes(ba_dict['action_id'])
                    ba_dict['identity_key'] = bytes(ba_dict['identity_key'])
                    ba_dict['task_id'] = uuid.UUID(bytes=ba_dict['task_id'])
                    return ba_dict
                else:
                    return None
        except Exception as ex:
            self.logger.error("Error querying boot action %s" % action_id,
                              exc_info=ex)