Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
OLPSUP-9046: High-level tests for the target expiration case
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
Mike Sul committed Feb 3, 2020
1 parent a5e12f6 commit 6fffd1e
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/libaktualizr/primary/metadata_expiration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ TEST_F(MetadataExpirationTest, MetadataExpirationAfterInstallationAndBeforeReboo
result::UpdateCheck update_result = aktualizr_->CheckUpdates().get();
EXPECT_EQ(update_result.status, result::UpdateStatus::kNoUpdatesAvailable);

addTargetToInstall(2);
addTargetToInstall(3);

// run the uptane cycle to install the target
aktualizr_->UptaneCycle();
Expand Down Expand Up @@ -168,7 +168,7 @@ TEST_F(MetadataExpirationTest, MetadataExpirationAfterInstallationAndBeforeAppli
result::UpdateCheck update_result = aktualizr_->CheckUpdates().get();
EXPECT_EQ(update_result.status, result::UpdateStatus::kNoUpdatesAvailable);

addTargetToInstall(2);
addTargetToInstall(3);

// run the uptane cycle to install the target
aktualizr_->UptaneCycle();
Expand Down
1 change: 1 addition & 0 deletions src/libaktualizr/uptane/directorrepository.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ bool DirectorRepository::updateMeta(INvStorage& storage, const IMetadataFetcher&
}

if (targetsExpired()) {
last_exception = Uptane::ExpiredMetadata(type.toString(), Role::Targets().ToString());
return false;
}
}
Expand Down
9 changes: 7 additions & 2 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import signal
import socket
import time

from os import devnull
from os import path
Expand Down Expand Up @@ -741,7 +742,7 @@ def add_image(self, id, image_filename, target_name=None, image_size=1024, custo

return target_hash

def add_ostree_target(self, id, rev_hash, target_name=None):
def add_ostree_target(self, id, rev_hash, target_name=None, expires_within_sec=(60 * 5)):
# emulate the backend behavior on defining a target name for OSTREE target format
target_name = rev_hash if target_name is None else "{}-{}".format(target_name, rev_hash)
image_creation_cmdline = [self._repo_manager_exe,
Expand All @@ -754,12 +755,16 @@ def add_ostree_target(self, id, rev_hash, target_name=None):
'--hwid', id[0]]
subprocess.run(image_creation_cmdline, check=True)

expiration_time = time.time() + expires_within_sec
expiration_time_str = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(expiration_time))

subprocess.run([self._repo_manager_exe,
'--command', 'addtarget',
'--path', self.root_dir,
'--targetname', target_name,
'--hwid', id[0],
'--serial', id[1]],
'--serial', id[1],
'--expires', expiration_time_str],
check=True)

subprocess.run([self._repo_manager_exe, '--path', self.root_dir, '--command', 'signtargets'], check=True)
Expand Down
112 changes: 106 additions & 6 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import argparse
import time

from os import getcwd, chdir

Expand All @@ -13,10 +14,11 @@


