Skip to content

Commit

Permalink
Fix package version querying on non-dpkg distros
Browse files Browse the repository at this point in the history
Non-Debian based amphora agents raise internal server error when
querying for a package version. That is due to the fact that the agent
currently assumes dpkg-based distros ignoring other OS families such as
Red Hat, SUSE, etc where the output from package info querying output is
slightly different from dpkg.

Story: 2002961
Task: 22963

Change-Id: Ied37bb0191ca8af4966d097f47ec80536dfc843f
  • Loading branch information
cgoncalves committed Jul 12, 2018
1 parent 26852b0 commit 2a7f1e5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
5 changes: 2 additions & 3 deletions octavia/amphorae/backends/agent/api_server/amphora_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ def compile_amphora_details(self):
def _get_version_of_installed_package(self, name):

cmd = self._osutils.cmd_get_version_of_installed_package(name)
out = subprocess.check_output(cmd.split())
m = re.search(b'Version: .*', out)
return m.group(0)[len('Version: '):]
version = subprocess.check_output(cmd.split())
return version

def _count_haproxy_processes(self, listener_list):
num = 0
Expand Down
5 changes: 3 additions & 2 deletions octavia/amphorae/backends/agent/api_server/osutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def is_os_name(cls, os_name):
return os_name in ['ubuntu']

def cmd_get_version_of_installed_package(self, package_name):
return "dpkg --status {name}".format(name=package_name)
return "dpkg-query -W -f=${{Version}} {name}".format(name=package_name)

def get_network_interface_file(self, interface):
if CONF.amphora_agent.agent_server_network_file:
Expand Down Expand Up @@ -307,7 +307,8 @@ def is_os_name(cls, os_name):
return os_name in ['fedora', 'rhel', 'centos']

def cmd_get_version_of_installed_package(self, package_name):
return "rpm -qi {name}".format(name=package_name)
return "rpm -q --queryformat %{{VERSION}} {name}".format(
name=package_name)

def get_network_interface_file(self, interface):
if CONF.amphora_agent.agent_server_network_file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,7 @@ def test_centos_info(self):
def _test_info(self, distro, mock_subbprocess, mock_hostname):
self.assertIn(distro, [consts.UBUNTU, consts.CENTOS])
mock_hostname.side_effect = ['test-host']
mock_subbprocess.side_effect = [
b"""Package: haproxy
Status: install ok installed
Priority: optional
Section: net
Installed-Size: 803
Maintainer: Ubuntu Developers
Architecture: amd64
Version: 9.9.99-9
"""]
mock_subbprocess.side_effect = ['9.9.99-9']

if distro == consts.UBUNTU:
rv = self.ubuntu_app.get('/' + api_server.VERSION + '/info')
Expand Down Expand Up @@ -2437,16 +2428,7 @@ def _test_details(self, distro, mock_subbprocess, mock_hostname,

mock_hostname.side_effect = ['test-host']

mock_subbprocess.side_effect = [
b"""Package: haproxy
Status: install ok installed
Priority: optional
Section: net
Installed-Size: 803
Maintainer: Ubuntu Developers
Architecture: amd64
Version: 9.9.99-9
"""]
mock_subbprocess.side_effect = ['9.9.99-9']

MemTotal = random.randrange(0, 1000)
MemFree = random.randrange(0, 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ def test_get_network_interface_file(self):

def test_cmd_get_version_of_installed_package(self):
package_name = 'foo'
ubuntu_cmd = "dpkg --status {name}".format(name=package_name)
rh_cmd = "rpm -qi {name}".format(name=package_name)
ubuntu_cmd = "dpkg-query -W -f=${{Version}} {name}".format(
name=package_name)
rh_cmd = "rpm -q --queryformat %{{VERSION}} {name}".format(
name=package_name)

returned_ubuntu_cmd = (
self.ubuntu_os_util.cmd_get_version_of_installed_package(
Expand Down

0 comments on commit 2a7f1e5

Please sign in to comment.