def update(package_name): """ Update the package on the local node """ SDMUpdateController._logger.debug('Installing package {0}'.format(package_name)) PackageManager.install(package_name=package_name, client=SDMUpdateController._local_client) SDMUpdateController._logger.debug('Installed package {0}'.format(package_name))
def update_package_cache(): counter = 0 max_counter = 3 while True and counter < max_counter: counter += 1 try: PackageManager.update(UpdateController._local_client) break except CalledProcessError as cpe: time.sleep(3) if counter == max_counter: raise cpe
def get_package_information(package_name): installed, candidate = PackageManager.get_installed_candidate_version(package_name, UpdateController._local_client) UpdateController._log('Installed version for package {0}: {1}'.format(package_name, installed)) UpdateController._log('Candidate version for package {0}: {1}'.format(package_name, candidate)) return installed, candidate
def get_package_information(): """ Retrieve information about the currently installed versions of the core packages Retrieve information about the versions to which each package can potentially be updated If installed version is different from candidate version --> store this information in model Additionally if installed version is identical to candidate version, check the services with a 'run' file Verify whether the running version is identical to the candidate version If different --> store this information in the model Result: Every package with updates or which requires services to be restarted is stored in the model :return: Package information :rtype: dict """ binaries = PackageManager.get_binary_versions(client=SDMUpdateController._local_client, package_names=['alba']) installed = PackageManager.get_installed_versions(client=SDMUpdateController._local_client, package_names=PackageManager.SDM_PACKAGE_NAMES) candidate = PackageManager.get_candidate_versions(client=SDMUpdateController._local_client, package_names=PackageManager.SDM_PACKAGE_NAMES) if set(installed.keys()) != set(PackageManager.SDM_PACKAGE_NAMES) or set(candidate.keys()) != set(PackageManager.SDM_PACKAGE_NAMES): raise RuntimeError('Failed to retrieve the installed and candidate versions for packages: {0}'.format(', '.join(PackageManager.SDM_PACKAGE_NAMES))) package_info = {} default_entry = {'candidate': None, 'installed': None, 'services_to_restart': []} # component: package_name: services_with_run_file for component, info in {'alba': {'alba': list(ASDController.list_asd_services()) + list(MaintenanceController.get_services()), 'openvstorage-sdm': []}}.iteritems(): component_info = {} for package, services in info.iteritems(): for service in services: version_file = '/opt/asd-manager/run/{0}.version'.format(service) if not SDMUpdateController._local_client.file_exists(version_file): SDMUpdateController._logger.warning('Failed to find a version file in /opt/asd-manager/run for service {0}'.format(service)) continue package_name = package running_versions = SDMUpdateController._local_client.file_read(version_file).strip() for version in running_versions.split(';'): if '=' in version: package_name = version.split('=')[0] running_version = version.split('=')[1] else: running_version = version if package_name not in PackageManager.SDM_PACKAGE_NAMES: raise ValueError('Unknown package dependency found in {0}'.format(version_file)) if package_name not in binaries: raise RuntimeError('Binary version for package {0} was not retrieved'.format(package_name)) if running_version != binaries[package_name]: if package_name not in component_info: component_info[package_name] = copy.deepcopy(default_entry) component_info[package_name]['installed'] = running_version component_info[package_name]['candidate'] = binaries[package_name] component_info[package_name]['services_to_restart'].append(service) if installed[package] != candidate[package] and package not in component_info: component_info[package] = copy.deepcopy(default_entry) component_info[package]['installed'] = installed[package] component_info[package]['candidate'] = candidate[package] if component_info: package_info[component] = component_info return package_info