Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Simon János
/
orchestrator
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b927b8e6
authored
Nov 19, 2016
by
Simon János
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diff returns added and removed resources separately
parent
4aa2bf9e
Pipeline
#290
passed with stage
in 33 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
orchestrator/model/resources.py
+7
-1
tests/test_model.py
+24
-6
No files found.
orchestrator/model/resources.py
View file @
b927b8e6
...
@@ -142,10 +142,16 @@ class ResourceGroup(Resource):
...
@@ -142,10 +142,16 @@ class ResourceGroup(Resource):
return
list
(
self
.
__resources
.
values
())
return
list
(
self
.
__resources
.
values
())
def
diff
(
self
,
other
,
flat_leaves
=
True
):
def
diff
(
self
,
other
,
flat_leaves
=
True
):
diff
=
{
'added'
:
{},
'removed'
:
{}}
flat_self
=
self
.
flatten
(
flat_leaves
=
flat_leaves
)
flat_self
=
self
.
flatten
(
flat_leaves
=
flat_leaves
)
flat_other
=
other
.
flatten
(
flat_leaves
=
flat_leaves
)
flat_other
=
other
.
flatten
(
flat_leaves
=
flat_leaves
)
diff_keys
=
set
(
flat_self
.
keys
())
.
symmetric_difference
(
flat_other
.
keys
())
diff_keys
=
set
(
flat_self
.
keys
())
.
symmetric_difference
(
flat_other
.
keys
())
return
{
key
:
flat_self
.
get
(
key
,
flat_other
.
get
(
key
))
for
key
in
diff_keys
}
for
key
in
diff_keys
:
if
key
in
flat_self
.
keys
():
diff
[
'removed'
][
key
]
=
flat_self
[
key
]
if
key
in
flat_other
.
keys
():
diff
[
'added'
][
key
]
=
flat_other
[
key
]
return
diff
def
flatten
(
self
,
fqn
=
None
,
flat_leaves
=
True
):
def
flatten
(
self
,
fqn
=
None
,
flat_leaves
=
True
):
flat
=
dict
()
flat
=
dict
()
...
...
tests/test_model.py
View file @
b927b8e6
...
@@ -342,18 +342,27 @@ class ResourceGroupTest(TestCase):
...
@@ -342,18 +342,27 @@ class ResourceGroupTest(TestCase):
del
tree_dict2
[
'resources'
][
0
]
del
tree_dict2
[
'resources'
][
0
]
group2
=
ResourceGroup
(
tree_dict2
)
group2
=
ResourceGroup
(
tree_dict2
)
expected_diff
=
{
expected_diff
_values
=
{
'root.instance-1.id'
:
'instance-1'
,
'root.instance-1.id'
:
'instance-1'
,
'root.instance-1.type'
:
'instance'
,
'root.instance-1.type'
:
'instance'
,
}
}
expected_diff_added
=
{
'added'
:
expected_diff_values
,
'removed'
:
{}
}
expected_diff_removed
=
{
'added'
:
{},
'removed'
:
expected_diff_values
}
# when
# when
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
True
)
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
True
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
True
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
True
)
# then
# then
self
.
assertEqual
(
diff1
,
diff2
)
self
.
assertNotEqual
(
diff1
,
diff2
)
self
.
assertEqual
(
expected_diff
,
diff1
)
self
.
assertEqual
(
expected_diff_removed
,
diff1
)
self
.
assertEqual
(
expected_diff_added
,
diff2
)
def
test_resource_group_diff_not_flat_leaves
(
self
):
def
test_resource_group_diff_not_flat_leaves
(
self
):
# given
# given
...
@@ -364,14 +373,23 @@ class ResourceGroupTest(TestCase):
...
@@ -364,14 +373,23 @@ class ResourceGroupTest(TestCase):
del
tree_dict2
[
'resources'
][
0
]
del
tree_dict2
[
'resources'
][
0
]
group2
=
ResourceGroup
(
tree_dict2
)
group2
=
ResourceGroup
(
tree_dict2
)
expected_diff
=
{
expected_diff
_values
=
{
'root.instance-1'
:
Instance
(
id
=
removed_resource
[
'id'
])
'root.instance-1'
:
Instance
(
id
=
removed_resource
[
'id'
])
}
}
expected_diff_added
=
{
'added'
:
expected_diff_values
,
'removed'
:
{}
}
expected_diff_removed
=
{
'added'
:
{},
'removed'
:
expected_diff_values
}
# when
# when
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
False
)
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
False
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
False
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
False
)
# then
# then
self
.
assertEqual
(
diff1
,
diff2
)
self
.
assertNotEqual
(
diff1
,
diff2
)
self
.
assertEqual
(
expected_diff
,
diff1
)
self
.
assertEqual
(
expected_diff_removed
,
diff1
)
self
.
assertEqual
(
expected_diff_added
,
diff2
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment