-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor and Testing Augmentations Refactored the helm client commands to allow for better isolation between classes and easier unit testing. Also refactored some of the dependent classes to consume a helm client vs instantiate one. This will hopefully increase the ability to test each component for subtle bugs. See Changelog for more information. * Added tests around provider to assure it accepts HelmCommand and outputs HelmCmdResponse * Added test for not implemented * Adjusted verbosity of logging to be more palatable * Adjusted Client Since we're not in static type land we need to validate we instantiated with an iterator for default_helm_arguments. So now we allow to be instantiated with `None` and convert to `[]` and all other non-iterators raise an error. * Fixed problem calling exception method * Adjustments to docs and fixed a test confusion * Removed the always pass circle ci release
- Loading branch information
Showing
26 changed files
with
829 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
venvbuild | ||
dist | ||
venv | ||
.coverage | ||
htmlcov/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +0,0 @@ | ||
# -- coding: utf-8 -- | ||
|
||
# Copyright 2017 Reactive Ops Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License.__init__.py | ||
|
||
import subprocess | ||
import logging | ||
|
||
from exception import ReckonerCommandException | ||
|
||
|
||
class Response(object): | ||
""" | ||
Description: | ||
- Utility class to simplify the results from call() | ||
Arguments: | ||
- stdout(string) | ||
- stderr (string) | ||
- exitcode (sting,int) | ||
Attributes: | ||
- stdout | ||
- stderr | ||
- exitcode | ||
Returns: | ||
- Instance of Response() is truthy where Reponse.exitcode == 0 | ||
- Instance Response() is falsey where Reponse.exitcode != 0 | ||
""" | ||
|
||
def __init__(self, stdout, stderr, exitcode): | ||
|
||
self._dict = {} | ||
self._dict['stdout'] = stdout | ||
self._dict['stderr'] = stderr | ||
self._dict['exitcode'] = exitcode | ||
|
||
def __getattr__(self, name): | ||
return self._dict.get(name) | ||
|
||
def __str__(self): | ||
return str(self._dict) | ||
|
||
def __bool__(self): | ||
return not self._dict['exitcode'] | ||
|
||
def __eq__(self, other): | ||
return self._dict == other._dict | ||
|
||
|
||
def call(args, shell=False, executable=None): | ||
""" | ||
Description: | ||
- Wrapper for subprocess.Popen. Joins `args` and passes | ||
to `subprocess.Popen` | ||
Arguments: | ||
- args (list or string) | ||
Returns: | ||
- Instance of Response() | ||
""" | ||
if type(args) == str: | ||
args_string = args | ||
else: | ||
args_string = ' '.join(args) | ||
logging.debug(args_string) | ||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, executable=executable) | ||
stdout, stderr = p.communicate() | ||
exitcode = p.returncode | ||
|
||
if exitcode > 0: | ||
raise ReckonerCommandException("Error with subprocess call: {}".format(args_string), stdout, stderr, exitcode) | ||
return Response(stdout, stderr, exitcode) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# -- coding: utf-8 -- | ||
|
||
# Copyright 2017 Reactive Ops Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License.__init__.py | ||
|
||
import subprocess | ||
import logging | ||
|
||
|
||
class Response(object): | ||
""" | ||
Description: | ||
- Utility class to simplify the results from call() | ||
Arguments: | ||
- stdout(string) | ||
- stderr (string) | ||
- exitcode (sting,int) | ||
Attributes: | ||
- stdout | ||
- stderr | ||
- exitcode | ||
Returns: | ||
- Instance of Response() is truthy where Reponse.exitcode == 0 | ||
- Instance Response() is falsey where Reponse.exitcode != 0 | ||
""" | ||
|
||
def __init__(self, stdout, stderr, exitcode): | ||
|
||
self._dict = {} | ||
self._dict['stdout'] = stdout | ||
self._dict['stderr'] = stderr | ||
self._dict['exitcode'] = exitcode | ||
|
||
def __getattr__(self, name): | ||
return self._dict.get(name) | ||
|
||
def __str__(self): | ||
return str(self._dict) | ||
|
||
def __bool__(self): | ||
return not self._dict['exitcode'] | ||
|
||
def __eq__(self, other): | ||
return self._dict == other._dict | ||
|
||
|
||
def call(args, shell=False, executable=None): | ||
""" | ||
Description: | ||
- Wrapper for subprocess.Popen. Joins `args` and passes | ||
to `subprocess.Popen` | ||
Arguments: | ||
- args (list or string) | ||
Returns: | ||
- Instance of Response() | ||
""" | ||
if type(args) == str: | ||
args_string = args | ||
else: | ||
args_string = ' '.join(args) | ||
logging.debug(args_string) | ||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, executable=executable) | ||
stdout, stderr = p.communicate() | ||
exitcode = p.returncode | ||
|
||
return Response(stdout, stderr, exitcode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.