Best Python code snippet using autotest_python
iscsi_unittest.py
Source:iscsi_unittest.py
...26 self.setup_stubs_portal_visible(iscsi_obj, "127.0.0.1:3260,1 %s"27 % iscsi_obj.target)28 lg_msg = "successful"29 utils.system_output.expect_call(lg_cmd).and_return(lg_msg)30 def setup_stubs_get_device_name(self, iscsi_obj):31 s_msg = "tcp [15] 127.0.0.1:3260,1 %s" % iscsi_obj.target32 utils.system_output.expect_call("iscsiadm --mode session",33 ignore_status=True34 ).and_return(s_msg)35 detail = "Target: iqn.iscsitest\n Attached scsi disk "36 detail += "sdb State running"37 utils.system_output.expect_call("iscsiadm -m session -P 3"38 ).and_return(detail)39 def setup_stubs_cleanup(self, iscsi_obj, fname=""):40 s_msg = "tcp [15] 127.0.0.1:3260,1 %s" % iscsi_obj.target41 utils.system_output.expect_call("iscsiadm --mode session",42 ignore_status=True43 ).and_return(s_msg)44 out_cmd = "iscsiadm --mode node --logout -T %s" % iscsi_obj.target45 utils.system_output.expect_call(out_cmd).and_return("successful")46 os.path.isfile.expect_call(fname).and_return(False)47 s_cmd = "tgtadm --lld iscsi --mode target --op show"48 utils.system_output.expect_call(s_cmd49 ).and_return("Target 1: iqn.iscsitest")50 d_cmd = "tgtadm --lld iscsi --mode target --op delete"51 d_cmd += " --tid %s" % iscsi_obj.emulated_id52 utils.system.expect_call(d_cmd)53 def setup_stubs_logged_in(self, result=""):54 utils.system_output.expect_call("iscsiadm --mode session",55 ignore_status=True56 ).and_return(result)57 def setup_stubs_portal_visible(self, iscsi_obj, result=""):58 host_name = iscsi_obj.portal_ip59 v_cmd = "iscsiadm -m discovery -t sendtargets -p %s" % host_name60 utils.system_output.expect_call(v_cmd,61 ignore_status=True).and_return(result)62 def setup_stubs_export_target(self, iscsi_obj):63 s_cmd = "tgtadm --lld iscsi --mode target --op show"64 utils.system_output.expect_call(s_cmd).and_return("")65 utils.system_output.expect_call(s_cmd).and_return("")66 t_cmd = "tgtadm --mode target --op new --tid"67 t_cmd += " %s --lld iscsi " % iscsi_obj.emulated_id68 t_cmd += "--targetname %s" % iscsi_obj.target69 utils.system.expect_call(t_cmd)70 l_cmd = "tgtadm --lld iscsi --op bind --mode target"71 l_cmd += " --tid %s -I ALL" % iscsi_obj.emulated_id72 utils.system.expect_call(l_cmd)73 utils.system_output.expect_call(s_cmd).and_return("")74 t_cmd = "tgtadm --mode logicalunit --op new "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):...
iscsi_uinttest.py
Source:iscsi_uinttest.py
...26 self.setup_stubs_portal_visible(iscsi_obj, "127.0.0.1:3260,1 %s"27 % iscsi_obj.target)28 lg_msg = "successful"29 utils.system_output.expect_call(lg_cmd).and_return(lg_msg)30 def setup_stubs_get_device_name(self, iscsi_obj):31 s_msg = "127.0.0.1:3260,1 %s" % iscsi_obj.target32 utils.system_output.expect_call("iscsiadm --mode session"33 ).and_return(s_msg)34 detail = "Target: iqn.iscsitest\n Attached scsi disk sdb State"35 utils.system_output.expect_call("iscsiadm -m session -P 3"36 ).and_return(detail)37 def setup_stubs_cleanup(self, iscsi_obj, fname=""):38 s_msg = "127.0.0.1:3260,1 %s" % iscsi_obj.target39 utils.system_output.expect_call("iscsiadm --mode session"40 ).and_return(s_msg)41 utils.system_output.expect_call("iscsiadm --mode session"42 ).and_return(s_msg)43 out_cmd = "iscsiadm --mode node --logout -T %s" % iscsi_obj.target44 utils.system_output.expect_call(out_cmd).and_return("successful")45 os.path.isfile.expect_call(fname).and_return(False)46 s_cmd = "tgtadm --lld iscsi --mode target --op show"47 utils.system_output.expect_call(s_cmd48 ).and_return("Target 1: iqn.iscsitest")49 d_cmd = "tgtadm --lld iscsi --mode target --op delete"50 d_cmd += " --tid %s" % iscsi_obj.emulated_id51 utils.system.expect_call(d_cmd)52 def setup_stubs_logged_in(self, result=""):53 utils.system_output.expect_call("iscsiadm --mode session"54 ).and_return(result)55 def setup_stubs_portal_visible(self, iscsi_obj, result=""):56 host_name = iscsi_obj.portal_ip57 v_cmd = "iscsiadm -m discovery -t sendtargets -p %s" % host_name58 utils.system_output.expect_call(v_cmd).and_return(result)59 def setup_stubs_export_target(self, iscsi_obj):60 s_cmd = "tgtadm --lld iscsi --mode target --op show"61 utils.system_output.expect_call(s_cmd).and_return("")62 utils.system_output.expect_call(s_cmd).and_return("")63 t_cmd = "tgtadm --mode target --op new --tid"64 t_cmd += " %s --lld iscsi " % iscsi_obj.emulated_id65 t_cmd += "--targetname %s" % iscsi_obj.target66 utils.system.expect_call(t_cmd)67 l_cmd = "tgtadm --mode logicalunit --op new --tid"68 l_cmd += " %s --lld iscsi" % iscsi_obj.emulated_id69 l_cmd += " --lun 1 --backing-store "70 l_cmd += "%s" % iscsi_obj.emulated_image71 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):...
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!!