---
# System prepended metadata

title: Test Mesh Upgrade

---

# Test Mesh Upgrade


1.  crear una carpeta local con el bin, la lates de librerouter y la sig. 
La carpeta tests el json ya tiene la url apropiada para funcionar con qemu en pc. Solo es necesario agregar el bin de libremesh como se muestra en la estructura de abajo 

    ├── latest
    │   ├── librerouter-librerouter-v1.json
    │   └── librerouter-librerouter-v1.json.sig
    ├── librerouteros-1.5-r0+11434-e93615c947-ath79-generic-librerouter_librerouter-v1-squashfs-sysupgrade.bin

en test puse una carpeta con los archivos de purebas. Esto mismo se puede encontrar en http://repo.librerouter.org/lros/api/v1/latest/ 
es importante notar que el json tiene la url desde donde obtener por primera vez el archivo a descargar y un hash del archivo.

NOTA:eupgrade fue modificado para que funcione meshupgrade recordar copiar la version modificada para que funcione en un router

2. levantar un server http en la carpeta test (recordar poner en la carpeta el bin de libremesh)
```bash
jjorge@pluma: packages/lime-mesh-upgrade/tests$ python -m  http.server 8080
```
3. - Levantar el master 00 y compartirle internet ...en mi caso eth0
```bash
sudo ./tools/qemu_dev_start tools/ansible/files/generic-rootfs.tar.gz tools/ansible/files/ramfs.bzImage --libremesh-workdir . --enable-wan eth0
```

4. Verificar el Initial state
```bash
echo | shared-state reqsync mesh_wide_upgrade
```

