Skip to content

codecharacter/devops-take-home

Repository files navigation

DevOps Take Home - Python Challenge

Note: this was a take home assignment for a DevOps interview in 2022

Take an IP address and determine if it's in a range of CIDRs

made-with-python

Personal Statement

Thank you for the opportunities - to learn, to grow, and to be challenged to produce a higher quality output. I appreciate the time, patience and consideration.

And while I may not be confused for Kent Beck or Brian Okken anytime soon, this exercise has helped me practically pursue improvement.

I understand this process is to help us both see if we're a good fit. So, in an effort to be intellectually honest, I've captured my learnings to date and added notes at: Testing, Test Driven Development, Unit Testing, and Pytest Framework. In completing this exercise, I've only referenced what I could search online.

I fully appreciate you have to build the team to meet the needs of the business. I will always respect that. In the end we both want to be each other's first choice.

I know there are things I need to work on and will continue to sharpen going forward. And am confident I can efficiently manage any gaps. Again, thank you for your time and the opportunity. I look forward to meeting soon.

Requirements

  • Take IP address as a command line argument
  • Get JSON data from RIPE Network Coordination Center
  • Using the ipv4 block in JSON:
    • Determine whether IP address provided on CLI is in any of the CIDRs
  • Output a Pass/Fail result
    • based on the presence of the IP address in the CIDR ranges

How to Setup

Run the following commands given Python 3.7+ is installed.

Developed on Python Version: 3.9.13 (pyenv local 3.9.13)

OS X & Linux:

# Clone repo from codecharacter GitHub
git clone https://github.com/codecharacter/devops-take-home.git
cd devops-take-home

# (Recommended) Set up virtual environment to safeguard from any package conflicts with current
python3 -m venv venv
source venv/bin/activate

# For running tests, install/restore dependencies from the requirements-dev.txt file
pip install -r requirements-dev.txt

# For running the script without test framework install/restore from requirements.txt
pip install -r requirements.txt

Usage Examples

# Navigate to script directory
cd devops-take-home
python main.py [IPv4 address]

Example:
python main.py 2.56.8.1

Example Output for a PASS:

Example Output for a Fail:

Running Tests

Framework: pytest

# In cloned GitHub directory (you may very well be aware of all this)
cd devops-take-home

pytest  # Run all tests
pytest tests/[filename].py  # Run any individual test

# Pytest coverage report
pytest --cov

Libraries/Tools Used

  • argparse (Std Lib)
    • The recommended command-line parsing module in the Python standard library.
    • argparse provides options:
      • positional arguments,
      • default value for arguments,
      • help message,
      • specifying data types of argument
  • ipaddress (Std Lib)
    • provides many capabilities to work with IP addresses (input) and networks (CIDRs)
    • including relevant to this task:
      • checking validity of an IP address (input)
      • iterating over all hosts in a particular subnet (CIDR)
  • requests (PyPI)
    • a simple HTTP library in Python that allows sending requests easily
    • abstracts complexities of making requests so focus can be on consuming data & interacting with services
    • relevant features:
      • keep-alive & connection pooling
      • timeouts
      • sessions
  • responses (PyPI)
    • a utility library for mocking out the requests Python library
    • including integration with unit test frameworks, and more:
      • responses as a pytest fixture
      • assertions on declared responses
  • pytest (PyPI)
    • testing framework used to write tests for this exercise
    • alternate testing framework available (not used): unittest
    • generally, easy to use, available resources online, usable output
      • ability to filter tests
      • allows test parametrization
  • pytest-cov (PyPI)
    • plugin that produces coverage reports

Workflow for Selecting Packages

I collected this workflow from one of the training courses I completed and applying when possible.

1. Find Candidate Packages

2. Check Package Popularity

  • Check download stats if available
  • Google/Reddit/SO recommendations
  • GitHub 'stars' (visible on PyPI)
  • python.libhunt.com popularity indicator

3. Check Project Homepage

  • Is it helpful?
  • Is it well-maintained?
  • How "successful" does the project look?

4. Check Project README

  • Does it cover what the project does & how to install it?
  • What license is the project under?
  • Who is the author?

5. Is the Project Actively Maintained?

  • Skim the changelog/update history
  • Is there activity on the bug tracker?
  • When was the last commit of the project?

6. Spot-Check the Source Code

  • note: looking to grow in my ability to do this; principles apply
  • Does it follow best practices? (formatting, style, comments, docstrings)
  • Are there (automated) tests?
  • How experienced were the developers who wrote it?
  • Would I feel comfortable making small changes if I had to?
    • if I had to maintain the library going forward

7. Try Out a Few Candidates

  • Take the (narrowed down) list of candidates and try them out in an interpreter session.
  • Does the package install and import cleanly?
  • Do I enjoy working with the package?

Resources

Release History

  • 2.0
    • Submitted 7/1/2022
  • 1.0
    • Submitted 6/24/2022

Info: Dan Wadleigh

https://github.com/codecharacter

About

DevOps take home exercise: Python | Pytest

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages