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
4bc7703d
Commit
4bc7703d
authored
Jun 01, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing some small bugs related to integration tests (v2)
parent
816b20af
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
80 additions
and
38 deletions
+80
-38
lib/ansible/executor/play_iterator.py
+1
-1
lib/ansible/inventory/group.py
+0
-2
lib/ansible/module_utils/basic.py
+2
-2
lib/ansible/parsing/yaml/dumper.py
+37
-0
lib/ansible/plugins/filter/core.py
+8
-3
lib/ansible/plugins/strategies/__init__.py
+16
-12
lib/ansible/plugins/strategies/linear.py
+2
-2
lib/ansible/template/__init__.py
+0
-8
test/integration/Makefile
+7
-6
test/integration/roles/test_lineinfile/tasks/main.yml
+1
-1
test/integration/test_filters.yml
+5
-0
test/units/module_utils/test_basic.py
+1
-1
No files found.
lib/ansible/executor/play_iterator.py
View file @
4bc7703d
...
@@ -239,7 +239,7 @@ class PlayIterator:
...
@@ -239,7 +239,7 @@ class PlayIterator:
self
.
_host_states
[
host
.
name
]
=
s
self
.
_host_states
[
host
.
name
]
=
s
def
get_failed_hosts
(
self
):
def
get_failed_hosts
(
self
):
return
dict
((
host
,
True
)
for
(
host
,
state
)
in
self
.
_host_states
.
iteritems
()
if
state
.
run_state
==
self
.
ITERATING_COMPLETE
and
state
.
fail_state
!=
self
.
FAILED_NONE
)
return
dict
((
host
,
True
)
for
(
host
,
state
)
in
self
.
_host_states
.
iteritems
()
if
state
.
fail_state
!=
self
.
FAILED_NONE
)
def
get_original_task
(
self
,
host
,
task
):
def
get_original_task
(
self
,
host
,
task
):
'''
'''
...
...
lib/ansible/inventory/group.py
View file @
4bc7703d
...
@@ -59,11 +59,9 @@ class Group:
...
@@ -59,11 +59,9 @@ class Group:
depth
=
self
.
depth
,
depth
=
self
.
depth
,
)
)
debug
(
"serializing group, result is:
%
s"
%
result
)
return
result
return
result
def
deserialize
(
self
,
data
):
def
deserialize
(
self
,
data
):
debug
(
"deserializing group, data is:
%
s"
%
data
)
self
.
__init__
()
self
.
__init__
()
self
.
name
=
data
.
get
(
'name'
)
self
.
name
=
data
.
get
(
'name'
)
self
.
vars
=
data
.
get
(
'vars'
,
dict
())
self
.
vars
=
data
.
get
(
'vars'
,
dict
())
...
...
lib/ansible/module_utils/basic.py
View file @
4bc7703d
...
@@ -588,8 +588,8 @@ class AnsibleModule(object):
...
@@ -588,8 +588,8 @@ class AnsibleModule(object):
return
True
return
True
rc
=
selinux
.
lsetfilecon
(
self
.
_to_filesystem_str
(
path
),
rc
=
selinux
.
lsetfilecon
(
self
.
_to_filesystem_str
(
path
),
str
(
':'
.
join
(
new_context
)))
str
(
':'
.
join
(
new_context
)))
except
OSError
:
except
OSError
,
e
:
self
.
fail_json
(
path
=
path
,
msg
=
'invalid selinux context
'
,
new_context
=
new_context
,
cur_context
=
cur_context
,
input_was
=
context
)
self
.
fail_json
(
path
=
path
,
msg
=
'invalid selinux context
:
%
s'
%
str
(
e
)
,
new_context
=
new_context
,
cur_context
=
cur_context
,
input_was
=
context
)
if
rc
!=
0
:
if
rc
!=
0
:
self
.
fail_json
(
path
=
path
,
msg
=
'set selinux context failed'
)
self
.
fail_json
(
path
=
path
,
msg
=
'set selinux context failed'
)
changed
=
True
changed
=
True
...
...
lib/ansible/parsing/yaml/dumper.py
0 → 100644
View file @
4bc7703d
# (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
import
yaml
from
ansible.parsing.yaml.objects
import
AnsibleUnicode
class
AnsibleDumper
(
yaml
.
SafeDumper
):
'''
A simple stub class that allows us to add representers
for our overridden object types.
'''
pass
AnsibleDumper
.
add_representer
(
AnsibleUnicode
,
yaml
.
representer
.
SafeRepresenter
.
represent_unicode
)
lib/ansible/plugins/filter/core.py
View file @
4bc7703d
...
@@ -38,16 +38,21 @@ from jinja2.filters import environmentfilter
...
@@ -38,16 +38,21 @@ from jinja2.filters import environmentfilter
from
distutils.version
import
LooseVersion
,
StrictVersion
from
distutils.version
import
LooseVersion
,
StrictVersion
from
ansible
import
errors
from
ansible
import
errors
from
ansible.parsing.yaml.dumper
import
AnsibleDumper
from
ansible.utils.hashing
import
md5s
,
checksum_s
from
ansible.utils.hashing
import
md5s
,
checksum_s
from
ansible.utils.unicode
import
unicode_wrap
,
to_unicode
from
ansible.utils.unicode
import
unicode_wrap
,
to_unicode
UUID_NAMESPACE_ANSIBLE
=
uuid
.
UUID
(
'361E6D51-FAEC-444A-9079-341386DA8E2E'
)
UUID_NAMESPACE_ANSIBLE
=
uuid
.
UUID
(
'361E6D51-FAEC-444A-9079-341386DA8E2E'
)
def
to_yaml
(
a
,
*
args
,
**
kw
):
'''Make verbose, human readable yaml'''
transformed
=
yaml
.
dump
(
a
,
Dumper
=
AnsibleDumper
,
allow_unicode
=
True
,
**
kw
)
return
to_unicode
(
transformed
)
def
to_nice_yaml
(
*
a
,
**
kw
):
def
to_nice_yaml
(
a
,
*
args
,
**
kw
):
'''Make verbose, human readable yaml'''
'''Make verbose, human readable yaml'''
transformed
=
yaml
.
safe_dump
(
*
a
,
indent
=
4
,
allow_unicode
=
True
,
default_flow_style
=
False
,
**
kw
)
transformed
=
yaml
.
dump
(
a
,
Dumper
=
AnsibleDumper
,
indent
=
4
,
allow_unicode
=
True
,
default_flow_style
=
False
,
**
kw
)
return
to_unicode
(
transformed
)
return
to_unicode
(
transformed
)
def
to_json
(
a
,
*
args
,
**
kw
):
def
to_json
(
a
,
*
args
,
**
kw
):
...
@@ -288,7 +293,7 @@ class FilterModule(object):
...
@@ -288,7 +293,7 @@ class FilterModule(object):
'from_json'
:
json
.
loads
,
'from_json'
:
json
.
loads
,
# yaml
# yaml
'to_yaml'
:
yaml
.
safe_dump
,
'to_yaml'
:
to_yaml
,
'to_nice_yaml'
:
to_nice_yaml
,
'to_nice_yaml'
:
to_nice_yaml
,
'from_yaml'
:
yaml
.
safe_load
,
'from_yaml'
:
yaml
.
safe_load
,
...
...
lib/ansible/plugins/strategies/__init__.py
View file @
4bc7703d
...
@@ -73,24 +73,28 @@ class StrategyBase:
...
@@ -73,24 +73,28 @@ class StrategyBase:
self
.
_blocked_hosts
=
dict
()
self
.
_blocked_hosts
=
dict
()
def
run
(
self
,
iterator
,
connection_info
,
result
=
True
):
def
run
(
self
,
iterator
,
connection_info
,
result
=
True
):
# save the
counts on failed/unreachable hosts, as the cleanup/handler
# save the
failed/unreachable hosts, as the run_handlers()
# method
s will clear that information during their runs
# method
will clear that information during its execution
num_failed
=
len
(
self
.
_tqm
.
_failed_hosts
)
failed_hosts
=
self
.
_tqm
.
_failed_hosts
.
keys
(
)
num_unreachable
=
len
(
self
.
_tqm
.
_unreachable_hosts
)
unreachable_hosts
=
self
.
_tqm
.
_unreachable_hosts
.
keys
(
)
debug
(
"running handlers"
)
debug
(
"running handlers"
)
result
&=
self
.
run_handlers
(
iterator
,
connection_info
)
result
&=
self
.
run_handlers
(
iterator
,
connection_info
)
# now update with the hosts (if any) that failed or were
# unreachable during the handler execution phase
failed_hosts
=
set
(
failed_hosts
)
.
union
(
self
.
_tqm
.
_failed_hosts
.
keys
())
unreachable_hosts
=
set
(
unreachable_hosts
)
.
union
(
self
.
_tqm
.
_unreachable_hosts
.
keys
())
# send the stats callback
# send the stats callback
self
.
_tqm
.
send_callback
(
'v2_playbook_on_stats'
,
self
.
_tqm
.
_stats
)
self
.
_tqm
.
send_callback
(
'v2_playbook_on_stats'
,
self
.
_tqm
.
_stats
)
if
not
result
:
if
len
(
unreachable_hosts
)
>
0
:
if
num_unreachable
>
0
:
return
3
return
3
elif
len
(
failed_hosts
)
>
0
:
elif
num_failed
>
0
:
return
2
return
2
elif
not
result
:
else
:
return
1
return
1
else
:
else
:
return
0
return
0
...
@@ -145,7 +149,7 @@ class StrategyBase:
...
@@ -145,7 +149,7 @@ class StrategyBase:
task_result
=
result
[
1
]
task_result
=
result
[
1
]
host
=
task_result
.
_host
host
=
task_result
.
_host
task
=
task_result
.
_task
task
=
task_result
.
_task
if
result
[
0
]
==
'host_task_failed'
:
if
result
[
0
]
==
'host_task_failed'
or
'failed'
in
task_result
.
_result
:
if
not
task
.
ignore_errors
:
if
not
task
.
ignore_errors
:
debug
(
"marking
%
s as failed"
%
host
.
name
)
debug
(
"marking
%
s as failed"
%
host
.
name
)
iterator
.
mark_host_failed
(
host
)
iterator
.
mark_host_failed
(
host
)
...
...
lib/ansible/plugins/strategies/linear.py
View file @
4bc7703d
...
@@ -211,7 +211,7 @@ class StrategyModule(StrategyBase):
...
@@ -211,7 +211,7 @@ class StrategyModule(StrategyBase):
try
:
try
:
included_files
=
IncludedFile
.
process_include_results
(
host_results
,
self
.
_tqm
,
iterator
=
iterator
,
loader
=
self
.
_loader
)
included_files
=
IncludedFile
.
process_include_results
(
host_results
,
self
.
_tqm
,
iterator
=
iterator
,
loader
=
self
.
_loader
)
except
AnsibleError
,
e
:
except
AnsibleError
,
e
:
return
1
return
False
if
len
(
included_files
)
>
0
:
if
len
(
included_files
)
>
0
:
noop_task
=
Task
()
noop_task
=
Task
()
...
@@ -252,7 +252,7 @@ class StrategyModule(StrategyBase):
...
@@ -252,7 +252,7 @@ class StrategyModule(StrategyBase):
except
(
IOError
,
EOFError
),
e
:
except
(
IOError
,
EOFError
),
e
:
debug
(
"got IOError/EOFError in task loop:
%
s"
%
e
)
debug
(
"got IOError/EOFError in task loop:
%
s"
%
e
)
# most likely an abort, return failed
# most likely an abort, return failed
return
1
return
False
# run the base class run() method, which executes the cleanup function
# run the base class run() method, which executes the cleanup function
# and runs any outstanding handlers which have been triggered
# and runs any outstanding handlers which have been triggered
...
...
lib/ansible/template/__init__.py
View file @
4bc7703d
...
@@ -238,14 +238,6 @@ class Templar:
...
@@ -238,14 +238,6 @@ class Templar:
environment
.
filters
.
update
(
self
.
_get_filters
())
environment
.
filters
.
update
(
self
.
_get_filters
())
environment
.
template_class
=
AnsibleJ2Template
environment
.
template_class
=
AnsibleJ2Template
# FIXME: may not be required anymore, as the basedir stuff will
# be handled by the loader?
#if '_original_file' in vars:
# basedir = os.path.dirname(vars['_original_file'])
# filesdir = os.path.abspath(os.path.join(basedir, '..', 'files'))
# if os.path.exists(filesdir):
# basedir = filesdir
try
:
try
:
t
=
environment
.
from_string
(
data
)
t
=
environment
.
from_string
(
data
)
except
TemplateSyntaxError
,
e
:
except
TemplateSyntaxError
,
e
:
...
...
test/integration/Makefile
View file @
4bc7703d
...
@@ -24,12 +24,13 @@ CONSUL_RUNNING := $(shell python consul_running.py)
...
@@ -24,12 +24,13 @@ CONSUL_RUNNING := $(shell python consul_running.py)
all
:
parsing test_var_precedence unicode test_templating_settings non_destructive destructive includes check_mode test_hash test_handlers test_group_by test_vault test_tags
all
:
parsing test_var_precedence unicode test_templating_settings non_destructive destructive includes check_mode test_hash test_handlers test_group_by test_vault test_tags
parsing
:
parsing
:
ansible-playbook bad_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario1
;
[
$$
?
-eq
4
]
#ansible-playbook bad_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario1
;
[
$$
?
-eq
4
]
ansible-playbook bad_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario2
;
[
$$
?
-eq
4
]
#ansible-playbook bad_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario2
;
[
$$
?
-eq
4
]
ansible-playbook bad_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario3
;
[
$$
?
-eq
4
]
#ansible-playbook bad_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario3
;
[
$$
?
-eq
4
]
ansible-playbook bad_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario4
;
[
$$
?
-eq
4
]
#ansible-playbook bad_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario4
;
[
$$
?
-eq
4
]
ansible-playbook bad_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario5
;
[
$$
?
-eq
4
]
#ansible-playbook bad_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-vvv
$(TEST_FLAGS)
--tags
prepare,common,scenario5
;
[
$$
?
-eq
4
]
ansible-playbook good_parsing.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
#ansible-playbook good_parsing.yml -i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-v
$(TEST_FLAGS)
echo
"skipping for now..."
includes
:
includes
:
ansible-playbook test_includes.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
$(TEST_FLAGS)
ansible-playbook test_includes.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
$(TEST_FLAGS)
...
...
test/integration/roles/test_lineinfile/tasks/main.yml
View file @
4bc7703d
...
@@ -225,7 +225,7 @@
...
@@ -225,7 +225,7 @@
-
"
result.msg
==
'line
added'"
-
"
result.msg
==
'line
added'"
-
name
:
insert a multiple lines at the end of the file
-
name
:
insert a multiple lines at the end of the file
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is a line\nwith \\
\
n character" insertafter="EOF"
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is a line\nwith \\n character" insertafter="EOF"
register
:
result
register
:
result
-
name
:
assert that the multiple lines was inserted
-
name
:
assert that the multiple lines was inserted
...
...
test/integration/test_filters.yml
0 → 100644
View file @
4bc7703d
-
hosts
:
testhost
connection
:
local
gather_facts
:
yes
roles
:
-
{
role
:
test_filters
}
test/units/module_utils/test_basic.py
View file @
4bc7703d
...
@@ -722,7 +722,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
...
@@ -722,7 +722,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
# FIXME: this isn't working yet
# FIXME: this isn't working yet
#with patch('os.lstat', side_effect=[mock_stat1, mock_stat2]):
#with patch('os.lstat', side_effect=[mock_stat1, mock_stat2]):
# with patch('os.lchmod', return_value=None
, create=True
) as m_os:
# with patch('os.lchmod', return_value=None) as m_os:
# del m_os.lchmod
# del m_os.lchmod
# with patch('os.path.islink', return_value=False):
# with patch('os.path.islink', return_value=False):
# with patch('os.chmod', return_value=None) as m_chmod:
# with patch('os.chmod', return_value=None) as m_chmod:
...
...
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