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
119434d0
Commit
119434d0
authored
Mar 06, 2014
by
Richard Isaacson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6319 from risaacson/fix_test_dir_inventory
Fix TestInventory Unit Tests Tested clean.
parents
868746b0
913c855d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
21 deletions
+40
-21
lib/ansible/inventory/ini.py
+16
-6
test/units/TestInventory.py
+21
-12
test/units/inventory_test_data/inventory_dir/0hosts
+1
-1
test/units/inventory_test_data/inventory_dir/2levels
+1
-1
test/units/inventory_test_data/inventory_dir/3comments
+1
-1
No files found.
lib/ansible/inventory/ini.py
View file @
119434d0
...
...
@@ -123,12 +123,22 @@ class InventoryParser(object):
(
k
,
v
)
=
t
.
split
(
"="
,
1
)
except
ValueError
,
e
:
raise
errors
.
AnsibleError
(
"Invalid ini entry:
%
s -
%
s"
%
(
t
,
str
(
e
)))
try
:
host
.
set_variable
(
k
,
ast
.
literal_eval
(
v
))
except
:
# most likely a string that literal_eval
# doesn't like, so just set it
host
.
set_variable
(
k
,
v
)
# If there is a hash in the value don't pass it through to ast at ast will split at the hash.
if
"#"
in
v
:
host
.
set_variable
(
k
,
v
)
else
:
try
:
host
.
set_variable
(
k
,
ast
.
literal_eval
(
v
))
# Using explicit exceptions.
# Likely a string that literal_eval does not like. We wil then just set it.
except
ValueError
:
# For some reason this was thought to be malformed.
host
.
set_variable
(
k
,
v
)
except
SyntaxError
:
# Is this a hash with an equals at the end?
host
.
set_variable
(
k
,
v
)
self
.
groups
[
active_group_name
]
.
add_host
(
host
)
# [southeast:children]
...
...
test/units/TestInventory.py
View file @
119434d0
...
...
@@ -417,15 +417,24 @@ class TestInventory(unittest.TestCase):
auth
=
inventory
.
get_variables
(
'neptun'
)[
'auth'
]
assert
auth
==
'YWRtaW46YWRtaW4='
# test disabled as needs to be updated to model desired behavior
#
#def test_dir_inventory(self):
# inventory = self.dir_inventory()
# vars = inventory.get_variables('zeus')
#
# print "VARS=%s" % vars
#
# assert vars == {'inventory_hostname': 'zeus',
# 'inventory_hostname_short': 'zeus',
# 'group_names': ['greek', 'major-god', 'ungrouped'],
# 'var_a': '1#2'}
def
test_dir_inventory
(
self
):
inventory
=
self
.
dir_inventory
()
host_vars
=
inventory
.
get_variables
(
'zeus'
)
expected_vars
=
{
'inventory_hostname'
:
'zeus'
,
'inventory_hostname_short'
:
'zeus'
,
'group_names'
:
[
'greek'
,
'major-god'
,
'ungrouped'
],
'var_a'
:
'3#4'
}
print
"HOST VARS=
%
s"
%
host_vars
print
"EXPECTED VARS=
%
s"
%
expected_vars
assert
host_vars
==
expected_vars
def
test_dir_inventory_multiple_groups
(
self
):
inventory
=
self
.
dir_inventory
()
group_greek
=
inventory
.
get_hosts
(
'greek'
)
actual_host_names
=
[
host
.
name
for
host
in
group_greek
]
print
"greek :
%
s "
%
actual_host_names
assert
actual_host_names
==
[
'zeus'
,
'morpheus'
]
test/units/inventory_test_data/inventory_dir/0hosts
View file @
119434d0
zeus var_a=
2
zeus var_a=
0
morpheus
thor
test/units/inventory_test_data/inventory_dir/2levels
View file @
119434d0
[major-god]
zeus var_a=
1
zeus var_a=
2
thor
[minor-god]
...
...
test/units/inventory_test_data/inventory_dir/3comments
View file @
119434d0
[major-god] # group with inline comments
zeus var_a="
1#2
" # host with inline comments and "#" in the var string
zeus var_a="
3\#4
" # host with inline comments and "#" in the var string
# A comment
thor
...
...
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