diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-02-27 20:37:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-27 20:37:40 -0500 |
commit | b71d56847b27a39b7c6d9b64c5fdb0870e8d46c1 (patch) | |
tree | bb60a518f6f611d32a55911d9667f4f5a3f4a54d /roles/lib_openshift/src/class/oc_sdnvalidator.py | |
parent | 35203336a0294e5aee61ba845b0c7f0a326fe89a (diff) | |
parent | d20f526eb7adb27abd8d5c41c1e14c0eb22b0736 (diff) | |
download | openshift-b71d56847b27a39b7c6d9b64c5fdb0870e8d46c1.tar.gz openshift-b71d56847b27a39b7c6d9b64c5fdb0870e8d46c1.tar.bz2 openshift-b71d56847b27a39b7c6d9b64c5fdb0870e8d46c1.tar.xz openshift-b71d56847b27a39b7c6d9b64c5fdb0870e8d46c1.zip |
Merge pull request #3387 from enj/enj/f/sdn_module
Add SDNValidator Module
Diffstat (limited to 'roles/lib_openshift/src/class/oc_sdnvalidator.py')
-rw-r--r-- | roles/lib_openshift/src/class/oc_sdnvalidator.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/roles/lib_openshift/src/class/oc_sdnvalidator.py b/roles/lib_openshift/src/class/oc_sdnvalidator.py new file mode 100644 index 000000000..da923337b --- /dev/null +++ b/roles/lib_openshift/src/class/oc_sdnvalidator.py @@ -0,0 +1,58 @@ +# pylint: skip-file +# flake8: noqa + +# pylint: disable=too-many-instance-attributes +class OCSDNValidator(OpenShiftCLI): + ''' Class to wrap the oc command line tools ''' + + def __init__(self, kubeconfig): + ''' Constructor for OCSDNValidator ''' + # namespace has no meaning for SDN validation, hardcode to 'default' + super(OCSDNValidator, self).__init__('default', kubeconfig) + + def get(self, kind, invalid_filter): + ''' return SDN information ''' + + rval = self._get(kind) + if rval['returncode'] != 0: + return False, rval, [] + + return True, rval, filter(invalid_filter, rval['results'][0]['items']) + + # pylint: disable=too-many-return-statements + @staticmethod + def run_ansible(params): + ''' run the idempotent ansible code + + params comes from the ansible portion of this module + ''' + + sdnvalidator = OCSDNValidator(params['kubeconfig']) + all_invalid = {} + failed = False + + checks = ( + ( + 'hostsubnet', + lambda x: x['metadata']['name'] != x['host'], + u'hostsubnets where metadata.name != host', + ), + ( + 'netnamespace', + lambda x: x['metadata']['name'] != x['netname'], + u'netnamespaces where metadata.name != netname', + ), + ) + + for resource, invalid_filter, invalid_msg in checks: + success, rval, invalid = sdnvalidator.get(resource, invalid_filter) + if not success: + return {'failed': True, 'msg': 'Failed to GET {}.'.format(resource), 'state': 'list', 'results': rval} + if invalid: + failed = True + all_invalid[invalid_msg] = invalid + + if failed: + return {'failed': True, 'msg': 'All SDN objects are not valid.', 'state': 'list', 'results': all_invalid} + + return {'msg': 'All SDN objects are valid.'} |