This is method is overly complex and should be broken down. When
reducing the max complexity allowed by flake8 this method was flagged.
Reducing the complexity of this method will allow better testing and
maintenance.
Partial-Bug: #1501331
Change-Id: Id0bdb2d03614ba31de0d96ed09c33695d933b9f7