From b5c1d07f975859ef3170d438d0b768a356ad66ea Mon Sep 17 00:00:00 2001 From: mudakavip Date: Tue, 3 Sep 2024 13:52:40 -0500 Subject: [PATCH 1/4] feat: PUC-494 update sync server workflow to return node state --- .gitignore | 1 + .../sync-server-to-ironic.yaml | 40 ++++++++++++------- .../understack_workflows/main/sync_server.py | 7 +++- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index b0ca2cf14..0e462e362 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ venv/ /python/*/dist/ __pycache__ .coverage +.idea # auto-generated argo-workflows docs # see .github/workflows/mkdocs.yaaml diff --git a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml index c7fb110b6..0b8fa4ee3 100644 --- a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml +++ b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml @@ -11,18 +11,28 @@ spec: - name: interface_update_event value: "{}" templates: - - name: sync-server - container: - image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest - command: - - sync-server - args: - - "{{workflow.parameters.interface_update_event}}" - volumeMounts: - - mountPath: /etc/ironic-secrets/ - name: ironic-secrets - readOnly: true - volumes: - - name: ironic-secrets - secret: - secretName: production-ironic-for-argo-creds + - name: main + input: + parameters: + - name: interface_update_event + output: + parameters: + - name: server_state + valueFrom: + expression: "{{ steps.sync-server.outputs.parameters.result }}" + steps: + - - name: sync-server + container: + image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest + command: + - sync-server + args: + - "{{input.parameters.interface_update_event}}" + volumeMounts: + - mountPath: /etc/ironic-secrets/ + name: ironic-secrets + readOnly: true + volumes: + - name: ironic-secrets + secret: + secretName: production-ironic-for-argo-creds diff --git a/python/understack-workflows/understack_workflows/main/sync_server.py b/python/understack-workflows/understack_workflows/main/sync_server.py index f4f261aca..53156b247 100644 --- a/python/understack-workflows/understack_workflows/main/sync_server.py +++ b/python/understack-workflows/understack_workflows/main/sync_server.py @@ -48,7 +48,7 @@ def main(): f"Device {node.uuid} is in a {ironic_node.provision_state} " f"provision_state, so the updates are not allowed." ) - sys.exit(0) + return ironic_node.provision_state drac_ip = update_data["ip_addresses"][0]["host"] expected_address = f"https://{drac_ip}" @@ -77,3 +77,8 @@ def main(): response = client.update_node(node.uuid, patches) logger.info(f"Patching: {patches}") logger.info(f"Updated: {response}") + return ironic_node.provision_state + + +if __name__ == "__main__": + main() From 67cf894eba76fbf1d6eb0a8db79cc0e643a866a5 Mon Sep 17 00:00:00 2001 From: mudakavip Date: Wed, 4 Sep 2024 13:56:11 -0500 Subject: [PATCH 2/4] based on PR feedback --- .../sync-server-to-ironic.yaml | 35 +++++++++---------- .../understack_workflows/main/sync_server.py | 4 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml index 0b8fa4ee3..ef0495c97 100644 --- a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml +++ b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml @@ -12,27 +12,26 @@ spec: value: "{}" templates: - name: main - input: - parameters: - - name: interface_update_event - output: - parameters: - - name: server_state - valueFrom: - expression: "{{ steps.sync-server.outputs.parameters.result }}" steps: - - name: sync-server + input: + parameters: + - name: interface_update_event + output: + parameters: + - name: server_state + value: "{{ steps.sync-server.outputs.parameters.result.server_state }}" container: - image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest - command: - - sync-server - args: - - "{{input.parameters.interface_update_event}}" - volumeMounts: - - mountPath: /etc/ironic-secrets/ - name: ironic-secrets - readOnly: true + image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest + command: + - sync-server + args: + - "{{input.parameters.interface_update_event}}" + volumeMounts: + - mountPath: /etc/ironic-secrets/ + name: ironic-secrets + readOnly: true volumes: - name: ironic-secrets secret: - secretName: production-ironic-for-argo-creds + secretName: production-ironic-for-argo-creds diff --git a/python/understack-workflows/understack_workflows/main/sync_server.py b/python/understack-workflows/understack_workflows/main/sync_server.py index 53156b247..eef6538f1 100644 --- a/python/understack-workflows/understack_workflows/main/sync_server.py +++ b/python/understack-workflows/understack_workflows/main/sync_server.py @@ -48,7 +48,7 @@ def main(): f"Device {node.uuid} is in a {ironic_node.provision_state} " f"provision_state, so the updates are not allowed." ) - return ironic_node.provision_state + sys.exit(0) drac_ip = update_data["ip_addresses"][0]["host"] expected_address = f"https://{drac_ip}" @@ -81,4 +81,4 @@ def main(): if __name__ == "__main__": - main() + sys.stdout.write(main()) From e6f713483c0f972b696f6630a32748839265cfab Mon Sep 17 00:00:00 2001 From: mudakavip Date: Thu, 5 Sep 2024 10:19:12 -0500 Subject: [PATCH 3/4] moving output form script to a txt file and using it --- .../sync-server-to-ironic.yaml | 42 +++++++++---------- .../understack_workflows/main/sync_server.py | 11 ++--- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml index ef0495c97..9d6e6f8fc 100644 --- a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml +++ b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml @@ -12,26 +12,22 @@ spec: value: "{}" templates: - name: main - steps: - - - name: sync-server - input: - parameters: - - name: interface_update_event - output: - parameters: - - name: server_state - value: "{{ steps.sync-server.outputs.parameters.result.server_state }}" - container: - image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest - command: - - sync-server - args: - - "{{input.parameters.interface_update_event}}" - volumeMounts: - - mountPath: /etc/ironic-secrets/ - name: ironic-secrets - readOnly: true - volumes: - - name: ironic-secrets - secret: - secretName: production-ironic-for-argo-creds + outputs: + parameters: + - name: server_state + valueFrom: + path: "/tmp/ironic_state.txt" + container: + image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest + command: + - sync-server + args: + - "{{workflow.parameters.interface_update_event}}" + volumeMounts: + - mountPath: /etc/ironic-secrets/ + name: ironic-secrets + readOnly: true + volumes: + - name: ironic-secrets + secret: + secretName: production-ironic-for-argo-creds diff --git a/python/understack-workflows/understack_workflows/main/sync_server.py b/python/understack-workflows/understack_workflows/main/sync_server.py index eef6538f1..bea09cde2 100644 --- a/python/understack-workflows/understack_workflows/main/sync_server.py +++ b/python/understack-workflows/understack_workflows/main/sync_server.py @@ -12,6 +12,11 @@ logger = setup_logger(__name__) +def write_ironic_state_to_file(state): + with open("/tmp/ironic_state.txt", "w") as f: + f.write(state) + + def main(): if len(sys.argv) < 1: raise ValueError( @@ -77,8 +82,4 @@ def main(): response = client.update_node(node.uuid, patches) logger.info(f"Patching: {patches}") logger.info(f"Updated: {response}") - return ironic_node.provision_state - - -if __name__ == "__main__": - sys.stdout.write(main()) + write_ironic_state_to_file(ironic_node.provision_state) From bb7b1c336ab6c798e6a31fdd1d71a088ff2008ba Mon Sep 17 00:00:00 2001 From: mudakavip Date: Thu, 5 Sep 2024 12:45:44 -0500 Subject: [PATCH 4/4] changing templates name from main to sync-server --- .../workflowtemplates/sync-server-to-ironic.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml index 9d6e6f8fc..27ab7d6f1 100644 --- a/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml +++ b/argo-workflows/sync-nb-server-to-ironic/workflowtemplates/sync-server-to-ironic.yaml @@ -11,7 +11,7 @@ spec: - name: interface_update_event value: "{}" templates: - - name: main + - name: sync-server outputs: parameters: - name: server_state