Some advice on when to run provision scripts

Hi guys,

I would like to have some advice from the community on which preconditions to put in the presets for
for the following scripts because every now and then I get errors of for example incorrect request credentials or invalid parameter name

My provision scripts are:
force_refresh

log("bootstrap");

let now = Date.now();


clear("Device", now);
clear("InternetGatewayDevice", now);

declare("Tags.Provisioned", null, { value: false });

log("DONE bootstrap");

get_creds:

const now = Date.now();

log('Set Connection Request params');
declare("InternetGatewayDevice.ManagementServer", {value: now});
declare("InternetGatewayDevice.ManagementServer.ConnectionRequestUsername", {value: now}, {value: "user"});
declare("InternetGatewayDevice.ManagementServer.ConnectionRequestPassword", {value: now}, {value: "password!"});

I also put my effective provision script for Huawei, which is what I most often get faults :

const now = Date.now();

let provisioned = declare("Tags.Provisioned", {value: 1});
if (provisioned.value !== undefined) {
    log('CPE is (allegedly) provisioned, returning');
    return;
}

let model = declare("InternetGatewayDevice.DeviceInfo.ModelName", {value: 1}).value[0];
let serialNumber = declare("InternetGatewayDevice.DeviceInfo.SerialNumber", {value: 1}).value[0];
let productClass = declare("InternetGatewayDevice.DeviceInfo.ProductClass", {value: 1}).value[0];
let oui = declare("InternetGatewayDevice.DeviceInfo.ManufacturerOUI", {value: 1}).value[0];
let args = {serial: serialNumber, productClass: productClass, oui: oui};

log(JSON.stringify(args));

//Get the PPPoE creds
let config = ext('cpe-config', 'getConfig', JSON.stringify(args));
if (!config) {
    log('ERROR !No configuration returned ');
    return;
}
log(JSON.stringify(config));
//Disable the WANIPConnection instance on the ATM interface
log('Disabling WANIPConnection');
declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.*.Enable", {path: now, value: now}, {value: false});


setupBaseWanPppConnection();
setAccountSpecificSettings(config);


//Refresh the mac and external ip
declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPPConnection.*.MACAddress", {value: now});

updateTags(config);
bouncePppoeConnection();

return; //Not explicitly needed, but I want to prevent any extranious code at the bottom from executing...


function updateTags(config) {

    let unprovisioned = declare("Tags.Unprovisioned", {value: 1});

    log('Removing unprovisioned tag (if there is)');
    declare("Tags.Unprovisioned", null, {value: false});
    
    log('Done configuring. Setting provisioned tag');
    declare("Tags.Provisioned", null, {value: true});

    log('Done configuring. Setting customer code tag');
    declare("Tags."+config.codice_cliente, null, {value: true});
}



function setupBaseWanPppConnection() {
    //Ensure we have a WANPPPConnection instance
    log('Creating WANPPPConnection (if necessary)');
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*", null, {path: 1});

    log('Setting up WANPPPConnection');
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*.*", {path: now}); //Refresh the node...


    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*.NATEnabled", {value: now}, {value: true});
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*.Enable", {value: now}, {value: true});
}


function setAccountSpecificSettings(config) {


    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.DNSEnabled", {value: now},{value:true});
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_ExServiceList",{value: now}, {value: "TR069_IPTV_INTERNET"});
    declare("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.IPInterface.1.IPInterfaceIPAddress", {value: now}, {value: "192.168.1.254"});
    declare("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.MinAddress", {value: now},{value:"192.168.1.20"});
    declare("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.MaxAddress", {value: now},{value:"192.168.1.200"});
    declare("InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DNSServers", {value: now}, {value:"0.0.0.0,1.1.1.1"});
    declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.1.X_HW_L3Enable",{value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.2.X_HW_L3Enable",{value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.3.X_HW_L3Enable",{value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.4.X_HW_L3Enable",{value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.Enable", {value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.Enable", {value: now}, {value: true});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID", {value: now},{value:"Provider-"+config.codice_cliente});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.SSID", {value: now},{value:"Provider-"+config.codice_cliente});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey",{value:now},{value:config.pw_wifi});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.PreSharedKey.1.PreSharedKey",{value:now},{value:config.pw_wifi});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.RegulatoryDomain",{value: now}, {value:"IT"});
    declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.RegulatoryDomain",{value: now}, {value:"IT"});

    declare("InternetGatewayDevice.Time.NTPServer1",{value: now},{value:"ntp1.inrim.it"});
    declare("InternetGatewayDevice.Time.NTPServer2",{value: now},{value:"ntp2.inrim.it"});
    declare("InternetGatewayDevice.Time.Enable",{value: now}, {value: true});
    declare("InternetGatewayDevice.Time.LocalTimeZone",{value: now}, {value: "+01:00"});
    declare("InternetGatewayDevice.Time.LocalTimeZoneName", {value: now},{value:"Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna"});

    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.2.UserName",{value: now}, {value:"isiline"});
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.2.Password", {value: now}, {value: config.pw_entrata});


    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListEnable", {value: now}, {value: true});
    declare ("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*", null, {path: 2});

    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.Mode", {value: now}, {value: "0"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.Priority", {value: now}, {value: "1"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.ServicePort",{value: now}, {value: "TELNET,HTTP,SSH,FTP,ICMP"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.SrcIp",{value: now}, {value: "0.0.0.0-1.1.1.1"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.SrcPortName",{value: now}, {value: "ALL"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.1.SrcPortType", {value: now}, {value: "2"});

    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.Mode", {value: now}, {value: "0"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.Priority", {value: now}, {value: "2"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.ServicePort",{value: now}, {value: "TELNET,HTTP,SSH,FTP,ICMP"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.SrcIp",{value: now}, {value: "0.0.0.0-1.1.1.1"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.SrcPortName",{value: now}, {value: "ALL"});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.2.SrcPortType", {value: now}, {value: "2"});

    declare("InternetGatewayDevice.X_HW_Security.AclServices.HTTPWanEnable",{value: now}, {value: true});
    declare("InternetGatewayDevice.X_HW_Security.AclServices.SSHWanEnable",{value: now}, {value: true});
    declare("InternetGatewayDevice.X_HW_Security.WANSrcWhiteList.WANSrcWhiteListEnable", {value: now}, {value: true});


    //{value: now} forces GenieACS to update the value of the username/password if the value hasn't been updated before now
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Username", {value: now}, {value: config.pppoe_username});
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Password", {value: now}, {value: config.pppoe_password});

    //Refresh the vParams
    declare("VirtualParameters.pppoeUsername", {value: now});
    declare("VirtualParameters.pppoePassword", {value: now});

}


function bouncePppoeConnection() {
    //Bounce the PPPoE connection
    switch (model) {
        case 'SR515ac':
            log('Rebooting, because the CPE is dumb', {model: model});
            declare("Reboot", null, {value: Date.now()});
            break;
        case 'SR510N':
        default:
            log('Bouncing the WANPPPConnection instances');
            declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPPConnection.*.Reset", {value: now}, {value: true});
    }
}

I would like to understand which is the best configuration because for example now I run the force_refresh on 0 BOOSTRAP and get_creds on 1 BOOT but by doing so if I then look for that CPE through the serial number I cannot find it because there is no copy of the data in the database there is