def _get_login_credentials(self, style): """Get credentials for the login. The current page from the loginAuthNotebook defines how to grab credentials out of the UI. This works as long as loginAuthNotebook keeps the filler page at the front, and we check to make sure "Use the credentials from discovery" is not selected first. :param style: an id of the login style :return: an instance of Credentials """ # No credentials. credentials = Credentials() # CHAP if style is STYLE_CHAP: credentials.username = self._get_text("loginChapUsernameEntry") credentials.password = self._get_text("loginChapPasswordEntry") # Reverse CHAP. if style is STYLE_REVERSE_CHAP: credentials.username = self._get_text("loginRchapUsernameEntry") credentials.password = self._get_text("loginRchapPasswordEntry") credentials.reverse_username = self._get_text("loginRchapReverseUsername") credentials.reverse_password = self._get_text("loginRchapReversePassword") return credentials
def _get_discover_credentials(self, style): """Get credentials for the discovery. The current page from the authNotebook defines how to grab credentials out of the UI. This works as long as authNotebook keeps the filler page at the front. :param style: an id of the discovery style :return: an instance of Credentials """ # No credentials. credentials = Credentials() # CHAP if style is STYLE_CHAP: credentials.username = self._get_text("chapUsernameEntry") credentials.password = self._get_text("chapPasswordEntry") # Reverse CHAP. if style is STYLE_REVERSE_CHAP: credentials.username = self._get_text("rchapUsernameEntry") credentials.password = self._get_text("rchapPasswordEntry") credentials.reverse_username = self._get_text("rchapReverseUsername") credentials.reverse_password = self._get_text("rchapReversePassword") return credentials
def setUp(self): """Set up the module.""" self.iscsi_module = ISCSIModule() self.iscsi_interface = ISCSIInterface(self.iscsi_module) self._portal = Portal() self._portal.ip_address = "10.43.136.67" self._portal.port = "3260" self._credentials = Credentials() self._credentials.username = "******" self._credentials.password = "******" self._credentials.reverse_username = "******" self._credentials.reverse_password = "******" self._node = Node() self._node.name = "iqn.2014-08.com.example:t1" self._node.address = "10.43.136.67" self._node.port = "3260" self._node.iface = "iface0" self._node.net_ifacename = "ens3" # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.iscsi_interface.PropertiesChanged.connect(self.callback)
def on_login_clicked(self, *args): """Start the login task.""" row = self._find_row_for_login() # Skip, if there is nothing to do. if not row: return # First update widgets. self._set_login_sensitive(False) self._okButton.set_sensitive(False) self._cancelButton.set_sensitive(False) self._loginButton.set_sensitive(False) self._loginConditionNotebook.set_current_page(0) # Get data. portal = self._get_portal() node = self._find_node_for_row(row) _style, credentials = self._get_login_style_and_credentials() # Get the login task. task_path = self._iscsi_module.LoginWithTask( Portal.to_structure(portal), Credentials.to_structure(credentials), Node.to_structure(node) ) task_proxy = STORAGE.get_proxy(task_path) # Start the login. async_run_task(task_proxy, lambda task_proxy: self.process_login_result(task_proxy, row)) self._loginSpinner.start() self._loginSpinner.show()
def DiscoverWithTask(self, portal: Structure, credentials: Structure, interfaces_mode: Str) -> ObjPath: """Discover an iSCSI device. :param portal: the portal information :param credentials: the iSCSI credentials :param interfaces_mode: required mode specified by IscsiInterfacesMode string value :return: a DBus path to a task """ portal = Portal.from_structure(portal) credentials = Credentials.from_structure(credentials) interfaces_mode = IscsiInterfacesMode(interfaces_mode) return self.implementation.discover_with_task(portal, credentials, interfaces_mode)
def LoginWithTask(self, portal: Structure, credentials: Structure, node: Structure) -> ObjPath: """Login into an iSCSI node discovered on a portal. :param portal: the portal information :param credentials: the iSCSI credentials :param node: the node information :return: a DBus path to a task """ portal = Portal.from_structure(portal) credentials = Credentials.from_structure(credentials) node = Node.from_structure(node) return self.implementation.login_with_task(portal, credentials, node)
def test_login_with_task(self, publisher): """Test the login task.""" task_path = self.iscsi_interface.LoginWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), Node.to_structure(self._node), ) obj = check_task_creation(task_path, publisher, ISCSILoginTask) assert obj.implementation._portal == self._portal assert obj.implementation._credentials == self._credentials assert obj.implementation._node == self._node
def login_with_task_test(self, publisher): """Test the login task.""" task_path = self.iscsi_interface.LoginWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), Node.to_structure(self._node), ) obj = check_task_creation(self, task_path, publisher, ISCSILoginTask) self.assertEqual(obj.implementation._portal, self._portal) self.assertEqual(obj.implementation._credentials, self._credentials) self.assertEqual(obj.implementation._node, self._node)
def test_discover_with_task(self, publisher): """Test the discover task.""" interfaces_mode = "default" task_path = self.iscsi_interface.DiscoverWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), interfaces_mode) obj = check_task_creation(task_path, publisher, ISCSIDiscoverTask) assert isinstance(obj, ISCSIDiscoverTaskInterface) assert obj.implementation._portal == self._portal assert obj.implementation._credentials == self._credentials assert obj.implementation._interfaces_mode == IscsiInterfacesMode.DEFAULT
def discover_with_task_test(self, publisher): """Test the discover task.""" interfaces_mode = "default" task_path = self.iscsi_interface.DiscoverWithTask( Portal.to_structure(self._portal), Credentials.to_structure(self._credentials), interfaces_mode) obj = check_task_creation(self, task_path, publisher, ISCSIDiscoverTask) self.assertIsInstance(obj, ISCSIDiscoverTaskInterface) self.assertEqual(obj.implementation._portal, self._portal) self.assertEqual(obj.implementation._credentials, self._credentials) self.assertEqual(obj.implementation._interfaces_mode, IscsiInterfacesMode.DEFAULT)
def on_start_clicked(self, *args): """Start the discovery task.""" # First update widgets. self._startButton.hide() self._cancelButton.set_sensitive(False) self._okButton.set_sensitive(False) self._conditionNotebook.set_current_page(1) self._set_configure_sensitive(False) self._initiatorEntry.set_sensitive(False) # Get the node discovery credentials. style = self._authNotebook.get_current_page() portal = self._get_portal() credentials = self._get_discover_credentials(style) initiator = self._get_text("initiatorEntry") self._discoveredLabel.set_markup(_( "The following nodes were discovered using the iSCSI initiator " "<b>%(initiatorName)s</b> using the portal IP address " "<b>%(portalAddress)s</b>. Please select which nodes you " "wish to log into:") % { "initiatorName": escape_markup(initiator), "portalAddress": escape_markup(portal.ip_address) } ) # Get the discovery task. if self._bindCheckbox.get_active(): interfaces_mode = ISCSI_INTERFACE_IFACENAME else: interfaces_mode = ISCSI_INTERFACE_DEFAULT task_path = self._iscsi_module.DiscoverWithTask( Portal.to_structure(portal), Credentials.to_structure(credentials), interfaces_mode ) task_proxy = STORAGE.get_proxy(task_path) if self._iscsi_module.CanSetInitiator(): self._iscsi_module.Initiator = initiator # Start the discovery. async_run_task(task_proxy, self.process_discovery_result) self._discoverySpinner.start()