本文整理汇总了Python中jnpr.junos.utils.sw.SW.validate方法的典型用法代码示例。如果您正苦于以下问题:Python SW.validate方法的具体用法?Python SW.validate怎么用?Python SW.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jnpr.junos.utils.sw.SW
的用法示例。
在下文中一共展示了SW.validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import validate [as 别名]
#.........这里部分代码省略.........
nssu=True, issu=True)
@patch('jnpr.junos.Device.execute')
def test_sw_install_issu_single_re_error(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.sw._multi_RE = False
self.assertRaises(TypeError, self.sw.install, package,
nssu=True, issu=True)
@patch('jnpr.junos.Device.execute')
def test_sw_pkgaddISSU(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgaddISSU(package))
@patch('jnpr.junos.Device.execute')
def test_sw_pkgaddNSSU(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgaddNSSU(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))
@patch('jnpr.junos.Device.execute')
def test_sw_validate_issu(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'package.tgz'
self.assertTrue(self.sw.validate(package, issu=True))
@patch('jnpr.junos.Device.execute')
def test_sw_validate_issu(self, mock_execute):
rpc_reply = """<rpc-reply><output>mgd: commit complete
Validation succeeded
</output>
<package-result>1</package-result>
</rpc-reply>"""
mock_execute.side_effect = etree.fromstring(rpc_reply)
package = 'package.tgz'
self.assertFalse(self.sw.validate(package, issu=True))
@patch('jnpr.junos.Device.execute')
def test_sw_remote_checksum_not_found(self, mock_execute):
xml = '''<rpc-error>
<error-severity>error</error-severity>
<error-message>
md5: /var/tmp/123: No such file or directory
</error-message>
</rpc-error>'''
mock_execute.side_effect = RpcError(rsp=etree.fromstring(xml))
package = 'test.tgz'
self.assertEqual(self.sw.remote_checksum(package), None)
示例2: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import validate [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 validate [as 别名]
#.........这里部分代码省略.........
self.assertEqual(str(ex), 'ISSU/NSSU requires Multi RE setup')
@patch('jnpr.junos.Device.execute')
def test_sw_install_issu_nssu_single_re_error(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.sw._multi_RE = False
self.assertRaises(TypeError, self.sw.install, package,
nssu=True, issu=True)
@patch('jnpr.junos.Device.execute')
def test_sw_pkgaddISSU(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgaddISSU(package))
@patch('jnpr.junos.Device.execute')
def test_sw_pkgaddNSSU(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertTrue(self.sw.pkgaddNSSU(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
self.assertTrue(self.sw.validate('package.tgz'))
@patch('jnpr.junos.Device.execute')
def test_sw_validate_nssu(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw.log = MagicMock()
# get_config returns false
self.assertFalse(self.sw.validate('package.tgz', nssu=True))
self.sw.log.assert_called_with(
'Requirement FAILED: GRES is not Enabled in configuration')
@patch('jnpr.junos.Device.execute')
def test_sw_validate_issu(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.dev.rpc.get_config = MagicMock()
self.assertTrue(self.sw.validate('package.tgz', issu=True))
@patch('jnpr.junos.Device.execute')
def test_sw_val_issu_request_shell_execute_gres_on(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.dev.rpc.get_config = MagicMock()
self.dev.rpc.request_shell_execute = MagicMock()
self.dev.rpc.request_shell_execute.return_value = etree.fromstring(
"""<rpc-reply>
<output>Graceful switchover: On</output>
</rpc-reply>""")
self.assertTrue(self.sw.validate('package.tgz', issu=True))
@patch('jnpr.junos.Device.execute')
def test_sw_validate_issu_2re_false(self, mock_execute):
mock_execute.side_effect = self._mock_manager
示例4: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import validate [as 别名]
#.........这里部分代码省略.........
'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))
@patch('jnpr.junos.Device.execute')
def test_sw_safe_copy(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'safecopy.tgz'
self.sw.put = MagicMock()
with patch('jnpr.junos.utils.sw.SW.local_md5'):
self.assertTrue(self.sw.safe_copy(package, progress=self._myprogress,
cleanfs=True,
checksum='96a35ab371e1ca10408c3caecdbd8a67'))
@patch('jnpr.junos.Device.execute')
def test_sw_safe_copy_return_false(self, mock_execute):
# not passing checksum value, will get random from magicmock
mock_execute.side_effect = self._mock_manager
package = 'safecopy.tgz'
self.sw.put = MagicMock()
with patch('jnpr.junos.utils.sw.SW.local_md5'):
self.assertFalse(self.sw.safe_copy(package, progress=self._myprogress,
cleanfs=True))
@patch('jnpr.junos.Device.execute')
def test_sw_safe_copy_checksum_none(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'safecopy.tgz'
self.sw.put = MagicMock()
with patch('jnpr.junos.utils.sw.SW.local_md5',
MagicMock(return_value='96a35ab371e1ca10408c3caecdbd8a67')):
self.assertTrue(self.sw.safe_copy(package, progress=self._myprogress,
示例5: TestSW
# 需要导入模块: from jnpr.junos.utils.sw import SW [as 别名]
# 或者: from jnpr.junos.utils.sw.SW import validate [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))
#.........这里部分代码省略.........