Top Banner
Lessons we learned developing infrastructure software at Box April 2018, Aleksandr Kuzminsky
33

Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Jun 23, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Lessons we learned developing infrastructure software at BoxApril 2018, Aleksandr Kuzminsky

Page 2: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Today’s agenda 1. Branching model

2. Tests

3. Dependencies

4. Artifacts

Page 3: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Git Flow: Develop and Master Branches

3

Page 4: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Git Flow: Feature Branches

4

Page 5: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Git Flow: Release Branches

5

Page 6: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Git Flow: Hotfix Branches

6

Page 7: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Security and Compliance on direct git-push

7

Page 8: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Box flow: based on git-flow

8

# git flow feature start innodb-fast

# git flow feature publish innodb-fast

• 📝 PR ⭃ develop branch• ✔️ CI must pass• 👀 CR is optional

Page 9: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Box flow: develop branch protection

9

ü Protect this branchü Require status checks to pass before mergingü Include administrators

Page 10: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Box flow: release

10

# git flow release start 1.2.3

# bumpversion patch

# git flow release publish 1.2.3

• 📝 PR ⭃ develop, PR ⭃ master• ✔️ CI tests must pass• 👀 CR is mandatory• 🎯 Comment fixes go to release/1.2.3

Page 11: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Box flow: master branch protection

11

ü Protect this branchü Require pull request reviews before mergingü Require status checks to pass before mergingü Include administrators

Page 12: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Box flow: hotfixes

12

# git flow hotfix start 1.2.4

# bumpversion patch

# git flow release publish 1.2.4

• 📝 PR ⭃ develop, PR ⭃ master• ✔️ CI tests must pass• 👀 CR is mandatory• 🎯 Comment fixes go to hotfix/1.2.4

Page 13: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Tests

Page 14: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Unit tests• Test Driven Development

• For critical classes• For bugs

• pytest for computations and files• unittest.mock for external resource and code

• MySQL instances, APIs, already tested code

14

Page 15: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Tests hierarchy

15

Page 16: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Tests hierarchy

16

Module

Page 17: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Tests hierarchy

17

Class

Page 18: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Tests hierarchy

18

Methods

Page 19: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytestdef test_multiply():

assert multiply(2, 3) == 6

19

Page 20: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytest: write test that failsfrom pydata import multiply

def test_multiply():assert multiply(2, 3) == 6

20

def multiply(x, y):return 0

$ pytest test/unit/test_demo.py

> assert multiply(2, 3) == 6

E assert 0 == 6E

+ where 0 = multiply(2, 3)

test/unit/test_demo.py:5: AssertionError

Page 21: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytest: fix implementationfrom pydata import multiply

def test_multiply():assert multiply(2, 3) == 6

21

def multiply(x, y):return x * y

$ pytest test/unit/test_demo.py

test/unit/test_demo.py::test_multiply PASSED [100%]

Page 22: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytest: parameterized tests

@pytest.mark.parametrize('x, y, result', [(2, 3, 6),(2, 2, 4)

])def test_multiply(x, y, result):

assert multiply(x, y) == result

22

Page 23: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytest: Expecting exceptions

@pytest.mark.parametrize('x, y', [(None, 1),(1, None),(None, None)

])def test_multiply(x, y):

with pytest.raises(ValueError):multiply(x, y)

23

Page 24: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

To mock or not to mock (for unit tests)• Mock:

• API calls• External code calls• Database queries• Anything external• already tested code

24

• No Mock:• Calculations• Objects manipulations• Anything that works with

CPU, memory, files

Page 25: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

pytest: mock API calls

@mock.patch(

‘pydata.call_api’

)def test_multiply(m_api):multiply(2, 3)

m_api.assert_called_once_with(

“http://x.com/x=2&y=3”

)

25

def multiply(x, y):

result = call_api(

“http://x.com/x=%d&y=%d”

% (x, y)

)return result

Page 26: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Further watching

Michael Tom-Wing, Christie Wilson - Introduction to Unit Testing in Python with Pytest - PyCon 2016https://youtu.be/UPanUFVFfzY

Bay PIGgies March 2017: Testing in Layershttps://youtu.be/pCrW_LiSb34

26

Page 27: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Dependencies

Page 28: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Artifacts: Local PyPI repo

28

Page 29: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

$ cat ~/.pip/pip.conf[global]extra-index-url = https://pypi.box.com/simple

29

Page 30: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Packages

Page 31: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

RPM Packages with Omnibus• Full-stack installers – RPM with no dependencies

• Includes Python+libs• No dependency hell• Doesn’t break existing packages• Python/modules version flexibility

• https://github.com/chef/omnibus

• Store in your Yum Repo of choice

31

Page 32: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Thank you!

Also, We’re Hiring!

32

Page 33: Lessons we learned developing infrastructure software at Box · # git flow hotfix start 1.2.4 # bumpversion patch # git flow release publish 1.2.4 • ! PR ⭃ develop, PR ⭃ master

Picture credits• https://www.atlassian.com/git/tutorials/comparing-

workflows/gitflow-workflow

33