# Specs failing on devel

**URL:** <https://forum.ansible.com/t/specs-failing-on-devel/26659>\
**Category:** Ansible Developer\
**Created:** [February 5, 2018, 12:53am UTC](https://forum.ansible.com/t/specs-failing-on-devel/26659 "2018-02-05T00:53:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eshan\_TANDON](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@eshan\_TANDON](https://forum.ansible.com/u/eshan_TANDON)\
**Post date:** [February 5, 2018, 12:53am UTC](https://forum.ansible.com/t/specs-failing-on-devel/26659/1 "2018-02-05T00:53:19Z")

</div>

Hi All,  
I am new bee to ansible project, I was just trying to run the specs but seems like specs are not passing:

**============================================ 15 failed, 3625 passed, 31 skipped in 773.89 seconds =============================================**

================================================================== FAILURES ===================================================================

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ test\_existing\_file[stdin0-True] \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

atomic\_am = \<ansible.module\_utils.basic.AnsibleModule object at 0x1107f6490\>

atomic\_mocks = {‘chmod’: , ‘chown’: , ‘close’: , ‘copy2’: , …}

fake\_stat = , mocker = \<pytest\_mock.MockFixture object at 0x11080a090\>, selinux = True

@pytest.mark.parametrize(‘stdin, selinux’, product([{}], (True, False)), indirect=[‘stdin’])

def test\_existing\_file(atomic\_am, atomic\_mocks, fake\_stat, mocker, selinux):

# Test destination already present

mock\_context = atomic\_am.selinux\_context.return\_value

atomic\_mocks[‘stat’].return\_value = fake\_stat

atomic\_mocks[‘path\_exists’].return\_value = True

atomic\_am.selinux\_enabled.return\_value = selinux

> atomic\_am.atomic\_move(‘/path/to/src’, ‘/path/to/dest’)

test/units/module\_utils/basic/test\_atomic\_move.py:96:

* * *

self = \<ansible.module\_utils.basic.AnsibleModule object at 0x1107f6490\>, src = ‘/path/to/src’, dest = ‘/path/to/dest’, unsafe\_writes = False

def atomic\_move(self, src, dest, unsafe\_writes=False):

‘’'atomically move src to dest, copying attributes from dest, returns true on success

it uses os.rename to ensure this as it is an atomic operation, rest of the function is

to work around limitations, corner cases and ensure selinux context is saved if possible’‘’

context = None

dest\_stat = None

b\_src = to\_bytes(src, errors=‘surrogate\_or\_strict’)

b\_dest = to\_bytes(dest, errors=‘surrogate\_or\_strict’)

if os.path.exists(b\_dest):

try:

dest\_stat = os.stat(b\_dest)

# copy mode and ownership

os.chmod(b\_src, dest\_stat.st\_mode & PERM\_BITS)

os.chown(b\_src, dest\_stat.st\_uid, dest\_stat.st\_gid)

# try to copy flags if possible

if hasattr(os, ‘chflags’) and hasattr(dest\_stat, ‘st\_flags’):

try:

> os.chflags(b\_src, dest\_stat.st\_flags)

E TypeError: chflags() argument 2 must be an integer, not MagicMock

lib/ansible/module\_utils/basic.py:2458: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ test\_existing\_file[stdin1-False] \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

atomic\_am = \<ansible.module\_utils.basic.AnsibleModule object at 0x1107c0a90\>

atomic\_mocks = {‘chmod’: , ‘chown’: , ‘close’: , ‘copy2’: , …}

fake\_stat = , mocker = \<pytest\_mock.MockFixture object at 0x1107f64d0\>, selinux = False

@pytest.mark.parametrize(‘stdin, selinux’, product([{}], (True, False)), indirect=[‘stdin’])

def test\_existing\_file(atomic\_am, atomic\_mocks, fake\_stat, mocker, selinux):

# Test destination already present

mock\_context = atomic\_am.selinux\_context.return\_value

atomic\_mocks[‘stat’].return\_value = fake\_stat

atomic\_mocks[‘path\_exists’].return\_value = True

atomic\_am.selinux\_enabled.return\_value = selinux

> atomic\_am.atomic\_move(‘/path/to/src’, ‘/path/to/dest’)

test/units/module\_utils/basic/test\_atomic\_move.py:96:

* * *

self = \<ansible.module\_utils.basic.AnsibleModule object at 0x1107c0a90\>, src = ‘/path/to/src’, dest = ‘/path/to/dest’, unsafe\_writes = False

def atomic\_move(self, src, dest, unsafe\_writes=False):

‘’'atomically move src to dest, copying attributes from dest, returns true on success

it uses os.rename to ensure this as it is an atomic operation, rest of the function is

to work around limitations, corner cases and ensure selinux context is saved if possible’‘’

context = None

dest\_stat = None

b\_src = to\_bytes(src, errors=‘surrogate\_or\_strict’)

b\_dest = to\_bytes(dest, errors=‘surrogate\_or\_strict’)

if os.path.exists(b\_dest):

try:

dest\_stat = os.stat(b\_dest)

# copy mode and ownership

os.chmod(b\_src, dest\_stat.st\_mode & PERM\_BITS)

os.chown(b\_src, dest\_stat.st\_uid, dest\_stat.st\_gid)

# try to copy flags if possible

if hasattr(os, ‘chflags’) and hasattr(dest\_stat, ‘st\_flags’):

try:

> os.chflags(b\_src, dest\_stat.st\_flags)

E TypeError: chflags() argument 2 must be an integer, not MagicMock

lib/ansible/module\_utils/basic.py:2458: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ test\_no\_tty\_fallback[stdin0] \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

atomic\_am = \<ansible.module\_utils.basic.AnsibleModule object at 0x110817410\>

atomic\_mocks = {‘chmod’: , ‘chown’: , ‘close’: , ‘copy2’: , …}

fake\_stat = , mocker = \<pytest\_mock.MockFixture object at 0x1107c0a90\>

@pytest.mark.parametrize(‘stdin’, [{}], indirect=[‘stdin’])

def test\_no\_tty\_fallback(atomic\_am, atomic\_mocks, fake\_stat, mocker):

“”“Raise OSError when using getlogin() to simulate no tty cornercase”“”

mock\_context = atomic\_am.selinux\_context.return\_value

atomic\_mocks[‘stat’].return\_value = fake\_stat

atomic\_mocks[‘path\_exists’].return\_value = True

atomic\_am.selinux\_enabled.return\_value = True

atomic\_mocks[‘getlogin’].side\_effect = OSError()

atomic\_mocks[‘environ’][‘LOGNAME’] = ‘root’

> atomic\_am.atomic\_move(‘/path/to/src’, ‘/path/to/dest’)

test/units/module\_utils/basic/test\_atomic\_move.py:119:

* * *

self = \<ansible.module\_utils.basic.AnsibleModule object at 0x110817410\>, src = ‘/path/to/src’, dest = ‘/path/to/dest’, unsafe\_writes = False

def atomic\_move(self, src, dest, unsafe\_writes=False):

‘’'atomically move src to dest, copying attributes from dest, returns true on success

it uses os.rename to ensure this as it is an atomic operation, rest of the function is

to work around limitations, corner cases and ensure selinux context is saved if possible’‘’

context = None

dest\_stat = None

b\_src = to\_bytes(src, errors=‘surrogate\_or\_strict’)

b\_dest = to\_bytes(dest, errors=‘surrogate\_or\_strict’)

if os.path.exists(b\_dest):

try:

dest\_stat = os.stat(b\_dest)

# copy mode and ownership

os.chmod(b\_src, dest\_stat.st\_mode & PERM\_BITS)

os.chown(b\_src, dest\_stat.st\_uid, dest\_stat.st\_gid)

# try to copy flags if possible

if hasattr(os, ‘chflags’) and hasattr(dest\_stat, ‘st\_flags’):

try:

> os.chflags(b\_src, dest\_stat.st\_flags)

E TypeError: chflags() argument 2 must be an integer, not MagicMock

lib/ansible/module\_utils/basic.py:2458: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestCollectedFacts.test\_expected\_facts \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_ansible\_collector.TestCollectedFacts testMethod=test\_expected\_facts\>

def test\_expected\_facts(self):

> self.\_assert\_expected\_facts(self.facts)

test/units/module\_utils/facts/test\_ansible\_collector.py:228:

* * *

test/units/module\_utils/facts/test\_ansible\_collector.py:255: in \_assert\_expected\_facts

self.assertIn(expected\_fact, facts\_keys)

E AssertionError: ‘distribution’ not found in [‘apparmor’, ‘architecture’, ‘date\_time’, ‘dns’, ‘domain’, ‘effective\_group\_id’, ‘effective\_user\_id’, ‘env’, ‘fips’, ‘fqdn’, ‘gather\_subset’, ‘hostname’, ‘kernel’, ‘local’, ‘lsb’, ‘machine’, ‘module\_setup’, ‘nodename’, ‘pkg\_mgr’, ‘python’, ‘python\_version’, ‘real\_group\_id’, ‘real\_user\_id’, ‘selinux’, ‘selinux\_python\_present’, ‘system’, ‘user\_dir’, ‘user\_gecos’, ‘user\_gid’, ‘user\_id’, ‘user\_shell’, ‘user\_uid’, ‘userspace\_architecture’, ‘userspace\_bits’, ‘virtualization\_role’, ‘virtualization\_type’]

------------------------------------------------------------ Captured stderr call -------------------------------------------------------------

TypeError(“‘Mock’ object is not iterable”,)

TypeError(“‘Mock’ object is not iterable”,)

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestExceptionCollectedFacts.test\_expected\_facts \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_ansible\_collector.TestExceptionCollectedFacts testMethod=test\_expected\_facts\>

def test\_expected\_facts(self):

> self.\_assert\_expected\_facts(self.facts)

test/units/module\_utils/facts/test\_ansible\_collector.py:228:

* * *

test/units/module\_utils/facts/test\_ansible\_collector.py:255: in \_assert\_expected\_facts

self.assertIn(expected\_fact, facts\_keys)

E AssertionError: ‘distribution’ not found in [‘apparmor’, ‘architecture’, ‘date\_time’, ‘dns’, ‘domain’, ‘effective\_group\_id’, ‘effective\_user\_id’, ‘env’, ‘fips’, ‘fqdn’, ‘gather\_subset’, ‘hostname’, ‘kernel’, ‘local’, ‘lsb’, ‘machine’, ‘module\_setup’, ‘nodename’, ‘pkg\_mgr’, ‘python’, ‘python\_version’, ‘real\_group\_id’, ‘real\_user\_id’, ‘selinux’, ‘selinux\_python\_present’, ‘system’, ‘user\_dir’, ‘user\_gecos’, ‘user\_gid’, ‘user\_id’, ‘user\_shell’, ‘user\_uid’, ‘userspace\_architecture’, ‘userspace\_bits’, ‘virtualization\_role’, ‘virtualization\_type’]

------------------------------------------------------------ Captured stderr call -------------------------------------------------------------

Exception(‘A collector failed’,)

TypeError(“‘Mock’ object is not iterable”,)

TypeError(“‘Mock’ object is not iterable”,)

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestDistributionFacts.test\_collect \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_collectors.TestDistributionFacts testMethod=test\_collect\>

def test\_collect(self):

module = self.\_mock\_module()

fact\_collector = self.collector\_class()

> facts\_dict = fact\_collector.collect(module=module, collected\_facts=self.collected\_facts)

test/units/module\_utils/facts/base.py:51:

* * *

lib/ansible/module\_utils/facts/system/distribution.py:592: in collect

distro\_facts = distribution.get\_distribution\_facts()

lib/ansible/module\_utils/facts/system/distribution.py:453: in get\_distribution\_facts

dist\_func\_facts = distfunc()

* * *

self = \<ansible.module\_utils.facts.system.distribution.Distribution object at 0x11094d5d0\>

def get\_distribution\_Darwin(self):

darwin\_facts = {}

darwin\_facts[‘distribution’] = ‘MacOSX’

> rc, out, err = self.module.run\_command(“/usr/bin/sw\_vers -productVersion”)

E TypeError: ‘Mock’ object is not iterable

lib/ansible/module\_utils/facts/system/distribution.py:492: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestDistributionFacts.test\_collect\_with\_namespace \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_collectors.TestDistributionFacts testMethod=test\_collect\_with\_namespace\>

def test\_collect\_with\_namespace(self):

module = self.\_mock\_module()

fact\_collector = self.collector\_class()

facts\_dict = fact\_collector.collect\_with\_namespace(module=module,

> collected\_facts=self.collected\_facts)

test/units/module\_utils/facts/base.py:59:

* * *

lib/ansible/module\_utils/facts/collector.py:101: in collect\_with\_namespace

facts\_dict = self.collect(module=module, collected\_facts=collected\_facts)

lib/ansible/module\_utils/facts/system/distribution.py:592: in collect

distro\_facts = distribution.get\_distribution\_facts()

lib/ansible/module\_utils/facts/system/distribution.py:453: in get\_distribution\_facts

dist\_func\_facts = distfunc()

* * *

self = \<ansible.module\_utils.facts.system.distribution.Distribution object at 0x110940e10\>

def get\_distribution\_Darwin(self):

darwin\_facts = {}

darwin\_facts[‘distribution’] = ‘MacOSX’

> rc, out, err = self.module.run\_command(“/usr/bin/sw\_vers -productVersion”)

E TypeError: ‘Mock’ object is not iterable

lib/ansible/module\_utils/facts/system/distribution.py:492: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestServiceMgrFacts.test\_collect \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_collectors.TestServiceMgrFacts testMethod=test\_collect\>

def test\_collect(self):

module = self.\_mock\_module()

fact\_collector = self.collector\_class()

> facts\_dict = fact\_collector.collect(module=module, collected\_facts=self.collected\_facts)

test/units/module\_utils/facts/base.py:51:

* * *

self = \<ansible.module\_utils.facts.system.service\_mgr.ServiceMgrFactCollector object at 0x1109650d0\>, module =

collected\_facts = {}

def collect(self, module=None, collected\_facts=None):

facts\_dict = {}

if not module:

return facts\_dict

collected\_facts = collected\_facts or {}

service\_mgr\_name = None

# TODO: detect more custom init setups like bootscripts, dmd, s6, Epoch, etc

# also other OSs other than linux might need to check across several possible candidates

# Mapping of proc\_1 values to more useful names

proc\_1\_map = {

‘procd’: ‘openwrt\_init’,

‘runit-init’: ‘runit’,

‘svscan’: ‘svc’,

‘openrc-init’: ‘openrc’,

}

# try various forms of querying pid 1

proc\_1 = get\_file\_content(‘/proc/1/comm’)

if proc\_1 is None:

# FIXME: return code isnt checked

# FIXME: if stdout is empty string, odd things

# FIXME: other code seems to think we could get proc\_1 == None past this point

> rc, proc\_1, err = module.run\_command(“ps -p 1 -o comm|tail -n 1”, use\_unsafe\_shell=True)

E TypeError: ‘Mock’ object is not iterable

lib/ansible/module\_utils/facts/system/service\_mgr.py:81: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestServiceMgrFacts.test\_collect\_with\_namespace \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.module\_utils.facts.test\_collectors.TestServiceMgrFacts testMethod=test\_collect\_with\_namespace\>

def test\_collect\_with\_namespace(self):

module = self.\_mock\_module()

fact\_collector = self.collector\_class()

facts\_dict = fact\_collector.collect\_with\_namespace(module=module,

> collected\_facts=self.collected\_facts)

test/units/module\_utils/facts/base.py:59:

* * *

lib/ansible/module\_utils/facts/collector.py:101: in collect\_with\_namespace

facts\_dict = self.collect(module=module, collected\_facts=collected\_facts)

* * *

self = \<ansible.module\_utils.facts.system.service\_mgr.ServiceMgrFactCollector object at 0x110966390\>, module =

collected\_facts = {}

def collect(self, module=None, collected\_facts=None):

facts\_dict = {}

if not module:

return facts\_dict

collected\_facts = collected\_facts or {}

service\_mgr\_name = None

# TODO: detect more custom init setups like bootscripts, dmd, s6, Epoch, etc

# also other OSs other than linux might need to check across several possible candidates

# Mapping of proc\_1 values to more useful names

proc\_1\_map = {

‘procd’: ‘openwrt\_init’,

‘runit-init’: ‘runit’,

‘svscan’: ‘svc’,

‘openrc-init’: ‘openrc’,

}

# try various forms of querying pid 1

proc\_1 = get\_file\_content(‘/proc/1/comm’)

if proc\_1 is None:

# FIXME: return code isnt checked

# FIXME: if stdout is empty string, odd things

# FIXME: other code seems to think we could get proc\_1 == None past this point

> rc, proc\_1, err = module.run\_command(“ps -p 1 -o comm|tail -n 1”, use\_unsafe\_shell=True)

E TypeError: ‘Mock’ object is not iterable

lib/ansible/module\_utils/facts/system/service\_mgr.py:81: TypeError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestParameters.test\_destination\_mutex\_10 \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.modules.network.f5.test\_bigip\_virtual\_server.TestParameters testMethod=test\_destination\_mutex\_10\>

def test\_destination\_mutex\_10(self):

args = dict(

destination=‘2700:bc00:1f10:101::6%2’

)

p = ApiParameters(params=args)

> assert p.destination\_tuple.ip == ‘2700:bc00:1f10:101::6’

E AssertionError: assert ‘2700:bc00:1f10:101::6%2’ == ‘2700:bc00:1f10:101::6’

E - 2700:bc00:1f10:101::6%2

E ? –

E + 2700:bc00:1f10:101::6

test/units/modules/network/f5/test\_bigip\_virtual\_server.py:141: AssertionError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestParameters.test\_destination\_mutex\_12 \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.modules.network.f5.test\_bigip\_virtual\_server.TestParameters testMethod=test\_destination\_mutex\_12\>

def test\_destination\_mutex\_12(self):

args = dict(

destination=‘2700:bc00:1f10:101::6%2.80’

)

p = ApiParameters(params=args)

> assert p.destination\_tuple.ip == ‘2700:bc00:1f10:101::6’

E AssertionError: assert ‘2700:bc00:1f10:101::6%2.80’ == ‘2700:bc00:1f10:101::6’

E - 2700:bc00:1f10:101::6%2.80

E ? -----

E + 2700:bc00:1f10:101::6

test/units/modules/network/f5/test\_bigip\_virtual\_server.py:157: AssertionError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestGetFileVaultSecret.test\_file\_not\_found \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.parsing.vault.test\_vault.TestGetFileVaultSecret testMethod=test\_file\_not\_found\>

def test\_file\_not\_found(self):

tmp\_file = tempfile.NamedTemporaryFile()

filename = tmp\_file.name

tmp\_file.close()

fake\_loader = DictDataLoader({filename: ‘sdfadf’})

self.assertRaisesRegexp(errors.AnsibleError,

‘._The vault password file %s was not found._’ % filename,

vault.get\_file\_vault\_secret,

filename=filename,

> loader=fake\_loader)

E AssertionError: “._The vault password file /tmp/tmpd6umLT was not found._” does not match “The vault password file /private/tmp/tmpd6umLT was not found”

test/units/parsing/vault/test\_vault.py:402: AssertionError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestVaultEditor.test\_real\_path\_symlink \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.parsing.vault.test\_vault\_editor.TestVaultEditor testMethod=test\_real\_path\_symlink\>

def test\_real\_path\_symlink(self):

self.\_test\_dir = self.\_create\_test\_dir()

file\_path = self.\_create\_file(self.\_test\_dir, ‘test\_file’, content=b’this is a test file’)

file\_link\_path = os.path.join(self.\_test\_dir, ‘a\_link\_to\_test\_file’)

os.symlink(file\_path, file\_link\_path)

ve = self.\_vault\_editor()

res = ve.\_real\_path(file\_link\_path)

> self.assertEqual(res, file\_path)

E AssertionError: ‘/private/tmp/tmpuKx09t\_ansible\_unit\_test\_TestVaultEditor\_/test\_file’ != ‘/tmp/tmpuKx09t\_ansible\_unit\_test\_TestVaultEditor\_/test\_file’

test/units/parsing/vault/test\_vault\_editor.py:573: AssertionError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestLoadListOfRoles.test\_block\_unknown\_action \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.playbook.test\_helpers.TestLoadListOfRoles testMethod=test\_block\_unknown\_action\>

def test\_block\_unknown\_action(self):

ds = [{

‘block’: [{‘action’: ‘foo\_test\_block\_unknown\_action’}]

}]

ds = [{‘name’: ‘bogus\_role’}]

res = helpers.load\_list\_of\_roles(ds, self.mock\_play,

> variable\_manager=self.mock\_variable\_manager, loader=self.fake\_role\_loader)

test/units/playbook/test\_helpers.py:359:

* * *

lib/ansible/playbook/helpers.py:359: in load\_list\_of\_roles

i = RoleInclude.load(role\_def, play=play, current\_role\_path=current\_role\_path, variable\_manager=variable\_manager, loader=loader)

lib/ansible/playbook/role/include.py:59: in load

return ri.load\_data(data, variable\_manager=variable\_manager, loader=loader)

lib/ansible/playbook/base.py:245: in load\_data

ds = self.preprocess\_data(ds)

lib/ansible/playbook/role/definition.py:95: in preprocess\_data

(role\_name, role\_path) = self.\_load\_role\_path(role\_name)

* * *

self = \<ansible.playbook.role.include.RoleInclude object at 0x1114d2a50\>, role\_name = ‘bogus\_role’

def \_load\_role\_path(self, role\_name):

‘’’

the ‘role’, as specified in the ds (or as a bare string), can either

be a simple name or a full path. If it is a full path, we use the

basename as the role name, otherwise we take the name as-given and

append it to the default role path

‘’’

# we always start the search for roles in the base directory of the playbook

role\_search\_paths = [

os.path.join(self.\_loader.get\_basedir(), u’roles’),

]

# also search in the configured roles path

if C.DEFAULT\_ROLES\_PATH:

role\_search\_paths.extend(C.DEFAULT\_ROLES\_PATH)

# next, append the roles basedir, if it was set, so we can

# search relative to that directory for dependent roles

if self.\_role\_basedir:

role\_search\_paths.append(self.\_role\_basedir)

# finally as a last resort we look in the current basedir as set

# in the loader (which should be the playbook dir itself) but without

# the roles/ dir appended

role\_search\_paths.append(self.\_loader.get\_basedir())

# create a templar class to template the dependency names, in

# case they contain variables

if self.\_variable\_manager is not None:

all\_vars = self.\_variable\_manager.get\_vars(play=self.\_play)

else:

all\_vars = dict()

templar = Templar(loader=self.\_loader, variables=all\_vars)

role\_name = templar.template(role\_name)

# now iterate through the possible paths and return the first one we find

for path in role\_search\_paths:

path = templar.template(path)

role\_path = unfrackpath(os.path.join(path, role\_name))

if self.\_loader.path\_exists(role\_path):

return (role\_name, role\_path)

# if not found elsewhere try to extract path from name

role\_path = unfrackpath(role\_name)

if self.\_loader.path\_exists(role\_path):

role\_name = os.path.basename(role\_name)

return (role\_name, role\_path)

> raise AnsibleError(“the role ‘%s’ was not found in %s” % (role\_name, “:”.join(role\_search\_paths)), obj=self.\_ds)

E AnsibleError: the role ‘bogus\_role’ was not found in /Users/eshan.tandon/IdeaProjects/ansible/roles:/Users/eshan.tandon/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/eshan.tandon/IdeaProjects/ansible

lib/ansible/playbook/role/definition.py:188: AnsibleError

**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ TestLoadListOfRoles.test\_empty\_role\_just\_name \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_**

self = \<units.playbook.test\_helpers.TestLoadListOfRoles testMethod=test\_empty\_role\_just\_name\>

def test\_empty\_role\_just\_name(self):

ds = [{‘name’: ‘bogus\_role’}]

res = helpers.load\_list\_of\_roles(ds, self.mock\_play,

> variable\_manager=self.mock\_variable\_manager, loader=self.fake\_role\_loader)

test/units/playbook/test\_helpers.py:348:

* * *

lib/ansible/playbook/helpers.py:359: in load\_list\_of\_roles

i = RoleInclude.load(role\_def, play=play, current\_role\_path=current\_role\_path, variable\_manager=variable\_manager, loader=loader)

lib/ansible/playbook/role/include.py:59: in load

return ri.load\_data(data, variable\_manager=variable\_manager, loader=loader)

lib/ansible/playbook/base.py:245: in load\_data

ds = self.preprocess\_data(ds)

lib/ansible/playbook/role/definition.py:95: in preprocess\_data

(role\_name, role\_path) = self.\_load\_role\_path(role\_name)

* * *

self = \<ansible.playbook.role.include.RoleInclude object at 0x10c043f90\>, role\_name = ‘bogus\_role’

def \_load\_role\_path(self, role\_name):

‘’’

the ‘role’, as specified in the ds (or as a bare string), can either

be a simple name or a full path. If it is a full path, we use the

basename as the role name, otherwise we take the name as-given and

append it to the default role path

‘’’

# we always start the search for roles in the base directory of the playbook

role\_search\_paths = [

os.path.join(self.\_loader.get\_basedir(), u’roles’),

]

# also search in the configured roles path

if C.DEFAULT\_ROLES\_PATH:

role\_search\_paths.extend(C.DEFAULT\_ROLES\_PATH)

# next, append the roles basedir, if it was set, so we can

# search relative to that directory for dependent roles

if self.\_role\_basedir:

role\_search\_paths.append(self.\_role\_basedir)

# finally as a last resort we look in the current basedir as set

# in the loader (which should be the playbook dir itself) but without

# the roles/ dir appended

role\_search\_paths.append(self.\_loader.get\_basedir())

# create a templar class to template the dependency names, in

# case they contain variables

if self.\_variable\_manager is not None:

all\_vars = self.\_variable\_manager.get\_vars(play=self.\_play)

else:

all\_vars = dict()

templar = Templar(loader=self.\_loader, variables=all\_vars)

role\_name = templar.template(role\_name)

# now iterate through the possible paths and return the first one we find

for path in role\_search\_paths:

path = templar.template(path)

role\_path = unfrackpath(os.path.join(path, role\_name))

if self.\_loader.path\_exists(role\_path):

return (role\_name, role\_path)

# if not found elsewhere try to extract path from name

role\_path = unfrackpath(role\_name)

if self.\_loader.path\_exists(role\_path):

role\_name = os.path.basename(role\_name)

return (role\_name, role\_path)

> raise AnsibleError(“the role ‘%s’ was not found in %s” % (role\_name, “:”.join(role\_search\_paths)), obj=self.\_ds)

E AnsibleError: the role ‘bogus\_role’ was not found in /Users/eshan.tandon/IdeaProjects/ansible/roles:/Users/eshan.tandon/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/eshan.tandon/IdeaProjects/ansible

lib/ansible/playbook/role/definition.py:188: AnsibleError
