Merge "Rename config_id
to static_id
"
This commit is contained in:
commit
a4a8cc08c0
@ -48,4 +48,4 @@ OPTS = [
|
||||
|
||||
|
||||
class StaticFields(TopologyFields):
|
||||
CONFIG_ID = 'config_id'
|
||||
STATIC_ID = 'static_id'
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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:
|
||||
|
@ -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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user