Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: u.pro.services.enable.v1 (SC-1619) #2904

Closed
wants to merge 4 commits into from
Closed
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
353 changes: 186 additions & 167 deletions debian/po/pt_BR.po

Large diffs are not rendered by default.

353 changes: 186 additions & 167 deletions debian/po/ubuntu-pro.pot

Large diffs are not rendered by default.

209 changes: 209 additions & 0 deletions features/api_enable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
Feature: u.pro.services.enable

Scenario Outline: u.pro.services.enable.v1 container services
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed
When I apt update
And I apt install `jq`

# Requires attach
When I verify that running `pro api u.pro.services.enable.v1 --args service=esm-infra` `with sudo` exits `1`
When I run shell command `pro api u.pro.services.enable.v1 --args service=esm-infra | jq .errors[0]` with sudo
Then I will see the following on stdout:
"""
{
"code": "unattached",
"meta": {},
"title": "This machine is not attached to an Ubuntu Pro subscription.\nSee https://ubuntu.com/pro"
}
"""

When I attach `contract_token` with sudo and options `--no-auto-enable`

# Requires root
When I verify that running `pro api u.pro.services.enable.v1 --args service=esm-infra` `as non-root` exits `1`
When I run shell command `pro api u.pro.services.enable.v1 --args service=esm-infra | jq .errors[0]` as non-root
Then I will see the following on stdout:
"""
{
"code": "nonroot-user",
"meta": {},
"title": "This command must be run as root (try using sudo)."
}
"""

# Basic enable
When I run shell command `pro api u.pro.services.enable.v1 --args service=esm-infra | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [],
"enabled": [
"esm-infra"
],
"messages": [],
"reboot_required": false
}
"""
Then I verify that `esm-infra` is enabled
# Enable already enabled service succeeds
When I run shell command `pro api u.pro.services.enable.v1 --args service=esm-infra | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [],
"enabled": [],
"messages": [],
"reboot_required": false
}
"""
# Disallowing required services when required causes error
When I verify that running `pro api u.pro.services.enable.v1 --data '{"service": "ros", "enable_required_services": false}'` `with sudo` exits `1`
When I run shell command `pro api u.pro.services.enable.v1 --data \"{\\\"service\\\": \\\"ros\\\", \\\"enable_required_services\\\": false}\" | jq .errors[0]` with sudo
Then I will see the following on stdout:
"""
{
"code": "enable-blocked-required-service",
"meta": {
"required": "esm-apps",
"target": "ros"
},
"title": "Could not enable ros because esm-apps is not enabled"
}
"""
# Default allows enabling required services
When I run shell command `pro api u.pro.services.enable.v1 --args service=ros | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [],
"enabled": [
"esm-apps",
"ros"
],
"messages": [],
"reboot_required": false
}
"""
# Access only works and post enable messages work
When I run shell command `pro api u.pro.services.enable.v1 --data \"{\\\"service\\\": \\\"cis\\\", \\\"access_only\\\": true}\" | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [],
"enabled": [
"cis"
],
"messages": [
"Visit https://ubuntu.com/security/cis to learn how to use CIS"
],
"reboot_required": false
}
"""
When I run `apt-cache policy usg-common` as non-root
Then stdout contains substring:
"""
Installed: (none)
"""
# Access only on service that doesn't support it fails
When I verify that running `pro api u.pro.services.enable.v1 --data '{"service": "ros-updates", "access_only": true}'` `with sudo` exits `1`
When I run shell command `pro api u.pro.services.enable.v1 --data \"{\\\"service\\\": \\\"ros-updates\\\", \\\"access_only\\\": true}\" | jq .errors[0]` with sudo
Then I will see the following on stdout:
"""
{
"code": "entitlement-not-enabled",
"meta": {
"reason": {
"code": "enable-access-only-not-supported",
"title": "ROS ESM All Updates does not support being enabled with --access-only"
}
},
"title": "failed to enable ros-updates"
}
"""
orndorffgrant marked this conversation as resolved.
Show resolved Hide resolved
Examples:
| release | machine_type |
| xenial | lxd-container |
| bionic | lxd-container |

Scenario Outline: u.pro.services.enable.v1 landscape
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed
When I apt update
And I apt install `jq`
And I attach `contract_token` with sudo and options `--no-auto-enable`

