From 5468748d5c21337c28ab0e13ac90d9f34d47d385 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Tue, 30 May 2017 17:58:58 +0800 Subject: [PATCH] Set default directory of equivalence under templates directory Putting the together will imply user about the inner connection between them. Change-Id: Ib78d1cf0dc0e83f2a7ecdccc822332dba71f69eb Signed-off-by: Yujun Zhang --- vitrage/evaluator/__init__.py | 2 +- vitrage/evaluator/scenario_repository.py | 4 ++-- .../equivalences_dup/dup-in-multi-def/multi.yaml | 0 .../equivalences_dup/dup-in-multi-file/first.yaml | 0 .../equivalences_dup/dup-in-multi-file/second.yaml | 0 .../equivalences_dup/dup-in-one-def/one.yaml | 0 .../equivalent_scenarios}/basic.yaml | 0 .../equivalent_scenarios}/equivalences/basic.yaml | 0 .../{ => templates/general}/equivalences/basic.yaml | 0 .../tests/unit/evaluator/test_equivalence_data.py | 5 +++-- .../unit/evaluator/test_equivalence_repository.py | 6 +++--- .../unit/evaluator/test_scenario_repository.py | 13 ++++++------- 12 files changed, 15 insertions(+), 15 deletions(-) rename vitrage/tests/resources/{ => templates}/equivalences_dup/dup-in-multi-def/multi.yaml (100%) rename vitrage/tests/resources/{ => templates}/equivalences_dup/dup-in-multi-file/first.yaml (100%) rename vitrage/tests/resources/{ => templates}/equivalences_dup/dup-in-multi-file/second.yaml (100%) rename vitrage/tests/resources/{ => templates}/equivalences_dup/dup-in-one-def/one.yaml (100%) rename vitrage/tests/resources/{scenario_expansion/templates => templates/equivalent_scenarios}/basic.yaml (100%) rename vitrage/tests/resources/{scenario_expansion => templates/equivalent_scenarios}/equivalences/basic.yaml (100%) rename vitrage/tests/resources/{ => templates/general}/equivalences/basic.yaml (100%) diff --git a/vitrage/evaluator/__init__.py b/vitrage/evaluator/__init__.py index 578a67882..ee0c40f13 100644 --- a/vitrage/evaluator/__init__.py +++ b/vitrage/evaluator/__init__.py @@ -22,7 +22,7 @@ OPTS = [ help='A path for the templates used by the evaluator' ), cfg.StrOpt('equivalences_dir', - default='/etc/vitrage/equivalences', + default='/etc/vitrage/templates/equivalences', help='A path for entity equivalences used by the evaluator' ) ] diff --git a/vitrage/evaluator/scenario_repository.py b/vitrage/evaluator/scenario_repository.py index 0b39a7999..b087a3389 100644 --- a/vitrage/evaluator/scenario_repository.py +++ b/vitrage/evaluator/scenario_repository.py @@ -36,8 +36,8 @@ EdgeKeyScenario = namedtuple('EdgeKeyScenario', ['label', 'source', 'target']) class ScenarioRepository(object): def __init__(self, conf): self._templates = {} - self.entity_equivalences = \ - EquivalenceRepository().load_files(conf.evaluator.equivalences_dir) + self.entity_equivalences = EquivalenceRepository().load_files( + conf.evaluator.equivalences_dir) self.relationship_scenarios = defaultdict(list) self.entity_scenarios = defaultdict(list) self._load_templates_files(conf) diff --git a/vitrage/tests/resources/equivalences_dup/dup-in-multi-def/multi.yaml b/vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-def/multi.yaml similarity index 100% rename from vitrage/tests/resources/equivalences_dup/dup-in-multi-def/multi.yaml rename to vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-def/multi.yaml diff --git a/vitrage/tests/resources/equivalences_dup/dup-in-multi-file/first.yaml b/vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-file/first.yaml similarity index 100% rename from vitrage/tests/resources/equivalences_dup/dup-in-multi-file/first.yaml rename to vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-file/first.yaml diff --git a/vitrage/tests/resources/equivalences_dup/dup-in-multi-file/second.yaml b/vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-file/second.yaml similarity index 100% rename from vitrage/tests/resources/equivalences_dup/dup-in-multi-file/second.yaml rename to vitrage/tests/resources/templates/equivalences_dup/dup-in-multi-file/second.yaml diff --git a/vitrage/tests/resources/equivalences_dup/dup-in-one-def/one.yaml b/vitrage/tests/resources/templates/equivalences_dup/dup-in-one-def/one.yaml similarity index 100% rename from vitrage/tests/resources/equivalences_dup/dup-in-one-def/one.yaml rename to vitrage/tests/resources/templates/equivalences_dup/dup-in-one-def/one.yaml diff --git a/vitrage/tests/resources/scenario_expansion/templates/basic.yaml b/vitrage/tests/resources/templates/equivalent_scenarios/basic.yaml similarity index 100% rename from vitrage/tests/resources/scenario_expansion/templates/basic.yaml rename to vitrage/tests/resources/templates/equivalent_scenarios/basic.yaml diff --git a/vitrage/tests/resources/scenario_expansion/equivalences/basic.yaml b/vitrage/tests/resources/templates/equivalent_scenarios/equivalences/basic.yaml similarity index 100% rename from vitrage/tests/resources/scenario_expansion/equivalences/basic.yaml rename to vitrage/tests/resources/templates/equivalent_scenarios/equivalences/basic.yaml diff --git a/vitrage/tests/resources/equivalences/basic.yaml b/vitrage/tests/resources/templates/general/equivalences/basic.yaml similarity index 100% rename from vitrage/tests/resources/equivalences/basic.yaml rename to vitrage/tests/resources/templates/general/equivalences/basic.yaml diff --git a/vitrage/tests/unit/evaluator/test_equivalence_data.py b/vitrage/tests/unit/evaluator/test_equivalence_data.py index 4e1bdde51..dad012208 100644 --- a/vitrage/tests/unit/evaluator/test_equivalence_data.py +++ b/vitrage/tests/unit/evaluator/test_equivalence_data.py @@ -24,8 +24,9 @@ class EquivalenceTemplateTest(base.BaseTest): def test_equivalence_template(self): - equivalence_path = '%s/equivalences/%s' % (utils.get_resources_dir(), - self.BASIC_TEMPLATE) + equivalence_path = '%s/templates/general/equivalences/%s' % ( + utils.get_resources_dir(), + self.BASIC_TEMPLATE) equivalence_definition = file_utils.load_yaml_file(equivalence_path, True) equivalence_data = EquivalenceData(equivalence_definition) diff --git a/vitrage/tests/unit/evaluator/test_equivalence_repository.py b/vitrage/tests/unit/evaluator/test_equivalence_repository.py index 158ea24d7..05bb5ce04 100644 --- a/vitrage/tests/unit/evaluator/test_equivalence_repository.py +++ b/vitrage/tests/unit/evaluator/test_equivalence_repository.py @@ -28,8 +28,8 @@ class TestEquivalenceRepository(base.BaseTest): self.equivalence_repository = EquivalenceRepository() def test_duplicate_entities_in_equivalence(self): - equivalences_dup_dir = utils.get_resources_dir() + '/equivalences_dup' - for directory in os.listdir(equivalences_dup_dir): + base_dir = utils.get_resources_dir() + '/templates/equivalences_dup' + for directory in os.listdir(base_dir): self.assertRaises(VitrageError, self.equivalence_repository.load_files, - os.path.join(equivalences_dup_dir, directory)) + os.path.join(base_dir, directory)) diff --git a/vitrage/tests/unit/evaluator/test_scenario_repository.py b/vitrage/tests/unit/evaluator/test_scenario_repository.py index 70b028529..65467869f 100644 --- a/vitrage/tests/unit/evaluator/test_scenario_repository.py +++ b/vitrage/tests/unit/evaluator/test_scenario_repository.py @@ -24,15 +24,14 @@ from vitrage.utils import file as file_utils class ScenarioRepositoryTest(base.BaseTest): - + BASE_DIR = utils.get_resources_dir() + '/templates/general' HOST_HIGH_CPU = 'host_high_cpu_load_to_instance_cpu_suboptimal' OPTS = [ cfg.StrOpt('templates_dir', - default=utils.get_resources_dir() + '/templates/general', + default=BASE_DIR, ), cfg.StrOpt('equivalences_dir', - default=utils.get_resources_dir() + - '/equivalences', + default='equivalences', ), ] @@ -97,11 +96,11 @@ class ScenarioRepositoryTest(base.BaseTest): pass -class ScenarioExpansionTest(base.BaseTest): - BASE_DIR = utils.get_resources_dir() + '/scenario_expansion/' +class EquivalentScenarioTest(base.BaseTest): + BASE_DIR = utils.get_resources_dir() + '/templates/equivalent_scenarios/' OPTS = [ cfg.StrOpt('templates_dir', - default=BASE_DIR + 'templates'), + default=BASE_DIR), cfg.StrOpt('equivalences_dir', default=BASE_DIR + '/equivalences')]