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