Skip to content

Commit

Permalink
Add a new test to verify a package update (#149)
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur authored Jun 6, 2023
1 parent e19c6b3 commit 317d2dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ def check_packages_available(self, packages):
""" Check if a given package list is available in the YUM repositories. """
return len(self.ssh(['repoquery'] + packages).splitlines()) == len(packages)

def get_available_package_versions(self, package):
return self.ssh(['repoquery', '--show-duplicates', package]).splitlines()

def is_package_installed(self, package):
try:
self.ssh(['yum', 'list', 'installed', package])
return True
except commands.SSHCommandFailed as e:
if e.stdout.endswith('Error: No matching Packages to list'):
return False
raise e

def yum_save_state(self):
logging.info(f"Save yum state for host {self}")
# For now, that saved state feature does not support several saved states
Expand Down
15 changes: 15 additions & 0 deletions tests/xapi-plugins/plugin_updater/test_updater.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pkgfixtures import host_with_saved_yum_state
import json

# Requirements:
Expand All @@ -19,6 +20,20 @@ def test_update(self, host):

host.yum_restore_saved_state()

def test_package_update(self, host_with_saved_yum_state):
host = host_with_saved_yum_state
packages = host.get_available_package_versions('dummypkg')
assert len(packages) == 2
assert packages[0].startswith('dummypkg-0:1.0-1.xcpng')
assert packages[1].startswith('dummypkg-0:1.0-2.xcpng')

assert not host.is_package_installed(packages[0])
host.call_plugin('updater.py', 'install', {'packages': packages[0]})
assert host.is_package_installed(packages[0])

host.call_plugin('updater.py', 'update', {'packages': 'dummypkg'})
assert host.is_package_installed(packages[1])

class TestProxies:
def test_get_proxies(self, host):
proxies = json.loads(host.call_plugin('updater.py', 'get_proxies'))
Expand Down

0 comments on commit 317d2dc

Please sign in to comment.