Rename config_id
to static_id
Change-Id: Iefd7fcd0f0bd0108060c2cc828043588cecffb8d
This commit is contained in:
parent
c771ad1a1b
commit
6076a7c428
@ -48,4 +48,4 @@ OPTS = [
|
|||||||
|
|
||||||
|
|
||||||
class StaticFields(TopologyFields):
|
class StaticFields(TopologyFields):
|
||||||
CONFIG_ID = 'config_id'
|
STATIC_ID = 'static_id'
|
||||||
|
@ -30,7 +30,7 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class StaticDriver(DriverBase):
|
class StaticDriver(DriverBase):
|
||||||
# base fields are required for all entities, others are treated as metadata
|
# 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):
|
def __init__(self, conf):
|
||||||
super(StaticDriver, self).__init__()
|
super(StaticDriver, self).__init__()
|
||||||
@ -95,11 +95,11 @@ class StaticDriver(DriverBase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _pack_entity(cls, entities_dict, entity):
|
def _pack_entity(cls, entities_dict, entity):
|
||||||
config_id = entity[StaticFields.CONFIG_ID]
|
static_id = entity[StaticFields.STATIC_ID]
|
||||||
if config_id not in entities_dict:
|
if static_id not in entities_dict:
|
||||||
metadata = {key: value for key, value in iteritems(entity)
|
metadata = {key: value for key, value in iteritems(entity)
|
||||||
if key not in cls.BASE_FIELDS}
|
if key not in cls.BASE_FIELDS}
|
||||||
entities_dict[config_id] = entity
|
entities_dict[static_id] = entity
|
||||||
entity[TopologyFields.RELATIONSHIPS] = []
|
entity[TopologyFields.RELATIONSHIPS] = []
|
||||||
entity[TopologyFields.METADATA] = metadata
|
entity[TopologyFields.METADATA] = metadata
|
||||||
else:
|
else:
|
||||||
@ -123,15 +123,15 @@ class StaticDriver(DriverBase):
|
|||||||
"""Expand config id to neighbor entity
|
"""Expand config id to neighbor entity
|
||||||
|
|
||||||
rel={'source': 's1', 'target': 'r1', 'relationship_type': 'attached'}
|
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',
|
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()
|
rel = rel.copy()
|
||||||
if rel[StaticFields.SOURCE] == neighbor[StaticFields.CONFIG_ID]:
|
if rel[StaticFields.SOURCE] == neighbor[StaticFields.STATIC_ID]:
|
||||||
rel[StaticFields.SOURCE] = neighbor
|
rel[StaticFields.SOURCE] = neighbor
|
||||||
elif rel[StaticFields.TARGET] == neighbor[StaticFields.CONFIG_ID]:
|
elif rel[StaticFields.TARGET] == neighbor[StaticFields.STATIC_ID]:
|
||||||
rel[StaticFields.TARGET] = neighbor
|
rel[StaticFields.TARGET] = neighbor
|
||||||
else:
|
else:
|
||||||
# TODO(yujunz) raise exception and ignore invalid relationship
|
# TODO(yujunz) raise exception and ignore invalid relationship
|
||||||
|
@ -89,10 +89,10 @@ class StaticTransformer(ResourceTransformerBase):
|
|||||||
metadata=metadata)
|
metadata=metadata)
|
||||||
|
|
||||||
def _create_static_neighbor(self, entity_event, rel):
|
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]
|
neighbor = rel[StaticFields.TARGET]
|
||||||
is_entity_source = True
|
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]
|
neighbor = rel[StaticFields.SOURCE]
|
||||||
is_entity_source = False
|
is_entity_source = False
|
||||||
else:
|
else:
|
||||||
|
@ -582,7 +582,7 @@ def _get_static_snapshot_driver_values(spec):
|
|||||||
if switch_id not in touched:
|
if switch_id not in touched:
|
||||||
switch_name = "switch-{}".format(switch_index)
|
switch_name = "switch-{}".format(switch_index)
|
||||||
vals = {
|
vals = {
|
||||||
StaticFields.CONFIG_ID: switch_id,
|
StaticFields.STATIC_ID: switch_id,
|
||||||
StaticFields.TYPE: 'switch',
|
StaticFields.TYPE: 'switch',
|
||||||
StaticFields.ID: str(randint(0, 100000)),
|
StaticFields.ID: str(randint(0, 100000)),
|
||||||
StaticFields.NAME: switch_name,
|
StaticFields.NAME: switch_name,
|
||||||
@ -594,7 +594,7 @@ def _get_static_snapshot_driver_values(spec):
|
|||||||
host_id = "h{}".format(host_index)
|
host_id = "h{}".format(host_index)
|
||||||
if host_id not in touched:
|
if host_id not in touched:
|
||||||
vals = {
|
vals = {
|
||||||
StaticFields.CONFIG_ID: host_id,
|
StaticFields.STATIC_ID: host_id,
|
||||||
StaticFields.TYPE: NOVA_HOST_DATASOURCE,
|
StaticFields.TYPE: NOVA_HOST_DATASOURCE,
|
||||||
StaticFields.ID: str(randint(0, 100000)),
|
StaticFields.ID: str(randint(0, 100000)),
|
||||||
StaticFields.RELATIONSHIPS: relationships[host_id]
|
StaticFields.RELATIONSHIPS: relationships[host_id]
|
||||||
@ -613,7 +613,7 @@ def _get_static_snapshot_driver_values(spec):
|
|||||||
target_id = 'c{}'.format(custom_num - 1 - index)
|
target_id = 'c{}'.format(custom_num - 1 - index)
|
||||||
source_name = 'custom-{}'.format(source_id)
|
source_name = 'custom-{}'.format(source_id)
|
||||||
vals = {
|
vals = {
|
||||||
StaticFields.CONFIG_ID: source_id,
|
StaticFields.STATIC_ID: source_id,
|
||||||
StaticFields.TYPE: 'custom',
|
StaticFields.TYPE: 'custom',
|
||||||
StaticFields.ID: str(randint(0, 100000)),
|
StaticFields.ID: str(randint(0, 100000)),
|
||||||
StaticFields.NAME: source_name,
|
StaticFields.NAME: source_name,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "[switch|host|custom]-[1-9]",
|
"name": "[switch|host|custom]-[1-9]",
|
||||||
"id": "[1-9]{5}",
|
"id": "[1-9]{5}",
|
||||||
"config_id": "[shc][1-9]",
|
"static_id": "[shc][1-9]",
|
||||||
"type": "[switch|nova.host|custom]",
|
"type": "[switch|nova.host|custom]",
|
||||||
"state": "available",
|
"state": "available",
|
||||||
"vitrage_datasource_action": "snapshot",
|
"vitrage_datasource_action": "snapshot",
|
||||||
|
@ -3,35 +3,35 @@ metadata:
|
|||||||
description: static datasource for test
|
description: static datasource for test
|
||||||
definitions:
|
definitions:
|
||||||
entities:
|
entities:
|
||||||
- config_id: s1
|
- static_id: s1
|
||||||
type: switch
|
type: switch
|
||||||
name: switch-1
|
name: switch-1
|
||||||
id: 12345
|
id: 12345
|
||||||
state: available
|
state: available
|
||||||
- config_id: s2
|
- static_id: s2
|
||||||
type: switch
|
type: switch
|
||||||
name: switch-2
|
name: switch-2
|
||||||
id: 23456
|
id: 23456
|
||||||
state: available
|
state: available
|
||||||
- config_id: s3
|
- static_id: s3
|
||||||
type: switch
|
type: switch
|
||||||
name: switch-3
|
name: switch-3
|
||||||
id: 34567
|
id: 34567
|
||||||
state: available
|
state: available
|
||||||
- config_id: r1
|
- static_id: r1
|
||||||
type: router
|
type: router
|
||||||
name: router-1
|
name: router-1
|
||||||
id: 45678
|
id: 45678
|
||||||
- config_id: h1
|
- static_id: h1
|
||||||
type: nova.host
|
type: nova.host
|
||||||
id: 1
|
id: 1
|
||||||
- config_id: h2
|
- static_id: h2
|
||||||
type: nova.host
|
type: nova.host
|
||||||
id: 2
|
id: 2
|
||||||
- config_id: h3
|
- static_id: h3
|
||||||
type: nova.host
|
type: nova.host
|
||||||
id: 3
|
id: 3
|
||||||
- config_id: h4
|
- static_id: h4
|
||||||
type: nova.host
|
type: nova.host
|
||||||
id: 4
|
id: 4
|
||||||
relationships:
|
relationships:
|
||||||
|
@ -107,12 +107,12 @@ class TestStaticDriver(base.BaseTest):
|
|||||||
self._validate_static_rel(entity, rel)
|
self._validate_static_rel(entity, rel)
|
||||||
|
|
||||||
def _validate_static_rel(self, 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]))
|
(rel[StaticFields.SOURCE], rel[StaticFields.TARGET]))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
isinstance(rel[StaticFields.SOURCE], dict)
|
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)
|
or isinstance(rel[StaticFields.TARGET], dict)
|
||||||
and entity[StaticFields.CONFIG_ID] == rel[StaticFields.SOURCE]
|
and entity[StaticFields.STATIC_ID] == rel[StaticFields.SOURCE]
|
||||||
or entity[StaticFields.CONFIG_ID] == rel[StaticFields.SOURCE]
|
or entity[StaticFields.STATIC_ID] == rel[StaticFields.SOURCE]
|
||||||
and entity[StaticFields.CONFIG_ID] == rel[StaticFields.TARGET])
|
and entity[StaticFields.STATIC_ID] == rel[StaticFields.TARGET])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user