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
87cc9250
authored
Nov 16, 2016
by
Simon János
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resource group diff method based on flat model keys
parent
9b554083
Pipeline
#284
passed with stage
in 32 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
orchestrator/model/resources.py
+6
-0
tests/test_resources.py
+49
-0
No files found.
orchestrator/model/resources.py
View file @
87cc9250
...
...
@@ -134,6 +134,12 @@ class ResourceGroup(Resource):
def
resources
(
self
):
return
list
(
self
.
__resources
.
values
())
def
diff
(
self
,
other
):
flat_self
=
self
.
flatten
()
flat_other
=
other
.
flatten
()
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
}
def
flatten
(
self
,
fqn
=
None
):
flat
=
dict
()
for
resource
in
self
.
resources
:
...
...
tests/test_resources.py
View file @
87cc9250
import
copy
import
json
from
unittest.case
import
TestCase
...
...
@@ -251,6 +252,7 @@ class ResourceGroupTest(TestCase):
ResourceGroup
(
id
=
'some_group'
,
resources
=
[
resource2
]))
def
test_resource_group_flatten
(
self
):
# given
tree_dict
=
{
'id'
:
'root'
,
'type'
:
'group'
,
...
...
@@ -284,7 +286,54 @@ class ResourceGroupTest(TestCase):
'root.level-1.instance-3.type'
:
'instance'
}
# when
tree_resource
=
Resource
(
tree_dict
)
flat_dict
=
tree_resource
.
flatten
()
# then
self
.
assertEqual
(
expected_flat_dict
,
flat_dict
)
def
test_resource_group_diff
(
self
):
# given
tree_dict1
=
{
'id'
:
'root'
,
'type'
:
'group'
,
'resources'
:
[
{
'id'
:
'instance-1'
,
'type'
:
'instance'
},
{
'id'
:
'level-1'
,
'type'
:
'group'
,
'resources'
:
[
{
'id'
:
'instance-2'
,
'type'
:
'instance'
},
{
'id'
:
'instance-3'
,
'type'
:
'instance'
}
]
}
]
}
group1
=
ResourceGroup
(
tree_dict1
)
tree_dict2
=
copy
.
deepcopy
(
tree_dict1
)
del
tree_dict2
[
'resources'
][
0
]
group2
=
ResourceGroup
(
tree_dict2
)
expected_diff
=
{
'root.instance-1.id'
:
'instance-1'
,
'root.instance-1.type'
:
'instance'
,
}
# when
diff1
=
group1
.
diff
(
group2
)
diff2
=
group2
.
diff
(
group1
)
# then
self
.
assertEqual
(
diff1
,
diff2
)
self
.
assertEqual
(
expected_diff
,
diff1
)
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