def test_voss_config_config(self): config = 'prompt "VSP300"' lines = ['prompt router'] set_module_args(dict(lines=lines, config=config)) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), config)) commands = ['prompt router'] self.execute_module(changed=True, commands=commands)
def test_voss_config_after(self): lines = ['prompt "VSP8K"'] set_module_args(dict(lines=lines, after=['test1', 'test2'])) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config)) commands = ['prompt "VSP8K"', 'test1', 'test2'] self.execute_module(changed=True, commands=commands, sort=False)
def test_voss_config_src_ipv6(self): src = load_fixture('voss_config_ipv6.cfg') set_module_args(dict(src=src)) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config)) commands = ['interface loopback 1', 'ip address 1 2.2.2.2/255.255.255.255', 'ipv6 interface address 2011:0:0:0:0:0:0:2/128', 'exit'] self.execute_module(changed=True, commands=commands)
def test_voss_config_src(self): src = load_fixture('voss_config_src.cfg') set_module_args(dict(src=src)) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config)) commands = ['prompt "VSP8K"', 'interface GigabitEthernet 1/1', 'name "UNUSED"', 'exit'] self.execute_module(changed=True, commands=commands)
def test_voss_facts_hardware(self): set_module_args(dict(gather_subset='hardware')) result = self.execute_module() self.assertEqual(result['ansible_facts']['ansible_net_memfree_mb'], 625) self.assertEqual(result['ansible_facts']['ansible_net_memtotal_mb'], 1002)
def test_voss_config_before_after_no_change(self): lines = ['prompt "VSP300"'] set_module_args(dict(lines=lines, before=['test1', 'test2'], after=['test3', 'test4'])) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config)) self.execute_module()
def test_voss_command_match_any(self): wait_for = [ 'result[0] contains "General Info"', 'result[0] contains "test string"' ] set_module_args( dict(commands=['show sys-info'], wait_for=wait_for, match='any')) self.execute_module()
def test_voss_facts_default(self): set_module_args(dict(gather_subset='default')) result = self.execute_module() self.assertEqual(result['ansible_facts']['ansible_net_model'], '4450GSX-PWR+') self.assertEqual(result['ansible_facts']['ansible_net_serialnum'], '14JP512E0001') self.assertEqual(result['ansible_facts']['ansible_net_version'], '7.0.0.0_B015')
def test_voss_config_save_always(self): self.run_commands.return_value = "Hostname foo" set_module_args(dict(save_when='always')) self.execute_module(changed=True) self.assertEqual(self.run_commands.call_count, 1) self.assertEqual(self.get_config.call_count, 0) self.assertEqual(self.conn.edit_config.call_count, 0) args = self.run_commands.call_args[0][1] self.assertIn('save config\r', args)
def test_voss_command_match_all_failure(self): wait_for = [ 'result[0] contains "General Info"', 'result[0] contains "test string"' ] commands = ['show sys-info', 'show sys-info'] set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) self.execute_module(failed=True)
def test_voss_config_ipv6(self): lines = ['ip address 1 1.1.1.1/255.255.255.255', 'ipv6 interface address 2011:0:0:0:0:0:0:1/128'] parents = ['interface loopback 1'] set_module_args(dict(lines=lines, parents=parents)) module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = voss_config.get_candidate_config(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config)) self.execute_module(changed=False)
def test_voss_command_configure_error(self): commands = ['configure terminal'] set_module_args({ 'commands': commands, '_ansible_check_mode': True, }) result = self.execute_module(failed=True) self.assertEqual( result['msg'], 'voss_command does not support running config mode commands. Please use voss_config instead' )
def test_voss_config_match_exact(self): lines = ['name "ServerA"', 'vlacp enable', 'no shutdown'] parents = ['interface GigabitEthernet 1/1'] set_module_args(dict(lines=lines, parents=parents, match='exact')) module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = voss_config.get_candidate_config(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_match='exact', path=parents)) commands = parents + lines self.execute_module(changed=True, commands=commands, sort=False)
def test_voss_config_lines_w_parents(self): lines = ['no shutdown'] parents = ['interface GigabitEthernet 1/1'] set_module_args(dict(lines=lines, parents=parents)) module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = voss_config.get_candidate_config(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config)) commands = ['interface GigabitEthernet 1/1', 'no shutdown'] self.execute_module(changed=True, commands=commands)
def test_voss_config_save_changed_true(self): src = load_fixture('voss_config_src.cfg') set_module_args(dict(src=src, save_when='changed')) commands = ['prompt "VSP8K"', 'interface GigabitEthernet 1/1', 'name "UNUSED"', 'exit'] self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config)) self.execute_module(changed=True, commands=commands) self.assertEqual(self.run_commands.call_count, 1) self.assertEqual(self.get_config.call_count, 1) self.assertEqual(self.conn.edit_config.call_count, 1) args = self.run_commands.call_args[0][1] self.assertIn('save config\r', args)
def test_voss_facts_interfaces(self): set_module_args(dict(gather_subset='interfaces')) result = self.execute_module() self.assertEqual( result['ansible_facts']['ansible_net_interfaces']['1/1'] ['description'], 'serverA') self.assertEqual( result['ansible_facts']['ansible_net_interfaces']['Clip1']['ipv4'] [0]['address'], '1.1.1.1') self.assertEqual( result['ansible_facts']['ansible_net_neighbors']['1/1'][0]['host'], 'X690-48t-2q-4c')
def test_voss_config_replace_block(self): lines = ['name "ServerB"', 'test string'] parents = ['interface GigabitEthernet 1/2'] set_module_args(dict(lines=lines, replace='block', parents=parents)) module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = voss_config.get_candidate_config(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_replace='block', path=parents)) commands = parents + lines self.execute_module(changed=True, commands=commands)
def test_voss_config_match_none(self): lines = ['prompt router'] set_module_args(dict(lines=lines, match='none')) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config, diff_match='none')) self.execute_module(changed=True, commands=lines)
def test_voss_config_backup(self): set_module_args(dict(backup=True)) result = self.execute_module() self.assertIn('__backup__', result)
def test_voss_config_save_changed_false(self): set_module_args(dict(save_when='changed')) self.execute_module(changed=False) self.assertEqual(self.run_commands.call_count, 0) self.assertEqual(self.get_config.call_count, 0) self.assertEqual(self.conn.edit_config.call_count, 0)
def test_voss_command_retries(self): wait_for = 'result[0] contains "test string"' set_module_args( dict(commands=['show sys-info'], wait_for=wait_for, retries=2)) self.execute_module(failed=True) self.assertEqual(self.run_commands.call_count, 2)
def test_voss_command_multiple(self): set_module_args(dict(commands=['show sys-info', 'show sys-info'])) result = self.execute_module() self.assertEqual(len(result['stdout']), 2) self.assertTrue(result['stdout'][0].startswith('General Info'))
def test_voss_config_replace_config_requires_src(self): args = dict(replace='config') set_module_args(args) self.execute_module(failed=True)
def test_voss_config_match_strict_requires_lines(self): args = dict(match='strict') set_module_args(args) self.execute_module(failed=True)
def test_voss_config_src_and_parents_fails(self): args = dict(src='foo', parents='foo') set_module_args(args) self.execute_module(failed=True)
def test_voss_command_wait_for(self): wait_for = 'result[0] contains "General Info"' set_module_args(dict(commands=['show sys-info'], wait_for=wait_for)) self.execute_module()
def test_voss_config_lines_wo_parents(self): lines = ['prompt "VSP8K"'] set_module_args(dict(lines=lines)) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config)) commands = ['prompt "VSP8K"'] self.execute_module(changed=True, commands=commands)
def test_voss_config_replace_block_requires_lines(self): args = dict(replace='block') set_module_args(args) self.execute_module(failed=True)
def test_voss_config_unchanged(self): src = load_fixture('voss_config_config.cfg') self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, src)) set_module_args(dict(src=src)) self.execute_module()