diff --git a/lib/Conch/Controller/DeviceReport.pm b/lib/Conch/Controller/DeviceReport.pm index ca620a908..a298d8bfe 100644 --- a/lib/Conch/Controller/DeviceReport.pm +++ b/lib/Conch/Controller/DeviceReport.pm @@ -100,6 +100,14 @@ sub process ($c) { }); if (not $device) { + if (my $serial_device = $c->db_devices->find({ id => $c->stash('device_id') })) { + $serial_device->health('error'); + $serial_device->update({ updated => \'now()' }) if $serial_device->is_changed; + } + if (my $system_uuid_device = $c->db_devices->find({ system_uuid => $unserialized_report->{system_uuid} })) { + $system_uuid_device->health('error'); + $system_uuid_device->update({ updated => \'now()' }) if $system_uuid_device->is_changed; + } return $c->status(400, { error => 'could not process report for device ' .$c->stash('device_id') .($c->stash('exception') ? ': '.(split(/\n/, $c->stash('exception'), 2))[0] : '') }); diff --git a/t/integration/device-reports.t b/t/integration/device-reports.t index 07104218d..d86c991c9 100644 --- a/t/integration/device-reports.t +++ b/t/integration/device-reports.t @@ -91,6 +91,12 @@ subtest 'system_uuid collisions' => sub { $t->post_ok('/device/i_was_here_first', json => $report_data) ->json_cmp_deeply({ error => re(qr/could not process report for device i_was_here_first.*duplicate key value violates unique constraint "device_system_uuid_key"/) }); + + $existing_device->discard_changes; + is($existing_device->health, 'error', 'existing device had health set to error'); + + my $test_device = $t->app->db_devices->find('TEST'); + is($test_device->health, 'error', 'TEST device had health set to error as well'); }; done_testing;