TheThingsNetwork / lorawan-stack-migrate

Migrate devices from other LoRaWAN Network Servers to The Things Stack
Apache License 2.0
8 stars 3 forks source link

Cannot migrate devices with numeric names #33

Closed dajtxx closed 3 years ago

dajtxx commented 3 years ago

Summary

We have a couple of devices with purely numeric names - 19 and 26.

The device name checking regexp doesn't allow for these:

++ ttn-lw-migrate device --dry-run --source ttnv2
  INFO Clearing device keys                     dev_eui=70B3D5CD000101BD device_id=19
Error: error:go.thethings.network/lorawan-stack-migrate/cmd:invalid_fields (invalid fields for device `19`)
error:go.thethings.network/lorawan-stack-migrate/cmd:invalid_fields (invalid fields for device `19`)
    device_id=19
    dev_eui=70B3D5CD000101BD
--- error:pkg/errors:validation (invalid `ids`: embedded message failed validation)
    name=EndDeviceValidationError
    field=ids
    reason=embedded message failed validation
--- error:pkg/errors:validation (invalid `device_id`: value does not match regex pattern "^[a-z0-9](?:[-]?[a-z0-9]){2,}$")
    name=EndDeviceIdentifiersValidationError
    field=device_id
    reason=value does not match regex pattern "^[a-z0-9](?:[-]?[a-z0-9]){2,}$"
dajtxx commented 3 years ago

I just noticed I could run the command with a numeric device id if I used all command line flags rather than redirecting from stdin as the examples show. This command runs ok:

/usr/local/bin/ttn-lw-migrate device 5228129 --dry-run --source ttnv2 --ttnv2.app-id axioma_flow --ttnv2.app-access-key <key here> --ttnv2.frequency-plan-id AS_920_923_TTN_AU

KrishnaIyer commented 3 years ago

The issue here is not the numeric names but the length of Identifier. IDs in v3 are required to be at least 3 characters in length. We will update the API to return a clearer error message but your two digit device IDs are not valid in v3.

dajtxx commented 3 years ago

Now v2 is read only I cannot change the key on the v2 device to prevent it joining. So even though I've created the device in v3 using the euis etc, I can't quite replicate whatever the migration tool does.

I think a better approach would have been to have the migration tool accept the name, emit a warning, and have the v3 cli tool and API reject the device definition if it contains an invalid name.

I guess the problem will be gone in a few months, but I have more 2 digit dev ids to migrate (some today) so have to jump through the hoops to do it.

KrishnaIyer commented 3 years ago

https://github.com/TheThingsNetwork/lorawan-stack-migrate/pull/34 This PR adds support to add a prefix to your device IDs before exporting them. That should fix the issue that you encountered here.

dajtxx commented 3 years ago

LOL, we probably migrated the last of the 2 digit numeric id devices last week.

Anyway, good you found a way to work a fix in with something else.