Skip to content

Commit

Permalink
Issues: Install test does not test validity of packages (rpm/deb)
Browse files Browse the repository at this point in the history
Fixes F5Networks#494

Problem:
The test install algorithm to work with a more generic pool

Analysis:
I made the changes to make it so that the .deb and .rpm install tests
would do what they're supposed to do.  Before this change, the .deb and
.rpm failures were not being properly tracked and would always fail due
to improper regExp handling of expected strings.

Tests:
This is a test.  To validate that this executes properly, use the
.travis_yml file in its normal execution phasing.
  • Loading branch information
sorensF5 committed Jan 25, 2017
1 parent add0fda commit 620bc47
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python

from __future__ import print_function

import glob
import os
import re
Expand All @@ -8,25 +10,23 @@

from collections import deque, namedtuple

f5_icontrol_rest_pattern = re.compile(
"^f5-icontrol-rest\s*=\s*(\d+\.\d+\.\d+)$")
dep_match_re = re.compile('^((python|f5-sdk)[\w\-]*)\s([<>=]{1,2})\s(\S+)')


def usage():
print "fetch_dependencies.py working_dir"
print("fetch_dependencies.py working_dir")


def runCommand(cmd):
output = ""
print " -- %s" % (cmd)
print(" -- %s" % (cmd))
try:
p = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(output) = p.communicate()[0]
except OSError, e:
print >>sys.stderr, "Execution failed: ", e
except OSError as e:
print("Execution failed: ", e, file=sys.stderr)
return (output, p.returncode)


Expand All @@ -36,27 +36,27 @@ def fetch_agent_dependencies(dist_dir, version, release, agent_pkg):
requires = deque()
# Copy agent package to /tmp
cpCmd = "cp %s /tmp" % agent_pkg
print "Copying agent package to /tmp install directory"
print("Copying agent package to /tmp install directory")
(output, status) = runCommand(cpCmd)
if status != 0:
print "Failed to copy f5-openstack-agent package"
print("Failed to copy f5-openstack-agent package")
else:
print "Success"
print("Success")

# Get the sdk requirement.
requiresCmd = "rpm -qRp %s" % agent_pkg
agent_pkg_base = os.path.basename(agent_pkg)
print "Getting dependencies for %s." % agent_pkg_base
print("Getting dependencies for %s." % agent_pkg_base)
(output, status) = runCommand(requiresCmd)

if status != 0:
print "Can't get package dependencies for %s" % agent_pkg_base
print("Can't get package dependencies for %s" % agent_pkg_base)
return 1
else:
print "Success"
print("Success")

for line in output.split('\n'):
print line, dep_match_re.pattern
print(line, dep_match_re.pattern)
match = dep_match_re.match(line)
if match:
groups = list(match.groups())
Expand All @@ -67,9 +67,8 @@ def fetch_agent_dependencies(dist_dir, version, release, agent_pkg):
requires.append(my_dep)

# we know we will always need this...
print requires
if not f5_sdk_version:
print "Can't find f5-sdk dependency for %s" % (agent_pkg)
print("Can't find f5-sdk dependency for %s" % (agent_pkg))
return 1

# Check if the required packages are present, then install the ones we are
Expand All @@ -82,26 +81,29 @@ def fetch_agent_dependencies(dist_dir, version, release, agent_pkg):
curlCmd = ("curl -L -o /tmp/%s %s/f5-sdk-%s-1.el7.noarch.rpm" %
(f5_sdk_pkg, github_sdk_url, f5_sdk_version))

print "Fetching f5-sdk package from github"
print("Fetching f5-sdk package from github")
(output, status) = runCommand(curlCmd)

# Get the icontrol rest dependency
requiresCmd = "rpm -qRp /tmp/%s" % (f5_sdk_pkg)
print "Getting dependencies for %s." % (f5_sdk_pkg)
print("Getting dependencies for %s." % (f5_sdk_pkg))
(output, status) = runCommand(requiresCmd)
if status != 0:
print "Failed to to get requirements for %s." % (f5_sdk_pkg)
print("Failed to to get requirements for %s." % (f5_sdk_pkg))
return 1
else:
print "Success"
print("Success")

