def determine_packages(): release = os_release('nova-common') cmp_release = CompareOpenStackReleases(release) packages = [] + BASE_PACKAGES net_manager = network_manager() if (net_manager in ['flatmanager', 'flatdhcpmanager'] and config('multi-host').lower() == 'yes' and CompareOpenStackReleases(os_release('nova-common')) < 'ocata'): packages.extend(['nova-api', 'nova-network']) if relation_ids('ceph'): packages.append('ceph-common') virt_type = config('virt-type') if virt_type == 'ironic' and release < 'victoria': # ironic compute driver is part of nova and # gets installed along with python3-nova # The nova-compute-ironic metapackage that satisfies # nova-compute-hypervisor does not exist for versions of # OpenStack prior to Victoria. Use nova-compute-vmware, # as that package has the least amount of dependencies. # We also add python3-ironicclient here. This is a dependency # which gets installed by nova-compute-ironic in Victoria and later. VIRT_TYPES[virt_type] = ['nova-compute-vmware', 'python3-ironicclient'] try: packages.extend(VIRT_TYPES[virt_type]) except KeyError: log('Unsupported virt-type configured: %s' % virt_type) raise enable_nova_metadata, _ = nova_metadata_requirement() if enable_nova_metadata: packages.append('nova-api-metadata') packages.extend(determine_packages_arch()) # LP#1806830 - ensure that multipath packages are installed when # use-multipath option is enabled. if config('use-multipath'): packages.extend(MULTIPATH_PACKAGES) if cmp_release >= 'rocky': packages = [p for p in packages if not p.startswith('python-')] packages.extend(PY3_PACKAGES) if filter_missing_packages(['python-ceilometer']): packages.append('python3-ceilometer') if filter_missing_packages(['python-neutron']): packages.append('python3-neutron') if filter_missing_packages(['python-neutron-fwaas']): packages.append('python3-neutron-fwaas') if virt_type == 'lxd': packages.append('python3-nova-lxd') packages = sorted( set(packages).union(get_subordinate_release_packages(release).install)) return packages
def remove_old_packages(): '''Purge any packages that need ot be removed. :returns: bool Whether packages were removed. ''' installed_packages = filter_missing_packages(determine_purge_packages()) if installed_packages: apt_mark(filter_missing_packages(determine_held_packages()), 'auto') apt_purge(installed_packages, fatal=True) apt_autoremove(purge=True, fatal=True) return bool(installed_packages)
def remove_old_packages(): '''Purge any packages that need ot be removed. :returns: bool Whether packages were removed. ''' installed_packages = filter_missing_packages(determine_purge_packages()) if installed_packages: apt_mark(filter_missing_packages(determine_held_packages()), 'auto') apt_purge(installed_packages, fatal=True) apt_autoremove(purge=True, fatal=True) return bool(installed_packages)
def validate_nfs(): """ Validate the nfs mount device """ usr = config('tvault-datamover-ext-usr') grp = config('tvault-datamover-ext-group') data_dir = config('tv-data-dir') device = config('nfs-shares') nfs_options = config('nfs-options') # install nfs-common package if not filter_missing_packages(['nfs-common']): log("'nfs-common' package not found, installing the package...") apt_install(['nfs-common'], fatal=True) if not device: log("NFS mount device can not be empty." "Check 'nfs-shares' value in config") return False # Ensure mount directory exists mkdir(data_dir, owner=usr, group=grp, perms=501, force=True) # check for mountable device if not mount(device, data_dir, options=nfs_options, filesystem='nfs'): log("Unable to mount, please enter valid mount device") return False log("Device mounted successfully") umount(data_dir) log("Device unmounted successfully") return True
def remove_plugin_config(): """Called when a dashboard plugin is leaving. This is necessary so that the packages that the plugin asked to install are removed and any conflicting packages are restored and the config updated. This ensures that when changing plugins the system isn't left in a broken state. """ resolve_CONFIGS() rid = juju_relation_id() runit = juju_remote_unit() pkg_data = get_plugin_packages_from_kv(rid, runit) changed = False if pkg_data['install_packages']: remove_packages = filter_missing_packages(pkg_data['install_packages']) if remove_packages: status_set('maintenance', 'Removing packages') apt_purge(remove_packages, fatal=True) apt_autoremove(purge=True, fatal=True) changed = True if pkg_data['conflicting_packages']: install_packages = filter_installed_packages( pkg_data['conflicting_packages']) if install_packages: status_set('maintenance', 'Installing packages') apt_install(install_packages, fatal=True) changed = True if changed: log("Package installation/purge detected, restarting services", "INFO") for s in services(): service_restart(s) CONFIGS.write(LOCAL_SETTINGS)
def install_packages(): c = config() if c.changed('source') or c.changed('key'): add_source(c.get('source'), c.get('key')) apt_update(fatal=True) if is_container(): PACKAGES.remove('ntp') # NOTE: just use full package list if we're in an upgrade # config-changed execution pkgs = (PACKAGES if upgrade_available() else filter_installed_packages(PACKAGES)) if pkgs: status_set('maintenance', 'Installing radosgw packages') if ('apache2' in pkgs): # NOTE(lourot): Apache's default config makes it listen on port 80, # which will prevent HAProxy from listening on that same port. We # use Apache in this setup however for SSL (different port). We # need to let Apache free port 80 before we can install HAProxy # otherwise HAProxy will crash. See lp:1904411 log('Installing Apache') apt_install(['apache2'], fatal=True) disable_unused_apache_sites() apt_install(pkgs, fatal=True) pkgs = filter_missing_packages(APACHE_PACKAGES) if pkgs: apt_purge(pkgs)
def determine_packages(): release = os_release('nova-common') cmp_release = CompareOpenStackReleases(release) packages = [] + BASE_PACKAGES net_manager = network_manager() if (net_manager in ['flatmanager', 'flatdhcpmanager'] and config('multi-host').lower() == 'yes' and CompareOpenStackReleases(os_release('nova-common')) < 'ocata'): packages.extend(['nova-api', 'nova-network']) if relation_ids('ceph'): packages.append('ceph-common') virt_type = config('virt-type') try: packages.extend(VIRT_TYPES[virt_type]) except KeyError: log('Unsupported virt-type configured: %s' % virt_type) raise enable_nova_metadata, _ = nova_metadata_requirement() if enable_nova_metadata: packages.append('nova-api-metadata') packages.extend(determine_packages_arch()) # LP#1806830 - ensure that multipath packages are installed when # use-multipath option is enabled. if config('use-multipath'): packages.extend(MULTIPATH_PACKAGES) if cmp_release >= 'rocky': packages = [p for p in packages if not p.startswith('python-')] packages.extend(PY3_PACKAGES) if filter_missing_packages(['python-ceilometer']): packages.append('python3-ceilometer') if filter_missing_packages(['python-neutron']): packages.append('python3-neutron') if filter_missing_packages(['python-neutron-fwaas']): packages.append('python3-neutron-fwaas') if virt_type == 'lxd': packages.append('python3-nova-lxd') return packages
def purge_packages(pkg_list): purge_pkgs = [] required_packages = determine_packages() for pkg in pkg_list: if pkg not in required_packages: purge_pkgs.append(pkg) purge_pkgs = filter_missing_packages(purge_pkgs) if purge_pkgs: status_set('maintenance', 'Purging unused packages') apt_purge(purge_pkgs, fatal=True) apt_autoremove(purge=True, fatal=True)
def purge_packages(pkg_list): purge_pkgs = [] required_packages = determine_packages() for pkg in pkg_list: if pkg not in required_packages: purge_pkgs.append(pkg) purge_pkgs = filter_missing_packages(purge_pkgs) if purge_pkgs: status_set('maintenance', 'Purging unused packages') apt_purge(purge_pkgs, fatal=True) apt_autoremove(purge=True, fatal=True)
def remove_old_packages(): '''Purge any packages that need to be removed. :returns: bool Whether packages were removed. ''' installed_packages = filter_missing_packages(determine_purge_packages()) if installed_packages: log('Removing apt packages') status_set('maintenance', 'Removing apt packages') apt_purge(installed_packages, fatal=True) apt_autoremove(purge=True, fatal=True) return bool(installed_packages)
def remove_old_packages(): '''Purge any packages that need ot be removed. :returns: bool Whether packages were removed. ''' installed_packages = filter_missing_packages(get_purge_packages()) if installed_packages: if 'neutron-lbaasv2-agent' in installed_packages: # Remove policyrd entry that would stop dpkg from stopping # service when package is removed. Bug #1931655 policy_rcd.remove_policy_block('neutron-lbaasv2-agent', ['restart', 'stop', 'try-restart']) deferred_events.clear_deferred_restarts('neutron-lbaasv2-agent') apt_purge(installed_packages, fatal=True) apt_autoremove(purge=True, fatal=True) return bool(installed_packages)
def install_packages(): c = config() if c.changed('source') or c.changed('key'): add_source(c.get('source'), c.get('key')) apt_update(fatal=True) if is_container(): PACKAGES.remove('ntp') # NOTE: just use full package list if we're in an upgrade # config-changed execution pkgs = (PACKAGES if upgrade_available() else filter_installed_packages(PACKAGES)) if pkgs: status_set('maintenance', 'Installing radosgw packages') apt_install(pkgs, fatal=True) pkgs = filter_missing_packages(APACHE_PACKAGES) if pkgs: apt_purge(pkgs) disable_unused_apache_sites()
def update_plugin_config(): resolve_CONFIGS() # NOTE(ajkavanagh) - plugins can indicate that they have packages to # install and purge. Grab them from the relation and install/update as # needed. rid = juju_relation_id() runit = juju_remote_unit() (add_packages, remove_packages) = update_plugin_packages_in_kv(rid, runit) remove_packages = filter_missing_packages(remove_packages) if remove_packages: status_set('maintenance', 'Removing packages') apt_purge(remove_packages, fatal=True) apt_autoremove(purge=True, fatal=True) add_packages = filter_installed_packages(add_packages) if add_packages: status_set('maintenance', 'Installing packages') apt_install(add_packages, fatal=True) if remove_packages or add_packages: log("Package installation/purge detected, restarting services", "INFO") for s in services(): service_restart(s) CONFIGS.write(LOCAL_SETTINGS)
def validate_nfs(): """ Validate the nfs mount device """ usr = DM_EXT_USR grp = DM_EXT_GRP data_dir = TV_DATA_DIR device = config('nfs-shares') # install nfs-common package if not filter_missing_packages(['nfs-common']): log("'nfs-common' package not found, installing the package...") apt_install(['nfs-common'], fatal=True) if not device: log("NFS shares can not be empty." "Check 'nfs-shares' value in config") status_set( 'blocked', 'No valid nfs-shares configuration found, please recheck') return False # Ensure mount directory exists mkdir(data_dir, owner=usr, group=grp, perms=501, force=True) # check for mountable device if not mount(device, data_dir, filesystem='nfs'): log("Unable to mount, please enter valid mount device") status_set( 'blocked', 'Failed while validating NFS mount, please recheck configuration') return False log("Device mounted successfully") umount(data_dir) log("Device unmounted successfully") return True
def install_packages(): c = config() if c.changed('source') or c.changed('key'): add_source(c.get('source'), c.get('key')) apt_update(fatal=True) if is_container(): PACKAGES.remove('ntp') # NOTE: just use full package list if we're in an upgrade # config-changed execution pkgs = ( PACKAGES if upgrade_available() else filter_installed_packages(PACKAGES) ) if pkgs: status_set('maintenance', 'Installing radosgw packages') apt_install(pkgs, fatal=True) pkgs = filter_missing_packages(APACHE_PACKAGES) if pkgs: apt_purge(pkgs) disable_unused_apache_sites()