How to use iscsi_discover method in autotest

Best Python code snippet using autotest_python

iscsi.py

Source:iscsi.py Github

copy

Full Screen

...59 target_logout = ""60 if "successful" in output:61 target_logout = target_name62 return target_logout63def iscsi_discover(portal_ip):64 """65 Query from iscsi server for available targets66 :param portal_ip: Ip for iscsi server67 """68 cmd = "iscsiadm -m discovery -t sendtargets -p %s" % portal_ip69 output = utils.system_output(cmd, ignore_status=True)70 session = ""71 if "Invalid" in output:72 logging.debug(output)73 else:74 session = output75 return session76class Iscsi(object):77 """78 Basic iscsi support class. Will handle the emulated iscsi export and79 access to both real iscsi and emulated iscsi device.80 """81 def __init__(self, params, root_dir="/tmp"):82 os_dep.command("iscsiadm")83 self.target = params.get("target")84 self.export_flag = False85 if params.get("portal_ip"):86 self.portal_ip = params.get("portal_ip")87 else:88 self.portal_ip = utils.system_output("hostname")89 if params.get("iscsi_thread_id"):90 self.id = params.get("iscsi_thread_id")91 else:92 self.id = utils.generate_random_string(4)93 self.initiator = params.get("initiator")94 if params.get("emulated_image"):95 self.initiator = None96 os_dep.command("tgtadm")97 emulated_image = params.get("emulated_image")98 self.emulated_image = os.path.join(root_dir, emulated_image)99 self.emulated_id = ""100 self.emulated_size = params.get("image_size")101 self.unit = self.emulated_size[-1].upper()102 self.emulated_size = self.emulated_size[:-1]103 # maps K,M,G,T => (count, bs)104 emulated_size = {'K': (1, 1),105 'M': (1, 1024),106 'G': (1024, 1024),107 'T': (1024, 1048576),108 }109 if self.unit in emulated_size:110 block_size = emulated_size[self.unit][1]111 size = int(self.emulated_size) * emulated_size[self.unit][0]112 self.create_cmd = ("dd if=/dev/zero of=%s count=%s bs=%sK"113 % (self.emulated_image, size, block_size))114 def logged_in(self):115 """116 Check if the session is login or not.117 """118 sessions = iscsi_get_sessions()119 login = False120 if self.target in map(lambda x: x[1], sessions):121 login = True122 return login123 def portal_visible(self):124 """125 Check if the portal can be found or not.126 """127 return bool(re.findall("%s$" % self.target,128 iscsi_discover(self.portal_ip), re.M))129 def login(self):130 """131 Login session for both real iscsi device and emulated iscsi. Include132 env check and setup.133 """134 login_flag = False135 if self.portal_visible():136 login_flag = True137 elif self.initiator:138 logging.debug("Try to update iscsi initiatorname")139 cmd = "mv /etc/iscsi/initiatorname.iscsi "140 cmd += "/etc/iscsi/initiatorname.iscsi-%s" % self.id141 utils.system(cmd)142 fd = open("/etc/iscsi/initiatorname.iscsi", 'w')...

Full Screen

Full Screen

test_iscsi_discover.py

Source:test_iscsi_discover.py Github

copy

Full Screen

...34 """35 self.server.set_xml_response("hosts/123/iscsidiscover", 200, "<action/>")36 hosts_service = self.connection.system_service().hosts_service()37 host_service = hosts_service.host_service('123')38 host_service.iscsi_discover(39 iscsi=types.IscsiDetails(40 address='iscsi.example.com',41 port=3260,42 ),43 )44 assert_equal(45 self.server.last_request_content,46 "<action>" +47 "<iscsi>" +48 "<address>iscsi.example.com</address>" +49 "<port>3260</port>" +50 "</iscsi>" +51 "</action>"52 )

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful