Best Python code snippet using autotest_python
iscsi_unittest.py
Source:iscsi_unittest.py
...75 t_cmd += "--tid %s --lld iscsi " % iscsi_obj.emulated_id76 t_cmd += "--lun %s " % 077 t_cmd += "--backing-store %s" % iscsi_obj.emulated_image78 utils.system.expect_call(t_cmd)79 def setup_stubs_get_target_id(self):80 s_cmd = "tgtadm --lld iscsi --mode target --op show"81 s_msg = "Target 1: iqn.iscsitest\nBacking store path: /tmp/iscsitest"82 utils.system_output.expect_call(s_cmd).and_return(s_msg)83 def setUp(self):84 # The normal iscsi with iscsi server should configure following85 # parameters. As this will need env support only test emulated86 # iscsi in local host.87 # self.iscsi_params = {"target": "",88 # "portal_ip": "",89 # "initiator": ""}90 self.iscsi_emulated_params = {"emulated_image": "/tmp/iscsitest",91 "target": "iqn.iscsitest",92 "image_size": "1024K"}93 self.god = mock.mock_god()94 self.god.stub_function(os_dep, "command")95 self.god.stub_function(utils, "system")96 self.god.stub_function(utils, "system_output")97 self.god.stub_function(os.path, "isfile")98 def tearDown(self):99 self.god.unstub_all()100 def test_iscsi_get_device_name(self):101 self.setup_stubs_init()102 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)103 iscsi_emulated.emulated_id = "1"104 self.setup_stubs_login(iscsi_emulated)105 iscsi_emulated.login()106 self.setup_stubs_get_device_name(iscsi_emulated)107 self.assertNotEqual(iscsi_emulated.get_device_name(), "")108 fname = "/etc/iscsi/initiatorname.iscsi-%s" % iscsi_emulated.id109 self.setup_stubs_cleanup(iscsi_emulated, fname=fname)110 iscsi_emulated.cleanup()111 self.god.check_playback()112 def test_iscsi_login(self):113 self.setup_stubs_init()114 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)115 self.setup_stubs_logged_in()116 self.assertFalse(iscsi_emulated.logged_in())117 result = "tcp [15] 127.0.0.1:3260,1 %s" % iscsi_emulated.target118 self.setup_stubs_logged_in(result)119 self.assertTrue(iscsi_emulated.logged_in())120 def test_iscsi_visible(self):121 self.setup_stubs_init()122 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)123 self.setup_stubs_portal_visible(iscsi_emulated)124 self.assertFalse(iscsi_emulated.portal_visible())125 self.setup_stubs_portal_visible(iscsi_emulated, "127.0.0.1:3260,1 %s"126 % iscsi_emulated.target)127 def test_iscsi_target_id(self):128 self.setup_stubs_init()129 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)130 self.setup_stubs_get_target_id()131 self.assertNotEqual(iscsi_emulated.get_target_id(), "")132if __name__ == "__main__":...
iscsi_uinttest.py
Source:iscsi_uinttest.py
...71 b_cmd = "tgtadm --lld iscsi --op bind --mode target --tid"72 b_cmd += " %s -I ALL" % iscsi_obj.emulated_id73 utils.system.expect_call(l_cmd)74 utils.system.expect_call(b_cmd)75 def setup_stubs_get_target_id(self):76 s_cmd = "tgtadm --lld iscsi --mode target --op show"77 s_msg = "Target 1: iqn.iscsitest\nBacking store path: /tmp/iscsitest"78 utils.system_output.expect_call(s_cmd).and_return(s_msg)79 def setUp(self):80 # The normal iscsi with iscsi server should configure following81 # parameters. As this will need env support only test emulated82 # iscsi in local host.83 # self.iscsi_params = {"target": "",84 # "portal_ip": "",85 # "initiator": ""}86 self.iscsi_emulated_params = {"emulated_image": "/tmp/iscsitest",87 "target": "iqn.iscsitest",88 "image_size": "1024K"}89 self.god = mock.mock_god()90 self.god.stub_function(os_dep, "command")91 self.god.stub_function(utils, "system")92 self.god.stub_function(utils, "system_output")93 self.god.stub_function(os.path, "isfile")94 def tearDown(self):95 self.god.unstub_all()96 def test_iscsi_get_device_name(self):97 self.setup_stubs_init()98 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)99 iscsi_emulated.emulated_id = "1"100 self.setup_stubs_login(iscsi_emulated)101 iscsi_emulated.login()102 self.setup_stubs_get_device_name(iscsi_emulated)103 self.assertNotEqual(iscsi_emulated.get_device_name(), "")104 fname = "/etc/iscsi/initiatorname.iscsi-%s" % iscsi_emulated.id105 self.setup_stubs_cleanup(iscsi_emulated, fname=fname)106 iscsi_emulated.cleanup()107 self.god.check_playback()108 def test_iscsi_login(self):109 self.setup_stubs_init()110 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)111 self.setup_stubs_logged_in()112 self.assertFalse(iscsi_emulated.logged_in())113 result = "127.0.0.1:3260,1 %s" % iscsi_emulated.target114 self.setup_stubs_logged_in(result)115 self.assertTrue(iscsi_emulated.logged_in())116 def test_iscsi_visible(self):117 self.setup_stubs_init()118 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)119 self.setup_stubs_portal_visible(iscsi_emulated)120 self.assertFalse(iscsi_emulated.portal_visible())121 self.setup_stubs_portal_visible(iscsi_emulated, "127.0.0.1:3260,1 %s"122 % iscsi_emulated.target)123 def test_iscsi_target_id(self):124 self.setup_stubs_init()125 iscsi_emulated = iscsi.Iscsi(self.iscsi_emulated_params)126 self.setup_stubs_get_target_id()127 self.assertNotEqual(iscsi_emulated.get_target_id(), "")128if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!