Exemple #1
0
def _nvdimm_create_ksdata(action=None, namespace=None, mode=None, sectorsize=None):
    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    # pylint: disable=E1101
    nvdimm_data = handler.NvdimmData()
    if action is not None:
        nvdimm_data.action = action
    if namespace is not None:
        nvdimm_data.namespace = namespace
    if mode is not None:
        nvdimm_data.mode = mode
    if sectorsize is not None:
        nvdimm_data.sectorsize = sectorsize
    return nvdimm_data
Exemple #2
0
    def _create_iscsi_data(self, device):
        from pyanaconda.kickstart import AnacondaKSHandler
        handler = AnacondaKSHandler()
        # pylint: disable=E1101
        iscsi_data = handler.IscsiData()
        dev_node = device.node
        iscsi_data.ipaddr = dev_node.address
        iscsi_data.target = dev_node.name
        iscsi_data.port = dev_node.port
        # Bind interface to target
        if self.storage.iscsi.ifaces:
            iscsi_data.iface = self.storage.iscsi.ifaces[device.iface]

        auth = dev_node.getAuth()
        if auth:
            if auth.username and auth.password:
                iscsi_data.user = auth.username
                iscsi_data.password = auth.password
            if auth.reverse_username and auth.reverse_password:
                iscsi_data.user_in = auth.reverse_username
                iscsi_data.password_in = auth.reverse_password
        return iscsi_data
Exemple #3
0
    def update_hostname_data_test(self):
        from pyanaconda.kickstart import AnacondaKSHandler
        handler = AnacondaKSHandler()
        ksdata = self.ksdata_mock

        # network --hostname oldhostname
        # pylint: disable=no-member
        nd = handler.NetworkData(hostname="oldhostname", bootProto="")
        ksdata.network.network = [nd]
        network.update_hostname_data(ksdata, "newhostname")
        # network --hostname newhostname
        self.assertEqual(ksdata.network.network[0].hostname, "newhostname")

        # no network in ks
        ksdata.network.network = []
        network.update_hostname_data(ksdata, "newhostname")
        # network --hostname newhostname
        self.assertEqual(ksdata.network.network[0].hostname, "newhostname")

        # network --bootproto dhcp --onboot no --device em1 --hostname oldhostname
        # pylint: disable=no-member
        nd = handler.NetworkData(bootProto="dhcp",
                                 onboot="no",
                                 device="em1",
                                 hostname="oldhostname")
        ksdata.network.network = [nd]
        network.update_hostname_data(ksdata, "newhostname")
        # network --bootproto dhcp --onboot no --device em1 --hostname newhostname
        self.assertEqual(ksdata.network.network[0].hostname, "newhostname")
        self.assertEqual(len(ksdata.network.network), 1)

        # network --bootproto dhcp --onboot no --device em1
        # pylint: disable=no-member
        nd = handler.NetworkData(bootProto="dhcp", onboot="no", device="em1")
        ksdata.network.network = [nd]
        network.update_hostname_data(ksdata, "newhostname")
        # network --bootproto dhcp --onboot no --device em1
        # network --hostname newhostname
        self.assertEqual(ksdata.network.network[0].hostname, "")
        self.assertEqual(ksdata.network.network[1].hostname, "newhostname")

        # network --bootproto dhcp --onboot no --device em1
        # network --hostname oldhostname
        # pylint: disable=no-member
        nd1 = handler.NetworkData(bootProto="dhcp", onboot="no", device="em1")
        # pylint: disable=no-member
        nd2 = handler.NetworkData(hostname="oldhostname", bootProto="")
        ksdata.network.network = [nd1, nd2]
        network.update_hostname_data(ksdata, "newhostname")
        # network --bootproto dhcp --onboot no --device em1
        # network --hostname newhostname
        self.assertEquals(ksdata.network.network[0].hostname, "")
        self.assertEquals(ksdata.network.network[1].hostname, "newhostname")
