コード例 #1
0
ファイル: initialization.py プロジェクト: shatil/anaconda
    def run(self):
        """Run the ONBOOT values updating.

        :return: names of devices for which ONBOOT was updated
        :rtype: list(str)
        """
        updated_devices = []

        if not self._nm_client:
            log.debug("%s: No NetworkManager available.", self.name)
            return updated_devices

        if not self._network_data:
            log.debug("%s: No kickstart data.", self.name)
            return updated_devices

        for network_data in self._network_data:
            device_name = get_device_name_from_network_data(
                self._nm_client, network_data, self._supported_devices,
                self._bootif)
            if not device_name:
                log.warning("%s: --device %s does not exist.", self.name,
                            network_data.device)

            devices_to_update = [device_name]
            master = device_name
            # When defining both bond/team and vlan in one command we need more care
            # network --onboot yes --device bond0 --bootproto static --bondslaves ens9,ens10
            # --bondopts mode=active-backup,miimon=100,primary=ens9,fail_over_mac=2
            # --ip 192.168.111.1 --netmask 255.255.255.0 --gateway 192.168.111.222 --noipv6
            # --vlanid 222 --no-activate
            if network_data.vlanid and (network_data.bondslaves
                                        or network_data.teamslaves):
                master = network_data.device
                devices_to_update.append(master)

            cons_to_update = []
            for devname in devices_to_update:
                cons = get_connections_available_for_iface(
                    self._nm_client, devname)
                n_cons = len(cons)
                con = None
                if n_cons == 1:
                    cons_to_update.append((devname, cons[0]))
                else:
                    log.debug("%s: %d connections found for %s", self.name,
                              n_cons, devname)
                    if n_cons > 1:
                        config_uuid = get_config_file_connection_of_device(
                            self._nm_client, devname)
                        con = self._nm_client.get_connection_by_uuid(
                            config_uuid)
                        if con:
                            cons_to_update.append((devname, con))

            # Handle slaves if there are any
            if network_data.bondslaves or network_data.teamslaves or network_data.bridgeslaves:
                # Master can be identified by devname or uuid, try to find master uuid
                master_uuid = None
                device = self._nm_client.get_device_by_iface(master)
                if device:
                    cons = device.get_available_connections()
                    n_cons = len(cons)
                    if n_cons == 1:
                        master_uuid = cons[0].get_uuid()
                    else:
                        log.debug("%s: %d connections found for %s", self.name,
                                  n_cons, master)
                if not master_uuid:
                    master_uuid = get_config_file_connection_of_device(
                        self._nm_client, master)
                master_specs = [master, master_uuid
                                ] if master_uuid else [master]

                for name, _iface, uuid in get_slaves_from_connections(
                        self._nm_client, ["bond", "bridge", "team"],
                        master_specs):
                    con = self._nm_client.get_connection_by_uuid(uuid)
                    cons_to_update.append((name, con))

            for con_name, con in cons_to_update:
                log.debug(
                    "updating ONBOOT values of connection %s for device %s",
                    con.get_uuid(), con_name)
                update_connection_values(
                    con, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT,
                           network_data.onboot)])
                commit_changes_with_autoconnection_blocked(con)
                updated_devices.append(con_name)

        return updated_devices
コード例 #2
0
    def get_slaves_from_connections_test(self, get_iface_from_connection):
        nm_client = Mock()

        ENS3_UUID = "50f1ddc3-cfa5-441d-8afe-729213f5ca92"
        ENS7_UUID = "d9e90dce-93bb-4c30-be16-8f4e77744742"
        ENS8_UUID = "12740d58-c17f-4e8a-a449-2affc6298853"
        ENS11_UUID = "1ea657e7-98a5-4b1a-bb1e-e1763f0140a9"
        TEAM1_UUID = "39ba5d2f-90d1-4bc0-b212-57f643aa7ec1"

        cons_specs = [
            {
                "get_setting_connection.return_value.get_slave_type.return_value":
                "",
                "get_setting_connection.return_value.get_master.return_value":
                "",
                "get_uuid.return_value": ENS3_UUID,
            },
            {
                "get_setting_connection.return_value.get_slave_type.return_value":
                "team",
                "get_setting_connection.return_value.get_master.return_value":
                "team0",
                "get_uuid.return_value": ENS7_UUID,
            },
            {
                "get_setting_connection.return_value.get_slave_type.return_value":
                "team",
                "get_setting_connection.return_value.get_master.return_value":
                "team0",
                "get_uuid.return_value": ENS8_UUID,
            },
            {
                "get_setting_connection.return_value.get_slave_type.return_value":
                "team",
                "get_setting_connection.return_value.get_master.return_value":
                TEAM1_UUID,
                "get_uuid.return_value": ENS11_UUID,
            },
        ]
        cons = self._get_mock_objects_from_attrs(cons_specs)
        nm_client.get_connections.return_value = cons

        uuid_to_iface = {
            ENS3_UUID: "ens3",
            ENS7_UUID: "ens7",
            ENS8_UUID: "ens8",
            ENS11_UUID: "ens11",
        }
        get_iface_from_connection.side_effect = lambda nm_client, uuid: uuid_to_iface[
            uuid]

        self.assertSetEqual(get_slaves_from_connections(nm_client, "team", []),
                            set())
        self.assertSetEqual(
            get_slaves_from_connections(nm_client, "bridge", ["bridge0"]),
            set())
        self.assertSetEqual(
            get_slaves_from_connections(nm_client, "team", ["team2"]), set())
        # Matching of any specification is enough
        self.assertSetEqual(
            get_slaves_from_connections(nm_client, "team",
                                        ["team_nonexisting", TEAM1_UUID]),
            set([("ens11", ENS11_UUID)]))
        self.assertSetEqual(
            get_slaves_from_connections(nm_client, "team", ["team0"]),
            set([("ens7", ENS7_UUID), ("ens8", ENS8_UUID)]))
        self.assertSetEqual(
            get_slaves_from_connections(nm_client, "team", [TEAM1_UUID]),
            set([("ens11", ENS11_UUID)]))