Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/charms/data_platform_libs/v0/database_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Relation provider side abstraction for database relation.
"""[DEPRECATED] Relation provider side abstraction for database relation.

This library is a uniform interface to a selection of common database
metadata, with added custom events that add convenience to database management,
Expand Down Expand Up @@ -80,7 +80,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 2
LIBPATCH = 3

logger = logging.getLogger(__name__)

Expand Down
44 changes: 28 additions & 16 deletions lib/charms/operator_libs_linux/v0/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 6
LIBPATCH = 9


VALID_SOURCE_TYPES = ("deb", "deb-src")
Expand Down Expand Up @@ -206,14 +206,10 @@ def __eq__(self, other) -> bool:
Returns:
A boolean reflecting equality
"""
return (
isinstance(other, self.__class__)
and (
self._name,
self._version.number,
)
== (other._name, other._version.number)
)
return isinstance(other, self.__class__) and (
self._name,
self._version.number,
) == (other._name, other._version.number)

def __hash__(self):
"""A basic hash so this class can be used in Mappings and dicts."""
Expand Down Expand Up @@ -254,7 +250,9 @@ def _apt(
package_names = [package_names]
_cmd = ["apt-get", "-y", *optargs, command, *package_names]
try:
check_call(_cmd, stderr=PIPE, stdout=PIPE)
env = os.environ.copy()
env["DEBIAN_FRONTEND"] = "noninteractive"
check_call(_cmd, env=env, stderr=PIPE, stdout=PIPE)
except CalledProcessError as e:
raise PackageError(
"Could not {} package(s) [{}]: {}".format(command, [*package_names], e.output)
Expand Down Expand Up @@ -359,7 +357,7 @@ def from_system(

Args:
package: a string representing the package
version: an optional string if a specific version isr equested
version: an optional string if a specific version is requested
arch: an optional architecture, defaulting to `dpkg --print-architecture`. If an
architecture is not specified, this will be used for selection.

Expand Down Expand Up @@ -392,7 +390,7 @@ def from_installed_package(

Args:
package: a string representing the package
version: an optional string if a specific version isr equested
version: an optional string if a specific version is requested
arch: an optional architecture, defaulting to `dpkg --print-architecture`.
If an architecture is not specified, this will be used for selection.
"""
Expand Down Expand Up @@ -426,6 +424,16 @@ def from_installed_package(
for line in lines:
try:
matches = dpkg_matcher.search(line).groupdict()
package_status = matches["package_status"]

if not package_status.endswith("i"):
logger.debug(
"package '%s' in dpkg output but not installed, status: '%s'",
package,
package_status,
)
break

epoch, split_version = DebianPackage._get_epoch_from_version(matches["version"])
pkg = DebianPackage(
matches["package_name"],
Expand All @@ -452,7 +460,7 @@ def from_apt_cache(

Args:
package: a string representing the package
version: an optional string if a specific version isr equested
version: an optional string if a specific version is requested
arch: an optional architecture, defaulting to `dpkg --print-architecture`.
If an architecture is not specified, this will be used for selection.
"""
Expand Down Expand Up @@ -508,7 +516,7 @@ class Version:
"""An abstraction around package versions.

This seems like it should be strictly unnecessary, except that `apt_pkg` is not usable inside a
venv, and wedging version comparisions into `DebianPackage` would overcomplicate it.
venv, and wedging version comparisons into `DebianPackage` would overcomplicate it.

This class implements the algorithm found here:
https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
Expand Down Expand Up @@ -730,7 +738,9 @@ def add_package(
update_cache: whether or not to run `apt-get update` prior to operating

Raises:
TypeError if no package name is given, or explicit version is set for multiple packages
PackageNotFoundError if the package is not in the cache.
PackageError if packages fail to install
"""
cache_refreshed = False
if update_cache:
Expand Down Expand Up @@ -821,7 +831,9 @@ def remove_package(
except PackageNotFoundError:
logger.info("package '%s' was requested for removal, but it was not installed.", p)

return packages if len(packages) > 1 else packages[0]
# the list of packages will be empty when no package is removed
logger.debug("packages: '%s'", packages)
return packages[0] if len(packages) == 1 else packages


def update() -> None:
Expand Down Expand Up @@ -995,7 +1007,7 @@ def import_key(self, key: str) -> None:
A Radix64 format keyid is also supported for backwards
compatibility. In this case Ubuntu keyserver will be
queried for a key via HTTPS by its keyid. This method
is less preferrable because https proxy servers may
is less preferable because https proxy servers may
require traffic decryption which is equivalent to a
man-in-the-middle attack (a proxy server impersonates
keyserver TLS certificates and has to be explicitly
Expand Down
2 changes: 1 addition & 1 deletion lib/charms/rolling_ops/v0/rollingops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _restart(self, event):

To kick off the rolling restart, emit this library's AcquireLock event. The simplest way
to do so would be with an action, though it might make sense to acquire the lock in
response to another event.
response to another event.

```python
def _on_trigger_restart(self, event):
Expand Down
Loading