本文整理汇总了Python中jnpr.junos.utils.sw.SW.put方法的典型用法代码示例。如果您正苦于以下问题:Python SW.put方法的具体用法?Python SW.put怎么用?Python SW.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jnpr.junos.utils.sw.SW
的用法示例。
在下文中一共展示了SW.put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import put [as 别名]
class TestSW(unittest.TestCase):
@patch('ncclient.manager.connect')
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
self.dev.open()
self.dev._facts = facts
self.sw = self.get_sw()
@patch('jnpr.junos.Device.execute')
def get_sw(self, mock_execute):
mock_execute.side_effect = self._mock_manager
return SW(self.dev)
@patch('ncclient.operations.session.CloseSession.request')
def tearDown(self, mock_session):
self.dev.close()
def test_sw_hashfile(self):
with patch(builtin_string + '.open', mock_open(), create=True):
import jnpr.junos.utils.sw
with open('foo') as h:
h.read.side_effect = ('abc', 'a', '')
jnpr.junos.utils.sw._hashfile(h, MagicMock())
self.assertEqual(h.read.call_count, 3)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_re(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertTrue(self.sw._multi_RE)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_VC)
@patch(builtin_string + '.open')
def test_sw_local_sha256(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha256(package),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934'
'ca495991b7852b855')
@patch(builtin_string + '.open')
def test_sw_local_md5(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(self.sw.local_md5(package),
'd41d8cd98f00b204e9800998ecf8427e')
@patch(builtin_string + '.open')
def test_sw_local_sha1(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha1(package),
'da39a3ee5e6b4b0d3255bfef95601890afd80709')
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, 'running') as output:
self.assertEqual('1.1.1.1: running\n', output)
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, 'running') as output:
self.assertEqual('1.1.1.1: running\n', output)
@patch('jnpr.junos.Device.execute')
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_progress_true(self, scp_put, mock_paramiko, mock_execute):
mock_execute.side_effect = self._mock_manager
with self.capture(SW.progress, self.dev, 'testing') as output:
self.sw.install('test.tgz', progress=True, checksum=345,
cleanfs=False)
self.assertEqual('1.1.1.1: testing\n', output)
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_put(self, mock_scp_put, mock_scp):
package = 'test.tgz'
self.sw.put(package)
self.assertTrue(
call(
'test.tgz',
'/var/tmp') in mock_scp_put.mock_calls)
@patch('jnpr.junos.utils.sw.FTP')
def test_sw_put_ftp(self, mock_ftp_put):
dev = Device(host='1.1.1.1', user='rick', password='password123',
mode='telnet', port=23, gather_facts=False)
sw = SW(dev)
sw.put(package='test.tgz')
self.assertTrue(
call(
'test.tgz',
'/var/tmp') in mock_ftp_put.mock_calls)
@patch('jnpr.junos.utils.scp.SCP.__exit__')
@patch('jnpr.junos.utils.scp.SCP.__init__')
#.........这里部分代码省略.........
示例2: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import put [as 别名]
class TestSW(unittest.TestCase):
@patch('ncclient.manager.connect')
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
self.dev.open()
self.dev._facts = facts
self.sw = self.get_sw()
@patch('jnpr.junos.Device.execute')
def get_sw(self, mock_execute):
mock_execute.side_effect = self._mock_manager
return SW(self.dev)
@patch('ncclient.operations.session.CloseSession.request')
def tearDown(self, mock_session):
self.dev.close()
def test_sw_hashfile(self):
with patch('__builtin__.open', mock_open(), create=True):
import jnpr.junos.utils.sw
with open('foo') as h:
h.read.side_effect = ('abc', 'a', '')
jnpr.junos.utils.sw._hashfile(h, MagicMock())
self.assertEqual(h.read.call_count, 3)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_re(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_RE)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_VC)
@patch('__builtin__.open')
def test_sw_local_sha256(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha256(package),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934'
'ca495991b7852b855')
@patch('__builtin__.open')
def test_sw_local_md5(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_md5(package),
'd41d8cd98f00b204e9800998ecf8427e')
@patch('__builtin__.open')
def test_sw_local_sha1(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha1(package),
'da39a3ee5e6b4b0d3255bfef95601890afd80709')
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, 'running') as output:
self.assertEqual('1.1.1.1: running\n', output)
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_put(self, mock_scp_put, mock_scp):
# mock_scp_put.side_effect = self.mock_put
package = 'test.tgz'
self.sw.put(package)
self.assertTrue(call('test.tgz', '/var/tmp') in mock_scp_put.mock_calls)
@patch('jnpr.junos.utils.scp.SCP.__exit__')
@patch('jnpr.junos.utils.scp.SCP.__init__')
@patch('jnpr.junos.utils.scp.SCP.__enter__')
def test_sw_put_progress(self, mock_enter, mock_scp, mock_exit):
package = 'test.tgz'
mock_scp.side_effect = self._fake_scp
self.sw.put(package, progress=self._myprogress)
self.assertEqual(mock_scp.call_args_list[0][1]['progress'].by10pct, 50)
def _fake_scp(self, *args, **kwargs):
progress = kwargs['progress']
progress('test.tgz', 100, 50)
@patch('jnpr.junos.Device.execute')
def test_sw_pkgadd(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgadd(package))
@patch('jnpr.junos.Device.execute')
def test_sw_validate(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'package.tgz'
self.assertTrue(self.sw.validate(package))
@patch('jnpr.junos.Device.execute')
def test_sw_safe_copy(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'safecopy.tgz'
#.........这里部分代码省略.........
示例3: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import put [as 别名]
class TestSW(unittest.TestCase):
@patch('ncclient.manager.connect')
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
self.dev.open()
self.dev.facts = facts
self.sw = self.get_sw()
@patch('jnpr.junos.Device.execute')
def get_sw(self, mock_execute):
mock_execute.side_effect = self._mock_manager
return SW(self.dev)
@patch('ncclient.operations.session.CloseSession.request')
def tearDown(self, mock_session):
self.dev.close()
def test_sw_hashfile(self):
with patch(builtin_string + '.open', mock_open(), create=True):
import jnpr.junos.utils.sw
with open('foo') as h:
h.read.side_effect = ('abc', 'a', '')
jnpr.junos.utils.sw._hashfile(h, MagicMock())
self.assertEqual(h.read.call_count, 3)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_re(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertTrue(self.sw._multi_RE)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_VC)
@patch(builtin_string + '.open')
def test_sw_local_sha256(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_checksum(package, algorithm='sha256'),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934'
'ca495991b7852b855')
@patch(builtin_string + '.open')
def test_sw_local_md5(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(self.sw.local_checksum(package, algorithm='md5'),
'd41d8cd98f00b204e9800998ecf8427e')
@patch(builtin_string + '.open')
def test_sw_local_sha1(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_checksum(package, algorithm='sha1'),
'da39a3ee5e6b4b0d3255bfef95601890afd80709')
def test_sw_local_checksum_unknown_alg(self):
self.assertRaises(ValueError, SW.local_checksum, 'foo.tgz', algorithm='foo')
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, 'running') as output:
self.assertEqual('1.1.1.1: running\n', output)
@patch('jnpr.junos.Device.execute')
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_progress_true(self, scp_put, mock_paramiko, mock_execute):
mock_execute.side_effect = self._mock_manager
with self.capture(SW.progress, self.dev, 'testing') as output:
self.sw.install('test.tgz', progress=True, checksum=345,
cleanfs=False)
self.assertEqual('1.1.1.1: testing\n', output)
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_put(self, mock_scp_put, mock_scp):
package = 'test.tgz'
self.sw.put(package)
self.assertTrue(
call(
'test.tgz',
'/var/tmp') in mock_scp_put.mock_calls)
@patch('jnpr.junos.utils.sw.FTP')
def test_sw_put_ftp(self, mock_ftp_put):
dev = Device(host='1.1.1.1', user='rick', password='password123',
mode='telnet', port=23, gather_facts=False)
sw = SW(dev)
sw.put(package='test.tgz')
self.assertTrue(
call(
'test.tgz',
'/var/tmp') in mock_ftp_put.mock_calls)
@patch('jnpr.junos.utils.scp.SCP.__exit__')
@patch('jnpr.junos.utils.scp.SCP.__init__')
@patch('jnpr.junos.utils.scp.SCP.__enter__')
#.........这里部分代码省略.........
示例4: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import put [as 别名]
class TestSW(unittest.TestCase):
@patch('ncclient.manager.connect')
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
self.dev.open()
self.dev._facts = facts
self.sw = self.get_sw()
@patch('jnpr.junos.Device.execute')
def get_sw(self, mock_execute):
mock_execute.side_effect = self._mock_manager
return SW(self.dev)
@patch('ncclient.operations.session.CloseSession.request')
def tearDown(self, mock_session):
self.dev.close()
def test_sw_hashfile(self):
with patch('__builtin__.open', mock_open(), create=True):
import jnpr.junos.utils.sw
with open('foo') as h:
h.read.side_effect = ('abc', 'a', '')
jnpr.junos.utils.sw._hashfile(h, MagicMock())
self.assertEqual(h.read.call_count, 3)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_re(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_RE)
@patch('jnpr.junos.Device.execute')
def test_sw_constructor_multi_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_VC)
@patch('__builtin__.open')
def test_sw_local_sha256(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha256(package),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934'
'ca495991b7852b855')
@patch('__builtin__.open')
def test_sw_local_md5(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(self.sw.local_md5(package),
'd41d8cd98f00b204e9800998ecf8427e')
@patch('__builtin__.open')
def test_sw_local_sha1(self, mock_built_open):
package = 'test.tgz'
self.assertEqual(SW.local_sha1(package),
'da39a3ee5e6b4b0d3255bfef95601890afd80709')
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, 'running') as output:
self.assertEqual('1.1.1.1: running\n', output)
@patch('paramiko.SSHClient')
@patch('scp.SCPClient.put')
def test_sw_put(self, mock_scp_put, mock_scp):
# mock_scp_put.side_effect = self.mock_put
package = 'test.tgz'
self.sw.put(package)
self.assertTrue(
call(
'test.tgz',
'/var/tmp') in mock_scp_put.mock_calls)
@patch('jnpr.junos.utils.scp.SCP.__exit__')
@patch('jnpr.junos.utils.scp.SCP.__init__')
@patch('jnpr.junos.utils.scp.SCP.__enter__')
def test_sw_put_progress(self, mock_enter, mock_scp, mock_exit):
package = 'test.tgz'
mock_scp.side_effect = self._fake_scp
self.sw.put(package, progress=self._myprogress)
self.assertEqual(mock_scp.call_args_list[0][1]['progress'].by10pct, 50)
def _fake_scp(self, *args, **kwargs):
progress = kwargs['progress']
progress('test.tgz', 100, 50)
@patch('jnpr.junos.Device.execute')
def test_sw_pkgadd(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgadd(package))
@patch('jnpr.junos.Device.execute')
def test_sw_pkgadd_pkg_set(self, mock_execute):
mock_execute.side_effect = self._mock_manager
pkg_set = ['abc.tgz', 'pqr.tgz']
self.sw._mixed_VC = True
self.sw.pkgadd(pkg_set)
self.assertEqual([i.text for i in
#.........这里部分代码省略.........
示例5: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import put [as 别名]
class TestSW(unittest.TestCase):
@patch("ncclient.manager.connect")
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host="1.1.1.1", user="rick", password="password123", gather_facts=False)
self.dev.open()
self.dev._facts = facts
self.sw = self.get_sw()
@patch("jnpr.junos.Device.execute")
def get_sw(self, mock_execute):
mock_execute.side_effect = self._mock_manager
return SW(self.dev)
@patch("ncclient.operations.session.CloseSession.request")
def tearDown(self, mock_session):
self.dev.close()
def test_sw_hashfile(self):
with patch("__builtin__.open", mock_open(), create=True):
import jnpr.junos.utils.sw
with open("foo") as h:
h.read.side_effect = ("abc", "a", "")
jnpr.junos.utils.sw._hashfile(h, MagicMock())
self.assertEqual(h.read.call_count, 3)
@patch("jnpr.junos.Device.execute")
def test_sw_constructor_multi_re(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_RE)
@patch("jnpr.junos.Device.execute")
def test_sw_constructor_multi_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw = SW(self.dev)
self.assertFalse(self.sw._multi_VC)
@patch("__builtin__.open")
def test_sw_local_sha256(self, mock_built_open):
package = "test.tgz"
self.assertEqual(
SW.local_sha256(package), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934" "ca495991b7852b855"
)
@patch("__builtin__.open")
def test_sw_local_md5(self, mock_built_open):
package = "test.tgz"
self.assertEqual(self.sw.local_md5(package), "d41d8cd98f00b204e9800998ecf8427e")
@patch("__builtin__.open")
def test_sw_local_sha1(self, mock_built_open):
package = "test.tgz"
self.assertEqual(SW.local_sha1(package), "da39a3ee5e6b4b0d3255bfef95601890afd80709")
def test_sw_progress(self):
with self.capture(SW.progress, self.dev, "running") as output:
self.assertEqual("1.1.1.1: running\n", output)
@patch("paramiko.SSHClient")
@patch("scp.SCPClient.put")
def test_sw_put(self, mock_scp_put, mock_scp):
# mock_scp_put.side_effect = self.mock_put
package = "test.tgz"
self.sw.put(package)
self.assertTrue(call("test.tgz", "/var/tmp") in mock_scp_put.mock_calls)
@patch("jnpr.junos.utils.scp.SCP.__exit__")
@patch("jnpr.junos.utils.scp.SCP.__init__")
@patch("jnpr.junos.utils.scp.SCP.__enter__")
def test_sw_put_progress(self, mock_enter, mock_scp, mock_exit):
package = "test.tgz"
mock_scp.side_effect = self._fake_scp
self.sw.put(package, progress=self._myprogress)
self.assertEqual(mock_scp.call_args_list[0][1]["progress"].by10pct, 50)
def _fake_scp(self, *args, **kwargs):
progress = kwargs["progress"]
progress("test.tgz", 100, 50)
@patch("jnpr.junos.Device.execute")
def test_sw_pkgadd(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = "test.tgz"
self.assertTrue(self.sw.pkgadd(package))
@patch("jnpr.junos.Device.execute")
def test_sw_pkgadd_pkg_set(self, mock_execute):
mock_execute.side_effect = self._mock_manager
pkg_set = ["abc.tgz", "pqr.tgz"]
self.sw._mixed_VC = True
self.sw.pkgadd(pkg_set)
self.assertEqual([i.text for i in mock_execute.call_args[0][0].findall("set")], pkg_set)
@patch("jnpr.junos.Device.execute")
def test_sw_validate(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = "package.tgz"
self.assertTrue(self.sw.validate(package))
#.........这里部分代码省略.........