5. Luego en el master correr el script de pruebas 
el script de pruebas debe apuntar a una url alternativa que debe ser la del nuevo servidor (http://10.13.0.2:8080/)
[lua /usr/lib/lua/testmaster.lua](https://gist.github.com/javierbrk/9746f755e4024dd79b4e9e6e679e0ce7)

```bash=
root@LiMe-abc000:/# lua /usr/lib/lua/mastertest.lua  
10.13.192.0/16
http://10.13.156.241:8000/web_test/releases/api/
librerouter,librerouter-v1      1
Good signature of firmware_latest.json
{"release-info-url":"https:\/\/foro.librerouter.org\/t\/lanzamiento-librerouteros-1-5\/337","metadata-version":1,"images":[{"sha256":"2da0abb549d6178a7978b357be3493d5}
{"code":"not-initiated"}
{"code":"downloaded"}
seting up repo download info to READY_FOR_UPGRADE actual STARTING
{"code":"SUCCESS"}

```

6. - Verificar master ready for upgrade 


```bash
echo | shared-state reqsync mesh_wide_upgrade
```

```json
{
  "LiMe-abc000": {
    "bleachTTL": 29,
    "data": {
      "current_fw": "%LIME_DESCRIPTION%",
      "repo_url": "http://10.13.192.0/lros/",
      "candidate_fw": "LibreRouterOs 1.5",
      "board_name": "librerouter,librerouter-v1",
      "timestamp": "1706544854",
      "main_node": true,
      "upgrade_state": "READY_FOR_UPGRADE"
    },
    "author": "LiMe-abc000"
  }
}
```
7. iniciar un nodo el numero 2
```bash
sudo ./tools/qemu_dev_start tools/ansible/files/generic-rootfs.tar.gz tools/ansible/files/ramfs.bzImage --libremesh-workdir . --node-id 2
```

8. Si es necesario iniciar el sync a mano 
```bash=
root@LiMe-abc002:/# shared-state sync mesh_wide_upgrade

starting an upgrade process
transfoming into a bot node
seting up repo download info to STARTING actual DEFAULT
already started an upgrade process
Can't download signature http://10.13.192.0/lros/latest/qemu-standard-pc-i440fx-piix-1996.json.sig
Good signature of firmware_latest.json
start_node_download from  http://10.13.192.0/lros/
start_node_download 
downloading
Downloading the firmware from http://10.13.192.0/lros/upgrade-lr-1.5.sh
Firmware downloaded ok
{"download-urls":["http:\/\/10.13.192.0\/lros\/upgrade-lr-1.5.sh"],"type":"installer","sha256":"2da0abb549d6178a7978b357be3493d5aff5c07b993ea0962575fa61bef18c27","nam}
{"download-urls":["http:\/\/10.13.192.0\/lros\/upgrade-lr-1.5.sh"],"type":"installer","sha256":"2da0abb549d6178a7978b357be3493d5aff5c07b993ea0962575fa61bef18c27","nam}
root@LiMe-abc002:/# 
root@LiMe-abc002:/# already started an upgrade process
```
9. Verificar que ambos esten ready_for_upgrade 
```bash
root@LiMe-abc002:/#  echo | shared-state reqsync mesh_wide_upgrade
```

```json
{
  "LiMe-abc002": {
    "bleachTTL": 29,
    "data": {
      "current_fw": "%LIME_DESCRIPTION%",
      "repo_url": "http://10.13.192.0/lros/",
      "candidate_fw": "LibreRouterOs 1.5",
      "board_name": "qemu-standard-pc-i440fx-piix-1996",
      "timestamp": "1706545141",
      "main_node": false,
      "upgrade_state": "READY_FOR_UPGRADE"
    },
    "author": "LiMe-abc002"
  },
  "LiMe-abc000": {
    "bleachTTL": 27,
    "data": {
      "current_fw": "%LIME_DESCRIPTION%",
      "repo_url": "http://10.13.192.0/lros/",
      "candidate_fw": "LibreRouterOs 1.5",
      "board_name": "librerouter,librerouter-v1",
      "timestamp": "1706544854",
      "main_node": true,
      "upgrade_state": "READY_FOR_UPGRADE"
    },
    "author": "LiMe-abc000"
  }
}
```




```bash=

echo "librerouter,librerouter-v1" > /tmp/sysinfo/board_name

ubus -v list lime-mesh-upgrade

#--use remote server url, remember to fix bin downliad url in ".json "
#--eupgrade.set_custom_api_url('http://repo.librerouter.org/lros/api/v1/')
#eupgrade.set_custom_api_url('http://10.13.0.2:8080/')
#--eupgrade.set_custom_api_url('http://10.234.77.12:8080/')

ubus -v call lime-mesh-upgrade get_node_status

#lime_mesh_upgrade.become_main_node()
#utils.printJson(lime_mesh_upgrade.get_main_node_status())
ubus -v -t 30 call lime-mesh-upgrade become_main_node '{"url":"http://10.13.0.2:8080/"}'

ubus -v -t 30 call lime-mesh-upgrade start_firmware_upgrade_transaction
```

to start a new transaction in the bot node just sync
```bash
shared-state sync mesh_wide_upgrade

```
if the board type is not librerouter, then the software will retry some atempts and then stop. 
to enable a new retry you must abort current transaction. 

```bash
root@LiMe-abc002:/# ubus -v call lime-mesh-upgrade get_node_status
{
	"repo_url": "http://10.13.192.0/lros/",
	"candidate_fw": "LibreRouterOs 1.5",
	"retry_count": 0,
	"upgrade_state": "ERROR",
	"current_fw": "%LIME_DESCRIPTION%",
	"main_node": "NO",
	"board_name": "qemu-standard-pc-i440fx-piix-1996",
	"timestamp": 1708621236,
	"error": "aborted",
	"eupgradestate": "not-initiated"
}
root@LiMe-abc002:/# /usr/bin/shared-state-publish_mesh_wide_upgrade 
starting an upgrade process
0
por guardar 1
root@LiMe-abc002:/# starting an upgrade process
1
por guardar 2
starting an upgrade process
2
por guardar 3
starting an upgrade process
3
por guardar 4
starting an upgrade process
4

root@LiMe-abc002:/# ubus -v call lime-mesh-upgrade abort
{
	"error": "",
	"code": "SUCCESS"
}
root@LiMe-abc002:/# echo "librerouter,librerouter-v1" > /tmp/sysinfo/board_name
root@LiMe-abc002:/# /usr/bin/shared-state-publish_mesh_wide_upgrade 
starting an upgrade process
0
por guardar 1
Downloading the firmware from http://10.13.192.0/lros/upgrade-lr-1.5.sh
Firmware downloaded ok


```


sometimes the script creates images for librerouter and sometimes it creates images for qemu in qemu environment ... 
si llamamos al publisher frecuentemente cuando todavia no se decremento el ttl en otros nodos genera problemas no se sincronizan si el ttl es el mismo sera necesario esperar un rato a que se actualice la info del nodo 
