Test Driven Infrastructure Bringing Software Development Techniques to Operations Alejandro González Pérez Ebury - alejandro.gonzalez@ebury.com
Infrastructure as Code: Why? - Reproducible Results - Avoid Snowflake Servers - Testable - Automate deploy & Recovery process - Easier autoscaling - Versioning 2
Infrastructure as Code: What we want to avoid 3
Infrastructure as Code: Principles - Write definition files to define your infrastructure - Keep it in VCS: Git, SVN, Mercurial, etc. - Self documented process “Treat your servers as cattle, not pets” It’s need testing. 4
Test Driven Infrastructure Why TDI? - The earlier we found the bug the cheaper - Focus on the code you need - Code Quality We need to bring techniques from Software Developers Teams and TDD it’s a great example. 5
TDI 6
Testing your Infrastructure - Why we need to add tests to infrastructure? Because It’s code. - What to test? I’m not asking you to test everything, just complex situations that can escape to your control. 7
TDD / TDI Diagram 8
Test Pyramid 9
Avoiding an Unbalanced Test suite 10
Test Pyramid: Low-level tests 11
Low level tests – Static analysis– Ansible - Ansible Lint - https://github.com/willthames/ansible-lint - Ansible-playbook -- check and -- diff options 12
Low level tests – Other Options 13
Test Pyramid: Medium-level tests 14
Medium Level Tests: Inspec - Testing framework - Written in ruby - Human Readable Syntax - You can run your tests via: local, ssh ,winrm or docker 15
Medium Level Tests: Inspec basic usage How to install? - inspec init profile [Profile Name] - inspec exec [folder] [-t target] 16
Medium Level Tests: Inspec Syntax 17
Medium Level Tests: Inspec syntax 18
Medium Level Tests: Inspec resources - Around 100 different resources - System: service, crontab, port, etc. - Specific software config file checking: nginx_conf, mysql_conf, etc. - File parsing, XML, Yaml, json, etc. If none of those suits you, you can use “bash” or “command” 19
Test Pyramid: High-level tests 20
High-level tests: Inspec 21
High-level tests: Testing your cloud Awspec: https://github.com/k1LoW/awspec 22
Test Pyramid: Summary 23
Integrate it with your workflow 24
Integrate it with your workflow: Ebury Example 25
Testing Frameworks 26
Summary Test your code. 27
Testing your Infrastructure Resources: - Infrastructure as Code http://shop.oreilly.com/product/0636920039297.do - Inspec io Official Documentation https://www.inspec.io/ - Ansible Official documentation http://docs.ansible.com/ansible/latest/playbooks_checkmode.html - Puppet: http://puppet-lint.com/ - FoodCritic: http://www.foodcritic.io/ - Test Driven Development http://www.agilenutshell.com/test_driven_development - Molecule: https://molecule.readthedocs.io/en/latest/ - KitchenCI: http://kitchen.ci/ 28
Demo
Questions?
THANK YOU!