def install_packages(self, java_version='openjdk-11-headless', packages=[]): """Installs openjdk and extra packages requested.""" apt_update() apt_install(self.PACKAGE_LIST[java_version] + self.EXTRA_PACKAGES + packages)
def test_apt_update_nonfatal(self, call): fetch.apt_update() call.assert_called_with(['apt-get', 'update'], env={})
def test_apt_update_fatal(self, check_call): fetch.apt_update(fatal=True) check_call.assert_called_with(['apt-get', 'update'], env={})
def test_apt_update_nonfatal(self, call): fetch.apt_update() call.assert_called_with(['apt-get', 'update'], env=getenv( {'DEBIAN_FRONTEND': 'noninteractive'}))
def install_packages(self, java_version, packages, snap_connect=None): """Install the packages/snaps related to the chosen distro. Args: java_version: install the openjdk corresponding to that version packages: package list to be installed snap_connect: interfaces that need to be explicitly connected if snap option is chosen instead. """ MaintenanceStatus("Installing packages") version = self.config.get("version", self.LATEST_VERSION_CONFLUENT) if self.distro == "confluent": url_key = 'https://packages.confluent.io/deb/{}/archive.key' key = subprocess.check_output( ['wget', '-qO', '-', url_key.format(version)]).decode("ascii") url_apt = \ 'deb [arch=amd64] https://packages.confluent.io/deb/{}' + \ ' stable main' add_source(url_apt.format(version), key=key) apt_update() elif self.distro == "apache": raise Exception("Not Implemented Yet") elif self.distro == "apache_snap": # First, try to fetch the snap resource: resource = None try: # Fetch a resource with the same name as the snap. # Fetch raises a ModelError if not found resource = self.model.resources.fetch(self.snap) subprocess.check_output( ["snap", "install", "--dangerous", str(resource)]) except subprocess.CalledProcessError as e: raise KafkaCharmBaseFailedInstallation(error=str(e)) except Exception: # Failed to find a resource, next step is to try install # from snapstore resource = None if not resource: # Resource was not found, try install from upstream try: subprocess.check_output([ "snap", "install", self.snap, "--channel={}".format(version) ]) except subprocess.CalledProcessError as e: raise KafkaCharmBaseFailedInstallation(error=str(e)) try: if snap_connect: for conn in snap_connect: subprocess.check_output([ "snap", "connect", "{}:{}".format(self.snap, conn) ]) except subprocess.CalledProcessError as e: raise KafkaCharmBaseFailedInstallation(error=str(e)) # Install openjdk for keytool super().install_packages(java_version, packages=[]) # Packages will be already in place for snap # no need to run the logic below and setup folders return # Now, only package type distros are available # Setup folders, permissions, etc super().install_packages(java_version, packages) folders = [ "/etc/kafka", "/var/log/kafka", "/var/lib/kafka", self.JMX_EXPORTER_JAR_FOLDER ] self.set_folders_and_permissions(folders) # Now, setup jmx exporter logic self.jmx_version = self.config.get("jmx_exporter_version", "0.12.0") jar_url = self.config.get( "jmx_exporter_url", "https://repo1.maven.org/maven2/io/prometheus/jmx/" "jmx_prometheus_javaagent/{}/" "jmx_prometheus_javaagent-{}.jar") self.jmx_jar_url = jar_url.format(self.jmx_version, self.jmx_version) if len(self.jmx_version) == 0 or len(self.jmx_jar_url) == 0: # Not enabled, finish the method return subprocess.check_output([ 'wget', '-qO', self.JMX_EXPORTER_JAR_FOLDER + self.JMX_EXPORTER_JAR_NAME, self.jmx_jar_url ]) setFilePermissions( self.JMX_EXPORTER_JAR_FOLDER + self.JMX_EXPORTER_JAR_NAME, self.config.get("user", "kafka"), self.config.get("group", "kafka"), 0o640)