diff --git a/instances/jobs.py b/instances/jobs.py index b654d267..76c5b320 100644 --- a/instances/jobs.py +++ b/instances/jobs.py @@ -738,7 +738,8 @@ class CreateInstance(Kind): def normalize(self, raw): # what the API leaves out means what create_instance did by default params = {"template": "", "images": "", "firmware": "", "net_model": "virtio", "add_cdrom": "sata", - "add_input": "default", "meta_prealloc": False, "hdd_size": 0, "cloud_init": False, "tpm": False} + "add_input": "default", "meta_prealloc": False, "hdd_size": 0, "cloud_init": False, "tpm": False, + "mac": "", "nwfilter": ""} params.update({k: v for k, v in raw.items() if k not in ("submission_key", "create", "csrfmiddlewaretoken")}) params.update(compute=int(raw["compute"]), devices=[list(d) for d in raw.get("devices", [])]) if params["firmware"] == "UEFI Secure Boot" and "q35" not in params["machine"]: diff --git a/instances/tests/test_create_job.py b/instances/tests/test_create_job.py index 46d7ebea..1b44dd5f 100644 --- a/instances/tests/test_create_job.py +++ b/instances/tests/test_create_job.py @@ -131,3 +131,15 @@ class CreateJobTestCase(TransactionTestCase): op.user.save() with self.assertRaises(PermissionDenied): CreateInstance().precheck(op, None) + + def test_the_api_takes_a_body_without_a_mac_or_a_network_filter(self): + body = {k: v for k, v in BODY.items() if k not in ("mac", "nwfilter")} + response = self.client.post(f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/", body, + content_type="application/json") + self.assertEqual(response.status_code, 202) + op = Operation.objects.get() + acquire("wvc-test:1:a", "wvc-test") + Operation.objects.filter(pk=op.pk).update(state=Operation.RUNNING, worker="wvc-test:1:a") + op.refresh_from_db() + CreateInstance().run(op, Context(op, SimpleNamespace(identity="wvc-test:1:a"))) + self.assertEqual(self.conn.create_instance.call_args.kwargs["nwfilter"], "")