本文整理汇总了Python中units.modules.utils.set_module_args函数的典型用法代码示例。如果您正苦于以下问题:Python set_module_args函数的具体用法?Python set_module_args怎么用?Python set_module_args使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_module_args函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_graceful_nitro_error_on_login
def test_graceful_nitro_error_on_login(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_monitor
class MockException(Exception):
def __init__(self, *args, **kwargs):
self.errorcode = 0
self.message = ''
client_mock = Mock()
client_mock.login = Mock(side_effect=MockException)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_monitor',
get_nitro_client=m,
nitro_exception=MockException,
):
self.module = netscaler_lb_monitor
result = self.failed()
self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')
示例2: test_save_config_not_called_on_state_absent
def test_save_config_not_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_gslb_site
client_mock = Mock()
m = Mock(return_value=client_mock)
gslb_site_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_gslb_site',
get_nitro_client=m,
gslb_site_exists=Mock(side_effect=[True, False]),
nitro_exception=self.MockException,
ensure_feature_is_enabled=Mock(),
ConfigProxy=Mock(return_value=gslb_site_proxy_mock),
):
self.module = netscaler_gslb_site
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
示例3: test_absent_gslb_site_failed_delete
def test_absent_gslb_site_failed_delete(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_gslb_site
client_mock = Mock()
m = Mock(return_value=client_mock)
glsb_site_proxy_attrs = {
'diff_object.return_value': {},
}
gslb_site_proxy_mock = Mock()
gslb_site_proxy_mock.configure_mock(**glsb_site_proxy_attrs)
config_proxy_mock = Mock(return_value=gslb_site_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_gslb_site',
nitro_exception=self.MockException,
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
gslb_site_exists=Mock(side_effect=[True, True]),
gslb_site_identical=Mock(side_effect=[False, False]),
ensure_feature_is_enabled=Mock(),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_gslb_site
result = self.failed()
self.assertEqual(result['msg'], 'GSLB site still exists')
self.assertTrue(result['failed'])
示例4: test_bgp_add_network
def test_bgp_add_network(self):
neighbors = [dict(remote_as=173, neighbor='10.2.3.4')]
set_module_args(dict(as_number=172, router_id='1.2.3.4',
neighbors=neighbors,
networks=['172.16.1.0/24', '172.16.2.0/24']))
commands = ['router bgp 172 network 172.16.2.0 /24']
self.execute_module(changed=True, commands=commands)
示例5: test_graceful_login_error
def test_graceful_login_error(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_gslb_site
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
class MockException(Exception):
pass
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.SSLError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_gslb_site',
get_nitro_client=m,
nitro_exception=MockException,
):
self.module = netscaler_gslb_site
result = self.failed()
self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
示例6: test_save_config_not_called_on_state_absent
def test_save_config_not_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
):
self.module = netscaler_ssl_certkey
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
示例7: test_absent_server_noop_flow
def test_absent_server_noop_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[False, False]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_not_called()
示例8: test_save_config_not_called_on_state_present
def test_save_config_not_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_server
client_mock = Mock()
m = Mock(return_value=client_mock)
server_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_server',
get_nitro_client=m,
server_exists=Mock(side_effect=[False, True]),
ConfigProxy=Mock(return_value=server_proxy_mock),
diff_list=Mock(return_value={}),
do_state_change=Mock(return_value=Mock(errorcode=0))
):
self.module = netscaler_server
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
示例9: test_do_state_change_fail
def test_do_state_change_fail(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_server
client_mock = Mock()
m = Mock(return_value=client_mock)
server_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_server',
nitro_exception=self.MockException,
get_nitro_client=m,
server_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=server_proxy_mock),
diff_list=Mock(return_value={}),
do_state_change=Mock(return_value=Mock(errorcode=1, message='Failed on purpose'))
):
self.module = netscaler_server
result = self.failed()
self.assertEqual(result['msg'], 'Error when setting disabled state. errorcode: 1 message: Failed on purpose')
示例10: test_update_agent_status_traps
def test_update_agent_status_traps(self, *args):
set_module_args(dict(
sync_device_to_group='yes',
device_group="foo",
password='passsword',
server='localhost',
user='admin'
))
client = AnsibleF5Client(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode,
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
# Override methods to force specific logic in the module to happen
mm._device_group_exists = Mock(return_value=True)
mm._sync_to_group_required = Mock(return_value=False)
mm.execute_on_device = Mock(return_value=True)
mm.read_current_from_device = Mock(return_value=None)
mm._get_status_from_resource = Mock()
mm._get_status_from_resource.side_effect = [
'Changes Pending', 'Awaiting Initial Sync', 'In Sync'
]
results = mm.exec_module()
assert results['changed'] is True
示例11: test_iosxr_config_match_exact
def test_iosxr_config_match_exact(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
'shutdown']
parents = ['interface GigabitEthernet0/0']
set_module_args(dict(lines=lines, parents=parents, match='exact'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)
示例12: test_new_gslb_vserver_execution_flow
def test_new_gslb_vserver_execution_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_gslb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
glsb_service_proxy_attrs = {
'diff_object.return_value': {},
}
gslb_service_proxy_mock = Mock()
gslb_service_proxy_mock.configure_mock(**glsb_service_proxy_attrs)
config_proxy_mock = Mock(return_value=gslb_service_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_gslb_vserver',
get_nitro_client=m,
gslb_vserver_exists=Mock(side_effect=[False, True]),
gslb_vserver_identical=Mock(side_effect=[True]),
nitro_exception=self.MockException,
do_state_change=Mock(return_value=Mock(errorcode=0)),
ensure_feature_is_enabled=Mock(),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_gslb_vserver
self.exited()
gslb_service_proxy_mock.assert_has_calls([call.add()])
示例13: test_save_config_called_on_state_present
def test_save_config_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_gslb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
gslb_service_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_gslb_vserver',
get_nitro_client=m,
gslb_vserver_exists=Mock(side_effect=[False, True]),
gslb_vserver_identical=Mock(side_effect=[True]),
do_state_change=Mock(return_value=Mock(errorcode=0)),
nitro_exception=self.MockException,
ensure_feature_is_enabled=Mock(),
ConfigProxy=Mock(return_value=gslb_service_proxy_mock),
):
self.module = netscaler_gslb_vserver
self.exited()
self.assertIn(call.save_config(), client_mock.mock_calls)
示例14: test_dellos10_config_match_exact
def test_dellos10_config_match_exact(self):
lines = ['ip address 1.2.3.4/24', 'description test string',
'shutdown']
parents = ['interface ethernet1/1/2']
set_module_args(dict(lines=lines, parents=parents, match='exact'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)
示例15: test_port_channel_add
def test_port_channel_add(self):
set_module_args(dict(name='Po23', state='present',
members=['Eth1/8']))
self.load_port_channel_fixture()
commands = ['interface port-channel 23', 'exit',
'interface ethernet 1/8 channel-group 23 mode on']
self.execute_module(changed=True, commands=commands)