From 6076a7c4288abf77e58af7b45e114e6ba4731285 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Wed, 18 Jan 2017 22:12:43 +0800 Subject: [PATCH] Rename `config_id` to `static_id` Change-Id: Iefd7fcd0f0bd0108060c2cc828043588cecffb8d --- vitrage/datasources/static/__init__.py | 2 +- vitrage/datasources/static/driver.py | 16 ++++++++-------- vitrage/datasources/static/transformer.py | 4 ++-- vitrage/tests/mocks/trace_generator.py | 6 +++--- .../driver/driver_static_snapshot_dynamic.json | 2 +- .../static_datasources/switch_to_host.yaml | 16 ++++++++-------- .../datasources/static/test_static_driver.py | 10 +++++----- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/vitrage/datasources/static/__init__.py b/vitrage/datasources/static/__init__.py index 59137ed02..e150da33e 100644 --- a/vitrage/datasources/static/__init__.py +++ b/vitrage/datasources/static/__init__.py @@ -48,4 +48,4 @@ OPTS = [ class StaticFields(TopologyFields): - CONFIG_ID = 'config_id' + STATIC_ID = 'static_id' diff --git a/vitrage/datasources/static/driver.py b/vitrage/datasources/static/driver.py index c4624c3cd..62960da87 100644 --- a/vitrage/datasources/static/driver.py +++ b/vitrage/datasources/static/driver.py @@ -30,7 +30,7 @@ LOG = log.getLogger(__name__) class StaticDriver(DriverBase): # base fields are required for all entities, others are treated as metadata - BASE_FIELDS = {StaticFields.CONFIG_ID, StaticFields.TYPE, VProps.ID} + BASE_FIELDS = {StaticFields.STATIC_ID, StaticFields.TYPE, VProps.ID} def __init__(self, conf): super(StaticDriver, self).__init__() @@ -95,11 +95,11 @@ class StaticDriver(DriverBase): @classmethod def _pack_entity(cls, entities_dict, entity): - config_id = entity[StaticFields.CONFIG_ID] - if config_id not in entities_dict: + static_id = entity[StaticFields.STATIC_ID] + if static_id not in entities_dict: metadata = {key: value for key, value in iteritems(entity) if key not in cls.BASE_FIELDS} - entities_dict[config_id] = entity + entities_dict[static_id] = entity entity[TopologyFields.RELATIONSHIPS] = [] entity[TopologyFields.METADATA] = metadata else: @@ -123,15 +123,15 @@ class StaticDriver(DriverBase): """Expand config id to neighbor entity rel={'source': 's1', 'target': 'r1', 'relationship_type': 'attached'} - neighbor={'config_id': 'h1', 'type': 'host.nova', 'id': 1} + neighbor={'static_id': 'h1', 'type': 'host.nova', 'id': 1} result={'relationship_type': 'attached', 'source': 's1', - 'target': {'config_id': 'h1', 'type': 'host.nova', 'id': 1}} + 'target': {'static_id': 'h1', 'type': 'host.nova', 'id': 1}} """ rel = rel.copy() - if rel[StaticFields.SOURCE] == neighbor[StaticFields.CONFIG_ID]: + if rel[StaticFields.SOURCE] == neighbor[StaticFields.STATIC_ID]: rel[StaticFields.SOURCE] = neighbor - elif rel[StaticFields.TARGET] == neighbor[StaticFields.CONFIG_ID]: + elif rel[StaticFields.TARGET] == neighbor[StaticFields.STATIC_ID]: rel[StaticFields.TARGET] = neighbor else: # TODO(yujunz) raise exception and ignore invalid relationship diff --git a/vitrage/datasources/static/transformer.py b/vitrage/datasources/static/transformer.py index f61b187e7..dde042bb6 100644 --- a/vitrage/datasources/static/transformer.py +++ b/vitrage/datasources/static/transformer.py @@ -89,10 +89,10 @@ class StaticTransformer(ResourceTransformerBase): metadata=metadata) def _create_static_neighbor(self, entity_event, rel): - if entity_event[StaticFields.CONFIG_ID] == rel[StaticFields.SOURCE]: + if entity_event[StaticFields.STATIC_ID] == rel[StaticFields.SOURCE]: neighbor = rel[StaticFields.TARGET] is_entity_source = True - elif entity_event[StaticFields.CONFIG_ID] == rel[StaticFields.TARGET]: + elif entity_event[StaticFields.STATIC_ID] == rel[StaticFields.TARGET]: neighbor = rel[StaticFields.SOURCE] is_entity_source = False else: diff --git a/vitrage/tests/mocks/trace_generator.py b/vitrage/tests/mocks/trace_generator.py index e168c3aaf..4f562027a 100644 --- a/vitrage/tests/mocks/trace_generator.py +++ b/vitrage/tests/mocks/trace_generator.py @@ -582,7 +582,7 @@ def _get_static_snapshot_driver_values(spec): if switch_id not in touched: switch_name = "switch-{}".format(switch_index) vals = { - StaticFields.CONFIG_ID: switch_id, + StaticFields.STATIC_ID: switch_id, StaticFields.TYPE: 'switch', StaticFields.ID: str(randint(0, 100000)), StaticFields.NAME: switch_name, @@ -594,7 +594,7 @@ def _get_static_snapshot_driver_values(spec): host_id = "h{}".format(host_index) if host_id not in touched: vals = { - StaticFields.CONFIG_ID: host_id, + StaticFields.STATIC_ID: host_id, StaticFields.TYPE: NOVA_HOST_DATASOURCE, StaticFields.ID: str(randint(0, 100000)), StaticFields.RELATIONSHIPS: relationships[host_id] @@ -613,7 +613,7 @@ def _get_static_snapshot_driver_values(spec): target_id = 'c{}'.format(custom_num - 1 - index) source_name = 'custom-{}'.format(source_id) vals = { - StaticFields.CONFIG_ID: source_id, + StaticFields.STATIC_ID: source_id, StaticFields.TYPE: 'custom', StaticFields.ID: str(randint(0, 100000)), StaticFields.NAME: source_name, diff --git a/vitrage/tests/resources/mock_configurations/driver/driver_static_snapshot_dynamic.json b/vitrage/tests/resources/mock_configurations/driver/driver_static_snapshot_dynamic.json index a120ff30c..a46e0ad4d 100644 --- a/vitrage/tests/resources/mock_configurations/driver/driver_static_snapshot_dynamic.json +++ b/vitrage/tests/resources/mock_configurations/driver/driver_static_snapshot_dynamic.json @@ -1,7 +1,7 @@ { "name": "[switch|host|custom]-[1-9]", "id": "[1-9]{5}", - "config_id": "[shc][1-9]", + "static_id": "[shc][1-9]", "type": "[switch|nova.host|custom]", "state": "available", "vitrage_datasource_action": "snapshot", diff --git a/vitrage/tests/resources/static_datasources/switch_to_host.yaml b/vitrage/tests/resources/static_datasources/switch_to_host.yaml index 41283a580..46ee3f4ce 100644 --- a/vitrage/tests/resources/static_datasources/switch_to_host.yaml +++ b/vitrage/tests/resources/static_datasources/switch_to_host.yaml @@ -3,35 +3,35 @@ metadata: description: static datasource for test definitions: entities: - - config_id: s1 + - static_id: s1 type: switch name: switch-1 id: 12345 state: available - - config_id: s2 + - static_id: s2 type: switch name: switch-2 id: 23456 state: available - - config_id: s3 + - static_id: s3 type: switch name: switch-3 id: 34567 state: available - - config_id: r1 + - static_id: r1 type: router name: router-1 id: 45678 - - config_id: h1 + - static_id: h1 type: nova.host id: 1 - - config_id: h2 + - static_id: h2 type: nova.host id: 2 - - config_id: h3 + - static_id: h3 type: nova.host id: 3 - - config_id: h4 + - static_id: h4 type: nova.host id: 4 relationships: diff --git a/vitrage/tests/unit/datasources/static/test_static_driver.py b/vitrage/tests/unit/datasources/static/test_static_driver.py index 88ee6c380..6ca5c9e94 100644 --- a/vitrage/tests/unit/datasources/static/test_static_driver.py +++ b/vitrage/tests/unit/datasources/static/test_static_driver.py @@ -107,12 +107,12 @@ class TestStaticDriver(base.BaseTest): self._validate_static_rel(entity, rel) def _validate_static_rel(self, entity, rel): - self.assertTrue(entity[StaticFields.CONFIG_ID] in + self.assertTrue(entity[StaticFields.STATIC_ID] in (rel[StaticFields.SOURCE], rel[StaticFields.TARGET])) self.assertTrue( isinstance(rel[StaticFields.SOURCE], dict) - and entity[StaticFields.CONFIG_ID] == rel[StaticFields.TARGET] + and entity[StaticFields.STATIC_ID] == rel[StaticFields.TARGET] or isinstance(rel[StaticFields.TARGET], dict) - and entity[StaticFields.CONFIG_ID] == rel[StaticFields.SOURCE] - or entity[StaticFields.CONFIG_ID] == rel[StaticFields.SOURCE] - and entity[StaticFields.CONFIG_ID] == rel[StaticFields.TARGET]) + and entity[StaticFields.STATIC_ID] == rel[StaticFields.SOURCE] + or entity[StaticFields.STATIC_ID] == rel[StaticFields.SOURCE] + and entity[StaticFields.STATIC_ID] == rel[StaticFields.TARGET])