TT#141802 Add firmware 'tags' support for 'next' firmware endpoint

Historically NGCP supported Firmware tags for endpoint 'latest' only:
> http://<ngcp_fqdn>:<bootstrap_port>/device/autoprov/firmware/<mac>/from/<current_firmware_version>/latest/<tag>

For example: NGCP has 7 firmwares configured for SNOM D715 with MAC 0004138aa403.
For the simplicity let's call firmwares versions: 1, 2, 3, 4, 5, 6, 7.
the firmwares '4' and '6' has the same tag 'mytag'.
The latest firmware is firmware with id '7' and it has no tag set.
The endpoint 'latest' gives access to firmware '6' only:

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/0/latest
> firmware 7
>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/0/latest/mytag
> firmware 6

This commit adds 'tags' support for enpoint 'next'.
It allows to address the complete chain of firmwares using tags:

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/0/next
> firmware 1  # the next firmware after version '0' is firmware '1'

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/0/next/mytag
> firmware 4  # the next firmware after version '0' with tag 'mytag' is firmware '4'

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/2/next/mytag
> firmware 4  # the same as above, the firmware after version '2' with tag 'mytag' is firmware '4'

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/from/4/next/mytag
> firmware 6  # the next firmware after version '4' with tag 'mytag' is firmware '6'

P.S. $tmp variable was not in use, removed.
Also improve the 404 output for the 'tag' case.

Change-Id: Ifb896e1aef7b57328ab6492236768bc15ca8cc9e
mr10.1
Alexander Lutay 4 years ago
parent b106891f68
commit 31d954dfa8

@ -1977,7 +1977,7 @@ sub dev_field_firmware_version_base :Chained('dev_field_firmware_base') :PathPar
}
sub dev_field_firmware_next :Chained('dev_field_firmware_version_base') :PathPart('next') :Args {
my ($self, $c, $tmp) = @_;
my ($self, $c, $tag) = @_;
my $rs = $c->stash->{fw_rs}->search({
device_id => $c->stash->{dev}->profile->config->device->id,
@ -1985,6 +1985,11 @@ sub dev_field_firmware_next :Chained('dev_field_firmware_version_base') :PathPar
}, {
order_by => { -asc => 'version' },
});
if(defined $tag && length $tag > 0) {
$rs = $rs->search({
tag => $tag,
});
}
if(defined $c->req->params->{q}) {
$rs = $rs->search({
version => { 'like' => $c->req->params->{q} . '%' },
@ -1994,7 +1999,11 @@ sub dev_field_firmware_next :Chained('dev_field_firmware_version_base') :PathPar
my $fw = $rs->first;
unless($fw) {
$c->response->content_type('text/plain');
$c->response->body("404 - current firmware version '" . $c->stash->{dev_fw_string} . "' is latest");
if(defined $tag && length $tag > 0) {
$c->response->body("404 - current firmware with tag '$tag' is latest");
} else {
$c->response->body("404 - current firmware version '" . $c->stash->{dev_fw_string} . "' is latest");
}
$c->response->status(404);
return;
}
@ -2030,7 +2039,11 @@ sub dev_field_firmware_latest :Chained('dev_field_firmware_version_base') :PathP
my $fw = $rs->first;
unless($fw) {
$c->response->content_type('text/plain');
$c->response->body("404 - current firmware version '" . $c->stash->{dev_fw_string} . "' is latest");
if(defined $tag && length $tag > 0) {
$c->response->body("404 - current firmware with tag '$tag' is latest");
} else {
$c->response->body("404 - current firmware version '" . $c->stash->{dev_fw_string} . "' is latest");
}
$c->response->status(404);
return;
}

Loading…
Cancel
Save