"""
Test update of Primary and Secondary if their package manager differs, `ostree` and `fake` respectively
Test update of Primary and Secondary if their package manager differs, `ostree`
and binary (`none` or `fake`) respectively
Aktualizr/Primary's package manager is set to `ostree`
Secondary's package manager is set to `fake`
Secondary's package manager is set to `fake` which means a file/binary update
Primary goal is to verify whether aktualizr succeeds with a binary/fake update of secondary
while aktualizr/primary is configured with ostree package manager
"""
Expand All @@ -26,8 +28,8 @@
@with_treehub()
@with_sysroot()
@with_aktualizr(start=False, run_mode='once', output_logs=True)
def test_primary_ostree_secondary_fake_updates(uptane_repo, secondary, aktualizr, director,
uptane_server, sysroot, treehub):
def test_primary_ostree_secondary_file_updates(uptane_repo, secondary, aktualizr, director, sysroot,
treehub, uptane_server):
target_rev = treehub.revision
# add an ostree update for Primary
uptane_repo.add_ostree_target(aktualizr.id, target_rev)
Expand Down Expand Up @@ -62,6 +64,103 @@ def test_primary_ostree_secondary_fake_updates(uptane_repo, secondary, aktualizr
return result


"""
Test update of Secondary's ostree repo if an ostree target metadata are expired
Metadata are valid at the moment of a new ostree revision installation,
but are expired after that and before Secondary is rebooted,
we still expect that the installed update is applied in this case
"""
@with_treehub()
@with_uptane_backend()
@with_director()
@with_sysroot()
@with_secondary(start=False)
@with_aktualizr(start=False, run_mode='once', output_logs=True)
def test_secodary_ostree_update_if_metadata_expires(uptane_repo, secondary, aktualizr, treehub, sysroot, director, **kwargs):
target_rev = treehub.revision
start_time = time.time()
expires_within_sec = 10

uptane_repo.add_ostree_target(secondary.id, target_rev, expires_within_sec=expires_within_sec)

with secondary:
with aktualizr:
aktualizr.wait_for_completion()

pending_rev = aktualizr.get_current_pending_image_info(secondary.id)

if pending_rev != target_rev:
logger.error("Pending version {} != the target one {}".format(pending_rev, target_rev))
return False

# wait until the target metadata are expired
time.sleep(expires_within_sec - (time.time() - start_time))

sysroot.update_revision(pending_rev)
secondary.emulate_reboot()

with secondary:
with aktualizr:
aktualizr.wait_for_completion()

if not director.get_install_result():
logger.error("Installation result is not successful")
return False

installed_rev = aktualizr.get_current_image_info(secondary.id)

if installed_rev != target_rev:
logger.error("Installed version {} != the target one {}".format(installed_rev, target_rev))
return False

return True


"""
Test update of Primary's ostree repo if an ostree target metadata are expired
Metadata are valid at the moment of a new ostree revision installation,
but are expired after that and before Primary is rebooted,
we still expect that the installed update is applied in this case
"""
@with_uptane_backend(start_generic_server=True)
@with_director()
@with_treehub()
@with_sysroot()
@with_aktualizr(start=False, run_mode='once', output_logs=True)
def test_primary_ostree_update_if_metadata_expires(uptane_repo, aktualizr, director, sysroot, treehub, uptane_server):
target_rev = treehub.revision
start_time = time.time()
expires_within_sec = 10

# add an ostree update for Primary
uptane_repo.add_ostree_target(aktualizr.id, target_rev, expires_within_sec=expires_within_sec)

with aktualizr:
aktualizr.wait_for_completion()

# check the Primary update, must be in pending state since it requires reboot
pending_rev = aktualizr.get_primary_pending_version()
if pending_rev != target_rev:
logger.error("Pending version {} != the target version {}".format(pending_rev, target_rev))
return False

# wait until the target metadata are expired
time.sleep(expires_within_sec - (time.time() - start_time))

# emulate reboot and run aktualizr once more
sysroot.update_revision(pending_rev)
aktualizr.emulate_reboot()

with aktualizr:
aktualizr.wait_for_completion()

# check the Primary update after reboot
result = director.get_install_result() and (target_rev == aktualizr.get_current_primary_image_info())
return result


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)

Expand All @@ -76,7 +175,9 @@ def test_primary_ostree_secondary_fake_updates(uptane_repo, secondary, aktualizr
chdir(input_params.build_dir)

test_suite = [
test_primary_ostree_secondary_fake_updates
test_primary_ostree_secondary_file_updates,
test_secodary_ostree_update_if_metadata_expires,
test_primary_ostree_update_if_metadata_expires
]

test_suite_run_result = True
Expand All @@ -88,4 +189,3 @@ def test_primary_ostree_secondary_fake_updates(uptane_repo, secondary, aktualizr

chdir(initial_cwd)
exit(0 if test_suite_run_result else 1)

0 comments on commit 6fffd1e

Please sign in to comment.