Browse Source

Merge pull request #9511 from Miciah/sdn-check-ignore-node's-canonical-name

SDN check: Ignore node's canonical name
OpenShift Merge Robot 6 years ago
parent
commit
03d98d8f8c

+ 6 - 4
roles/openshift_health_checker/openshift_checks/sdn.py

@@ -119,7 +119,7 @@ class SDNCheck(OpenShiftCheck):
         """
         self.register_file(path, self.read_command_output(command))
 
-    def read_command_output(self, command):
+    def read_command_output(self, command, utf8=True):
         """Execute the provided command using the command module
         and return its output.
 
@@ -141,7 +141,9 @@ class SDNCheck(OpenShiftCheck):
                 'RemoteCommandFailure',
                 'Failed to execute command on remote host: %s' % command)
 
-        return result['stdout'].encode('utf-8')
+        if utf8:
+            return result['stdout'].encode('utf-8')
+        return result['stdout']
 
     def check_master(self):
         """Gather diagnostic information on a master and ensure it can connect
@@ -425,7 +427,7 @@ class SDNCheck(OpenShiftCheck):
         """Look up the given IPv4 address using getent."""
         command = ' '.join(['/bin/getent', 'ahostsv4', addr])
         try:
-            out = self.read_command_output(command)
+            out = self.read_command_output(command, False)
         except OpenShiftCheckException as exc:
             raise OpenShiftCheckException(
                 'NameResolutionError',
@@ -433,7 +435,7 @@ class SDNCheck(OpenShiftCheck):
 
         for line in out.splitlines():
             record = line.split()
-            if record[1:3] == ['STREAM', addr]:
+            if record[1] == 'STREAM':
                 return record[0]
 
         return None

+ 28 - 0
roles/openshift_health_checker/test/sdn_tests.py

@@ -1,5 +1,6 @@
 import pytest
 from openshift_checks.sdn import SDNCheck
+from openshift_checks import OpenShiftCheckException
 
 
 def fake_execute_module(*args):
@@ -170,6 +171,33 @@ def test_check_nodes():
     SDNCheck(execute_module, task_vars).run()
 
 
+def test_resolve_address():
+    def execute_module(module_name, args, *_):
+        if module_name != 'command':
+            raise ValueError('not expecting module %s' % module_name)
+
+        command_args = args['_raw_params'].split()
+        if command_args[0] != '/bin/getent':
+            raise ValueError('not expecting command: %s' % args.raw_params)
+
+        # The expected command_args is ['/bin/getent', 'ahostsv4', 'foo'].
+        if command_args[2] == 'foo':
+            return {
+                'rc': 0,
+                'stdout': '''1.2.3.4         STREAM bar
+1.2.3.4         DGRAM
+1.2.3.4         RAW
+'''
+            }
+
+        return {'rc': 2}
+
+    check = SDNCheck(execute_module, None)
+    assert check.resolve_address('foo') == '1.2.3.4'
+    with pytest.raises(OpenShiftCheckException):
+        check.resolve_address('baz')
+
+
 def test_no_nodes():
     task_vars = dict(
         group_names=['oo_masters_to_config'],