Example #1
0
    def test_get_dracut_arguments(self, iscsi):
        """Test the get_dracut_arguments function."""
        blivet_node = Mock()
        blivet_node.name = self._node.name
        blivet_node.address = self._node.address
        blivet_node.port = int(self._node.port)
        blivet_node.iface = self._node.iface

        # The node is iBFT node
        iscsi.ibft_nodes = [blivet_node]
        assert self.iscsi_interface.GetDracutArguments(Node.to_structure(self._node)) == \
            ["rd.iscsi.firmware"]

        # The node is not found
        iscsi.ibft_nodes = []
        iscsi.get_node.return_value = None
        assert self.iscsi_interface.GetDracutArguments(Node.to_structure(self._node)) == \
            []

        iscsi.ifaces = {
            "iface0": "ens3",
            "iface1": "ens7",
        }

        # The node is active
        iscsi.get_node.return_value = blivet_node
        blivet_node.username = ""
        blivet_node.r_username = ""
        blivet_node.password = ""
        blivet_node.r_password = ""
        iscsi.initiator = "iqn.1994-05.com.redhat:blablabla"
        assert self.iscsi_interface.GetDracutArguments(Node.to_structure(self._node)) == \
            ["netroot=iscsi:@10.43.136.67::3260:iface0:ens3::iqn.2014-08.com.example:t1",
             "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla"]

        # The node is active, with default interface
        iscsi.get_node.return_value = blivet_node
        blivet_node.iface = "default"
        iscsi.initiator = "iqn.1994-05.com.redhat:blablabla"
        assert self.iscsi_interface.GetDracutArguments(Node.to_structure(self._node)) == \
            ["netroot=iscsi:@10.43.136.67::3260::iqn.2014-08.com.example:t1",
             "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla"]

        # The node is active, with offload interface, and reverse chap
        iscsi.get_node.return_value = blivet_node
        blivet_node.username = "******"
        blivet_node.r_username = "******"
        blivet_node.password = "******"
        blivet_node.r_password = "******"
        blivet_node.iface = "qedi.a6:26:77:80:00:63"
        iscsi.initiator = "iqn.1994-05.com.redhat:blablabla"
        assert self.iscsi_interface.GetDracutArguments(Node.to_structure(self._node)) == \
            ["netroot=iscsi:uname:passwd:r_uname:[email protected]::3260:qedi.a6:26:77:80:00:63:qedi.a6:26:77:80:00:63::iqn.2014-08.com.example:t1",
             "rd.iscsi.initiator=iqn.1994-05.com.redhat:blablabla"]
Example #2
0
    def IsNodeFromIbft(self, node: Structure) -> Bool:
        """Is the node configured from iBFT table?.

        :param node: the node information
        """
        node = Node.from_structure(node)
        return self.implementation.is_node_from_ibft(node)
Example #3
0
    def test_is_node_from_ibft(self, iscsi):
        """Test IsNodeFromIbft method."""
        iscsi.ibft_nodes = []
        result = self.iscsi_interface.IsNodeFromIbft(
            Node.to_structure(self._node))
        assert not result

        blivet_node = Mock()
        blivet_node.name = self._node.name
        blivet_node.address = self._node.address
        blivet_node.port = int(self._node.port)
        blivet_node.iface = self._node.iface
        iscsi.ibft_nodes = [blivet_node]
        result = self.iscsi_interface.IsNodeFromIbft(
            Node.to_structure(self._node))
        assert result
Example #4
0
    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)
Example #5
0
    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()
Example #6
0
    def is_node_from_ibft_test(self, iscsi):
        """Test IsNodeFromIbft method."""
        iscsi.ibft_nodes = []
        result = self.iscsi_interface.IsNodeFromIbft(
            self._unpack_structure_content(Node.to_structure(self._node)))
        self.assertFalse(result)

        blivet_node = Mock()
        blivet_node.name = self._node.name
        blivet_node.address = self._node.address
        blivet_node.port = int(self._node.port)
        blivet_node.iface = self._node.iface
        iscsi.ibft_nodes = [blivet_node]
        result = self.iscsi_interface.IsNodeFromIbft(
            self._unpack_structure_content(Node.to_structure(self._node)))
        self.assertTrue(result)
Example #7
0
    def GetDracutArguments(self, node: Structure) -> List[Str]:
        """Get dracut arguments for iSCSI device backed by the node.

        :param node: the node information
        :return: a list of dracut arguments

        FIXME: This is just a temporary method.
        """
        node = Node.from_structure(node)
        return self.implementation.get_dracut_arguments(node)
Example #8
0
def _is_on_ibft(device):
    """Tells whether a given device is ibft disk or not."""
    iscsi_proxy = STORAGE.get_proxy(ISCSI)
    for disk in device.disks:
        if not isinstance(disk, blivet.devices.iScsiDiskDevice):
            return False
        node = _get_iscsi_node_from_device(disk)
        if not iscsi_proxy.IsNodeFromIbft(Node.to_structure(node)):
            return False
    return True
Example #9
0
 def _get_node_from_node_info(self, node_info):
     node = Node()
     node.name = node_info.name
     node.address = node_info.address
     node.port = str(node_info.port)
     node.iface = node_info.iface
     if self._interfaces_mode == IscsiInterfacesMode.IFACENAME:
         node.net_ifacename = iscsi.ifaces[node_info.iface]
     return node
Example #10
0
    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)
Example #11
0
def _get_iscsi_node_from_device(device):
    node = Node()
    node.name = device.target
    node.address = device.address
    node.port = device.port
    node.iface = device.iface
    return node
Example #12
0
    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
Example #13
0
    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)
