Skip to content

Commit

Permalink
tests: add test for transition package
Browse files Browse the repository at this point in the history
Add integration test that install the ubuntu-advantage-tools
transition package and checks that it also install the
new ubuntu-pro-client package.

We are also performing the same check for the ubuntu-advantage-pro
package
  • Loading branch information
lucasmoura committed Jan 10, 2024
1 parent 23e58f7 commit 1817847
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
15 changes: 15 additions & 0 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,21 @@ def before_scenario(context: Context, scenario: Scenario):
)
return

install_from = context.pro_config.install_from
if install_from == InstallationSource.LOCAL:
if "skip_local_environment" in scenario.effective_tags:
scenario.skip(
reason="Scenario does not support install_from local"
)
return

if install_from == InstallationSource.PREBUILT:
if "skip_prebuilt_environment" in scenario.effective_tags:
scenario.skip(
reason="Scenario does not support install_from prebuilt"
)
return

# before_step doesn't execute early enough to modify the step
# so we perform step text surgery here
# Also, logging capture is not set up when before_scenario is called,
Expand Down
28 changes: 28 additions & 0 deletions features/install_uninstall.feature
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,31 @@ Feature: Pro Install and Uninstall related tests
| bionic | lxd-container |
| focal | lxd-container |
| jammy | lxd-container |

@skip_local_environment
@skip_prebuilt_environment
Scenario Outline: Package ubuntu-advantage-tools now install
Given a `<release>` `<machine_type>` machine
When I install transition package ubuntu-advantage-tools
Then I verify that `ubuntu-pro-client` is installed

Examples: ubuntu release
| release | machine_type |
| xenial | lxd-container |
| bionic | lxd-container |
| focal | lxd-container |

@skip_local_environment
@skip_prebuilt_environment
Scenario Outline: Package ubuntu-advantage-tools now install
Given a `<release>` `<machine_type>` machine
When I install transition package ubuntu-advantage-tools
Then I verify that `ubuntu-pro-image-auto-attach` is installed

Examples: ubuntu release
| release | machine_type |
| xenial | aws.pro |
| bionic | aws.pro |
| focal | aws.pro |
| jammy | aws.pro |
| jammy | aws.pro |
11 changes: 10 additions & 1 deletion features/steps/packages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from behave import then, when
from hamcrest import assert_that, contains_string, matches_regexp
from hamcrest import assert_that, contains_string, matches_regexp, not_

from features.steps.shell import when_i_retry_run_command, when_i_run_command
from features.util import SUT
Expand Down Expand Up @@ -161,6 +161,15 @@ def verify_package_not_installed(context, package):
# then the package is neither installed nor known


@then("I verify that `{package}` is installed")
def verify_package_installed(context, package):
when_i_run_command(context, "dpkg -l {}".format(package), "as non-root")
assert_that(
context.process.stdout.strip(),
not_(contains_string("no packages found matching {}".format(package))),
)


@then("I verify that `{package}` is installed from apt source `{apt_source}`")
def verify_package_is_installed_from_apt_source(context, package, apt_source):
when_i_run_command(
Expand Down
108 changes: 108 additions & 0 deletions features/steps/ubuntu_advantage_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,111 @@ def when_i_check_apt_cache_policy(context):
for step in context.scenario.steps:
if step.name == APT_POLICY_IS:
step.text = context.process.stdout


@when("I install transition package ubuntu-advantage-tools")
def when_i_install_transition_uat(context, machine_name=SUT):
instance = context.machines[machine_name].instance
series = context.machines[machine_name].series
is_pro = "pro" in context.machines[machine_name].machine_type
if context.pro_config.install_from is InstallationSource.ARCHIVE:
instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro",
machine_name=machine_name,
)
elif context.pro_config.install_from is InstallationSource.DAILY:
instance.execute("sudo add-apt-repository ppa:ua-client/daily")
instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro=31",
machine_name=machine_name,
)
elif context.pro_config.install_from is InstallationSource.STAGING:
instance.execute("sudo add-apt-repository ppa:ua-client/staging")
instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro=31",
machine_name=machine_name,
)
elif context.pro_config.install_from is InstallationSource.STABLE:
instance.execute("sudo add-apt-repository ppa:ua-client/stable")
instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro",
machine_name=machine_name,
)
elif context.pro_config.install_from is InstallationSource.PROPOSED:
context.text = "deb http://archive.ubuntu.com/ubuntu/ {series}-proposed main\n".format( # noqa: E501
series=series
)
when_i_create_file_with_content(
context,
"/etc/apt/sources.list.d/uaclient-proposed.list",
machine_name=machine_name,
)

context.text = "Package: *\nPin: release a={series}-proposed\nPin-Priority: 400\n".format( # noqa: E501
series=series
)
when_i_create_file_with_content(
context,
"/etc/apt/preferences.d/lower-proposed",
machine_name=machine_name,
)

for package in ALL_BINARY_PACKAGE_NAMES:
context.text = "Package: {package}\nPin: release a={series}-proposed\nPin-Priority: 1001\n".format( # noqa: E501
package=package,
series=series,
)
when_i_create_file_with_content(
context,
"/etc/apt/preferences.d/{}-proposed".format(package),
machine_name=machine_name,
)

instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro",
machine_name=machine_name,
)
elif context.pro_config.install_from is InstallationSource.CUSTOM:
instance.execute(
"sudo add-apt-repository {}".format(context.pro_config.custom_ppa)
)
instance.execute("sudo apt update")
when_i_apt_install(
context, "ubuntu-advantage-tools", machine_name=machine_name
)
if is_pro:
when_i_apt_install(
context,
"ubuntu-advantage-pro",
machine_name=machine_name,
)

0 comments on commit 1817847

Please sign in to comment.