How I Learned to Stop Fearing Blueprints and Love cfy-lint

Writing a blueprint might be one of the hardest tasks for new or experienced users, so why would you punish yourself by writing a blueprint the old way? Cloudify’s cfy-lint tool makes writing new blueprints or improving existing ones easier. 

In this article, I’ll explain some of the errors cfy-lint can identify and how to fix errors automatically. We’ll go over some use cases of cfy-lint, since the examples in this article use sample blueprints filled with errors, we didn’t upload them to a Git repo, but the article has links for each example in the relevant section to each example. 

I’ll run through seven examples that highlights the new feature with the cfy-lint tool:  

  1. Blueprints Import Issues 
  1. Inputs 
  1. dsl_def 
  1. client_config 
  1. Unimported & Deprecated 
  1. Missing Relationships 
  1. Trailing-spaces, Empty-lines, Braces, and Commas 

The first function of cfy-lint is identifying errors in blueprints. The types of errors cfy-lint is capable of identifying includes validating node types used, intrinsic function are supported by the DSL version used, validating relationships, that all inputs have an explicit type are used and have a display label, trailing white spaces and extra empty lines and many more issues.  

The second function is to automatically fix unambiguous issues in a blueprint. For example, if a deprecated node is used in a blueprint, cfy-lint can replace it with the corresponding recommended node, or if you forgot to add display labels to all inputs, cfy-lint can take care of it, or getting rid of trailing whitespaces & extra empty lines. 
 
In order to install cfy-lint you can simply run `pip install cfy-lint` or go to PyPi or the GitHub repository

Before we begin, here are some important flags: 

  • `-b` is used to indicate the path to the blueprint, default: blueprint.yaml 
  • `-af` will fix all (supported auto fix) issues in place 
  • `–fix` fixes a single issue in place, to use this `–fix <issue type>:<line number>` 

1. Blueprints Import Issues & DSL Version 

Add blueprint link 

Let’s look at the blueprint and errors cfy-lint found. 

The first issue on line 1 is that we want to use cloudify_dsl_1_7 when as the time of writing this the latest version is 1_4, with 5 to be released in the future. 
 
On line 6, we see an import for Cloudify’s Azure plugin, but we recommend removing it as it’s not being used. 

On line 7, we try to use a scheme that doesn’t exists, we should import plugins, Cloudify types or links. 

On line 11, we see that since we don’t have an existing tosca_definitions_version, cfy-lint fails in validating that the input type is supported.   

To summarize, cfy-lint validates the tosca_definitions_version we use, our imports, and that the input types corresponding to the Tosca version. For more information on what inputs are supported in each tosca_definitions_version check out our documentation. 

2. Inputs 

Let’s look at the blueprint and errors cfy-lint found. 

The first error states that the aws_region_name is missing a display label. Cfy-lint’s auto fix can add one for you automatically. 

The second error informs us that the input foo is unused, we can either delete it or find out where was it supposed to be used. 

The third error lets us know that foo needs to specify a type and gives us a suggestion. 

The last error tells us that we typed FALSE/TRUE with different casing that is suggested, using cfy-lint we can fix the issue automatically. 

3. dsl_def 

Let’s look at the blueprint and error cfy-lint found. 

The error found tells us that we are using invalid parameters in our client_config. On line 25 it states that the node that calls client_config first in our blueprint (on line 36), we should simply delete line 20 to fix this issue. 

4. client_config 

Let’s look at the blueprint and errors cfy-lint found. 

We can see in the example below that the client_config is commented out on line 87 (for the example to have an error on the VM node). 

The second error on line 115 indicates that we used the deprecated property aws_config and should rename it client_config, this issue can also be fixed using cfy-lint auto fix. 

5. Unimported & Deprecated 

Let’s look at the blueprint and errors cfy-lint found. 

We can see that both errors are referencing the node ip_bad from line 137. 

The first issue states that the node type in question is deprecate and should be replaced, we can do this manually or using cfy-lint auto fix. 

The second error happens because in this blueprint we did not import cloudify-azure-plugin where the node cloudify.azure.nodes.network.PublicIPAddress is defined. 

6. Missing Relationships 

Let’s look at the example below. 

We can see on line 105 & 106 we have a relationship targeted at a node called amii, it does not exist in the blueprint, we are given a list of possible targets that we can use instead. 

7. Trailing-spaces, Empty-lines, Braces, and Commas 

In the example below we can see an array of styling errors, all of which can be fixed using the cfy-lint auto fix.  

Conclusion 

The upgraded cfy-lint tool can helps developers is a variety of ways. We saw from the examples above that we can identify errors and have them fixed automatically, including unambiguous issues in a blueprint.  

We learned how to identify errors and how simple it is to fix them, like in example one that validated the Tosca definition version. In another example we looked at inputs and how the cfy-lint found missing labels, unused terms, and how it suggests types.  

Read more about Cloudify’s new feature form version 7.0 in the release notes.  

comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Back to top