Example #14
0
    def process_discovery_result(self, task_proxy):
        """Process the result of the task.

        :param task_proxy: a task
        """
        # Stop the spinner.
        self._discoverySpinner.stop()
        self._cancelButton.set_sensitive(True)

        try:
            # Finish the task
            task_proxy.Finish()
        except StorageDiscoveryError as e:
            # Discovery has failed, show the error.
            self._set_configure_sensitive(True)
            self._discoveryErrorLabel.set_text(str(e))
            self._conditionNotebook.set_current_page(2)
        else:
            nodes = unwrap_variant(task_proxy.GetResult())
            # Discovery succeeded.
            # Populate the node store.
            self._discovered_nodes = Node.from_structure_list(nodes)

            for node in self._discovered_nodes:
                portal = "%s:%s" % (node.address, node.port)
                self._store.append(
                    [False, True, node.name, node.net_ifacename, portal])

            # We should select the first node by default.
            self._store[0][0] = True

            # Kick the user on over to that subscreen.
            self._iscsiNotebook.set_current_page(1)

            # If some form of login credentials were used for discovery,
            # default to using the same for login.
            if self._authTypeCombo.get_active() != 0:
                self._loginAuthTypeCombo.set_active(3)
Example #15
0
 def convert_result(value):
     return get_variant(List[Structure], Node.to_structure_list(value))
Example #16
0
    def _set_storage_boot_args(self, storage):
        """Set the storage boot args."""
        fcoe_proxy = STORAGE.get_proxy(FCOE)
        iscsi_proxy = STORAGE.get_proxy(ISCSI)

        # FIPS
        boot_device = storage.mountpoints.get("/boot")
        if kernel_arguments.get("fips") == "1" and boot_device:
            self.boot_args.add("boot=%s" % self.stage2_device.fstab_spec)

        # Storage
        dracut_devices = [storage.root_device]
        if self.stage2_device != storage.root_device:
            dracut_devices.append(self.stage2_device)

        swap_devices = storage.fsset.swap_devices
        dracut_devices.extend(swap_devices)

        # Add resume= option to enable hibernation on x86.
        # Choose the largest swap device for that.
        if blivet.arch.is_x86() and swap_devices:
            resume_device = max(swap_devices, key=lambda x: x.size)
            self.boot_args.add("resume=%s" % resume_device.fstab_spec)

        # Does /usr have its own device? If so, we need to tell dracut
        usr_device = storage.mountpoints.get("/usr")
        if usr_device:
            dracut_devices.extend([usr_device])

        netdevs = [d for d in storage.devices \
                   if (getattr(d, "complete", True) and
                       isinstance(d, NetworkStorageDevice))]

        rootdev = storage.root_device
        if any(rootdev.depends_on(netdev) for netdev in netdevs):
            dracut_devices = set(dracut_devices)
            # By this time this thread should be the only one running, and also
            # mountpoints is a property function that returns a new dict every
            # time, so iterating over the values is safe.
            for dev in storage.mountpoints.values():
                if any(dev.depends_on(netdev) for netdev in netdevs):
                    dracut_devices.add(dev)

        done = []
        for device in dracut_devices:
            for dep in storage.devices:
                if dep in done:
                    continue

                if device != dep and not device.depends_on(dep):
                    continue

                if isinstance(dep, blivet.devices.FcoeDiskDevice):
                    setup_args = fcoe_proxy.GetDracutArguments(dep.nic)
                elif isinstance(dep, blivet.devices.iScsiDiskDevice):
                    # (partial) offload devices do not need setup in dracut
                    if not dep.offload:
                        node = _get_iscsi_node_from_device(dep)
                        setup_args = iscsi_proxy.GetDracutArguments(
                            Node.to_structure(node))
                else:
                    setup_args = dep.dracut_setup_args()

                if not setup_args:
                    continue

                self.boot_args.update(setup_args)
                self.dracut_args.update(setup_args)
                done.append(dep)

                # network configuration arguments
                if isinstance(dep, NetworkStorageDevice):
                    network_proxy = NETWORK.get_proxy()
                    network_args = []
                    ibft = False
                    nic = ""
                    if isinstance(dep, blivet.devices.iScsiDiskDevice):
                        if dep.iface == "default" or ":" in dep.iface:
                            node = _get_iscsi_node_from_device(dep)
                            if iscsi_proxy.IsNodeFromIbft(
                                    Node.to_structure(node)):
                                ibft = True
                            else:
                                nic = iface_for_host_ip(dep.host_address)
                        else:
                            nic = iscsi_proxy.GetInterface(dep.iface)
                    else:
                        nic = dep.nic
                    if nic or ibft:
                        network_args = network_proxy.GetDracutArguments(
                            nic, dep.host_address, "", ibft)

                    self.boot_args.update(network_args)
                    self.dracut_args.update(network_args)

        # This is needed for FCoE, bug #743784. The case:
        # We discover LUN on an iface which is part of multipath setup.
        # If the iface is disconnected after discovery anaconda doesn't
        # write dracut ifname argument for the disconnected iface path
        # (in NETWORK.GetDracutArguments).
        # Dracut needs the explicit ifname= because biosdevname
        # fails to rename the iface (because of BFS booting from it).
        for nic in fcoe_proxy.GetNics():
            hwaddr = get_interface_hw_address(nic)
            if hwaddr:
                self.boot_args.add("ifname=%s:%s" % (nic, hwaddr.lower()))

        # Add rd.iscsi.firmware to trigger dracut running iscsistart
        # See rhbz#1099603 and rhbz#1185792
        if len(glob("/sys/firmware/iscsi_boot*")) > 0:
            self.boot_args.add("rd.iscsi.firmware")