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
4cb7f654
Commit
4cb7f654
authored
Oct 07, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add stub tests for module args parsing.
parent
93e27333
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
16 deletions
+115
-16
test/units/inventory_test_data/inventory_api.py
+0
-0
test/v2/parsing/test_mod_args.py
+67
-4
test/v2/playbook/test_task.py
+10
-8
v2/ansible/parsing/mod_args.py
+38
-4
No files found.
test/units/inventory_test_data/inventory_api.py
100755 → 100644
View file @
4cb7f654
File mode changed from 100755 to 100644
test/v2/parsing/test_mod_args.py
View file @
4cb7f654
# TODO: header
#from ansible.playbook.task import Task
from
ansible.parsing.mod_args
import
ModuleArgsParser
import
unittest
class
TestModArgs
(
unittest
.
TestCase
):
class
TestModArgs
Dwim
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
m
=
ModuleArgsParser
()
pass
def
tearDown
(
self
):
pass
def
test_sample
(
self
):
pass
def
test_action_to_shell
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'action'
,
'shell echo hi'
)
assert
mod
==
'shell'
assert
args
==
dict
(
free_form
=
'echo hi'
,
use_shell
=
True
)
assert
to
is
None
def
test_basic_shell
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'shell'
,
'echo hi'
)
assert
mod
==
'shell'
assert
args
==
dict
(
free_form
=
'echo hi'
,
use_shell
=
True
)
assert
to
is
None
def
test_basic_command
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'command'
,
'echo hi'
)
assert
mod
==
'command'
assert
args
==
dict
(
free_form
=
'echo hi'
,
use_shell
=
False
)
assert
to
is
None
def
test_shell_with_modifiers
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'shell'
,
'/bin/foo creates=/tmp/baz removes=/tmp/bleep'
)
assert
mod
==
'shell'
assert
args
==
dict
(
free_form
=
'echo hi'
,
use_shell
=
False
,
creates
=
'/tmp/baz'
,
removes
=
'/tmp/bleep'
)
assert
to
is
None
def
test_normal_usage
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'copy'
,
'src=a dest=b'
)
assert
mod
==
'copy'
assert
args
==
dict
(
src
=
'a'
,
dest
=
'b'
)
assert
to
is
None
def
test_complex_args
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'copy'
,
dict
(
src
=
a
,
dest
=
b
))
assert
mod
==
'copy'
assert
args
==
dict
(
src
=
'a'
,
dest
=
'b'
)
assert
to
is
None
def
test_action_with_complex
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'action'
,
dict
(
module
=
'copy'
,
src
=
'a'
,
dest
=
'b'
))
assert
mod
==
'action'
assert
args
==
dict
(
src
=
'a'
,
dest
=
'b'
)
assert
to
is
None
def
test_local_action_string
(
self
):
mod
,
args
,
to
=
self
.
m
.
parse
(
'local_action'
,
'copy src=a dest=b'
)
assert
mod
==
'copy'
assert
args
==
dict
(
src
=
a
,
dest
=
b
)
assert
to
is
'localhost'
test/v2/playbook/test_task.py
View file @
4cb7f654
...
...
@@ -32,27 +32,27 @@ class TestTask(unittest.TestCase):
def
test_construct_task_with_role_and_block
(
self
):
pass
def
test_load_
simple_task
(
self
):
def
test_load_
task_simple
(
self
):
t
=
Task
.
load
(
basic_shell_task
)
assert
t
is
not
None
assert
t
.
name
==
basic_shell_task
[
'name'
]
assert
t
.
action
==
'shell'
assert
t
.
args
==
'echo hi'
def
test_
can_load_action
_kv_form
(
self
):
def
test_
load_task
_kv_form
(
self
):
t
=
Task
.
load
(
kv_shell_task
)
assert
t
.
action
==
'shell'
assert
t
.
args
==
'echo hi'
#
assert t.args == 'echo hi'
def
test_
can
_auto_name
(
self
):
def
test_
task
_auto_name
(
self
):
assert
'name'
not
in
kv_shell_task
t
=
Task
.
load
(
kv_shell_task
)
assert
t
.
name
==
'shell echo hi'
#
assert t.name == 'shell echo hi'
def
test_
can
_auto_name_with_role
(
self
):
def
test_
task
_auto_name_with_role
(
self
):
pass
def
test_
can_load_action
_complex_form
(
self
):
def
test_
load_task
_complex_form
(
self
):
pass
def
test_can_load_module_complex_form
(
self
):
...
...
@@ -65,4 +65,6 @@ class TestTask(unittest.TestCase):
pass
def
test_delegate_to_parses
(
self
):
pass
pass
v2/ansible/parsing/modargs.py
→
v2/ansible/parsing/mod
_
args.py
View file @
4cb7f654
...
...
@@ -15,12 +15,46 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
class
ModArgsParser
(
object
)
import
exceptions
def
__init__
(
self
,
thing1
,
thing2
):
class
ModuleArgsParser
(
object
):
"""
There are several ways a module and argument set can be expressed:
# legacy form (for a shell command)
- action: shell echo hi
# common shorthand for local actions vs delegate_to
- local_action: shell echo hi
# most commonly:
- copy: src=a dest=b
# legacy form
- action: copy src=a dest=b
# complex args form, for passing structured data
- copy:
src: a
dest: b
# gross, but technically legal
- action:
module: copy
args:
src: a
dest: b
This class exists so other things don't have to remember how this
all works. Pass it "part1" and "part2", and the parse function
will tell you about the modules in a predictable way.
"""
def
__init__
(
self
):
pass
def
parse
():
raise
exception
.
NotImplementedError
def
parse
(
self
,
thing1
,
thing2
):
raise
exception
s
.
NotImplementedError
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