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
parent
88130dd72f
commit
0c2c045fd2
|
@ -609,24 +609,29 @@ async def start_ansible_job():
|
||||||
raise Exception(r.read())
|
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.connect()
|
||||||
await context.amqp.queue_declare(HOST_INFO_QUEUE, durable=True)
|
await context.amqp.queue_declare(HOST_INFO_QUEUE, durable=True)
|
||||||
context.amqp.publish(
|
context.amqp.publish(
|
||||||
exchange='',
|
exchange='',
|
||||||
routing_key=HOST_INFO_QUEUE,
|
routing_key=HOST_INFO_QUEUE,
|
||||||
body=json.dumps(
|
body=json.dumps(data).encode('utf-8'),
|
||||||
{
|
|
||||||
'hostname': hostname,
|
|
||||||
'sshkeys': sshkeys,
|
|
||||||
},
|
|
||||||
).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:
|
try:
|
||||||
await publish_host_info(hostname, sshkeys)
|
await publish_host_info(hostname, sshkeys, branch)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -721,5 +726,9 @@ async def jenkins_notify(request: fastapi.Request) -> None:
|
||||||
status_code=fastapi.status.HTTP_202_ACCEPTED,
|
status_code=fastapi.status.HTTP_202_ACCEPTED,
|
||||||
response_class=fastapi.responses.PlainTextResponse,
|
response_class=fastapi.responses.PlainTextResponse,
|
||||||
)
|
)
|
||||||
async def host_online(hostname: str = Form(), sshkeys: str = Form()) -> None:
|
async def host_online(
|
||||||
asyncio.create_task(handle_host_online(hostname, sshkeys))
|
hostname: str = Form(),
|
||||||
|
sshkeys: str = Form(),
|
||||||
|
branch: Optional[str] = Form(None),
|
||||||
|
) -> None:
|
||||||
|
asyncio.create_task(handle_host_online(hostname, sshkeys, branch))
|
||||||
|
|
Loading…
Reference in New Issue