Skip to content

Commit

Permalink
fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianvf committed Sep 28, 2017
1 parent 059870a commit c048a57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion openshift/helper/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def object_from_params(self, module_params, obj=None):
obj.string_data = None

logger.debug("Object from params:")
logger.debug(json.dumps(obj.to_dict(), indent=4))
logger.debug(obj.to_str())
return obj

def request_body_from_params(self, module_params):
Expand Down
21 changes: 15 additions & 6 deletions openshift/helper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ def has_method(self, method_action):
return False
return method is not None

def fix_serialization(self, obj):
if obj and obj.kind == "Service":
for port in obj.spec.ports:
try:
port.target_port = int(port.target_port)
except ValueError:
pass
return obj

def get_object(self, name=None, namespace=None):
k8s_obj = None
method_name = 'list' if self.kind.endswith('list') else 'read'
Expand Down Expand Up @@ -198,7 +207,7 @@ def patch_object(self, name, namespace, k8s_obj):
self.__remove_creation_timestamps(k8s_obj)
w, stream = self._create_stream(namespace)
return_obj = None
self.logger.debug("Patching object: {}".format(json.dumps(k8s_obj.to_dict())))
self.logger.debug("Patching object: {}".format(k8s_obj.to_str()))
try:
patch_method = self.lookup_method('patch', namespace)
if namespace:
Expand All @@ -215,7 +224,7 @@ def patch_object(self, name, namespace, k8s_obj):
if not return_obj or self.kind in ('project', 'namespace'):
return_obj = self._wait_for_response(name, namespace, 'patch')

return return_obj
return self.fix_serialization(return_obj)

def create_object(self, namespace=None, k8s_obj=None, body=None):
"""
Expand Down Expand Up @@ -257,7 +266,7 @@ def create_object(self, namespace=None, k8s_obj=None, body=None):
if not return_obj or self.kind in ('project', 'namespace'):
return_obj = self._wait_for_response(name, namespace, 'create')

return return_obj
return self.fix_serialization(return_obj)

def delete_object(self, name, namespace):
self.logger.debug('Starting delete object {0} {1} {2}'.format(self.kind, name, namespace))
Expand Down Expand Up @@ -342,7 +351,7 @@ def replace_object(self, name, namespace, k8s_obj=None, body=None):
if not return_obj or self.kind in ('project', 'namespace'):
return_obj = self._wait_for_response(name, namespace, 'replace')

return return_obj
return self.fix_serialization(return_obj)

@staticmethod
def objects_match(obj_a, obj_b):
Expand Down Expand Up @@ -557,7 +566,7 @@ def _read_stream(self, watcher, stream, name):
for event in stream:
obj = None
if event.get('object'):
obj_json = json.dumps(event['object'].to_dict())
obj_json = event['object'].to_str()
self.logger.debug(
"EVENT type: {0} object: {1}".format(event['type'], obj_json)
)
Expand Down Expand Up @@ -609,4 +618,4 @@ def _read_stream(self, watcher, stream, name):
self.logger.debug('STREAM FAILED: {}'.format(exc))
pass

return return_obj
return self.fix_serialization(return_obj)

0 comments on commit c048a57

Please sign in to comment.