diff options
Diffstat (limited to 'roles')
26 files changed, 420 insertions, 115 deletions
diff --git a/roles/lib_openshift/library/oadm_manage_node.py b/roles/lib_openshift/library/oadm_manage_node.py index 8c0a29ac7..612f62e81 100644 --- a/roles/lib_openshift/library/oadm_manage_node.py +++ b/roles/lib_openshift/library/oadm_manage_node.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1344,7 +1345,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_adm_ca_server_cert.py b/roles/lib_openshift/library/oc_adm_ca_server_cert.py index bbcd9d0c5..775fefb05 100644 --- a/roles/lib_openshift/library/oc_adm_ca_server_cert.py +++ b/roles/lib_openshift/library/oc_adm_ca_server_cert.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1352,7 +1353,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_adm_policy_group.py b/roles/lib_openshift/library/oc_adm_policy_group.py index 0ab1c8d49..be32d42e0 100644 --- a/roles/lib_openshift/library/oc_adm_policy_group.py +++ b/roles/lib_openshift/library/oc_adm_policy_group.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1330,7 +1331,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_adm_policy_user.py b/roles/lib_openshift/library/oc_adm_policy_user.py index 91bd85122..f76295fb9 100644 --- a/roles/lib_openshift/library/oc_adm_policy_user.py +++ b/roles/lib_openshift/library/oc_adm_policy_user.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1330,7 +1331,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_adm_registry.py b/roles/lib_openshift/library/oc_adm_registry.py index dcfc326a9..dc9aadf36 100644 --- a/roles/lib_openshift/library/oc_adm_registry.py +++ b/roles/lib_openshift/library/oc_adm_registry.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1448,7 +1449,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): @@ -2266,7 +2267,6 @@ class Registry(OpenShiftCLI): def exists(self): '''does the object exist?''' - self.get() if self.deploymentconfig and self.service: return True @@ -2327,7 +2327,8 @@ class Registry(OpenShiftCLI): service.put('spec.portalIP', self.portal_ip) # the dry-run doesn't apply the selector correctly - service.put('spec.selector', self.service.get_selector()) + if self.service: + service.put('spec.selector', self.service.get_selector()) # need to create the service and the deploymentconfig service_file = Utils.create_tmp_file_from_contents('service', service.yaml_dict) diff --git a/roles/lib_openshift/library/oc_adm_router.py b/roles/lib_openshift/library/oc_adm_router.py index 68b797577..00a1015a9 100644 --- a/roles/lib_openshift/library/oc_adm_router.py +++ b/roles/lib_openshift/library/oc_adm_router.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1473,7 +1474,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_edit.py b/roles/lib_openshift/library/oc_edit.py index 0347644eb..ae19a9094 100644 --- a/roles/lib_openshift/library/oc_edit.py +++ b/roles/lib_openshift/library/oc_edit.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1372,7 +1373,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_env.py b/roles/lib_openshift/library/oc_env.py index e343c70df..40240b17d 100644 --- a/roles/lib_openshift/library/oc_env.py +++ b/roles/lib_openshift/library/oc_env.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1339,7 +1340,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_label.py b/roles/lib_openshift/library/oc_label.py index c4ed42bbe..e0147790b 100644 --- a/roles/lib_openshift/library/oc_label.py +++ b/roles/lib_openshift/library/oc_label.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1348,7 +1349,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_obj.py b/roles/lib_openshift/library/oc_obj.py index 863443517..54914d484 100644 --- a/roles/lib_openshift/library/oc_obj.py +++ b/roles/lib_openshift/library/oc_obj.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1351,7 +1352,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_objectvalidator.py b/roles/lib_openshift/library/oc_objectvalidator.py index f6802a9b3..3b005f1b7 100644 --- a/roles/lib_openshift/library/oc_objectvalidator.py +++ b/roles/lib_openshift/library/oc_objectvalidator.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1283,7 +1284,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_process.py b/roles/lib_openshift/library/oc_process.py index 03c9d2044..f215b09a7 100644 --- a/roles/lib_openshift/library/oc_process.py +++ b/roles/lib_openshift/library/oc_process.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1340,7 +1341,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_project.py b/roles/lib_openshift/library/oc_project.py index 812c67de5..147813693 100644 --- a/roles/lib_openshift/library/oc_project.py +++ b/roles/lib_openshift/library/oc_project.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1337,7 +1338,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_route.py b/roles/lib_openshift/library/oc_route.py index 2ce3824e9..e487147dc 100644 --- a/roles/lib_openshift/library/oc_route.py +++ b/roles/lib_openshift/library/oc_route.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1382,7 +1383,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_scale.py b/roles/lib_openshift/library/oc_scale.py index c9e9b1790..8257040b3 100644 --- a/roles/lib_openshift/library/oc_scale.py +++ b/roles/lib_openshift/library/oc_scale.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1326,7 +1327,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_secret.py b/roles/lib_openshift/library/oc_secret.py index 6058f0ee2..cff27083f 100644 --- a/roles/lib_openshift/library/oc_secret.py +++ b/roles/lib_openshift/library/oc_secret.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1372,7 +1373,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_service.py b/roles/lib_openshift/library/oc_service.py index 8f6303a66..5b4a8271e 100644 --- a/roles/lib_openshift/library/oc_service.py +++ b/roles/lib_openshift/library/oc_service.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1378,7 +1379,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_serviceaccount.py b/roles/lib_openshift/library/oc_serviceaccount.py index 7d78c96d0..ea178f4ee 100644 --- a/roles/lib_openshift/library/oc_serviceaccount.py +++ b/roles/lib_openshift/library/oc_serviceaccount.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1324,7 +1325,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_serviceaccount_secret.py b/roles/lib_openshift/library/oc_serviceaccount_secret.py index c058c555b..39d2c3ef8 100644 --- a/roles/lib_openshift/library/oc_serviceaccount_secret.py +++ b/roles/lib_openshift/library/oc_serviceaccount_secret.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1324,7 +1325,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/library/oc_version.py b/roles/lib_openshift/library/oc_version.py index 4e65b8a0a..e4e4833c0 100644 --- a/roles/lib_openshift/library/oc_version.py +++ b/roles/lib_openshift/library/oc_version.py @@ -33,6 +33,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os @@ -1296,7 +1297,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/src/class/oc_adm_registry.py b/roles/lib_openshift/src/class/oc_adm_registry.py index 37904c43f..a9911966b 100644 --- a/roles/lib_openshift/src/class/oc_adm_registry.py +++ b/roles/lib_openshift/src/class/oc_adm_registry.py @@ -119,7 +119,6 @@ class Registry(OpenShiftCLI): def exists(self): '''does the object exist?''' - self.get() if self.deploymentconfig and self.service: return True @@ -180,7 +179,8 @@ class Registry(OpenShiftCLI): service.put('spec.portalIP', self.portal_ip) # the dry-run doesn't apply the selector correctly - service.put('spec.selector', self.service.get_selector()) + if self.service: + service.put('spec.selector', self.service.get_selector()) # need to create the service and the deploymentconfig service_file = Utils.create_tmp_file_from_contents('service', service.yaml_dict) diff --git a/roles/lib_openshift/src/lib/base.py b/roles/lib_openshift/src/lib/base.py index d037074a5..3bc34a675 100644 --- a/roles/lib_openshift/src/lib/base.py +++ b/roles/lib_openshift/src/lib/base.py @@ -577,7 +577,7 @@ class OpenShiftCLIConfig(object): self.kubeconfig = kubeconfig self.name = rname self.namespace = namespace - self._options = options + self._options = collections.OrderedDict(options) @property def config_options(self): diff --git a/roles/lib_openshift/src/lib/import.py b/roles/lib_openshift/src/lib/import.py index a79297898..97e03062e 100644 --- a/roles/lib_openshift/src/lib/import.py +++ b/roles/lib_openshift/src/lib/import.py @@ -7,6 +7,7 @@ from __future__ import print_function import atexit +import collections import copy import json import os diff --git a/roles/lib_openshift/src/test/unit/oc_adm_ca.py b/roles/lib_openshift/src/test/unit/oc_adm_ca.py deleted file mode 100755 index 836285ac6..000000000 --- a/roles/lib_openshift/src/test/unit/oc_adm_ca.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python2 -''' - Unit tests for oadm certificate authority -''' -# To run -# python -m unittest version -# -# . -# Ran 1 test in 0.597s -# -# OK - -import os -import sys -import unittest -import mock - -# Removing invalid variable names for tests so that I can -# keep them brief -# pylint: disable=invalid-name,no-name-in-module -# Disable import-error b/c our libraries aren't loaded in jenkins -# pylint: disable=import-error -# place class in our python path -module_path = os.path.join('/'.join(os.path.realpath(__file__).split('/')[:-4]), 'library') # noqa: E501 -sys.path.insert(0, module_path) -from oadm_ca import CertificateAuthority # noqa: E402 - - -# pylint: disable=too-many-public-methods -class OadmCATest(unittest.TestCase): - ''' - Test class for oadm_ca - ''' - - def setUp(self): - ''' setup method will set to known configuration ''' - pass - - @mock.patch('oadm_ca.Utils.create_tmpfile_copy') - @mock.patch('oadm_ca.CertificateAuthority._run') - def test_state_list(self, mock_cmd, mock_tmpfile_copy): - ''' Testing a get ''' - - - - params = {'cmd': 'create-server-cert', - 'signer_cert': '/etc/origin/master/ca.crt', - 'signer_key': '/etc/origin/master/ca.key', - 'signer_serial': '/etc/origin/master/ca.serial.txt', - 'hostnames': ['registry.test.openshift.com', - '127.0.0.1', - 'docker-registry.default.svc.cluster.local'], - 'cert': '/etc/origin/master/registry.crt', - 'key': '/etc/origin/master/registry.key', - 'kubeconfig': '/etc/origin/master/admin.kubeconfig', - 'private_key': None, - 'public_key': None, - 'cert_dir': None, - 'master': None, - 'public_master': None, - 'overwrite': False, - 'state': 'present', - 'debug': False} - - mock_cmd.side_effect = [ - (0, '', '') - ] - - mock_tmpfile_copy.side_effect = [ - '/tmp/mock_kubeconfig', - ] - - results = CertificateAuthority.run_ansible(params, False) - import pdb; pdb.set_trace() - - self.assertFalse(results['changed']) - self.assertEqual(results['results']['results'][0]['metadata']['name'], 'mysql-ephemeral') - - def tearDown(self): - '''TearDown method''' - pass - - -if __name__ == "__main__": - unittest.main() diff --git a/roles/lib_openshift/src/test/unit/test_oc_adm_registry.py b/roles/lib_openshift/src/test/unit/test_oc_adm_registry.py new file mode 100755 index 000000000..a663c5a97 --- /dev/null +++ b/roles/lib_openshift/src/test/unit/test_oc_adm_registry.py @@ -0,0 +1,370 @@ +#!/usr/bin/env python +''' + Unit tests for oc adm registry +''' + +import os +import six +import sys +import unittest +import mock + +# Removing invalid variable names for tests so that I can +# keep them brief +# pylint: disable=invalid-name,no-name-in-module +# Disable import-error b/c our libraries aren't loaded in jenkins +# pylint: disable=import-error +# place class in our python path +module_path = os.path.join('/'.join(os.path.realpath(__file__).split('/')[:-4]), 'library') # noqa: E501 +sys.path.insert(0, module_path) +from oc_adm_registry import Registry, locate_oc_binary # noqa: E402 + + +# pylint: disable=too-many-public-methods +class RegistryTest(unittest.TestCase): + ''' + Test class for Registry + ''' + dry_run = '''{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ServiceAccount", + "apiVersion": "v1", + "metadata": { + "name": "registry", + "creationTimestamp": null + } + }, + { + "kind": "ClusterRoleBinding", + "apiVersion": "v1", + "metadata": { + "name": "registry-registry-role", + "creationTimestamp": null + }, + "userNames": [ + "system:serviceaccount:default:registry" + ], + "groupNames": null, + "subjects": [ + { + "kind": "ServiceAccount", + "namespace": "default", + "name": "registry" + } + ], + "roleRef": { + "kind": "ClusterRole", + "name": "system:registry" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "docker-registry", + "creationTimestamp": null, + "labels": { + "docker-registry": "default" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + } + ], + "replicas": 1, + "test": false, + "selector": { + "docker-registry": "default" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "docker-registry": "default" + } + }, + "spec": { + "volumes": [ + { + "name": "registry-storage", + "emptyDir": {} + } + ], + "containers": [ + { + "name": "registry", + "image": "openshift3/ose-docker-registry:v3.5.0.39", + "ports": [ + { + "containerPort": 5000 + } + ], + "env": [ + { + "name": "REGISTRY_HTTP_ADDR", + "value": ":5000" + }, + { + "name": "REGISTRY_HTTP_NET", + "value": "tcp" + }, + { + "name": "REGISTRY_HTTP_SECRET", + "value": "WQjSGeUu5KFZRTwGeIXgwIjyraNDLmdJblsFbtzZdF8=" + }, + { + "name": "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_ENFORCEQUOTA", + "value": "false" + } + ], + "resources": { + "requests": { + "cpu": "100m", + "memory": "256Mi" + } + }, + "volumeMounts": [ + { + "name": "registry-storage", + "mountPath": "/registry" + } + ], + "livenessProbe": { + "httpGet": { + "path": "/healthz", + "port": 5000 + }, + "initialDelaySeconds": 10, + "timeoutSeconds": 5 + }, + "readinessProbe": { + "httpGet": { + "path": "/healthz", + "port": 5000 + }, + "timeoutSeconds": 5 + }, + "securityContext": { + "privileged": false + } + } + ], + "nodeSelector": { + "type": "infra" + }, + "serviceAccountName": "registry", + "serviceAccount": "registry" + } + } + }, + "status": { + "latestVersion": 0, + "observedGeneration": 0, + "replicas": 0, + "updatedReplicas": 0, + "availableReplicas": 0, + "unavailableReplicas": 0 + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "docker-registry", + "creationTimestamp": null, + "labels": { + "docker-registry": "default" + } + }, + "spec": { + "ports": [ + { + "name": "5000-tcp", + "port": 5000, + "targetPort": 5000 + } + ], + "selector": { + "docker-registry": "default" + }, + "clusterIP": "172.30.119.110", + "sessionAffinity": "ClientIP" + }, + "status": { + "loadBalancer": {} + } + } + ]}''' + + + @mock.patch('oc_adm_registry.Utils._write') + @mock.patch('oc_adm_registry.Utils.create_tmpfile_copy') + @mock.patch('oc_adm_registry.Registry._run') + def test_state_list(self, mock_cmd, mock_tmpfile_copy, mock_write): + ''' Testing state present ''' + params = {'state': 'present', + 'debug': False, + 'namespace': 'default', + 'name': 'docker-registry', + 'kubeconfig': '/etc/origin/master/admin.kubeconfig', + 'images': None, + 'latest_images': None, + 'labels': None, + 'ports': ['5000'], + 'replicas': 1, + 'selector': 'type=infra', + 'service_account': 'registry', + 'mount_host': None, + 'volume_mounts': None, + 'env_vars': {}, + 'enforce_quota': False, + 'force': False, + 'daemonset': False, + 'tls_key': None, + 'tls_certificate': None, + 'edits': []} + + mock_cmd.side_effect = [ + (1, '', 'Error from server (NotFound): deploymentconfigs "docker-registry" not found'), + (1, '', 'Error from server (NotFound): service "docker-registry" not found'), + (0, RegistryTest.dry_run, ''), + (0, '', ''), + (0, '', ''), + ] + + mock_tmpfile_copy.side_effect = [ + '/tmp/mocked_kubeconfig', + '/tmp/mocked_kubeconfig', + ] + + results = Registry.run_ansible(params, False) + + self.assertTrue(results['changed']) + for result in results['results']['results']: + self.assertEqual(result['returncode'], 0) + + mock_cmd.assert_has_calls([ + mock.call(['oc', 'get', 'dc', 'docker-registry', '-o', 'json', '-n', 'default'], None), + mock.call(['oc', 'get', 'svc', 'docker-registry', '-o', 'json', '-n', 'default'], None), + mock.call(['oc', 'adm', 'registry', '-n', 'default', '--replicas=1', '--selector=type=infra', + '--enforce-quota=False', '--service-account=registry', '--ports=5000', + '--daemonset=False', '--dry-run=True', '-o', 'json', '-n', 'default'], None), + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), ]) + + @unittest.skipIf(six.PY3, 'py2 test only') + @mock.patch('os.path.exists') + @mock.patch('os.environ.get') + def test_binary_lookup_fallback(self, mock_env_get, mock_path_exists): + ''' Testing binary lookup fallback ''' + + mock_env_get.side_effect = lambda _v, _d: '' + + mock_path_exists.side_effect = lambda _: False + + self.assertEqual(locate_oc_binary(), 'oc') + + @unittest.skipIf(six.PY3, 'py2 test only') + @mock.patch('os.path.exists') + @mock.patch('os.environ.get') + def test_binary_lookup_in_path(self, mock_env_get, mock_path_exists): + ''' Testing binary lookup in path ''' + + oc_bin = '/usr/bin/oc' + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_path_exists.side_effect = lambda f: f == oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) + + @unittest.skipIf(six.PY3, 'py2 test only') + @mock.patch('os.path.exists') + @mock.patch('os.environ.get') + def test_binary_lookup_in_usr_local(self, mock_env_get, mock_path_exists): + ''' Testing binary lookup in /usr/local/bin ''' + + oc_bin = '/usr/local/bin/oc' + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_path_exists.side_effect = lambda f: f == oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) + + @unittest.skipIf(six.PY3, 'py2 test only') + @mock.patch('os.path.exists') + @mock.patch('os.environ.get') + def test_binary_lookup_in_home(self, mock_env_get, mock_path_exists): + ''' Testing binary lookup in ~/bin ''' + + oc_bin = os.path.expanduser('~/bin/oc') + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_path_exists.side_effect = lambda f: f == oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) + + @unittest.skipIf(six.PY2, 'py3 test only') + @mock.patch('shutil.which') + @mock.patch('os.environ.get') + def test_binary_lookup_fallback_py3(self, mock_env_get, mock_shutil_which): + ''' Testing binary lookup fallback ''' + + mock_env_get.side_effect = lambda _v, _d: '' + + mock_shutil_which.side_effect = lambda _f, path=None: None + + self.assertEqual(locate_oc_binary(), 'oc') + + @unittest.skipIf(six.PY2, 'py3 test only') + @mock.patch('shutil.which') + @mock.patch('os.environ.get') + def test_binary_lookup_in_path_py3(self, mock_env_get, mock_shutil_which): + ''' Testing binary lookup in path ''' + + oc_bin = '/usr/bin/oc' + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_shutil_which.side_effect = lambda _f, path=None: oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) + + @unittest.skipIf(six.PY2, 'py3 test only') + @mock.patch('shutil.which') + @mock.patch('os.environ.get') + def test_binary_lookup_in_usr_local_py3(self, mock_env_get, mock_shutil_which): + ''' Testing binary lookup in /usr/local/bin ''' + + oc_bin = '/usr/local/bin/oc' + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_shutil_which.side_effect = lambda _f, path=None: oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) + + @unittest.skipIf(six.PY2, 'py3 test only') + @mock.patch('shutil.which') + @mock.patch('os.environ.get') + def test_binary_lookup_in_home_py3(self, mock_env_get, mock_shutil_which): + ''' Testing binary lookup in ~/bin ''' + + oc_bin = os.path.expanduser('~/bin/oc') + + mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin' + + mock_shutil_which.side_effect = lambda _f, path=None: oc_bin + + self.assertEqual(locate_oc_binary(), oc_bin) diff --git a/roles/lib_openshift/src/test/unit/test_oc_adm_router.py b/roles/lib_openshift/src/test/unit/test_oc_adm_router.py index 410ae3bd4..5184990e8 100755 --- a/roles/lib_openshift/src/test/unit/test_oc_adm_router.py +++ b/roles/lib_openshift/src/test/unit/test_oc_adm_router.py @@ -344,7 +344,6 @@ class RouterTest(unittest.TestCase): (0, '', ''), ] - mock_tmpfile_copy.side_effect = [ '/tmp/mocked_kubeconfig', ] @@ -362,10 +361,10 @@ class RouterTest(unittest.TestCase): mock.call(['oc', 'get', 'secret', 'router-certs', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'clusterrolebinding', 'router-router-role', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'adm', 'router', 'router', '-n', 'default', '--external-host-insecure=False', '--replicas=2', '--selector=type=infra', '--stats-port=1936', '--service-account=router', '--expose-metrics=False', '--ports=80:80,443:443', '--dry-run=True', '-o', 'json', '-n', 'default'], None), - mock.call(['oc', 'create', '-f', '/tmp/ClusterRoleBindingyDm_yh', '-n', 'default'], None), - mock.call(['oc', 'create', '-f', '/tmp/ServiceAccountbzYs4o', '-n', 'default'], None), - mock.call(['oc', 'create', '-f', '/tmp/ServiceWfYdjg', '-n', 'default'], None), - mock.call(['oc', 'create', '-f', '/tmp/DeploymentConfigxfIFpn', '-n', 'default'], None)]) + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), + mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None)]) @unittest.skipIf(six.PY3, 'py2 test only') @mock.patch('os.path.exists') |