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
4aa2bf9e
authored
Nov 19, 2016
by
Simon János
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flat_leaves option on ResourceGroup.diff()
parent
c70a8f28
Pipeline
#289
passed with stage
in 33 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
orchestrator/model/resources.py
+3
-3
tests/test_model.py
+24
-3
No files found.
orchestrator/model/resources.py
View file @
4aa2bf9e
...
@@ -141,9 +141,9 @@ class ResourceGroup(Resource):
...
@@ -141,9 +141,9 @@ class ResourceGroup(Resource):
def
resources
(
self
):
def
resources
(
self
):
return
list
(
self
.
__resources
.
values
())
return
list
(
self
.
__resources
.
values
())
def
diff
(
self
,
other
):
def
diff
(
self
,
other
,
flat_leaves
=
True
):
flat_self
=
self
.
flatten
()
flat_self
=
self
.
flatten
(
flat_leaves
=
flat_leaves
)
flat_other
=
other
.
flatten
()
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
}
return
{
key
:
flat_self
.
get
(
key
,
flat_other
.
get
(
key
))
for
key
in
diff_keys
}
...
...
tests/test_model.py
View file @
4aa2bf9e
...
@@ -334,7 +334,7 @@ class ResourceGroupTest(TestCase):
...
@@ -334,7 +334,7 @@ class ResourceGroupTest(TestCase):
# then
# then
self
.
assertEqual
(
expected_flat_dict
,
flat_dict
)
self
.
assertEqual
(
expected_flat_dict
,
flat_dict
)
def
test_resource_group_diff
(
self
):
def
test_resource_group_diff
_flat_leaves
(
self
):
# given
# given
group1
=
ResourceGroup
(
self
.
TEST_TREE_DICT
)
group1
=
ResourceGroup
(
self
.
TEST_TREE_DICT
)
...
@@ -348,8 +348,29 @@ class ResourceGroupTest(TestCase):
...
@@ -348,8 +348,29 @@ class ResourceGroupTest(TestCase):
}
}
# when
# when
diff1
=
group1
.
diff
(
group2
)
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
True
)
diff2
=
group2
.
diff
(
group1
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
True
)
# then
self
.
assertEqual
(
diff1
,
diff2
)
self
.
assertEqual
(
expected_diff
,
diff1
)
def
test_resource_group_diff_not_flat_leaves
(
self
):
# given
group1
=
ResourceGroup
(
self
.
TEST_TREE_DICT
)
tree_dict2
=
copy
.
deepcopy
(
self
.
TEST_TREE_DICT
)
removed_resource
=
tree_dict2
[
'resources'
][
0
]
del
tree_dict2
[
'resources'
][
0
]
group2
=
ResourceGroup
(
tree_dict2
)
expected_diff
=
{
'root.instance-1'
:
Instance
(
id
=
removed_resource
[
'id'
])
}
# when
diff1
=
group1
.
diff
(
group2
,
flat_leaves
=
False
)
diff2
=
group2
.
diff
(
group1
,
flat_leaves
=
False
)
# then
# then
self
.
assertEqual
(
diff1
,
diff2
)
self
.
assertEqual
(
diff1
,
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