for line in output.split('\n'):
m = f5_icontrol_rest_pattern.match(line)
m = dep_match_re.search(line)
if m:
f5_icr_version = m.group(1)
break
my_dep = ReqDetails(*m.groups())
if 'f5-icontrol-rest' in my_dep.name and \
re.search('^>?=', my_dep.oper):
f5_icr_version = my_dep.version
break
if not f5_sdk_version:
print "Can't find f5-sdk dependency for %s" % (f5_sdk_pkg)
print("Can't find f5-sdk dependency for %s" % (f5_sdk_pkg))
return 1

# Fectch the icontrol rest package
Expand All @@ -112,21 +114,21 @@ def fetch_agent_dependencies(dist_dir, version, release, agent_pkg):
curlCmd = ("curl -L -o /tmp/%s %s/%s" %
(f5_icr_pkg, github_icr_url, f5_icr_pkg))

print "Fetching f5-icontrol-reset package from github"
print("Fetching f5-icontrol-reset package from github")
(output, status) = runCommand(curlCmd)

if status != 0:
print "Failed to to fetch f5-icontrol-rest package."
print("Failed to to fetch f5-icontrol-rest package.")
return 1
else:
print "Success on F5 Libraries"
print("Success on F5 Libraries")
return check_other_dependencies(requires, dist_dir, agent_pkg)


def check_other_dependencies(requires, dist_dir, agent_pkg):
# triage the packages already installed
rpm_list_cmd = "rpm -qa"
print "Collecting a list of already-install pkgs"
print("Collecting a list of already-install pkgs")
(output, status) = runCommand(rpm_list_cmd)
to_get = deque()
ignore = []
Expand All @@ -135,7 +137,7 @@ def check_other_dependencies(requires, dist_dir, agent_pkg):
if my_dep.name not in output and my_dep.name not in ignore:
to_get.append(my_dep)
# install the repo-stored rpm's
print "Grabbing the ones we have copies of"
print("Grabbing the ones we have copies of")
to_install = glob.glob(dist_dir + "/Docker/redhat/7/*.rpm")
for rpm_file in to_install:
for rpm_dep in to_get:
Expand All @@ -144,14 +146,14 @@ def check_other_dependencies(requires, dist_dir, agent_pkg):
rpm_install_cmd = "rpm -i %s" % rpm_file
runCommand(rpm_install_cmd)
if to_get:
print "WARNING: there are missing dependencies!"
print("WARNING: there are missing dependencies!")
while to_get:
dep = to_get.popleft()
print "%s %s %s" % (dep.name, dep.oper, dep.version)
print("%s %s %s" % (dep.name, dep.oper, dep.version))
else:
print """Succsess!
print("""Succsess!
All dependencies search satisfied! However, by-version check may still fail...
"""
""")
# change to be dynamic if we decide to be more rigorous at this stage...
return 0

Expand All @@ -160,7 +162,7 @@ def install_agent_pkgs(repo):
installCmd = "rpm -ivh /tmp/*.rpm"
(output, status) = runCommand(installCmd)
if status != 0:
print "Agent install failed"
print("Agent install failed")
sys.exit(1)


Expand All @@ -173,9 +175,9 @@ def main(args):
pkg_fullname = args[2]
try:
os.chdir("/var/wdir")
except OSError, e:
print >>sys.stderr, "Can't change to directory %s (%s)" % (working_dir,
e)
except OSError as e:
print("Can't change to directory %s (%s)" % (working_dir, e),
file=sys.stderr)

dist_dir = os.path.join(working_dir, "f5-openstack-agent-dist")
version_tool = os.path.join(dist_dir, "scripts/get-version-release.py")
Expand Down
Loading

0 comments on commit 620bc47

Please sign in to comment.