cliconf refactor eos, nxos fix (#43596)

* cliconf refactor eos and nxos fix

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* move nxos replace check to plugins

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* address review comment

* fix shippable
pull/43606/head
Trishna Guha 6 years ago committed by GitHub
parent 6f4b2e8f7f
commit 09ae1ec308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -392,6 +392,9 @@ class Nxapi:
"""Sends the ordered set of commands to the device
"""
if replace:
device_info = self.get_device_info()
if '9K' not in device_info.get('network_os_platform', ''):
self._module.fail_json(msg='replace is supported only on Nexus 9K devices')
commands = 'config replace {0}'.format(replace)
commands = to_list(commands)

@ -281,7 +281,6 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.config import NetworkConfig, dumps
from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands, get_connection
from ansible.module_utils.network.nxos.nxos import get_capabilities
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import check_args as nxos_check_args
from ansible.module_utils.network.common.utils import to_list
@ -392,19 +391,6 @@ def main():
config = None
try:
info = get_capabilities(module)
api = info.get('network_api')
device_info = info.get('device_info', {})
os_platform = device_info.get('network_os_platform', '')
except ConnectionError:
api = ''
os_platform = ''
if api == 'cliconf' and module.params['replace'] == 'config':
if '9K' not in os_platform:
module.fail_json(msg='replace: config is supported only on Nexus 9K series switches')
diff_ignore_lines = module.params['diff_ignore_lines']
path = module.params['parents']
connection = get_connection(module)

@ -289,8 +289,8 @@ class Cliconf(CliconfBase):
def get_capabilities(self):
result = {}
result['rpc'] = self.get_base_rpc()
result['device_info'] = self.get_device_info()
rpc_list = ['commit', 'discard_changes', 'get_diff', 'run_commands', 'supports_sessions']
result['rpc'] = self.get_base_rpc() + rpc_list
result['device_info'] = self.get_device_info()
result['device_operations'] = self.get_device_operations()
result.update(self.get_option_values())

@ -158,6 +158,9 @@ class Cliconf(CliconfBase):
requests = []
if replace:
device_info = self.get_device_info()
if '9K' not in device_info.get('network_os_platform', ''):
raise ConnectionError(msg=u'replace is supported only on Nexus 9K devices')
candidate = 'config replace {0}'.format(replace)
if commit:
@ -244,8 +247,9 @@ class Cliconf(CliconfBase):
def get_capabilities(self):
result = {}
result['rpc'] = self.get_base_rpc()
result['rpc'] = self.get_base_rpc() + ['get_diff', 'run_commands']
result['device_info'] = self.get_device_info()
result['device_operations'] = self.get_device_operations()
result.update(self.get_option_values())
if isinstance(self._connection, NetworkCli):

@ -77,7 +77,11 @@ class HttpApi(HttpApiBase):
operations = self.connection.get_device_operations()
self.connection.check_edit_config_capabiltiy(operations, candidate, commit, replace, comment)
if replace:
device_info = self.connection.get_device_info()
if '9K' not in device_info.get('network_os_platform', ''):
raise ConnectionError(msg=u'replace is supported only on Nexus 9K devices')
candidate = 'config replace {0}'.format(replace)
responses = self.send_request(candidate, output='config')

@ -38,10 +38,6 @@ class TestNxosConfigModule(TestNxosModule):
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_config.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_capabilities = patch('ansible.modules.network.nxos.nxos_config.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {'device_info': {'network_os_platform': 'N9K-NXOSV'}}
self.mock_save_config = patch('ansible.modules.network.nxos.nxos_config.save_config')
self.save_config = self.mock_save_config.start()
@ -61,7 +57,6 @@ class TestNxosConfigModule(TestNxosModule):
super(TestNxosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_capabilities.stop()
self.mock_run_commands.stop()
self.mock_get_connection.stop()
@ -89,10 +84,10 @@ class TestNxosConfigModule(TestNxosModule):
self.assertEqual(sorted(config), sorted(result['commands']), result['commands'])
def test_nxos_config_replace_src(self):
set_module_args(dict(replace_src='config.txt', replace='config'))
set_module_args(dict(replace_src='bootflash:config', replace='config'))
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(self.running_config, self.running_config, diff_replace='config'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['config replace config.txt'])
self.assertEqual(result['commands'], ['config replace bootflash:config'])
def test_nxos_config_lines(self):
lines = ['hostname switch01', 'ip domain-name eng.ansible.com']

Loading…
Cancel
Save