def produce_commands(self): collector = self._collector() if Facter.get( OperatingSystem) != OperatingSystem.Fedora and Facter.get( OperatingSystemRelease).major() == '5': collector.collect_from_file('wget downloader', 'wget.sh') self._collect_repo(collector) self._collect_agent(collector) if self._installer.mode() == Mode.Server: self._collect_server(collector) return collector.lines()
def _collect_repo(self, collector): major = Facter.get(OperatingSystemRelease).major() os = Facter.get(OperatingSystem) if os == OperatingSystem.Fedora: abbr = 'fedora' else: abbr = 'el' mapping = dict(major=major, abbr=abbr) if ('%s-%s' % (abbr, major)) == 'el-5': script = 'pc3x-el5-repo.sh' else: script = 'pc3x-repo.sh' title = 'Puppet Package Repository setup (Puppet OSS 3.x)' collector.collect_from_template(title, script, mapping)
def process_fully_qualified_domain_name(self, fqdn): # type: (FqdnConfiguration) -> Sequence[Configurer] if Facter.get(Docker) == Docker.YES: raise NotImplementedError( 'Can\'t set FQDN when running inside Docker!') osfamily = Facter.get(OsFamily) try: return { OsFamily.RedHat: [RedHatFQDNConfigurer(fqdn)], OsFamily.Debian: [DebianFQDNConfigurer(fqdn)] }[osfamily] except KeyError as ex: raise NotImplementedError( ex, 'Unsupported OS family %s for setting FQDN' % osfamily)
def _collect_repo(self, collector): major = Facter.get(OperatingSystemRelease).major() os = Facter.get(OperatingSystem) if os == OperatingSystem.Fedora: abbr = 'fedora' else: abbr = 'el' mapping = dict(major=major, abbr=abbr) if ('%s-%s' % (abbr, major)) == 'el-5': script = self._repo_script_path_el5() else: script = self._repo_script_path() collector.collect_from_template(self._repo_setup_title(), script, mapping)
def __produce_commands(self, install): # type: (After4xCollectionInstaller) -> Sequence[str] args = [] # type: MutableSequence[str] mem = install.puppetserver_jvm_memory() jvmargs = install.puppetserver_jvm_args() if mem.is_set(): if mem.heap_minimum() is not None: args.append('-Xms{xms}'.format(xms=mem.heap_minimum())) if mem.heap_maximum() is not None: args.append('-Xmx{xmx}'.format(xmx=mem.heap_maximum())) java_version = Facter.get(JavaVersion) metaspace_arg = self.__get_metaspace_arg(java_version) if java_version.has_permgen_space( ) and mem.metaspace_maximum() is None: args.append(metaspace_arg.format(mspace='256m')) elif mem.metaspace_maximum() is not None: args.append( metaspace_arg.format(mspace=mem.metaspace_maximum())) if jvmargs.are_set(): args.extend(jvmargs) args_as_str = ' '.join(args) collector = self._collector() mapping = dict(jvmargs=args_as_str) collector.collect_from_template('Configuring PuppetServer JVM Args', 'puppetserver-jvmargs.pp', mapping, format=ScriptFormat.PUPPET) return collector.lines()
def _collect_repo(self, collector): codename = Facter.get(OperatingSystemCodename) collector.collect_from_template( 'Puppet Package Repository setup (Puppet OSS 3.x)', 'pc3x-repo.sh', dict(codename=codename) )
def test_osrelrelease_minor(self): rel = Facter.get(OperatingSystemRelease) minor = rel.minor() assert minor is not None assert type(minor) is str assert re.compile('^\d+$').match(minor) is not None
def test_osrelease_major_oninvalid(self): MockFacter.set_fact(OperatingSystemRelease, OperatingSystemRelease('alpha')) rel = Facter.get(OperatingSystemRelease) major = rel.major() assert major is not None assert major is 'alpha'
def __perform_installation(answers): # type: (Answers) -> Sequence[Configurer] configurers = [] if answers.installer() is not None: osfamily = Facter.get(osfacts.OsFamily) gateway = container.get_named(InstallerGateway, osfamily.name.lower()) configurers.extend( gateway.configurers(answers.installer()) ) return configurers
def calculate_osfamily(): return { OperatingSystem.CentOS: OsFamily.RedHat, OperatingSystem.OracleLinux: OsFamily.RedHat, OperatingSystem.RedHat: OsFamily.RedHat, OperatingSystem.Scientific: OsFamily.RedHat, OperatingSystem.Debian: OsFamily.Debian, OperatingSystem.Ubuntu: OsFamily.Debian, OperatingSystem.OpenSuse: OsFamily.Suse, OperatingSystem.SLES: OsFamily.Suse, OperatingSystem.ArchLinux: OsFamily.Arch }.get(Facter.get(OperatingSystem), OsFamily.Unknown)
def test_invalid_resolver(): # noinspection PyUnresolvedReferences,PyProtectedMember resolvers = Facter._Facter__resolvers before_count = len(resolvers) try: Facter.set(TEST_KEY, lambda: None) value = Facter.get(TEST_KEY) assert value is None assert len(resolvers) == before_count + 1 finally: resolvers.pop(TEST_KEY) assert len(resolvers) == before_count
def calculate_java_version(): # type: () -> JavaVersion osfamily = Facter.get(OsFamily) java_prog_name = 'java.exe' if osfamily is OsFamily.Windows else 'java' search_paths = environ['PATH'].split(path.pathsep) java_prog = None for search_path in search_paths: java_prog_candidate = path.join(search_path, java_prog_name) if __is_executable(java_prog_candidate): java_prog = java_prog_candidate break if java_prog is None: return JavaVersion.NOT_INSTALLED return __get_java_version(java_prog)
def produce_commands(self): if self.__installer.mode() == Mode.Agent: return [] if self.__installer.is_after_4x(): servicename = 'puppetserver' else: servicename = 'puppetmaster' enable = 'true' if Facter.get(Docker) is not Docker.YES else 'false' collector = self._collector() desc = 'Starting Puppet server service ({servicename})'.format( servicename=servicename) mapping = dict(servicename=servicename, enable=enable) collector.collect_from_template(desc, 'puppetserver.sh', mapping) return collector.lines()
def test_docker(self, tmpdir): old_chroot = puppeter.settings.chroot try: new_root = tmpdir.mkdir("docker-utest") puppeter.settings.chroot = str(new_root) + '/' p = new_root.mkdir('proc').mkdir('1').join('cgroup') p.write('11:blkio:/docker/885762619\n' '10:pids:/docker/885762619' '9:freezer:/docker/885762619\n' '8:cpuset:/docker/885762619\n' '7:perf_event:/docker/885762619\n' '6:devices:/docker/885762619\n' '5:hugetlb:/docker/885762619\n') docker = Facter.get(Docker) assert type(docker) is Docker assert docker is Docker.YES assert bool(docker) is True finally: puppeter.settings.chroot = old_chroot
def test_oscodename(self): codename = Facter.get(OperatingSystemCodename) assert codename == 'trusty' assert type(codename) is OperatingSystemCodename
def test_facter_get_unknown(): value = Facter.get(TEST_KEY) assert value is None
def test_oscodename(self): codename = Facter.get(OperatingSystemCodename) assert codename is not None
def test_operatingsystem(self): os = Facter.get(OperatingSystem) assert os is not None
def test_osfamily(self): osfamily = Facter.get(OsFamily) assert osfamily is not None
def _collect_repo(self, collector): codename = Facter.get(OperatingSystemCodename) collector.collect_from_template( 'Puppet Labs Collection Repository (PC1) setup (Puppet OSS 4.x)', 'pc4x-repo.sh', dict(codename=codename))
def test_osrelease(self): rel = Facter.get(OperatingSystemRelease) assert rel is not None
def test_osrelease(self): regex = OperatingSystemRelease.VERSION_RE rel = Facter.get(OperatingSystemRelease) assert rel is not None assert regex.match(rel) is not None
def _collect_repo(self, collector): rel = Facter.get(OperatingSystemRelease) collector.collect_from_file( 'Ensure EPEL is active', 'ensure-epel-{rel}.sh'.format(rel=rel.major()))