From 181784775fdf2746ac725fde2d6d00c17b1cb35c Mon Sep 17 00:00:00 2001 From: Lucas Moura Date: Wed, 10 Jan 2024 17:08:23 -0300 Subject: [PATCH] tests: add test for transition package 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 --- features/environment.py | 15 ++++ features/install_uninstall.feature | 28 ++++++ features/steps/packages.py | 11 ++- features/steps/ubuntu_advantage_tools.py | 108 +++++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) diff --git a/features/environment.py b/features/environment.py index 1927551688..d89c848c67 100644 --- a/features/environment.py +++ b/features/environment.py @@ -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, diff --git a/features/install_uninstall.feature b/features/install_uninstall.feature index 40956ffdaf..274e83a410 100644 --- a/features/install_uninstall.feature +++ b/features/install_uninstall.feature @@ -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 `` `` 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 `` `` 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 | diff --git a/features/steps/packages.py b/features/steps/packages.py index d95dbf8882..ed8a5f70e7 100644 --- a/features/steps/packages.py +++ b/features/steps/packages.py @@ -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 @@ -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( diff --git a/features/steps/ubuntu_advantage_tools.py b/features/steps/ubuntu_advantage_tools.py index 521b0e3685..5ad5af7f91 100644 --- a/features/steps/ubuntu_advantage_tools.py +++ b/features/steps/ubuntu_advantage_tools.py @@ -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, + )