def get_protected_devices(opts): specs = [] if os.path.exists("/run/initramfs/livedev") and \ stat.S_ISBLK(os.stat("/run/initramfs/livedev")[stat.ST_MODE]): specs.append(os.readlink("/run/initramfs/livedev")) # methodstr and stage2 become strings in ways that pylint can't figure out # pylint: disable=unsubscriptable-object if opts.method and SourceFactory.is_harddrive(opts.method): specs.append(opts.method[3:].split(":", 3)[0]) if opts.stage2 and SourceFactory.is_harddrive(opts.stage2): specs.append(opts.stage2[3:].split(":", 3)[0]) for additional_repo in opts.addRepo: _name, repo_url = Anaconda._get_additional_repo_name( additional_repo) if SourceFactory.is_harddrive(repo_url): specs.append(repo_url[3:].split(":", 3)[0]) # zRAM swap devices need to be protected for zram_dev in glob("/dev/zram*"): specs.append(zram_dev) return specs
def test_parse_repo_cmdline(self): for val in TestValues: klass = val.source if klass is None: with pytest.raises(PayloadSourceTypeUnrecognized): SourceFactory.parse_repo_cmdline_string(val.value) continue source = SourceFactory.parse_repo_cmdline_string(val.value) assert isinstance(source, klass), \ "Instance of source {} expected - get {}".format(klass, source)
def parse_repo_cmdline_test(self): for val in TestValues: klass = val.map_to_classes() if klass is None: with self.assertRaises(PayloadSourceTypeUnrecognized): SourceFactory.parse_repo_cmdline_string(val.value) continue source = SourceFactory.parse_repo_cmdline_string(val.value) self.assertIsInstance(source, klass, "Instance of source {} expected - get {}".format(klass, source))
def parse_repo_cmdline_test(self): for val in TestValues: klass = val.map_to_classes() if klass is None: with self.assertRaises(PayloadSourceTypeUnrecognized): SourceFactory.parse_repo_cmdline_string(val.value) continue source = SourceFactory.parse_repo_cmdline_string(val.value) self.assertIsInstance( source, klass, "Instance of source {} expected - get {}".format( klass, source))
def add_additional_repositories_to_ksdata(self): from pyanaconda.kickstart import RepoData for add_repo in self.additional_repos: name, repo_url = self._get_additional_repo_name(add_repo) try: source = SourceFactory.parse_repo_cmdline_string(repo_url) except PayloadSourceTypeUnrecognized: log.error("Type for additional repository %s is not recognized!", add_repo) return repo = RepoData(name=name, baseurl=repo_url, install=False) if source.is_nfs or source.is_http or source.is_https or source.is_ftp \ or source.is_file: repo.enabled = True elif source.is_harddrive: repo.enabled = True repo.partition = source.partition repo.iso_path = source.path repo.baseurl = "file://" else: log.error("Source type %s for additional repository %s is not supported!", source.source_type.value, add_repo) continue self._check_repo_name_uniqueness(repo) self.ksdata.repo.dataList().append(repo)
def add_additional_repositories_to_ksdata(self): from pyanaconda.kickstart import RepoData for add_repo in self.additional_repos: name, repo_url = self._get_additional_repo_name(add_repo) try: source = SourceFactory.parse_repo_cmdline_string(repo_url) except PayloadSourceTypeUnrecognized: log.error( "Type for additional repository %s is not recognized!", add_repo) return repo = RepoData(name=name, baseurl=repo_url, install=False) if source.is_nfs or source.is_http or source.is_https or source.is_ftp \ or source.is_file: repo.enabled = True elif source.is_harddrive: repo.enabled = True repo.partition = source.partition repo.iso_path = source.path repo.baseurl = "file://" else: log.error( "Source type %s for additional repository %s is not supported!", source.source_type.value, add_repo) continue self._check_repo_name_uniqueness(repo) self.ksdata.repo.dataList().append(repo)
def set_installation_method_from_anaconda_options(anaconda, ksdata): """Set the installation method from Anaconda options. This basically means to set the installation method from options provided to Anaconda via command line/boot options. :param anaconda: instance of the Anaconda class :param ksdata: data model corresponding to the installation kickstart """ try: source = SourceFactory.parse_repo_cmdline_string(anaconda.methodstr) except PayloadSourceTypeUnrecognized: log.error("Unknown method: %s", anaconda.methodstr) return ksdata.method.method = source.method_type if source.is_nfs: ksdata.method.server = source.server ksdata.method.dir = source.path ksdata.method.opts = source.options elif source.is_harddrive: ksdata.method.partition = source.partition ksdata.method.dir = source.path elif source.is_http or source.is_https or source.is_ftp: ksdata.method.url = source.url ksdata.method.mirrorlist = None ksdata.method.metalink = None # file is not url based but it is stored same way elif source.is_file: ksdata.method.url = source.path ksdata.method.mirrorlist = None ksdata.method.metalink = None elif source.is_livecd: ksdata.method.partition = source.partition
def get_protected_devices(opts): specs = [] # methodstr and stage2 become strings in ways that pylint can't figure out # pylint: disable=unsubscriptable-object if opts.method and SourceFactory.is_harddrive(opts.method): specs.append(opts.method[3:].split(":", 3)[0]) if opts.stage2 and SourceFactory.is_harddrive(opts.stage2): specs.append(opts.stage2[3:].split(":", 3)[0]) for _repo_name, repo_url in opts.addRepo: if SourceFactory.is_harddrive(repo_url): specs.append(repo_url[3:].split(":", 3)[0]) # zRAM swap devices need to be protected for zram_dev in glob("/dev/zram*"): specs.append(zram_dev) return specs
def _check_create_proxy(self, source_type, test_value): payloads_proxy = PAYLOADS.get_proxy() payloads_proxy.CreateSource.return_value = "my/source/1" source = SourceFactory.parse_repo_cmdline_string(test_value) source_proxy = source.create_proxy() payloads_proxy.CreateSource.assert_called_once_with(source_type) self.assertEqual(source_proxy, PAYLOADS.get_proxy("my/source/1")) return source_proxy
def get_protected_devices(opts): specs = [] # methodstr and stage2 become strings in ways that pylint can't figure out # pylint: disable=unsubscriptable-object if opts.method and SourceFactory.is_harddrive(opts.method): specs.append(opts.method[3:].split(":", 3)[0]) if opts.stage2 and SourceFactory.is_harddrive(opts.stage2): specs.append(opts.stage2[3:].split(":", 3)[0]) for additional_repo in opts.addRepo: _name, repo_url = Anaconda._get_additional_repo_name(additional_repo) if SourceFactory.is_harddrive(repo_url): specs.append(repo_url[3:].split(":", 3)[0]) # zRAM swap devices need to be protected for zram_dev in glob("/dev/zram*"): specs.append(zram_dev) return specs
def _set_source_from_opts(self, opts): """Change the source based on the Anaconda options. Set the source based on opts.method if it isn't already set - opts.method is currently set by command line/boot options. """ if opts.method and (not self.proxy.Sources or self._is_source_default()): try: source = SourceFactory.parse_repo_cmdline_string(opts.method) except PayloadSourceTypeUnrecognized: log.error("Unknown method: %s", opts.method) else: source_proxy = source.create_proxy() set_source(self.proxy, source_proxy)
def protected(self): specs = [] if os.path.exists("/run/initramfs/livedev") and \ stat.S_ISBLK(os.stat("/run/initramfs/livedev")[stat.ST_MODE]): specs.append(os.readlink("/run/initramfs/livedev")) # methodstr and stage2 become strings in ways that pylint can't figure out # pylint: disable=unsubscriptable-object if self.methodstr and SourceFactory.is_harddrive(self.methodstr): specs.append(self.methodstr[3:].split(":", 3)[0]) if self.stage2 and SourceFactory.is_harddrive(self.stage2): specs.append(self.stage2[3:].split(":", 3)[0]) for additional_repo in self.additional_repos: _name, repo_url = self._get_additional_repo_name(additional_repo) if SourceFactory.is_harddrive(repo_url): specs.append(repo_url[3:].split(":", 3)[0]) # zRAM swap devices need to be protected for zram_dev in glob("/dev/zram*"): specs.append(zram_dev) return specs
def set_from_opts(self, opts): """Set the payload from the Anaconda cmdline options. :param opts: a namespace of options """ # Set the source based on opts.method if it isn't already set # - opts.method is currently set by command line/boot options if opts.method and (not self.proxy.Sources or self._is_source_default()): try: source = SourceFactory.parse_repo_cmdline_string(opts.method) except PayloadSourceTypeUnrecognized: log.error("Unknown method: %s", opts.method) else: source_proxy = source.create_proxy() set_source(self.proxy, source_proxy) # Set up the current source. source_proxy = self.get_source_proxy() if source_proxy.Type == SOURCE_TYPE_URL: # Get the repo configuration. repo_configuration = RepoConfigurationData.from_structure( source_proxy.RepoConfiguration ) if opts.proxy: repo_configuration.proxy = opts.proxy if not conf.payload.verify_ssl: repo_configuration.ssl_verification_enabled = conf.payload.verify_ssl # Update the repo configuration. source_proxy.SetRepoConfiguration( RepoConfigurationData.to_structure(repo_configuration) ) # Set up packages. if opts.multiLib: configuration = self.get_packages_configuration() configuration.multilib_policy = MULTILIB_POLICY_ALL self.set_packages_configuration(configuration) # Reset all the other things now that we have new configuration. self._configure()
def _set_additional_repos_from_opts(self, opts): """Set additional repositories based on the Anaconda options.""" for repo_name, repo_url in opts.addRepo: try: source = SourceFactory.parse_repo_cmdline_string(repo_url) except PayloadSourceTypeUnrecognized: log.error( "Type for additional repository %s is not recognized!", repo_url) return if self.get_addon_repo(repo_name): log.warning( "Repository name %s is not unique. Only the first " "repo will be used!", repo_name) is_supported = source.is_nfs \ or source.is_http \ or source.is_https \ or source.is_ftp \ or source.is_file \ or source.is_harddrive if not is_supported: log.error( "Source type %s for additional repository %s is not supported!", source.source_type.value, repo_url) continue repo = RepoConfigurationData() repo.name = repo_name repo.enabled = True repo.type = URL_TYPE_BASEURL repo.url = repo_url repo.installation_enabled = False ks_repo = convert_repo_data_to_ks_repo(repo) self.data.repo.dataList().append(ks_repo)