From fe015b6c53ce0aeecca60f43732cd78edea0d261 Mon Sep 17 00:00:00 2001 From: Terje Kvernes Date: Tue, 20 Feb 2024 16:26:09 +0100 Subject: [PATCH] Improve error messages. --- ci/testsuite-result.json | 184 +++++++++++----------- mreg_cli/commands/host_submodules/core.py | 16 +- 2 files changed, 106 insertions(+), 94 deletions(-) diff --git a/ci/testsuite-result.json b/ci/testsuite-result.json index 5bb4b167..0afd3844 100644 --- a/ci/testsuite-result.json +++ b/ci/testsuite-result.json @@ -10423,10 +10423,10 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:12:59 [system-signals]: Txt create: txt = 'v=spf1 -all'", - "2024-02-20 16:13:00 [test]: Host create: name = 'somehost.example.org', contact = 'support@example.org'", - "2024-02-20 16:13:00 [test]: Ipaddress create: ipaddress = '10.0.1.4'", - "2024-02-20 16:13:00 [test]: Host update: contact: support@example.org -> new-support@example.org" + "2024-02-20 16:24:08 [system-signals]: Txt create: txt = 'v=spf1 -all'", + "2024-02-20 16:24:08 [test]: Host create: name = 'somehost.example.org', contact = 'support@example.org'", + "2024-02-20 16:24:08 [test]: Ipaddress create: ipaddress = '10.0.1.4'", + "2024-02-20 16:24:08 [test]: Host update: contact: support@example.org -> new-support@example.org" ], "api_requests": [ { @@ -10440,7 +10440,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:12:59.995297+01:00", + "timestamp": "2024-02-20T16:24:08.722102+01:00", "user": "system-signals", "resource": "host", "name": "somehost.example.org", @@ -10452,7 +10452,7 @@ } }, { - "timestamp": "2024-02-20T16:13:00.000473+01:00", + "timestamp": "2024-02-20T16:24:08.726961+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", @@ -10462,7 +10462,7 @@ "data": "{\"name\": \"somehost.example.org\", \"contact\": \"support@example.org\"}" }, { - "timestamp": "2024-02-20T16:13:00.006299+01:00", + "timestamp": "2024-02-20T16:24:08.732982+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", @@ -10472,14 +10472,14 @@ "data": "{\"ipaddress\": \"10.0.1.4\"}" }, { - "timestamp": "2024-02-20T16:13:00.294434+01:00", + "timestamp": "2024-02-20T16:24:08.976315+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", "model_id": 4, "model": "Host", "action": "update", - "data": "{\"current_data\": {\"id\": 4, \"ipaddresses\": [{\"id\": 3, \"macaddress\": \"\", \"created_at\": \"2024-02-20T16:13:00.005695+01:00\", \"updated_at\": \"2024-02-20T16:13:00.005704+01:00\", \"ipaddress\": \"10.0.1.4\", \"host\": 4}], \"cnames\": [], \"mxs\": [], \"txts\": [{\"id\": 4, \"created_at\": \"2024-02-20T16:12:59.994669+01:00\", \"updated_at\": \"2024-02-20T16:12:59.994679+01:00\", \"txt\": \"v=spf1 -all\", \"host\": 4}], \"ptr_overrides\": [], \"hinfo\": null, \"loc\": null, \"bacnetid\": null, \"created_at\": \"2024-02-20T16:12:59.992717+01:00\", \"updated_at\": \"2024-02-20T16:12:59.992728+01:00\", \"name\": \"somehost.example.org\", \"contact\": \"support@example.org\", \"ttl\": null, \"comment\": \"\", \"zone\": 1}, \"update\": {\"contact\": \"new-support@example.org\"}}" + "data": "{\"current_data\": {\"id\": 4, \"ipaddresses\": [{\"id\": 3, \"macaddress\": \"\", \"created_at\": \"2024-02-20T16:24:08.732348+01:00\", \"updated_at\": \"2024-02-20T16:24:08.732357+01:00\", \"ipaddress\": \"10.0.1.4\", \"host\": 4}], \"cnames\": [], \"mxs\": [], \"txts\": [{\"id\": 4, \"created_at\": \"2024-02-20T16:24:08.721641+01:00\", \"updated_at\": \"2024-02-20T16:24:08.721649+01:00\", \"txt\": \"v=spf1 -all\", \"host\": 4}], \"ptr_overrides\": [], \"hinfo\": null, \"loc\": null, \"bacnetid\": null, \"created_at\": \"2024-02-20T16:24:08.719929+01:00\", \"updated_at\": \"2024-02-20T16:24:08.719938+01:00\", \"name\": \"somehost.example.org\", \"contact\": \"support@example.org\", \"ttl\": null, \"comment\": \"\", \"zone\": 1}, \"update\": {\"contact\": \"new-support@example.org\"}}" } ] } @@ -10495,7 +10495,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:12:59.995297+01:00", + "timestamp": "2024-02-20T16:24:08.722102+01:00", "user": "system-signals", "resource": "host", "name": "somehost.example.org", @@ -10507,7 +10507,7 @@ } }, { - "timestamp": "2024-02-20T16:13:00.000473+01:00", + "timestamp": "2024-02-20T16:24:08.726961+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", @@ -10517,7 +10517,7 @@ "data": "{\"name\": \"somehost.example.org\", \"contact\": \"support@example.org\"}" }, { - "timestamp": "2024-02-20T16:13:00.006299+01:00", + "timestamp": "2024-02-20T16:24:08.732982+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", @@ -10527,14 +10527,14 @@ "data": "{\"ipaddress\": \"10.0.1.4\"}" }, { - "timestamp": "2024-02-20T16:13:00.294434+01:00", + "timestamp": "2024-02-20T16:24:08.976315+01:00", "user": "test", "resource": "host", "name": "somehost.example.org", "model_id": 4, "model": "Host", "action": "update", - "data": "{\"current_data\": {\"id\": 4, \"ipaddresses\": [{\"id\": 3, \"macaddress\": \"\", \"created_at\": \"2024-02-20T16:13:00.005695+01:00\", \"updated_at\": \"2024-02-20T16:13:00.005704+01:00\", \"ipaddress\": \"10.0.1.4\", \"host\": 4}], \"cnames\": [], \"mxs\": [], \"txts\": [{\"id\": 4, \"created_at\": \"2024-02-20T16:12:59.994669+01:00\", \"updated_at\": \"2024-02-20T16:12:59.994679+01:00\", \"txt\": \"v=spf1 -all\", \"host\": 4}], \"ptr_overrides\": [], \"hinfo\": null, \"loc\": null, \"bacnetid\": null, \"created_at\": \"2024-02-20T16:12:59.992717+01:00\", \"updated_at\": \"2024-02-20T16:12:59.992728+01:00\", \"name\": \"somehost.example.org\", \"contact\": \"support@example.org\", \"ttl\": null, \"comment\": \"\", \"zone\": 1}, \"update\": {\"contact\": \"new-support@example.org\"}}" + "data": "{\"current_data\": {\"id\": 4, \"ipaddresses\": [{\"id\": 3, \"macaddress\": \"\", \"created_at\": \"2024-02-20T16:24:08.732348+01:00\", \"updated_at\": \"2024-02-20T16:24:08.732357+01:00\", \"ipaddress\": \"10.0.1.4\", \"host\": 4}], \"cnames\": [], \"mxs\": [], \"txts\": [{\"id\": 4, \"created_at\": \"2024-02-20T16:24:08.721641+01:00\", \"updated_at\": \"2024-02-20T16:24:08.721649+01:00\", \"txt\": \"v=spf1 -all\", \"host\": 4}], \"ptr_overrides\": [], \"hinfo\": null, \"loc\": null, \"bacnetid\": null, \"created_at\": \"2024-02-20T16:24:08.719929+01:00\", \"updated_at\": \"2024-02-20T16:24:08.719938+01:00\", \"name\": \"somehost.example.org\", \"contact\": \"support@example.org\", \"ttl\": null, \"comment\": \"\", \"zone\": 1}, \"update\": {\"contact\": \"new-support@example.org\"}}" } ] } @@ -12284,11 +12284,11 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:13:01 [test]: HostGroup create: name = 'mygroup', description = 'This describes the group'", - "2024-02-20 16:13:01 [test]: Host add: testhost1.example.org", - "2024-02-20 16:13:01 [test]: Host add: testhost2.example.org", - "2024-02-20 16:13:02 [test]: Group add: myself", - "2024-02-20 16:13:02 [test]: Host remove: testhost2.example.org" + "2024-02-20 16:24:10 [test]: HostGroup create: name = 'mygroup', description = 'This describes the group'", + "2024-02-20 16:24:10 [test]: Host add: testhost1.example.org", + "2024-02-20 16:24:10 [test]: Host add: testhost2.example.org", + "2024-02-20 16:24:10 [test]: Group add: myself", + "2024-02-20 16:24:10 [test]: Host remove: testhost2.example.org" ], "api_requests": [ { @@ -12302,7 +12302,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:01.625280+01:00", + "timestamp": "2024-02-20T16:24:10.337571+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12312,7 +12312,7 @@ "data": "{\"name\": \"mygroup\", \"description\": \"This describes the group\"}" }, { - "timestamp": "2024-02-20T16:13:01.850851+01:00", + "timestamp": "2024-02-20T16:24:10.574803+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12325,7 +12325,7 @@ } }, { - "timestamp": "2024-02-20T16:13:01.924208+01:00", + "timestamp": "2024-02-20T16:24:10.632002+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12338,7 +12338,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.069449+01:00", + "timestamp": "2024-02-20T16:24:10.673440+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12351,7 +12351,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.137317+01:00", + "timestamp": "2024-02-20T16:24:10.730959+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12377,7 +12377,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:01.625280+01:00", + "timestamp": "2024-02-20T16:24:10.337571+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12387,7 +12387,7 @@ "data": "{\"name\": \"mygroup\", \"description\": \"This describes the group\"}" }, { - "timestamp": "2024-02-20T16:13:01.850851+01:00", + "timestamp": "2024-02-20T16:24:10.574803+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12400,7 +12400,7 @@ } }, { - "timestamp": "2024-02-20T16:13:01.924208+01:00", + "timestamp": "2024-02-20T16:24:10.632002+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12413,7 +12413,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.069449+01:00", + "timestamp": "2024-02-20T16:24:10.673440+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12426,7 +12426,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.137317+01:00", + "timestamp": "2024-02-20T16:24:10.730959+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12784,15 +12784,15 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:13:01 [test]: HostGroup create: name = 'mygroup', description = 'This describes the group'", - "2024-02-20 16:13:01 [test]: Host add: testhost1.example.org", - "2024-02-20 16:13:01 [test]: Host add: testhost2.example.org", - "2024-02-20 16:13:02 [test]: Group add: myself", - "2024-02-20 16:13:02 [test]: Host remove: testhost2.example.org", - "2024-02-20 16:13:02 [test]: HostGroup add: yourgroup", - "2024-02-20 16:13:02 [test]: HostGroup remove: yourgroup", - "2024-02-20 16:13:02 [test]: Group add: anotherowner", - "2024-02-20 16:13:02 [test]: Group remove: myself" + "2024-02-20 16:24:10 [test]: HostGroup create: name = 'mygroup', description = 'This describes the group'", + "2024-02-20 16:24:10 [test]: Host add: testhost1.example.org", + "2024-02-20 16:24:10 [test]: Host add: testhost2.example.org", + "2024-02-20 16:24:10 [test]: Group add: myself", + "2024-02-20 16:24:10 [test]: Host remove: testhost2.example.org", + "2024-02-20 16:24:10 [test]: HostGroup add: yourgroup", + "2024-02-20 16:24:10 [test]: HostGroup remove: yourgroup", + "2024-02-20 16:24:10 [test]: Group add: anotherowner", + "2024-02-20 16:24:11 [test]: Group remove: myself" ], "api_requests": [ { @@ -12806,7 +12806,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:01.625280+01:00", + "timestamp": "2024-02-20T16:24:10.337571+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12816,7 +12816,7 @@ "data": "{\"name\": \"mygroup\", \"description\": \"This describes the group\"}" }, { - "timestamp": "2024-02-20T16:13:01.850851+01:00", + "timestamp": "2024-02-20T16:24:10.574803+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12829,7 +12829,7 @@ } }, { - "timestamp": "2024-02-20T16:13:01.924208+01:00", + "timestamp": "2024-02-20T16:24:10.632002+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12842,7 +12842,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.069449+01:00", + "timestamp": "2024-02-20T16:24:10.673440+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12855,7 +12855,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.137317+01:00", + "timestamp": "2024-02-20T16:24:10.730959+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12868,7 +12868,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.298043+01:00", + "timestamp": "2024-02-20T16:24:10.886980+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12881,7 +12881,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.359473+01:00", + "timestamp": "2024-02-20T16:24:10.944823+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12894,7 +12894,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.401381+01:00", + "timestamp": "2024-02-20T16:24:10.983262+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12907,7 +12907,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.439139+01:00", + "timestamp": "2024-02-20T16:24:11.022156+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12933,7 +12933,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:01.625280+01:00", + "timestamp": "2024-02-20T16:24:10.337571+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12943,7 +12943,7 @@ "data": "{\"name\": \"mygroup\", \"description\": \"This describes the group\"}" }, { - "timestamp": "2024-02-20T16:13:01.850851+01:00", + "timestamp": "2024-02-20T16:24:10.574803+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12956,7 +12956,7 @@ } }, { - "timestamp": "2024-02-20T16:13:01.924208+01:00", + "timestamp": "2024-02-20T16:24:10.632002+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12969,7 +12969,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.069449+01:00", + "timestamp": "2024-02-20T16:24:10.673440+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12982,7 +12982,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.137317+01:00", + "timestamp": "2024-02-20T16:24:10.730959+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -12995,7 +12995,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.298043+01:00", + "timestamp": "2024-02-20T16:24:10.886980+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -13008,7 +13008,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.359473+01:00", + "timestamp": "2024-02-20T16:24:10.944823+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -13021,7 +13021,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.401381+01:00", + "timestamp": "2024-02-20T16:24:10.983262+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -13034,7 +13034,7 @@ } }, { - "timestamp": "2024-02-20T16:13:02.439139+01:00", + "timestamp": "2024-02-20T16:24:11.022156+01:00", "user": "test", "resource": "group", "name": "mygroup", @@ -14392,8 +14392,8 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:13:03 [test]: HostPolicyAtom create: description = 'Here's the description', name = 'apple'", - "2024-02-20 16:13:03 [test]: HostPolicyAtom add to: hostpolicy_role fruit" + "2024-02-20 16:24:11 [test]: HostPolicyAtom create: description = 'Here's the description', name = 'apple'", + "2024-02-20 16:24:12 [test]: HostPolicyAtom add to: hostpolicy_role fruit" ], "api_requests": [ { @@ -14407,7 +14407,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.300712+01:00", + "timestamp": "2024-02-20T16:24:11.876825+01:00", "user": "test", "resource": "hostpolicy_atom", "name": "apple", @@ -14430,7 +14430,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.300712+01:00", + "timestamp": "2024-02-20T16:24:11.876825+01:00", "user": "test", "resource": "hostpolicy_atom", "name": "apple", @@ -14453,7 +14453,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.700397+01:00", + "timestamp": "2024-02-20T16:24:12.106032+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -14592,9 +14592,9 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:13:03 [test]: HostPolicyAtom create: description = 'Here's the description', name = 'apple'", - "2024-02-20 16:13:03 [test]: HostPolicyAtom add to: hostpolicy_role fruit", - "2024-02-20 16:13:03 [test]: HostPolicyAtom remove from: hostpolicy_role fruit" + "2024-02-20 16:24:11 [test]: HostPolicyAtom create: description = 'Here's the description', name = 'apple'", + "2024-02-20 16:24:12 [test]: HostPolicyAtom add to: hostpolicy_role fruit", + "2024-02-20 16:24:12 [test]: HostPolicyAtom remove from: hostpolicy_role fruit" ], "api_requests": [ { @@ -14608,7 +14608,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.300712+01:00", + "timestamp": "2024-02-20T16:24:11.876825+01:00", "user": "test", "resource": "hostpolicy_atom", "name": "apple", @@ -14631,7 +14631,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.300712+01:00", + "timestamp": "2024-02-20T16:24:11.876825+01:00", "user": "test", "resource": "hostpolicy_atom", "name": "apple", @@ -14654,7 +14654,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.700397+01:00", + "timestamp": "2024-02-20T16:24:12.106032+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -14667,7 +14667,7 @@ } }, { - "timestamp": "2024-02-20T16:13:03.986460+01:00", + "timestamp": "2024-02-20T16:24:12.354300+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15516,13 +15516,13 @@ "warning": [], "error": [], "output": [ - "2024-02-20 16:13:03 [test]: HostPolicyRole create: description = '5 a day', name = 'fruit', labels = '[]'", - "2024-02-20 16:13:03 [test]: HostPolicyAtom add: apple", - "2024-02-20 16:13:03 [test]: HostPolicyAtom add: orange", - "2024-02-20 16:13:03 [test]: HostPolicyAtom remove: apple", - "2024-02-20 16:13:04 [test]: Host add: foo.example.org", - "2024-02-20 16:13:04 [test]: Host remove: foo.example.org", - "2024-02-20 16:13:04 [test]: HostPolicyAtom remove: tangerine" + "2024-02-20 16:24:11 [test]: HostPolicyRole create: description = '5 a day', name = 'fruit', labels = '[]'", + "2024-02-20 16:24:12 [test]: HostPolicyAtom add: apple", + "2024-02-20 16:24:12 [test]: HostPolicyAtom add: orange", + "2024-02-20 16:24:12 [test]: HostPolicyAtom remove: apple", + "2024-02-20 16:24:12 [test]: Host add: foo.example.org", + "2024-02-20 16:24:12 [test]: Host remove: foo.example.org", + "2024-02-20 16:24:13 [test]: HostPolicyAtom remove: tangerine" ], "api_requests": [ { @@ -15536,7 +15536,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.407055+01:00", + "timestamp": "2024-02-20T16:24:11.982410+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15546,7 +15546,7 @@ "data": "{\"description\": \"5 a day\", \"name\": \"fruit\", \"labels\": []}" }, { - "timestamp": "2024-02-20T16:13:03.700397+01:00", + "timestamp": "2024-02-20T16:24:12.106032+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15559,7 +15559,7 @@ } }, { - "timestamp": "2024-02-20T16:13:03.770737+01:00", + "timestamp": "2024-02-20T16:24:12.159770+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15572,7 +15572,7 @@ } }, { - "timestamp": "2024-02-20T16:13:03.986460+01:00", + "timestamp": "2024-02-20T16:24:12.354300+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15585,7 +15585,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.458754+01:00", + "timestamp": "2024-02-20T16:24:12.778366+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15598,7 +15598,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.696198+01:00", + "timestamp": "2024-02-20T16:24:12.989080+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15611,7 +15611,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.754487+01:00", + "timestamp": "2024-02-20T16:24:13.050249+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15637,7 +15637,7 @@ "previous": null, "results": [ { - "timestamp": "2024-02-20T16:13:03.407055+01:00", + "timestamp": "2024-02-20T16:24:11.982410+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15647,7 +15647,7 @@ "data": "{\"description\": \"5 a day\", \"name\": \"fruit\", \"labels\": []}" }, { - "timestamp": "2024-02-20T16:13:03.700397+01:00", + "timestamp": "2024-02-20T16:24:12.106032+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15660,7 +15660,7 @@ } }, { - "timestamp": "2024-02-20T16:13:03.770737+01:00", + "timestamp": "2024-02-20T16:24:12.159770+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15673,7 +15673,7 @@ } }, { - "timestamp": "2024-02-20T16:13:03.986460+01:00", + "timestamp": "2024-02-20T16:24:12.354300+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15686,7 +15686,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.458754+01:00", + "timestamp": "2024-02-20T16:24:12.778366+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15699,7 +15699,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.696198+01:00", + "timestamp": "2024-02-20T16:24:12.989080+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -15712,7 +15712,7 @@ } }, { - "timestamp": "2024-02-20T16:13:04.754487+01:00", + "timestamp": "2024-02-20T16:24:13.050249+01:00", "user": "test", "resource": "hostpolicy_role", "name": "fruit", @@ -19861,7 +19861,7 @@ "command_issued": "host remove bar # should fail, because it has multiple addresses, must force", "ok": [], "warning": [ - "WARNING: : bar.example.org requires force and override for deletion:\n multiple ipaddresses on the same VLAN. Must use 'force'." + "WARNING: : bar.example.org requires force for deletion:\n multiple ipaddresses on the same VLAN. Must use 'force'." ], "error": [], "output": [], @@ -20655,7 +20655,7 @@ "command_issued": "host remove bar # should fail, because it has a cname record, must force", "ok": [], "warning": [ - "WARNING: : bar.example.org requires force and override for deletion:\n 1 cnames, override with 'cnames'\n - fubar.example.org\n multiple ipaddresses on the same VLAN. Must use 'force'." + "WARNING: : bar.example.org requires force and cnames as overrides for deletion:\n 1 cnames, override with 'cnames'\n - fubar.example.org\n multiple ipaddresses on the same VLAN. Must use 'force'." ], "error": [], "output": [], @@ -21414,7 +21414,7 @@ "command_issued": "host remove baz # Should fail, because it has an MX record, must force", "ok": [], "warning": [ - "WARNING: : baz.example.org requires force and override for deletion:\n multiple ipaddresses on the same VLAN. Must use 'force'.\n 1 MX records, override with 'mxs'\n - mail.example.org (priority: 10)" + "WARNING: : baz.example.org requires force and mxs as overrides for deletion:\n multiple ipaddresses on the same VLAN. Must use 'force'.\n 1 MX records, override with 'mxs'\n - mail.example.org (priority: 10)" ], "error": [], "output": [], diff --git a/mreg_cli/commands/host_submodules/core.py b/mreg_cli/commands/host_submodules/core.py index fb597e23..1f70720c 100644 --- a/mreg_cli/commands/host_submodules/core.py +++ b/mreg_cli/commands/host_submodules/core.py @@ -161,6 +161,7 @@ def remove(args: argparse.Namespace) -> None: # Get host info or raise exception info = host_info_by_name_or_ip(args.name) overrides: List[str] = args.override.split(",") if args.override else [] + required_overrides: List[str] = [] def forced(override_required: str = None) -> bool: # If we require an override, check if it's in the list of provided overrides. @@ -176,7 +177,8 @@ def forced(override_required: str = None) -> bool: warnings: List[str] = [] # Require force if host has any cnames. - if info["cnames"] and not args.force: + if info["cnames"] and not forced("cnames"): + required_overrides.append("cnames") warnings.append(f" {len(info['cnames'])} cnames, override with 'cnames'") for cname in info["cnames"]: warnings.append(f" - {cname['name']}") @@ -188,6 +190,7 @@ def forced(override_required: str = None) -> bool: if same_vlan and not forced(): warnings.append(" multiple ipaddresses on the same VLAN. Must use 'force'.") elif not same_vlan and not forced("ipaddresses"): + required_overrides.append("ipaddresses") warnings.append( " {} ipaddresses on distinct VLANs, override with 'ipadresses'".format( len(info["ipaddresses"]) @@ -198,6 +201,7 @@ def forced(override_required: str = None) -> bool: warnings.append(f" - {ip['ipaddress']} (vlan: {vlan})") if info["mxs"] and not forced("mxs"): + required_overrides.append("mxs") warnings.append(f" {len(info['mxs'])} MX records, override with 'mxs'") for mx in info["mxs"]: warnings.append(f" - {mx['mx']} (priority: {mx['priority']})") @@ -208,6 +212,7 @@ def forced(override_required: str = None) -> bool: naptrs = get_list(path, params={"host": info["id"]}) if len(naptrs) > 0: if not forced("naptrs"): + required_overrides.append("naptrs") warnings.append(" {} NAPTR records. ".format(len(naptrs))) for naptr in naptrs: warnings.append(f" - {naptr['replacement']}") @@ -225,6 +230,7 @@ def forced(override_required: str = None) -> bool: srvs = get_list(path, params={"host__name": info["name"]}) if len(srvs) > 0: if not forced("srvs"): + required_overrides.append("srvs") warnings.append(f" {len(srvs)} SRV records, override with 'srvs'") for srv in srvs: warnings.append(f" - {srv['name']}") @@ -240,6 +246,7 @@ def forced(override_required: str = None) -> bool: # Require force if host has any PTR records. Delete the PTR records if force if len(info["ptr_overrides"]) > 0: if not forced("ptr"): + required_overrides.append("ptr") warnings.append(f" {len(info['ptr_overrides'])} PTR records, override with 'ptr'") for ptr in info["ptr_overrides"]: warnings.append(f" - {ptr['ipaddress']}") @@ -260,8 +267,13 @@ def forced(override_required: str = None) -> bool: # Warn user and raise exception if any force requirements was found if warnings: warn_msg = "\n".join(warnings) + override_str = ( + "and '{}' as overrides ".format(",".join(required_overrides)) + if required_overrides + else "" + ) cli_warning( - "{} requires force and override for deletion:\n{}".format(info["name"], warn_msg) + "{} requires force {}for deletion:\n{}".format(info["name"], override_str, warn_msg) ) # Delete host