Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
57d2622c
Commit
57d2622c
authored
Oct 16, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding block code and tests
parent
21577ff2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
11 deletions
+126
-11
v2/ansible/playbook/attribute.py
+0
-2
v2/ansible/playbook/base.py
+5
-5
v2/ansible/playbook/block.py
+42
-4
v2/test/playbook/test_block.py
+79
-0
No files found.
v2/ansible/playbook/attribute.py
View file @
57d2622c
...
...
@@ -19,8 +19,6 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
#from ansible.common.errors import AnsibleError
class
Attribute
:
def
__init__
(
self
,
isa
=
None
,
private
=
False
,
default
=
None
):
...
...
v2/ansible/playbook/base.py
View file @
57d2622c
...
...
@@ -65,11 +65,11 @@ class Base:
if
isinstance
(
attribute
,
FieldAttribute
):
# copy the value over unless a _load_field method is defined
method
=
getattr
(
self
,
'_load_
%
s'
%
aname
,
None
)
if
method
:
self
.
_attributes
[
aname
]
=
method
(
self
,
attribute
)
else
:
if
aname
in
ds
:
if
aname
in
ds
:
method
=
getattr
(
self
,
'_load_
%
s'
%
aname
,
None
)
if
method
:
self
.
_attributes
[
aname
]
=
method
(
aname
,
ds
[
aname
])
else
:
self
.
_attributes
[
aname
]
=
ds
[
aname
]
# return the constructed object
...
...
v2/ansible/playbook/block.py
View file @
57d2622c
...
...
@@ -19,10 +19,48 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
v2.playbook.base
import
PlaybookBase
from
ansible.playbook.base
import
Base
from
ansible.playbook.task
import
Task
from
ansible.playbook.attribute
import
Attribute
,
FieldAttribute
class
Block
(
Playbook
Base
):
class
Block
(
Base
):
def
__init__
(
self
):
pass
_begin
=
FieldAttribute
(
isa
=
'list'
)
_rescue
=
FieldAttribute
(
isa
=
'list'
)
_end
=
FieldAttribute
(
isa
=
'list'
)
_otherwise
=
FieldAttribute
(
isa
=
'list'
)
def
__init__
(
self
,
role
=
None
):
self
.
role
=
role
super
(
Block
,
self
)
.
__init__
()
def
get_variables
(
self
):
# blocks do not (currently) store any variables directly,
# so we just return an empty dict here
return
dict
()
@staticmethod
def
load
(
data
,
role
=
None
):
b
=
Block
(
role
=
role
)
return
b
.
load_data
(
data
)
def
_load_list_of_tasks
(
self
,
ds
):
assert
type
(
ds
)
==
list
task_list
=
[]
for
task
in
ds
:
t
=
Task
.
load
(
task
)
task_list
.
append
(
t
)
return
task_list
def
_load_begin
(
self
,
attr
,
ds
):
return
self
.
_load_list_of_tasks
(
ds
)
def
_load_rescue
(
self
,
attr
,
ds
):
return
self
.
_load_list_of_tasks
(
ds
)
def
_load_end
(
self
,
attr
,
ds
):
return
self
.
_load_list_of_tasks
(
ds
)
def
_load_otherwise
(
self
,
attr
,
ds
):
return
self
.
_load_list_of_tasks
(
ds
)
v2/test/playbook/test_block.py
0 → 100644
View file @
57d2622c
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
ansible.playbook.block
import
Block
from
ansible.playbook.task
import
Task
from
..
compat
import
unittest
class
TestBlock
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
def
tearDown
(
self
):
pass
def
test_construct_empty_block
(
self
):
b
=
Block
()
def
test_construct_block_with_role
(
self
):
pass
def
test_block__load_list_of_tasks
(
self
):
task
=
dict
(
action
=
'test'
)
b
=
Block
()
self
.
assertEqual
(
b
.
_load_list_of_tasks
([]),
[])
res
=
b
.
_load_list_of_tasks
([
task
])
self
.
assertEqual
(
len
(
res
),
1
)
assert
isinstance
(
res
[
0
],
Task
)
res
=
b
.
_load_list_of_tasks
([
task
,
task
,
task
])
self
.
assertEqual
(
len
(
res
),
3
)
def
test_load_block_simple
(
self
):
ds
=
dict
(
begin
=
[],
rescue
=
[],
end
=
[],
otherwise
=
[],
)
b
=
Block
.
load
(
ds
)
self
.
assertEqual
(
b
.
begin
,
[])
self
.
assertEqual
(
b
.
rescue
,
[])
self
.
assertEqual
(
b
.
end
,
[])
self
.
assertEqual
(
b
.
otherwise
,
[])
def
test_load_block_with_tasks
(
self
):
ds
=
dict
(
begin
=
[
dict
(
action
=
'begin'
)],
rescue
=
[
dict
(
action
=
'rescue'
)],
end
=
[
dict
(
action
=
'end'
)],
otherwise
=
[
dict
(
action
=
'otherwise'
)],
)
b
=
Block
.
load
(
ds
)
self
.
assertEqual
(
len
(
b
.
begin
),
1
)
assert
isinstance
(
b
.
begin
[
0
],
Task
)
self
.
assertEqual
(
len
(
b
.
rescue
),
1
)
assert
isinstance
(
b
.
rescue
[
0
],
Task
)
self
.
assertEqual
(
len
(
b
.
end
),
1
)
assert
isinstance
(
b
.
end
[
0
],
Task
)
self
.
assertEqual
(
len
(
b
.
otherwise
),
1
)
assert
isinstance
(
b
.
otherwise
[
0
],
Task
)
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