When I verify that running `pro api u.pro.services.enable.v1 --args service=landscape` `with sudo` exits `1`
And I run shell command `pro api u.pro.services.enable.v1 --args service=landscape | jq .errors[0]` with sudo
Then I will see the following on stdout:
"""
{
"code": "not-supported",
"meta": {},
"title": "The operation is not supported"
}
"""
Examples:
| release | machine_type |
| mantic | lxd-container |

Scenario Outline: u.pro.services.enable.v1 vm services
Given a `<release>` `<machine_type>` machine with ubuntu-advantage-tools installed
When I apt update
And I apt install `jq`
And I attach `contract_token` with sudo and options `--no-auto-enable`

# Basic enable
And I run shell command `pro api u.pro.services.enable.v1 --args service=livepatch | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [],
"enabled": [
"livepatch"
],
"messages": [],
"reboot_required": false
}
"""
# Enable without disable_incompatible fails
When I verify that running `pro api u.pro.services.enable.v1 --data '{"service": "realtime-kernel", "disable_incompatible_services": false}'` `with sudo` exits `1`
When I run shell command `pro api u.pro.services.enable.v1 --data \"{\\\"service\\\": \\\"realtime-kernel\\\", \\\"disable_incompatible_services\\\": false}\" | jq .errors[0]` with sudo
Then I will see the following on stdout:
"""
{
"code": "enable-blocked-incompatible-service",
"meta": {
"incompatible": "livepatch",
"target": "realtime-kernel"
},
"title": "Could not enable realtime-kernel because livepatch is enabled"
}
"""
# Enable with disable_incompatible works and variant works
When I run shell command `pro api u.pro.services.enable.v1 --data \"{\\\"service\\\": \\\"realtime-kernel\\\", \\\"variant\\\": \\\"intel-iotg\\\"}\" | jq .data.attributes` with sudo
Then I will see the following on stdout:
"""
{
"disabled": [
"livepatch"
],
"enabled": [
"realtime-kernel"
],
"messages": [],
"reboot_required": true
}
"""
When I run shell command `pro api u.pro.status.enabled_services.v1 | jq ".data.attributes.enabled_services | select(.name==\"realtime-kernel\")" ` with sudo
Then I will see the following on stdout:
"""
[
{
"name": "realtime-kernel",
"variant_enabled": true,
"variant_name": "intel-iotg"
}
]
"""
Examples:
| release | machine_type |
| jammy | lxd-vm |
4 changes: 1 addition & 3 deletions uaclient/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"u.pro.security.fix.usn.plan.v1",
"u.pro.security.status.livepatch_cves.v1",
"u.pro.security.status.reboot_required.v1",
"u.pro.services.enable.v1",
"u.pro.status.enabled_services.v1",
"u.pro.status.is_attached.v1",
"u.pro.version.v1",
Expand Down Expand Up @@ -74,9 +75,6 @@ def _process_data(
raise errors.APIJSONDataFormatError(data=data)

for k, v in json_data.items():
if not k or not v:
raise errors.APIBadArgsFormat(arg="{}:{}".format(k, v))

if k not in fields:
warnings.append(
ErrorWarningObject(
Expand Down
14 changes: 14 additions & 0 deletions uaclient/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
AlreadyAttachedError,
ConnectivityError,
ContractAPIError,
EnableBlockedByIncompatibleService,
EnableBlockedByRequiredService,
EntitlementNotEnabledError,
EntitlementNotFoundError,
EntitlementsNotEnabledError,
InvalidProImage,
LockHeldError,
NonAutoAttachImageError,
NonRootUserError,
UbuntuProError,
UnattachedError,
UrlError,
UserFacingError,
)
Expand All @@ -22,10 +27,15 @@
"InvalidProImage",
"LockHeldError",
"NonAutoAttachImageError",
"NonRootUserError",
"UbuntuProError",
"UnattachedError",
"UrlError",
"UserFacingError",
"EntitlementsNotEnabledError",
"EntitlementNotEnabledError",
"EnableBlockedByIncompatibleService",
"EnableBlockedByRequiredService",
]


Expand All @@ -35,3 +45,7 @@ class AutoAttachDisabledError(UbuntuProError):

class UnattendedUpgradesError(APIError):
_formatted_msg = messages.E_UNATTENDED_UPGRADES_ERROR


class NotSupported(UbuntuProError):
_msg = messages.E_NOT_SUPPORTED
Loading
Loading