Skip to content

Commit

Permalink
Merge c80b7a5 into 5407590
Browse files Browse the repository at this point in the history
  • Loading branch information
marekgr committed May 3, 2018
2 parents 5407590 + c80b7a5 commit 885b698
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ncclient/operations/edit.py
Expand Up @@ -95,7 +95,14 @@ def request(self, source, target):
:seealso: :ref:`srctarget_params`"""
node = new_ele("copy-config")
node.append(util.datastore_or_url("target", target, self._assert))
node.append(util.datastore_or_url("source", source, self._assert))

try:
# datastore name or URL
node.append(util.datastore_or_url("source", source, self._assert))
except Exception:
# `source` with `config` element containing the configuration subtree to copy
node.append(validated_element(source, ("source", qualify("source"))))

return self._request(node)


Expand Down
24 changes: 24 additions & 0 deletions test/unit/operations/test_edit.py
Expand Up @@ -97,6 +97,30 @@ def test_copy_config(self, mock_request):
call = ElementTree.tostring(call)
self.assertEqual(call, xml)

@patch('ncclient.operations.RPC._request')
def test_copy_config_2(self, mock_request):
session = ncclient.transport.SSHSession(self.device_handler)
obj = CopyConfig(
session,
self.device_handler,
raise_mode=RaiseMode.ALL)
source = new_ele('source')
config = sub_ele(source, 'config')
configuration = sub_ele(config, 'configuration')
system = sub_ele(configuration, 'system')
location = sub_ele(system, 'location')
sub_ele(location, 'building').text = "Main Campus, A"
sub_ele(location, 'floor').text = "5"
sub_ele(location, 'rack').text = "27"
obj.request(copy.deepcopy(source), "candidate")
node = new_ele("copy-config")
node.append(util.datastore_or_url("target", "candidate"))
node.append(validated_element(source, ("source", qualify("source"))))
xml = ElementTree.tostring(node)
call = mock_request.call_args_list[0][0][0]
call = ElementTree.tostring(call)
self.assertEqual(call, xml)

@patch('ncclient.operations.RPC._request')
def test_validate_config(self, mock_request):
session = ncclient.transport.SSHSession(self.device_handler)
Expand Down

0 comments on commit 885b698

Please sign in to comment.