mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
[stable-9] Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9840)
Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)
Make set_module_args() a context manager, and remove copies of set_module_args().
Prepares for Data Tagging.
(cherry picked from commit a1781d09dd
)
This commit is contained in:
parent
9a6bd80613
commit
013fb9c006
80 changed files with 3745 additions and 3977 deletions
|
@ -321,81 +321,81 @@ class TestPmem(ModuleTestCase):
|
|||
|
||||
def test_fail_when_required_args_missing(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
pmem_module.main()
|
||||
with set_module_args({}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_appdirect_only(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'appdirect': 10,
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_MemosyMode_only(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'memorymode': 70,
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_reserved_only(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'reserved': 10,
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_appdirect_memorymode_reserved_total_not_100(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'appdirect': 10,
|
||||
'memorymode': 70,
|
||||
'reserved': 10,
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_when_appdirect_memorymode(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'appdirect': 10,
|
||||
'memorymode': 70,
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
|
||||
def test_when_appdirect_memorymode_reserved(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'appdirect': 10,
|
||||
'memorymode': 70,
|
||||
'reserved': 20,
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
|
||||
def test_when_appdirect_notinterleaved_memorymode_reserved(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'appdirect': 10,
|
||||
'appdirect_interleaved': False,
|
||||
'memorymode': 70,
|
||||
'reserved': 20,
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[goal_plain, goal, dimmlist]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(result, False, [25769803776], [188978561024], [328230764544])
|
||||
|
||||
def test_fail_when_socket_id_appdirect(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'id': 0,
|
||||
|
@ -406,12 +406,12 @@ class TestPmem(ModuleTestCase):
|
|||
'appdirect': 10,
|
||||
},
|
||||
],
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_socket0_id_memorymode_socket1_id_appdirect(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'id': 0,
|
||||
|
@ -422,12 +422,12 @@ class TestPmem(ModuleTestCase):
|
|||
'appdirect': 10,
|
||||
},
|
||||
],
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_socket0_without_id(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'appdirect': 10,
|
||||
|
@ -439,11 +439,11 @@ class TestPmem(ModuleTestCase):
|
|||
'memorymode': 70,
|
||||
},
|
||||
],
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_when_socket0_and_1_appdirect_memorymode(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'id': 0,
|
||||
|
@ -456,18 +456,18 @@ class TestPmem(ModuleTestCase):
|
|||
'memorymode': 70,
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
|
||||
def test_when_socket0_and_1_appdirect_memorymode_reserved(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'id': 0,
|
||||
|
@ -482,18 +482,18 @@ class TestPmem(ModuleTestCase):
|
|||
'reserved': 20,
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
|
||||
def test_when_socket0_appdirect_notinterleaved_memorymode_reserved_socket1_appdirect_memorymode_reserved(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'socket': [
|
||||
{
|
||||
'id': 0,
|
||||
|
@ -509,19 +509,19 @@ class TestPmem(ModuleTestCase):
|
|||
'reserved': 20,
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[
|
||||
show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check(
|
||||
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272])
|
||||
|
||||
def test_fail_when_namespace_without_mode(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '1GB',
|
||||
|
@ -532,12 +532,12 @@ class TestPmem(ModuleTestCase):
|
|||
'type': 'blk',
|
||||
},
|
||||
],
|
||||
})
|
||||
pmem_module.main()
|
||||
}):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_region_is_empty(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '1GB',
|
||||
|
@ -545,15 +545,15 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector',
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region_empty]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region_empty]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_namespace_invalid_size(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '1XXX',
|
||||
|
@ -561,15 +561,15 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector',
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_size_is_invalid_alignment(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '400MB',
|
||||
|
@ -582,15 +582,15 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector'
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_blk_is_unsupported_type(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '4GB',
|
||||
|
@ -603,15 +603,15 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector'
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_size_isnot_set_to_multiple_namespaces(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'type': 'pmem',
|
||||
|
@ -623,15 +623,15 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector'
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_fail_when_size_of_namespace_over_available(self):
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '400GB',
|
||||
|
@ -644,30 +644,30 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'sector'
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region]):
|
||||
pmem_module.main()
|
||||
|
||||
def test_when_namespace0_without_size(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'type': 'pmem',
|
||||
'mode': 'sector'
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_without_size, ndctl_list_N]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N)
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_without_size, ndctl_list_N]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N)
|
||||
|
||||
def test_when_namespace0_with_namespace_append(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '640MB',
|
||||
|
@ -676,16 +676,16 @@ class TestPmem(ModuleTestCase):
|
|||
},
|
||||
],
|
||||
'namespace_append': True,
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_640M, ndctl_list_N_two_namespaces]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N_two_namespaces)
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_640M, ndctl_list_N_two_namespaces]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N_two_namespaces)
|
||||
|
||||
def test_when_namespace0_1GiB_pmem_sector_namespace1_640MiB_pmem_raw(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'namespace': [
|
||||
{
|
||||
'size': '1GB',
|
||||
|
@ -698,10 +698,10 @@ class TestPmem(ModuleTestCase):
|
|||
'mode': 'raw',
|
||||
},
|
||||
],
|
||||
})
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_1G, ndctl_create_640M, ndctl_list_N_two_namespaces]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N_two_namespaces)
|
||||
}):
|
||||
with patch(
|
||||
'ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command',
|
||||
side_effect=[ndctl_region, ndctl_create_1G, ndctl_create_640M, ndctl_list_N_two_namespaces]):
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
pmem_module.main()
|
||||
self.result_check_ns(result, ndctl_list_N_two_namespaces)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue