diff --git a/features/environment.py b/features/environment.py index 1927551688..480a1913d4 100644 --- a/features/environment.py +++ b/features/environment.py @@ -365,6 +365,21 @@ def before_scenario(context: Context, scenario: Scenario): ) return + # skip scenario based on install_from value + for tag in scenario.effective_tags: + parts = tag.split(".") + if all( + [len(parts) == 3, parts[0] == "skip", parts[1] == "install_from"] + ): + to_skip = InstallationSource(parts[2]) + if context.pro_config.install_from == to_skip: + scenario.skip( + reason="Scenario does not support install_from={}".format( + to_skip.value + ) + ) + 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..af7b4bb28f 100644 --- a/features/install_uninstall.feature +++ b/features/install_uninstall.feature @@ -82,3 +82,33 @@ Feature: Pro Install and Uninstall related tests | bionic | lxd-container | | focal | lxd-container | | jammy | lxd-container | + + @skip.install_from.local + @skip.install_from.prebuilt + Scenario Outline: ubuntu-pro-client brings up-to-date ubuntu-advantage-tools + Given a `` `` machine + When I set up the apt source for ubuntu-advantage-tools + When I apt install `ubuntu-pro-client` + Then I verify that the version of `ubuntu-pro-client` equals the version of `ubuntu-advantage-tools` + Examples: ubuntu release + | release | machine_type | + | xenial | lxd-container | + | bionic | lxd-container | + | focal | lxd-container | + | jammy | lxd-container | + | mantic | lxd-container | + + @skip.install_from.local + @skip.install_from.prebuilt + Scenario Outline: ubuntu-pro-image-auto-attach brings up-to-date ubuntu-advantage-pro + Given a `` `` machine + When I set up the apt source for ubuntu-advantage-tools + When I apt install `ubuntu-pro-image-auto-attach` + Then I verify that the version of `ubuntu-pro-image-auto-attach` equals the version of `ubuntu-advantage-pro` + Examples: ubuntu release + | release | machine_type | + | xenial | aws.pro | + | bionic | aws.pro | + | focal | aws.pro | + | jammy | aws.pro | + | mantic | aws.pro | diff --git a/features/steps/machines.py b/features/steps/machines.py index 3690afd23c..df516ae633 100644 --- a/features/steps/machines.py +++ b/features/steps/machines.py @@ -7,7 +7,10 @@ from pycloudlib.instance import BaseInstance # type: ignore from features.steps.shell import when_i_run_command -from features.steps.ubuntu_advantage_tools import when_i_install_uat +from features.steps.ubuntu_advantage_tools import ( + when_i_install_uat, + when_i_setup_uat_source, +) from features.util import ( BUILDER_NAME_PREFIX, SUT, @@ -190,6 +193,7 @@ def given_a_sut_machine(context, series, machine_type): machine_name=builder_name, cleanup=False, ) + when_i_setup_uat_source(context, machine_name=builder_name) when_i_install_uat(context, machine_name=builder_name) when_i_take_a_snapshot( context, @@ -205,6 +209,7 @@ def given_a_sut_machine(context, series, machine_type): ) else: given_a_machine(context, series, machine_type=machine_type) + when_i_setup_uat_source(context) when_i_install_uat(context) logging.info( @@ -219,6 +224,7 @@ def given_a_sut_machine_with_user_data(context, series, machine_type): # doesn't support snapshot strategy because the test depends on # custom user data given_a_machine(context, series, machine_type, user_data=context.text) + when_i_setup_uat_source(context) when_i_install_uat(context) diff --git a/features/steps/packages.py b/features/steps/packages.py index d95dbf8882..e460da3031 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, equal_to, matches_regexp from features.steps.shell import when_i_retry_run_command, when_i_run_command from features.util import SUT @@ -254,3 +254,23 @@ def store_candidate_version(context, package): context.stored_vars["candidate"] = candidate_version_match.group( 1 ).strip() + + +@then( + "I verify that the version of `{package1}` equals the version of `{package2}`" # noqa: E501 +) +def verify_package_version_equality(context, package1, package2): + when_i_run_command( + context, + "dpkg-query --showformat='${{Version}}' --show {}".format(package1), + "as non-root", + ) + package1_version_str = context.process.stdout.strip() + when_i_run_command( + context, + "dpkg-query --showformat='${{Version}}' --show {}".format(package2), + "as non-root", + ) + package2_version_str = context.process.stdout.strip() + + assert_that(package1_version_str, equal_to(package2_version_str)) diff --git a/features/steps/ubuntu_advantage_tools.py b/features/steps/ubuntu_advantage_tools.py index 5312dd12c9..cfd091a949 100644 --- a/features/steps/ubuntu_advantage_tools.py +++ b/features/steps/ubuntu_advantage_tools.py @@ -14,83 +14,21 @@ ) -@when("I install ubuntu-advantage-tools") -def when_i_install_uat(context, machine_name=SUT): +@when("I set up the apt source for ubuntu-advantage-tools") +def when_i_setup_uat_source(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.PREBUILT: - deb_paths = sorted( - get_debs_for_series(context.pro_config.debs_path, series) - ) - logging.info("using debs: {}".format(deb_paths)) - for deb_path in deb_paths: - if "advantage-pro" not in deb_path or is_pro: - instance.push_file(deb_path, "/tmp/behave_ua.deb") - when_i_apt_install( - context, "/tmp/behave_ua.deb", machine_name=machine_name - ) - instance.execute("sudo rm /tmp/behave_ua.deb") - elif context.pro_config.install_from is InstallationSource.LOCAL: - ua_deb_path, pro_deb_path, l10n_deb_path = build_debs( - series, - sbuild_output_to_terminal=context.pro_config.sbuild_output_to_terminal, # noqa: E501 - ) - instance.push_file(ua_deb_path, "/tmp/behave_ua.deb") - when_i_apt_install( - context, "/tmp/behave_ua.deb", machine_name=machine_name - ) - instance.execute("sudo rm /tmp/behave_ua.deb") - instance.push_file(l10n_deb_path, "/tmp/behave_ua.deb") - when_i_apt_install( - context, "/tmp/behave_ua.deb", machine_name=machine_name - ) - instance.execute("sudo rm /tmp/behave_ua.deb") - if is_pro: - instance.push_file(pro_deb_path, "/tmp/behave_ua.deb") - when_i_apt_install( - context, "/tmp/behave_ua.deb", machine_name=machine_name - ) - instance.execute("sudo rm /tmp/behave_ua.deb") 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", 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", 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 @@ -129,6 +67,26 @@ def when_i_install_uat(context, machine_name=SUT): ) instance.execute("sudo apt update") + 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 install ubuntu-advantage-tools") +def when_i_install_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 in [ + InstallationSource.ARCHIVE, + InstallationSource.DAILY, + InstallationSource.STAGING, + InstallationSource.STABLE, + InstallationSource.PROPOSED, + InstallationSource.CUSTOM, + ]: when_i_apt_install( context, "ubuntu-advantage-tools", machine_name=machine_name ) @@ -136,18 +94,39 @@ def when_i_install_uat(context, machine_name=SUT): 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) + elif context.pro_config.install_from is InstallationSource.PREBUILT: + deb_paths = sorted( + get_debs_for_series(context.pro_config.debs_path, series) ) - instance.execute("sudo apt update") + logging.info("using debs: {}".format(deb_paths)) + for deb_path in deb_paths: + if "advantage-pro" not in deb_path or is_pro: + instance.push_file(deb_path, "/tmp/behave_ua.deb") + when_i_apt_install( + context, "/tmp/behave_ua.deb", machine_name=machine_name + ) + instance.execute("sudo rm /tmp/behave_ua.deb") + elif context.pro_config.install_from is InstallationSource.LOCAL: + ua_deb_path, pro_deb_path, l10n_deb_path = build_debs( + series, + sbuild_output_to_terminal=context.pro_config.sbuild_output_to_terminal, # noqa: E501 + ) + instance.push_file(ua_deb_path, "/tmp/behave_ua.deb") when_i_apt_install( - context, "ubuntu-advantage-tools", machine_name=machine_name + context, "/tmp/behave_ua.deb", machine_name=machine_name ) + instance.execute("sudo rm /tmp/behave_ua.deb") + instance.push_file(l10n_deb_path, "/tmp/behave_ua.deb") + when_i_apt_install( + context, "/tmp/behave_ua.deb", machine_name=machine_name + ) + instance.execute("sudo rm /tmp/behave_ua.deb") if is_pro: + instance.push_file(pro_deb_path, "/tmp/behave_ua.deb") when_i_apt_install( - context, "ubuntu-advantage-pro", machine_name=machine_name + context, "/tmp/behave_ua.deb", machine_name=machine_name ) + instance.execute("sudo rm /tmp/behave_ua.deb") @when("I have the `{series}` debs under test in `{dest}`")