Week 3 recap¶
Monday¶
Cookiecutter
- Provides
- Linting, docstrings & code style
- Packaging & Dependency Management
- Docker Container Strategy
- CLI Application
- Doc building
- Testing
- Execution of builds, testing, etc.
- Tools
- Cookiecutter – Deliver and re-use the project templates
- Docker & Docker Compose - Container and containers management
- Poetry – dependency management and package publishing
- Invoke – Replacement for Makefiles, used by developers
- Click – Python CLI application, consumed by users
- Mkdocs (EM-K-Docs) - docs hosting standard
- Linters
- Python Black - Used for formatting
- Bandit - Security enforcement
- Pylint - Style enforcement
- Flake8 - Error checking and style enforcement
- Yamllint - Linter for yaml files
- Pydocstyle - docstring enforcement
- Mypy - Static typing
- Pytest - Python testing framework
- Creation of cookiecutter is to issue
cookiecutterto folder- Answer a series of questions and it "bakes" the cookie
- Primary mechanism to work with development environment is via invoke commands, such as
- Build your container
- Enter the container
- Run Tests
Workflow Discovery
- Need to understand the workflow before you attempt to automate it
- Often used within the context of a Strategic Architecture, Design Analysis (formerly called an Assessment)
- Collect key metrics
- How often?
- How much engineering time?
- How long to fulfill?
- Opportunity cost?
- Avoid ambiguity in metrics
- Direct Outcomes
- Workflow Metrics
- Diagram and step-by-step description of the Current Workflow
- Diagram and step-by-step description of the Automated Workflow
- Workflow recommendations and Analysis
- Indirect outcomes
- List of all the integrations (SoRs and others) and dependencies
- Network design reference
- The key/real stakeholders
- The value this process being automated will have (useful for prioritization)
- Uncover institutional and tribal knowledge
- Validated assumptions about how this process works
- Reference to acronyms
- Roles within a meeting
- Driver - drives the conversation
- Observer - documents the process
- Copilot - asks clarifying questions
- Each step is
- An input
- A process
- An output
- Helpful link: https://networktocode.atlassian.net/wiki/spaces/AAG/pages/1507229699/Assessment+and+Workflow+Links
- Helpful link: https://drive.google.com/drive/u/0/folders/1DrWyC5AoyoMD0WL67I5evQIBFuvfgvsB
Tuesday¶
Patterns and Nomenclature
- Imperative - A programming paradigm that uses statements to change a program's state
- Idempotent - An operation is idempotent if performing it multiple times yields the same result as performing it once
- Declarative - A programming paradigm that expresses the logic without describing its control flow
- DRY - A software development principle urging one to reduce repetition of code patterns
- Dispatcher - A method responsible for directing requests or tasks to appropriate handlers or methods based on certain criteria
- Inheritance - A mechanism where a new class derives properties and behaviors (methods) from an existing class
- Principle of Least Astonishment - Design principle stating that a system should behave in a manner consistent with how users expect it to, minimizing their surprise
- Robustness principle (Postel's Law) - Be conservative in what you send, be liberal in what you accept
- State Machine - A computational model designed to be in one of a finite number of states at any given time, transitioning between them based on inputs
Logging Best Practices
- Create an instance of the logging framework
- Leverage the logging levels (debug, info, warning, error, critical) in your logs
- The
loggingmodule has constants for each of the logging levels integers, e.g.logging.DEBUG - Logging supports formats
- Do not f-strings or format in your logs, instead use the % operator
Idempotent
- Mechanism to only make change if not in current state
- Generally completed by checking the current state to see if it is in it's desired state and if so, make no action
- Per REST (RFC 7231) PUT and DELETE are idempotent, PATCH and POST are not.
- Using set theory to build your idempotent logic
- Declarative functions are idempotent, but idempotent commands are not necessarily declarative
- Helpful Link: https://campusnetworkengineering.com/posts/practical-automation-series-part-3/
- Helpful Link: https://blog.networktocode.com/post/Principle-Series-Idempotent/
Wednesday¶
Declarative
- Describes the end state, not the steps to get there
- Leverages set theory
- Generally solved by getting what is missing and what is extra
- Used in SALT and Terraform
- Is in fact idempotent
- Helpful Link: https://blog.networktocode.com/post/Principle-Declarative-Imperative/
Dispatcher
- Dispatcher directs tasks, calls, or requests based on certain criteria
- Generally many if-else statements indicate a dispatcher idea
- Dictionary mapping the function object to be callable at run time
- Have to consider function signature, but can send in kwargs
- Easier to be explicit and map everything
- Reviewed
import_stringand how to use a dispatcher with that
Inheritance
- Great for reusability of code
- Great to extend existing code
- Can override methods in Python classes
- Can still call parent class with
superon any method - Be considerate about where
superis called - Concept is not limited to Python classes, used in Ansible variable structure, Nautobot Config Context, etc.
- Helpful Link: https://blog.networktocode.com/post/Principle-Series-Inhertiance/