diff options
Diffstat (limited to 'roles')
6 files changed, 402 insertions, 258 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 2495ad46c..a6f74168e 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1673,7 +1673,7 @@ def set_container_facts_if_unset(facts): cli_image = master_image node_image = 'openshift3/node' ovs_image = 'openshift3/openvswitch' - etcd_image = 'registry.access.redhat.com/rhel7/etcd3' + etcd_image = 'registry.access.redhat.com/rhel7/etcd' pod_image = 'openshift3/ose-pod' router_image = 'openshift3/ose-haproxy-router' registry_image = 'openshift3/ose-docker-registry' @@ -1683,7 +1683,7 @@ def set_container_facts_if_unset(facts): cli_image = master_image node_image = 'aep3_beta/node' ovs_image = 'aep3_beta/openvswitch' - etcd_image = 'registry.access.redhat.com/rhel7/etcd3' + etcd_image = 'registry.access.redhat.com/rhel7/etcd' pod_image = 'aep3_beta/aep-pod' router_image = 'aep3_beta/aep-haproxy-router' registry_image = 'aep3_beta/aep-docker-registry' @@ -1693,7 +1693,7 @@ def set_container_facts_if_unset(facts): cli_image = master_image node_image = 'openshift/node' ovs_image = 'openshift/openvswitch' - etcd_image = 'registry.access.redhat.com/rhel7/etcd3' + etcd_image = 'registry.access.redhat.com/rhel7/etcd' pod_image = 'openshift/origin-pod' router_image = 'openshift/origin-haproxy-router' registry_image = 'openshift/origin-docker-registry' diff --git a/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_predicates.py b/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_predicates.py index 05b62a7a6..4f7461827 100644 --- a/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_predicates.py +++ b/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_predicates.py @@ -6,26 +6,24 @@ from ansible.plugins.lookup import LookupBase class LookupModule(LookupBase): - # pylint: disable=too-many-branches,too-many-statements - - def run(self, terms, variables=None, regions_enabled=True, **kwargs): - if 'openshift' not in variables: - raise AnsibleError("This lookup module requires openshift_facts to be run prior to use") - if 'master' not in variables['openshift']: - raise AnsibleError("This lookup module is meant to be run against an OpenShift master host only") - - if 'openshift_master_scheduler_predicates' in variables: - return variables['openshift_master_scheduler_predicates'] - elif 'scheduler_predicates' in variables['openshift']['master']: - return variables['openshift']['master']['scheduler_predicates'] - else: - predicates = [] + # pylint: disable=too-many-branches,too-many-statements,too-many-arguments + + def run(self, terms, variables=None, regions_enabled=True, short_version=None, + deployment_type=None, **kwargs): + + predicates = [] + + if short_version is None or deployment_type is None: + if 'openshift' not in variables: + raise AnsibleError("This lookup module requires openshift_facts to be run prior to use") - if 'deployment_type' not in variables['openshift']['common']: + if deployment_type is None: + if 'common' not in variables['openshift'] or 'deployment_type' not in variables['openshift']['common']: raise AnsibleError("This lookup module requires that the deployment_type be set") deployment_type = variables['openshift']['common']['deployment_type'] + if short_version is None: if 'short_version' in variables['openshift']['common']: short_version = variables['openshift']['common']['short_version'] elif 'openshift_release' in variables: @@ -34,63 +32,62 @@ class LookupModule(LookupBase): short_version = release[1:] else: short_version = release + short_version = '.'.join(short_version.split('.')[0:2]) elif 'openshift_version' in variables: version = variables['openshift_version'] short_version = '.'.join(version.split('.')[0:2]) else: # pylint: disable=line-too-long raise AnsibleError("Either OpenShift needs to be installed or openshift_release needs to be specified") - if deployment_type not in ['origin', 'openshift-enterprise']: - raise AnsibleError("Unknown deployment_type %s" % deployment_type) - - if deployment_type == 'origin': - if short_version not in ['1.1', '1.2', '1.3', '1.4']: - raise AnsibleError("Unknown short_version %s" % short_version) - elif deployment_type == 'openshift_enterprise': - if short_version not in ['3.1', '3.2', '3.3', '3.4']: - raise AnsibleError("Unknown short_version %s" % short_version) - - if deployment_type == 'openshift-enterprise': - # convert short_version to origin short_version - short_version = re.sub('^3.', '1.', short_version) - - if short_version in ['1.1', '1.2']: - predicates.append({'name': 'PodFitsHostPorts'}) - predicates.append({'name': 'PodFitsResources'}) - - # applies to all known versions - predicates.append({'name': 'NoDiskConflict'}) - - # only 1.1 didn't include NoVolumeZoneConflict - if short_version != '1.1': - predicates.append({'name': 'NoVolumeZoneConflict'}) - - if short_version in ['1.1', '1.2']: - predicates.append({'name': 'MatchNodeSelector'}) - predicates.append({'name': 'Hostname'}) - - if short_version != '1.1': - predicates.append({'name': 'MaxEBSVolumeCount'}) - predicates.append({'name': 'MaxGCEPDVolumeCount'}) - - if short_version not in ['1.1', '1.2']: - predicates.append({'name': 'GeneralPredicates'}) - predicates.append({'name': 'PodToleratesNodeTaints'}) - predicates.append({'name': 'CheckNodeMemoryPressure'}) - - if short_version not in ['1.1', '1.2', '1.3']: - predicates.append({'name': 'CheckNodeDiskPressure'}) - predicates.append({'name': 'MatchInterPodAffinity'}) - - if regions_enabled: - region_predicate = { - 'name': 'Region', - 'argument': { - 'serviceAffinity': { - 'labels': ['region'] - } + if deployment_type == 'origin': + if short_version not in ['1.1', '1.2', '1.3', '1.4']: + raise AnsibleError("Unknown short_version %s" % short_version) + elif deployment_type == 'openshift-enterprise': + if short_version not in ['3.1', '3.2', '3.3', '3.4']: + raise AnsibleError("Unknown short_version %s" % short_version) + else: + raise AnsibleError("Unknown deployment_type %s" % deployment_type) + + if deployment_type == 'openshift-enterprise': + # convert short_version to origin short_version + short_version = re.sub('^3.', '1.', short_version) + + if short_version in ['1.1', '1.2']: + predicates.append({'name': 'PodFitsHostPorts'}) + predicates.append({'name': 'PodFitsResources'}) + + # applies to all known versions + predicates.append({'name': 'NoDiskConflict'}) + + # only 1.1 didn't include NoVolumeZoneConflict + if short_version != '1.1': + predicates.append({'name': 'NoVolumeZoneConflict'}) + + if short_version in ['1.1', '1.2']: + predicates.append({'name': 'MatchNodeSelector'}) + + if short_version != '1.1': + predicates.append({'name': 'MaxEBSVolumeCount'}) + predicates.append({'name': 'MaxGCEPDVolumeCount'}) + + if short_version not in ['1.1', '1.2']: + predicates.append({'name': 'GeneralPredicates'}) + predicates.append({'name': 'PodToleratesNodeTaints'}) + predicates.append({'name': 'CheckNodeMemoryPressure'}) + + if short_version not in ['1.1', '1.2', '1.3']: + predicates.append({'name': 'CheckNodeDiskPressure'}) + predicates.append({'name': 'MatchInterPodAffinity'}) + + if regions_enabled: + region_predicate = { + 'name': 'Region', + 'argument': { + 'serviceAffinity': { + 'labels': ['region'] } } - predicates.append(region_predicate) + } + predicates.append(region_predicate) - return predicates + return predicates diff --git a/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_priorities.py b/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_priorities.py index 3329d26b0..7087ff03c 100644 --- a/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_priorities.py +++ b/roles/openshift_master_facts/lookup_plugins/openshift_master_facts_default_priorities.py @@ -6,30 +6,28 @@ from ansible.plugins.lookup import LookupBase class LookupModule(LookupBase): - # pylint: disable=too-many-branches - - def run(self, terms, variables=None, zones_enabled=True, **kwargs): - if 'openshift' not in variables: - raise AnsibleError("This lookup module requires openshift_facts to be run prior to use") - if 'master' not in variables['openshift']: - raise AnsibleError("This lookup module is meant to be run against an OpenShift master host only") - - if 'openshift_master_scheduler_priorities' in variables: - return variables['openshift_master_scheduler_priorities'] - elif 'scheduler_priorities' in variables['openshift']['master']: - return variables['openshift']['master']['scheduler_priorities'] - else: - priorities = [ - {'name': 'LeastRequestedPriority', 'weight': 1}, - {'name': 'BalancedResourceAllocation', 'weight': 1}, - {'name': 'SelectorSpreadPriority', 'weight': 1} - ] + # pylint: disable=too-many-branches,too-many-statements,too-many-arguments + + def run(self, terms, variables=None, zones_enabled=True, short_version=None, + deployment_type=None, **kwargs): + + priorities = [ + {'name': 'LeastRequestedPriority', 'weight': 1}, + {'name': 'BalancedResourceAllocation', 'weight': 1}, + {'name': 'SelectorSpreadPriority', 'weight': 1} + ] - if 'deployment_type' not in variables['openshift']['common']: + if short_version is None or deployment_type is None: + if 'openshift' not in variables: + raise AnsibleError("This lookup module requires openshift_facts to be run prior to use") + + if deployment_type is None: + if 'common' not in variables['openshift'] or 'deployment_type' not in variables['openshift']['common']: raise AnsibleError("This lookup module requires that the deployment_type be set") deployment_type = variables['openshift']['common']['deployment_type'] + if short_version is None: if 'short_version' in variables['openshift']['common']: short_version = variables['openshift']['common']['short_version'] elif 'openshift_release' in variables: @@ -38,6 +36,7 @@ class LookupModule(LookupBase): short_version = release[1:] else: short_version = release + short_version = '.'.join(short_version.split('.')[0:2]) elif 'openshift_version' in variables: version = variables['openshift_version'] short_version = '.'.join(version.split('.')[0:2]) @@ -45,43 +44,42 @@ class LookupModule(LookupBase): # pylint: disable=line-too-long raise AnsibleError("Either OpenShift needs to be installed or openshift_release needs to be specified") - if deployment_type not in ['origin', 'openshift-enterprise']: - raise AnsibleError("Unknown deployment_type %s" % deployment_type) - - if deployment_type == 'origin': - if short_version not in ['1.1', '1.2', '1.3', '1.4']: - raise AnsibleError("Unknown short_version %s" % short_version) - elif deployment_type == 'openshift_enterprise': - if short_version not in ['3.1', '3.2', '3.3', '3.4']: - raise AnsibleError("Unknown short_version %s" % short_version) - - if deployment_type == 'openshift-enterprise': - # convert short_version to origin short_version - short_version = re.sub('^3.', '1.', short_version) - - if short_version == '1.4': - priorities.append({'name': 'NodePreferAvoidPodsPriority', 'weight': 10000}) - - # only 1.1 didn't include NodeAffinityPriority - if short_version != '1.1': - priorities.append({'name': 'NodeAffinityPriority', 'weight': 1}) - - if short_version not in ['1.1', '1.2']: - priorities.append({'name': 'TaintTolerationPriority', 'weight': 1}) - - if short_version not in ['1.1', '1.2', '1.3']: - priorities.append({'name': 'InterPodAffinityPriority', 'weight': 1}) - - if zones_enabled: - zone_priority = { - 'name': 'Zone', - 'argument': { - 'serviceAntiAffinity': { - 'label': 'zone' - } - }, - 'weight': 2 - } - priorities.append(zone_priority) - - return priorities + if deployment_type == 'origin': + if short_version not in ['1.1', '1.2', '1.3', '1.4']: + raise AnsibleError("Unknown short_version %s" % short_version) + elif deployment_type == 'openshift-enterprise': + if short_version not in ['3.1', '3.2', '3.3', '3.4']: + raise AnsibleError("Unknown short_version %s" % short_version) + else: + raise AnsibleError("Unknown deployment_type %s" % deployment_type) + + if deployment_type == 'openshift-enterprise': + # convert short_version to origin short_version + short_version = re.sub('^3.', '1.', short_version) + + if short_version == '1.4': + priorities.append({'name': 'NodePreferAvoidPodsPriority', 'weight': 10000}) + + # only 1.1 didn't include NodeAffinityPriority + if short_version != '1.1': + priorities.append({'name': 'NodeAffinityPriority', 'weight': 1}) + + if short_version not in ['1.1', '1.2']: + priorities.append({'name': 'TaintTolerationPriority', 'weight': 1}) + + if short_version not in ['1.1', '1.2', '1.3']: + priorities.append({'name': 'InterPodAffinityPriority', 'weight': 1}) + + if zones_enabled: + zone_priority = { + 'name': 'Zone', + 'argument': { + 'serviceAntiAffinity': { + 'label': 'zone' + } + }, + 'weight': 2 + } + priorities.append(zone_priority) + + return priorities diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 6f2a916d0..c95356908 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -14,7 +14,6 @@ DEFAULT_PREDICATES_1_1 = [ {'name': 'PodFitsResources'}, {'name': 'NoDiskConflict'}, {'name': 'MatchNodeSelector'}, - {'name': 'Hostname'} ] DEFAULT_PREDICATES_1_2 = [ @@ -23,7 +22,6 @@ DEFAULT_PREDICATES_1_2 = [ {'name': 'NoDiskConflict'}, {'name': 'NoVolumeZoneConflict'}, {'name': 'MatchNodeSelector'}, - {'name': 'Hostname'}, {'name': 'MaxEBSVolumeCount'}, {'name': 'MaxGCEPDVolumeCount'} ] @@ -59,13 +57,23 @@ REGION_PREDICATE = { } } +TEST_VARS = [ + ('1.1', 'origin', DEFAULT_PREDICATES_1_1), + ('3.1', 'openshift-enterprise', DEFAULT_PREDICATES_1_1), + ('1.2', 'origin', DEFAULT_PREDICATES_1_2), + ('3.2', 'openshift-enterprise', DEFAULT_PREDICATES_1_2), + ('1.3', 'origin', DEFAULT_PREDICATES_1_3), + ('3.3', 'openshift-enterprise', DEFAULT_PREDICATES_1_3), + ('1.4', 'origin', DEFAULT_PREDICATES_1_4), + ('3.4', 'openshift-enterprise', DEFAULT_PREDICATES_1_4) +] + class TestOpenShiftMasterFactsDefaultPredicates(object): def setUp(self): self.lookup = LookupModule() self.default_facts = { 'openshift': { - 'master': {}, 'common': {} } } @@ -76,13 +84,70 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): facts['openshift']['common']['deployment_type'] = 'origin' self.lookup.run(None, variables=facts) - def check_defaults(self, release, deployment_type, default_predicates, - regions_enabled, short_version): + 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) - if short_version: - facts['openshift']['common']['short_version'] = release + 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: - facts['openshift_release'] = release + 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) @@ -91,39 +156,63 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_predicates) - def test_openshift_release_defaults(self): - test_vars = [ - ('1.1', 'origin', DEFAULT_PREDICATES_1_1), - ('3.1', 'openshift-enterprise', DEFAULT_PREDICATES_1_1), - ('1.2', 'origin', DEFAULT_PREDICATES_1_2), - ('3.2', 'openshift-enterprise', DEFAULT_PREDICATES_1_2), - ('1.3', 'origin', DEFAULT_PREDICATES_1_3), - ('3.3', 'openshift-enterprise', DEFAULT_PREDICATES_1_3), - ('1.4', 'origin', DEFAULT_PREDICATES_1_4), - ('3.4', 'openshift-enterprise', DEFAULT_PREDICATES_1_4) - ] + def check_defaults_override_vars(self, release, deployment_type, + default_predicates, regions_enabled, + extra_facts=None): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + if extra_facts is not None: + for fact in extra_facts: + facts[fact] = extra_facts[fact] + results = self.lookup.run(None, variables=facts, + regions_enabled=regions_enabled, + return_set_vars=False) + 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: - for prepend_v in (True, False): - if prepend_v: - release = 'v' + release - yield self.check_defaults, release, deployment_type, default_predicates, regions_enabled, 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): - test_vars = [ - ('1.1', 'origin', DEFAULT_PREDICATES_1_1), - ('3.1', 'openshift-enterprise', DEFAULT_PREDICATES_1_1), - ('1.2', 'origin', DEFAULT_PREDICATES_1_2), - ('3.2', 'openshift-enterprise', DEFAULT_PREDICATES_1_2), - ('1.3', 'origin', DEFAULT_PREDICATES_1_3), - ('3.3', 'openshift-enterprise', DEFAULT_PREDICATES_1_3), - ('1.4', 'origin', DEFAULT_PREDICATES_1_4), - ('3.4', 'openshift-enterprise', DEFAULT_PREDICATES_1_4) - ] for regions_enabled in (True, False): - for short_version, deployment_type, default_predicates in test_vars: - yield self.check_defaults, short_version, deployment_type, default_predicates, regions_enabled, True + 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): @@ -133,42 +222,26 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): self.lookup.run(None, variables=facts) @raises(AnsibleError) - def test_missing_deployment_type(self): + def test_unknown_origin_version(self): facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' self.lookup.run(None, variables=facts) @raises(AnsibleError) - def testMissingOpenShiftFacts(self): - facts = {} + 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 testMissingMasterRole(self): - facts = {'openshift': {}} + 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) - def testPreExistingPredicates(self): - facts = { - 'openshift': { - 'master': { - 'scheduler_predicates': [ - {'name': 'pred_a'}, - {'name': 'pred_b'} - ] - } - } - } - result = self.lookup.run(None, variables=facts) - assert_equal(result, facts['openshift']['master']['scheduler_predicates']) - - def testDefinedPredicates(self): - facts = { - 'openshift': {'master': {}}, - 'openshift_master_scheduler_predicates': [ - {'name': 'pred_a'}, - {'name': 'pred_b'} - ] - } - result = self.lookup.run(None, variables=facts) - assert_equal(result, facts['openshift_master_scheduler_predicates']) + @raises(AnsibleError) + def testMissingOpenShiftFacts(self): + facts = {} + self.lookup.run(None, variables=facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index d63f06904..5427a07a1 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -50,13 +50,23 @@ ZONE_PRIORITY = { 'weight': 2 } +TEST_VARS = [ + ('1.1', 'origin', DEFAULT_PRIORITIES_1_1), + ('3.1', 'openshift-enterprise', DEFAULT_PRIORITIES_1_1), + ('1.2', 'origin', DEFAULT_PRIORITIES_1_2), + ('3.2', 'openshift-enterprise', DEFAULT_PRIORITIES_1_2), + ('1.3', 'origin', DEFAULT_PRIORITIES_1_3), + ('3.3', 'openshift-enterprise', DEFAULT_PRIORITIES_1_3), + ('1.4', 'origin', DEFAULT_PRIORITIES_1_4), + ('3.4', 'openshift-enterprise', DEFAULT_PRIORITIES_1_4) +] + class TestOpenShiftMasterFactsDefaultPredicates(object): def setUp(self): self.lookup = LookupModule() self.default_facts = { 'openshift': { - 'master': {}, 'common': {} } } @@ -67,13 +77,68 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): facts['openshift']['common']['deployment_type'] = 'origin' self.lookup.run(None, variables=facts) - def check_defaults(self, release, deployment_type, default_priorities, - zones_enabled, short_version): + def check_defaults_short_version(self, release, deployment_type, + default_priorities, zones_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def check_defaults_short_version_kwarg(self, release, deployment_type, + default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) - if short_version: - facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, + zones_enabled=zones_enabled, + short_version=release) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) else: - facts['openshift_release'] = release + assert_equal(results, default_priorities) + + def check_defaults_deployment_type_kwarg(self, release, deployment_type, + default_priorities, zones_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = release + results = self.lookup.run(None, variables=facts, + zones_enabled=zones_enabled, + deployment_type=deployment_type) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def check_defaults_only_kwargs(self, release, deployment_type, + default_priorities, zones_enabled): + facts = copy.deepcopy(self.default_facts) + results = self.lookup.run(None, variables=facts, + zones_enabled=zones_enabled, + short_version=release, + deployment_type=deployment_type) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def check_defaults_release(self, release, deployment_type, default_priorities, + zones_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, zones_enabled=zones_enabled) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def check_defaults_version(self, release, deployment_type, default_priorities, + zones_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift_version'] = release facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: @@ -81,39 +146,78 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_priorities) - def test_openshift_release_defaults(self): - test_vars = [ - ('1.1', 'origin', DEFAULT_PRIORITIES_1_1), - ('3.1', 'openshift-enterprise', DEFAULT_PRIORITIES_1_1), - ('1.2', 'origin', DEFAULT_PRIORITIES_1_2), - ('3.2', 'openshift-enterprise', DEFAULT_PRIORITIES_1_2), - ('1.3', 'origin', DEFAULT_PRIORITIES_1_3), - ('3.3', 'openshift-enterprise', DEFAULT_PRIORITIES_1_3), - ('1.4', 'origin', DEFAULT_PRIORITIES_1_4), - ('3.4', 'openshift-enterprise', DEFAULT_PRIORITIES_1_4) - ] + def check_defaults_override_vars(self, release, deployment_type, + default_priorities, zones_enabled, + extra_facts=None): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + if extra_facts is not None: + for fact in extra_facts: + facts[fact] = extra_facts[fact] + results = self.lookup.run(None, variables=facts, + zones_enabled=zones_enabled, + return_set_vars=False) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def test_openshift_version(self): + for zones_enabled in (True, False): + for release, deployment_type, default_priorities in TEST_VARS: + release = release + '.1' + yield self.check_defaults_version, release, deployment_type, default_priorities, zones_enabled + + def test_v_release_defaults(self): + for zones_enabled in (True, False): + for release, deployment_type, default_priorities in TEST_VARS: + release = 'v' + release + yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled + def test_release_defaults(self): for zones_enabled in (True, False): - for release, deployment_type, default_priorities in test_vars: - for prepend_v in (True, False): - if prepend_v: - release = 'v' + release - yield self.check_defaults, release, deployment_type, default_priorities, zones_enabled, False + for release, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled def test_short_version_defaults(self): - test_vars = [ - ('1.1', 'origin', DEFAULT_PRIORITIES_1_1), - ('3.1', 'openshift-enterprise', DEFAULT_PRIORITIES_1_1), - ('1.2', 'origin', DEFAULT_PRIORITIES_1_2), - ('3.2', 'openshift-enterprise', DEFAULT_PRIORITIES_1_2), - ('1.3', 'origin', DEFAULT_PRIORITIES_1_3), - ('3.3', 'openshift-enterprise', DEFAULT_PRIORITIES_1_3), - ('1.4', 'origin', DEFAULT_PRIORITIES_1_4), - ('3.4', 'openshift-enterprise', DEFAULT_PRIORITIES_1_4) - ] for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in test_vars: - yield self.check_defaults, short_version, deployment_type, default_priorities, zones_enabled, True + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled + + def test_only_kwargs(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled + + def test_deployment_type_kwarg(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled + + def test_release_kwarg(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled + + def test_trunc_openshift_release(self): + for release, deployment_type, default_priorities in TEST_VARS: + release = release + '.1' + yield self.check_defaults_release, release, deployment_type, default_priorities, False + + @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_unknown_deployment_types(self): @@ -132,33 +236,3 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_missing_openshift_facts(self): facts = {} self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_master_role(self): - facts = {'openshift': {}} - self.lookup.run(None, variables=facts) - - def test_pre_existing_priorities(self): - facts = { - 'openshift': { - 'master': { - 'scheduler_priorities': [ - {'name': 'pri_a', 'weight': 1}, - {'name': 'pri_b', 'weight': 1} - ] - } - } - } - result = self.lookup.run(None, variables=facts) - assert_equal(result, facts['openshift']['master']['scheduler_priorities']) - - def testDefinedPredicates(self): - facts = { - 'openshift': {'master': {}}, - 'openshift_master_scheduler_priorities': [ - {'name': 'pri_a', 'weight': 1}, - {'name': 'pri_b', 'weight': 1} - ] - } - result = self.lookup.run(None, variables=facts) - assert_equal(result, facts['openshift_master_scheduler_priorities']) diff --git a/roles/openshift_node/tasks/main.yml b/roles/openshift_node/tasks/main.yml index b8d0b6130..e970c4cd1 100644 --- a/roles/openshift_node/tasks/main.yml +++ b/roles/openshift_node/tasks/main.yml @@ -44,6 +44,8 @@ - name: Check for tuned package command: rpm -q tuned + args: + warn: no register: tuned_installed changed_when: false failed_when: false |