1
0
Fork 0

host-online: Accept cfgpol branch in form data

In order to support testing new policy on a development branch, the
_POST /host/online_ hook now accepts an optional `branch` parameter.
The value of this parameter is passed to the host provisioner via the
host info message published on the message queue.  In this way, new
machines can request a specific branch of the policy, providing a
method for automated testing prior to merging the branch in to the
main development line.

How hosts themselves know what branch to request is of course another
matter, and will depend on how they are provisioned, whether they are
physical or virtual, etc.
master
Dustin 2025-02-07 19:12:20 -06:00
parent 88130dd72f
commit 0c2c045fd2
1 changed files with 20 additions and 11 deletions

View File

@ -609,24 +609,29 @@ async def start_ansible_job():
raise Exception(r.read())
async def publish_host_info(hostname: str, sshkeys: str):
async def publish_host_info(
hostname: str, sshkeys: str, branch: Optional[str]
):
data = {
'hostname': hostname,
'sshkeys': sshkeys,
}
if branch:
data['branch'] = branch
await context.amqp.connect()
await context.amqp.queue_declare(HOST_INFO_QUEUE, durable=True)
context.amqp.publish(
exchange='',
routing_key=HOST_INFO_QUEUE,
body=json.dumps(
{
'hostname': hostname,
'sshkeys': sshkeys,
},
).encode('utf-8'),
body=json.dumps(data).encode('utf-8'),
)
async def handle_host_online(hostname: str, sshkeys: str):
async def handle_host_online(
hostname: str, sshkeys: str, branch: Optional[str]
):
try:
await publish_host_info(hostname, sshkeys)
await publish_host_info(hostname, sshkeys, branch)
except asyncio.CancelledError:
raise
except Exception:
@ -721,5 +726,9 @@ async def jenkins_notify(request: fastapi.Request) -> None:
status_code=fastapi.status.HTTP_202_ACCEPTED,
response_class=fastapi.responses.PlainTextResponse,
)
async def host_online(hostname: str = Form(), sshkeys: str = Form()) -> None:
asyncio.create_task(handle_host_online(hostname, sshkeys))
async def host_online(
hostname: str = Form(),
sshkeys: str = Form(),
branch: Optional[str] = Form(None),
) -> None:
asyncio.create_task(handle_host_online(hostname, sshkeys, branch))