Exemple #4
0
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    Returns list of devices for which ifcfg file was dumped.
    """
    rv = []

    for devname in nm.nm_devices():
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        try:
            con_uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
        except nm.SettingsNotFoundError:
            if find_ifcfg_file_of_device(devname):
                continue
            from pyanaconda.kickstart import AnacondaKSHandler
            handler = AnacondaKSHandler()
            network_data = handler.NetworkData(onboot=False, ipv6="auto")
            add_connection_for_ksdata(network_data, devname)
            rv.append(devname)

    return rv
Exemple #5
0
    def _run(self):
        from blivet.errors import StorageError

        # Set up disks/blivet.
        try:
            self.setupDisks()

            # Parse the kickstart using anaconda's parser, since it has more
            # advanced error detection.  This also requires having storage set
            # up first.
            parser = AnacondaKSParser(AnacondaKSHandler())
            parser.readKickstartFromString(self.ks)

            instClass = DefaultInstall()

            doKickstartStorage(self._blivet, parser.handler, instClass)
            self._blivet.updateKSData()
            self._blivet.doIt()
        except (KickstartError, StorageError) as e:
            # anaconda handles expected kickstart errors (like parsing busted
            # input files) by printing the error and quitting.  For testing, an
            # error might be expected so we should compare the result here with
            # what is expected.
            if self.expectedExceptionType and isinstance(
                    e, self.expectedExceptionType):
                # We expected an exception, and we got one of the correct type.
                # If it also contains the string we were expecting, then the
                # test case passes.  Otherwise, it's a failure.
                if self.expectedExceptionText and self._text_matches(str(e)):
                    return
                else:
                    raise FailedTest(str(e), self.expectedExceptionText)
            else:
                # We either got an exception when we were not expecting one,
                # or we got one of a type other than what we were expecting.
                # Either of these cases indicates a failure of the test case.
                raise FailedTest(e, self.expectedExceptionType)
        finally:
            self.tearDownDisks()

        if self.expectedExceptionType:
            raise FailedTest(None, self.expectedExceptionType)

        return
def hostname_ksdata(hostname):
    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    # pylint: disable-msg=E1101
    return handler.NetworkData(hostname=hostname, bootProto="")
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        return None
    # no network command for team slaves
    if ifcfg.get("TEAM_MASTER"):
        return None

    # ipv4 and ipv6
    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no":
        kwargs["onboot"] = False
    if ifcfg.get('MTU') and ifcfg.get('MTU') != "0":
        kwargs["mtu"] = ifcfg.get('MTU')
    # ipv4
    if not ifcfg.get('BOOTPROTO'):
        kwargs["noipv4"] = True
    else:
        if iutil.lowerASCII(ifcfg.get('BOOTPROTO')) == 'dhcp':
            kwargs["bootProto"] = "dhcp"
            if ifcfg.get('DHCPCLASS'):
                kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS')
        elif ifcfg.get('IPADDR'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR')
            netmask = ifcfg.get('NETMASK')
            prefix = ifcfg.get('PREFIX')
            if not netmask and prefix:
                netmask = prefix2netmask(int(prefix))
            if netmask:
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY'):
                kwargs["gateway"] = ifcfg.get('GATEWAY')
        elif ifcfg.get('IPADDR0'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR0')
            prefix = ifcfg.get('PREFIX0')
            if prefix:
                netmask = prefix2netmask(int(prefix))
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY0'):
                kwargs["gateway"] = ifcfg.get('GATEWAY0')

    # ipv6
    if (not ifcfg.get('IPV6INIT') or ifcfg.get('IPV6INIT') == "no"):
        kwargs["noipv6"] = True
    else:
        if ifcfg.get('IPV6_AUTOCONF') in ("yes", ""):
            kwargs["ipv6"] = "auto"
        else:
            if ifcfg.get('IPV6ADDR'):
                kwargs["ipv6"] = ifcfg.get('IPV6ADDR')
                if ifcfg.get('IPV6_DEFAULTGW') \
                   and ifcfg.get('IPV6_DEFAULTGW') != "::":
                    kwargs["ipv6gateway"] = ifcfg.get('IPV6_DEFAULTGW')
            if ifcfg.get('DHCPV6C') == "yes":
                kwargs["ipv6"] = "dhcp"

    # ipv4 and ipv6
    dnsline = ''
    for key in ifcfg.info.keys():
        if iutil.upperASCII(key).startswith('DNS'):
            if dnsline == '':
                dnsline = ifcfg.get(key)
            else:
                dnsline += "," + ifcfg.get(key)
    if dnsline:
        kwargs["nameserver"] = dnsline

    if ifcfg.get("ETHTOOL_OPTS"):
        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")

    if ifcfg.get("ESSID"):
        kwargs["essid"] = ifcfg.get("ESSID")

    # hostname
    if ifcfg.get("DHCP_HOSTNAME"):
        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(slaves)
        bondopts = ifcfg.get("BONDING_OPTS")
        if bondopts:
            sep = ","
            if sep in bondopts:
                sep = ";"
            kwargs["bondopts"] = sep.join(bondopts.split())

    # vlan
    if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    nd = handler.NetworkData(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = get_team_slaves([devname, ifcfg.get("UUID")])
        for dev, cfg in slaves:
            nd.teamslaves.append((dev, cfg))

        teamconfig = nm.nm_device_setting_value(devname, "team", "config")
        if teamconfig:
            nd.teamconfig = teamconfig

    return nd
Exemple #8
0
def hostname_ksdata(hostname):
    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    kwargs = {}
    return handler.NetworkData(hostname=hostname, bootProto="")