Removing tags on 0 BOOTSTRAP event

Hi.

I am trying to create a pattern/template so that I get started with using genieacs effectively.

Assume a default installation of genieacs. (This comes with 3 predefined presets: bootstrap, default and inform).

I have only added a custom preset with an attached provision script that sets a PROVISIONED tag.

//contents of my custom script
const now = new Date();  
let tag = declare("Tags.PROVISIONED", { value: 1 });
if (tag.value != null) { 
   log("Tags.Provisioned already set, returning...");
   return; 
}

//TODO: do some custom settings here, like wifi, vlans, etc...

declare("Tags.PROVISIONED", null, { value: true });

I had done a single line modification to the bootstrap script that removes the PROVISIONED tag

//contents of bootstrap script
const now = Date.now();  
// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);  
//remove tag
declare("Tags.PROVISIONED", null, { value: false });

With these settings, all seems good. A CPE registers and it has the PROVISIONED tag set.

However, when I factory reboot the CPE (which invokes the 0 BOOTSTRAP event), I expect that the PROVISIONED tag will be removed by bootstrap script, and then eventually set again by my custom provision script once it’s done doing its job.

What instead happens is that I get an error:

Why is it the case? I browsed the forums and it has been repeatedly mentioned that this pattern of clearing Tags on bootstrap event and then doing work in a provision script and setting a tag to mark it as finished (so that it doesn’t get called again) is supposedly a good approach.

I sort of underestand why is it happening; provision scripts are executed until no changes are detected. In this case one script is removing the tag (the bootstrap script i modified) and the other keeps adding it (my custom script). This causes the infinite loop.

However I have no reasonable idea how to prevent it. Setting other tags? Using specific preconditions in presets? Any pattern that is recommended?

I actually care for the CPE to be provisioned in two scenarios: When it connects for the first time to an ACS (by this I mean that it hasn’t been yet registered in genieacs). In my case it has in this situation a '1 BOOT' event and when it is factory rebooted, it has '0 BOOTSTRAP'. Not sure how to marry these two events together with a tag without getting into the infinite loop.

You need to change the preset that runs your provision script to exclude bootstrap events. What you have right now is the bootstrap event firing which removes the tag. Then your provision set runs and adds it back. But provision scripts in GenieACS can run multiple times, and will run multiple times until no more changes are detected.

Thank you for pointers, the -0 BOOTSTRAP (negation) syntax is new to me and certainly useful.

I eventually deleted the line responsible for removal of the provisioned tag from the default bootstrap script I modified in the first post, so besides the default installation presets (default, inform, bootstrap) I have just two of my own and settled for a single provision script with this structure:

//TODO: custom declare settings here like vlans, wifi, etc.
declare('Tags.PROVISIONED, null, { value: true } );

That is referenced by two presets.

  1. for event: 0 BOOTSTRAP (factory reset)
  2. for event: -0 BOOTSTRAP with a precondition of: Tags.PROVISIONED IS NOT NULL (will handle any other event such as power reset/first acs contact like 1 BOOT, but the precondition ensures it is only called when the tag is not present)

This lets me share a single provision script for both cases which is a big benefit.

I would prefer to be able to remove the tag on 0 BOOTSTRAP event, to me it seems natural to start from a clean state, but it also seems there is no simple way to do it without introducing a loop.

However now I don’t like the fact that if an already provisioned CPE gets factory reset, the provisioned tag stays intact and I have to hope that the 0 BOOTSTRAP event provision succeeds, because if it doesn’t the CPE still (falsely) has a provisioned tag attached to it.

If there’s a clean way to handle this case I would be open to suggestions.

If you use the appropriate event filters there is absolutely a way of doing this. I’ve been doing it for many, many years with no issues.