Why Provision's Script works on every device regardless on Preset

Hello guys, i stumbled on that problem a couple days ago, cant find the nature of that issue, but every Provision i added happen to trying change some parameters. How did i find out ? Thanks to Tags, on some script i change the tag to understand that worked, after a couple of times i notice, i didnt changed the Presets for filtering, but script provisioned anyway. After i played with tags on one device to find out some parameters to change\refresh, i opened “Devices” tab and you know what i found ? that anyhow Tags was appeared on all devices. Only Tags which was created with Provision Script

On some scripts i remove tags, add another one, sometimes tag still, sometimes tag removed (meaning that provisioning worked - but big very BUT parameter still untouched)
for example:
Have a Preset and Provision script
To enable remote access for GPON Tag should be 222:

declare("Tags.222", null, {value: false});
declare("Tags.remote_control", null, {value: true});
let now = Date.now();
declare("InternetGatewayDevice.X_HW_Security.AclServices",{path: now},{value: 1});
declare("InternetGatewayDevice.X_HW_Security.AclServices.SSHWanEnable",{path: now},{value: true});

And for Disable i use tag 444:

declare("Tags.444", null, {value: false});
declare("Tags.remote_control", null, {value: false});
const now = Date.now();
declare("InternetGatewayDevice.X_HW_Security.AclServices",{path: now},{value: 1});
declare("InternetGatewayDevice.X_HW_Security.AclServices.SSHWanEnable",{path: now},{value: false});

Cant understand why that happen. Which way i should dig, and how you guys debug ?How to stop it ? or i should to reinstall the Genieacs, and configure from the begining ?

Also find out that problem appeared on all devices. Maybe that could help.

name: Error
message: Invalid parameter path
stack: |-
  Error: Invalid parameter path
      at static (/usr/lib/node_modules/lib/common/path.ts:201:39)
      at null.value (/usr/lib/node_modules/lib/sandbox.ts:230:27)
      at Huawei_Provisioning:2:1
      at Huawei_Provisioning:29:3
      at Script.runInContext (node:vm:139:12)
      at async (/usr/lib/node_modules/lib/sandbox.ts:393:18)
      at async (/usr/lib/node_modules/lib/session.ts:642:14)
      at Array.map (<anonymous>)
      at async (/usr/lib/node_modules/lib/session.ts:606:16)
      at async (/usr/lib/node_modules/lib/session.ts:1067:15)


Removed all not default Provision Scripts and Presets.
Removed All tags from CPE.
Added only one Tag to initiate Provisioning
Rebooted server.

After I got another Fault:

Begin to realise that happens bc of bootstrap.

let now = Date.now();
// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
let device_class=declare("DeviceID.ProductClass",{value:1}).value[0];
let serial_number=declare("DeviceID.SerialNumber",{value:1}).value[0];

log('here we have ' + device_class + ' with that S/N ' + serial_number);
  if (device_class == "HG8546M"){
      log('Provisioning ...' + serial_number);
      declare("Tags.HG8546M",{path: now},{value:true});
  }   else {
      declare("Tags.WTF",{path: now},{value:true});
 }

Reconfigure script now it look like this

let now = Date.now();

// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
//Added that line
let provisioned=declare("Tags.Huawei_Done",{value:1}).value[0];
let device_class=declare("DeviceID.ProductClass",{value:1}).value[0];
let serial_number=declare("DeviceID.SerialNumber",{value:1}).value[0];

log('here we have ' + device_class + ' with that S/N ' + serial_number);
//Added and that one
if (provisioned == false){
  if (device_class == "HG8546M"){
      log('Provisioning ...' + serial_number);
      declare("Tags.HG8546M",{path: now},{value:true});
  }   else {
      declare("Tags.WTF",{path: now},{value:true});
  }
}

i will update if something goes wrong.

Your precondition for the preset is wrong. Try this Tags.222 IS NOT NULL.

1 Like

Thank you that worked !
My Upper solution for checking if there already a tag from Provisioning script - doesnt work well, error occur when device doesnt have that Tag, saying

Cannot read properties of undefined (reading ‘0’)

and stoping the script. While others which had that tag - passed well.

let provisioned=declare("Tags.Huawei_Done",{value:1}).value[0];
if (provisioned == false){ ...

is there a possible way to say Preset bootstrap “only work with devices which has no TAG at all ! and Ignore which has already any TAG” ?

It doesn’t work because tags aren’t an array. The reason the value of a declare would be an array is the first index of the array is the value, the second is the data type.

Put this function in your provision script and use it like so:

if (!hasTag('Huawei_Done')) {
    // Do stuff
}

function hasTag(name) {
    const result = declare(`Tags.${name}`, {value: 1});
    return result.value !== undefined;
}
1 Like