Skip to content

Commit

Permalink
tests: test that metapackage with new name works
Browse files Browse the repository at this point in the history
  • Loading branch information
orndorffgrant committed Jan 12, 2024
1 parent e0e6f23 commit 295030d
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 72 deletions.
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

# 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,
Expand Down
30 changes: 30 additions & 0 deletions features/install_uninstall.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<release>` `<machine_type>` 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 `<release>` `<machine_type>` 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 |
8 changes: 7 additions & 1 deletion features/steps/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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)


Expand Down
22 changes: 21 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, equal_to, matches_regexp

from features.steps.shell import when_i_retry_run_command, when_i_run_command
from features.util import SUT
Expand Down Expand Up @@ -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))
119 changes: 49 additions & 70 deletions features/steps/ubuntu_advantage_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,25 +67,66 @@ 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
)
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)
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}`")
Expand Down

0 comments on commit 295030d

Please sign in to comment.