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
ddd58226
Commit
ddd58226
authored
Aug 19, 2013
by
Michael Scherer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
increase test coverage of inventory by around 5% according to nose
parent
7ac3bbc1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletions
+30
-1
test/TestInventory.py
+28
-1
test/restrict_pattern
+2
-0
No files found.
test/TestInventory.py
View file @
ddd58226
import
os
import
unittest
from
nose.tools
import
raises
from
ansible
import
errors
from
ansible.inventory
import
Inventory
class
TestInventory
(
unittest
.
TestCase
):
...
...
@@ -65,6 +67,16 @@ class TestInventory(unittest.TestCase):
hosts
=
inventory
.
list_hosts
(
'all'
)
self
.
assertEqual
(
sorted
(
hosts
),
sorted
(
self
.
all_simple_hosts
))
def
test_get_hosts
(
self
):
inventory
=
Inventory
(
'127.0.0.1,192.168.1.1'
)
hosts
=
inventory
.
get_hosts
(
'!10.0.0.1'
)
hosts_all
=
inventory
.
get_hosts
(
'all'
)
self
.
assertEqual
(
sorted
(
hosts
),
sorted
(
hosts_all
))
def
test_no_src
(
self
):
inventory
=
Inventory
(
'127.0.0.1,'
)
self
.
assertEqual
(
inventory
.
src
(),
None
)
def
test_simple_norse
(
self
):
inventory
=
self
.
simple_inventory
()
hosts
=
inventory
.
list_hosts
(
"norse"
)
...
...
@@ -170,6 +182,20 @@ class TestInventory(unittest.TestCase):
hosts
=
inventory
.
list_hosts
()
self
.
assertEqual
(
sorted
(
hosts
),
sorted
(
'bob
%03
i'
%
i
for
i
in
range
(
0
,
143
)))
def
test_subset
(
self
):
inventory
=
self
.
simple_inventory
()
inventory
.
subset
(
'odin;thor,loki'
)
self
.
assertEqual
(
sorted
(
inventory
.
list_hosts
()),
sorted
([
'thor'
,
'odin'
,
'loki'
]))
def
test_subset_filename
(
self
):
inventory
=
self
.
simple_inventory
()
inventory
.
subset
(
'@'
+
os
.
path
.
join
(
self
.
test_dir
,
'restrict_pattern'
))
self
.
assertEqual
(
sorted
(
inventory
.
list_hosts
()),
sorted
([
'thor'
,
'odin'
]))
@raises
(
errors
.
AnsibleError
)
def
testinvalid_entry
(
self
):
Inventory
(
'1234'
)
###################################################
### INI file advanced tests
...
...
@@ -227,7 +253,8 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
complex_inventory
()
print
"ALL NC=
%
s"
%
inventory
.
list_hosts
(
"nc"
)
hosts
=
inventory
.
list_hosts
(
"nc[0-1]"
)
# use "-1" instead of 0-1 to test the syntax, on purpose
hosts
=
inventory
.
list_hosts
(
"nc[-1]"
)
self
.
compare
(
hosts
,
expected1
,
sort
=
False
)
hosts
=
inventory
.
list_hosts
(
"nc[2-3]"
)
self
.
compare
(
hosts
,
expected2
,
sort
=
False
)
...
...
test/restrict_pattern
0 → 100644
View file @
ddd58226
odin
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