|
@@ -1,13 +1,5 @@
|
|
|
-import copy
|
|
|
-import os
|
|
|
-import sys
|
|
|
+import pytest
|
|
|
|
|
|
-from ansible.errors import AnsibleError
|
|
|
-from nose.tools import raises, assert_equal
|
|
|
-
|
|
|
-sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../lookup_plugins/")] + sys.path
|
|
|
-
|
|
|
-from openshift_master_facts_default_predicates import LookupModule # noqa: E402
|
|
|
|
|
|
# Predicates ordered according to OpenShift Origin source:
|
|
|
# origin/vendor/k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
|
|
@@ -88,162 +80,83 @@ TEST_VARS = [
|
|
|
]
|
|
|
|
|
|
|
|
|
-class TestOpenShiftMasterFactsDefaultPredicates(object):
|
|
|
- def setUp(self):
|
|
|
- self.lookup = LookupModule()
|
|
|
- self.default_facts = {
|
|
|
- 'openshift': {
|
|
|
- 'common': {}
|
|
|
- }
|
|
|
- }
|
|
|
+def assert_ok(predicates_lookup, default_predicates, regions_enabled, **kwargs):
|
|
|
+ results = predicates_lookup.run(None, regions_enabled=regions_enabled, **kwargs)
|
|
|
+ if regions_enabled:
|
|
|
+ assert results == default_predicates + [REGION_PREDICATE]
|
|
|
+ else:
|
|
|
+ assert results == default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled):
|
|
|
+ facts, default_predicates = openshift_version_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def openshift_version_fixture(request, facts):
|
|
|
+ version, deployment_type, default_predicates = request.param
|
|
|
+ version += '.1'
|
|
|
+ facts['openshift_version'] = version
|
|
|
+ facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
+ return facts, default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled):
|
|
|
+ facts, default_predicates = openshift_release_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def openshift_release_fixture(request, facts, release_mod):
|
|
|
+ release, deployment_type, default_predicates = request.param
|
|
|
+ facts['openshift_release'] = release_mod(release)
|
|
|
+ facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
+ return facts, default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_short_version(predicates_lookup, short_version_fixture, regions_enabled):
|
|
|
+ facts, default_predicates = short_version_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def short_version_fixture(request, facts):
|
|
|
+ short_version, deployment_type, default_predicates = request.param
|
|
|
+ facts['openshift']['common']['short_version'] = short_version
|
|
|
+ facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
+ return facts, default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled):
|
|
|
+ facts, short_version, default_predicates = short_version_kwarg_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled, short_version=short_version)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def short_version_kwarg_fixture(request, facts):
|
|
|
+ short_version, deployment_type, default_predicates = request.param
|
|
|
+ facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
+ return facts, short_version, default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_deployment_type_kwarg(predicates_lookup, deployment_type_kwarg_fixture, regions_enabled):
|
|
|
+ facts, deployment_type, default_predicates = deployment_type_kwarg_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled, deployment_type=deployment_type)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def deployment_type_kwarg_fixture(request, facts):
|
|
|
+ short_version, deployment_type, default_predicates = request.param
|
|
|
+ facts['openshift']['common']['short_version'] = short_version
|
|
|
+ return facts, deployment_type, default_predicates
|
|
|
+
|
|
|
+
|
|
|
+def test_short_version_deployment_type_kwargs(predicates_lookup, short_version_deployment_type_kwargs_fixture, regions_enabled):
|
|
|
+ short_version, deployment_type, default_predicates = short_version_deployment_type_kwargs_fixture
|
|
|
+ assert_ok(predicates_lookup, default_predicates, regions_enabled=regions_enabled, short_version=short_version, deployment_type=deployment_type)
|
|
|
+
|
|
|
|
|
|
- @raises(AnsibleError)
|
|
|
- def test_missing_short_version_and_missing_openshift_release(self):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['deployment_type'] = 'origin'
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
-
|
|
|
- def check_defaults_short_version(self, short_version, deployment_type, default_predicates,
|
|
|
- regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = short_version
|
|
|
- facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_predicates,
|
|
|
- regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled,
|
|
|
- short_version=short_version)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def check_defaults_deployment_type_kwarg(self, short_version, deployment_type,
|
|
|
- default_predicates, regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = short_version
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled,
|
|
|
- deployment_type=deployment_type)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def check_defaults_only_kwargs(self, short_version, deployment_type,
|
|
|
- default_predicates, regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled,
|
|
|
- short_version=short_version,
|
|
|
- deployment_type=deployment_type)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def check_defaults_release(self, release, deployment_type, default_predicates,
|
|
|
- regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift_release'] = release
|
|
|
- facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def check_defaults_version(self, version, deployment_type, default_predicates,
|
|
|
- regions_enabled):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift_version'] = version
|
|
|
- facts['openshift']['common']['deployment_type'] = deployment_type
|
|
|
- results = self.lookup.run(None, variables=facts,
|
|
|
- regions_enabled=regions_enabled)
|
|
|
- if regions_enabled:
|
|
|
- assert_equal(results, default_predicates + [REGION_PREDICATE])
|
|
|
- else:
|
|
|
- assert_equal(results, default_predicates)
|
|
|
-
|
|
|
- def test_openshift_version(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- release = release + '.1'
|
|
|
- yield self.check_defaults_version, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_v_release_defaults(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_release, 'v' + release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_release_defaults(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_release, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_short_version_defaults(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_short_version, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_short_version_kwarg(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_short_version_kwarg, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_only_kwargs(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_only_kwargs, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_deployment_type_kwarg(self):
|
|
|
- for regions_enabled in (True, False):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- yield self.check_defaults_deployment_type_kwarg, release, deployment_type, default_predicates, regions_enabled
|
|
|
-
|
|
|
- def test_trunc_openshift_release(self):
|
|
|
- for release, deployment_type, default_predicates in TEST_VARS:
|
|
|
- release = release + '.1'
|
|
|
- yield self.check_defaults_release, release, deployment_type, default_predicates, False
|
|
|
-
|
|
|
- @raises(AnsibleError)
|
|
|
- def test_unknown_deployment_types(self):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = '1.1'
|
|
|
- facts['openshift']['common']['deployment_type'] = 'bogus'
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
-
|
|
|
- @raises(AnsibleError)
|
|
|
- def test_unknown_origin_version(self):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = '0.1'
|
|
|
- facts['openshift']['common']['deployment_type'] = 'origin'
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
-
|
|
|
- @raises(AnsibleError)
|
|
|
- def test_unknown_ocp_version(self):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = '0.1'
|
|
|
- facts['openshift']['common']['deployment_type'] = 'openshift-enterprise'
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
-
|
|
|
- @raises(AnsibleError)
|
|
|
- def test_missing_deployment_type(self):
|
|
|
- facts = copy.deepcopy(self.default_facts)
|
|
|
- facts['openshift']['common']['short_version'] = '10.10'
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
-
|
|
|
- @raises(AnsibleError)
|
|
|
- def testMissingOpenShiftFacts(self):
|
|
|
- facts = {}
|
|
|
- self.lookup.run(None, variables=facts)
|
|
|
+@pytest.fixture(params=TEST_VARS)
|
|
|
+def short_version_deployment_type_kwargs_fixture(request):
|
|
|
+ return request.param
|