summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2018-02-16 10:45:55 -0500
committerTim Rozet <trozet@redhat.com>2018-02-16 10:59:39 -0500
commit2beef21903d7a36bdac19b3170003043693562dd (patch)
tree16915957eccb08d19f1a5442fb6f5528416c72c8
parent2111e5a85f8d0a894e1a7684c2e1a6d897091c9d (diff)
Fixes stale undercloud delorean repos
When we build artifacts for release, we try to freeze the disk images and artifacts we use for deployment. This includes the delorean repo which provides OpenStack packages. This repo however expires after a couple months and then if any packages were missing in the Undercloud released artifact, they will attempt to be downloaded during install and fail. This patch adds some logic to detect if there is internet connectivity, and if so then download and update the delorean repo on the undercloud. JIRA: APEX-565 Change-Id: I58c28437fb5c5b179033c939377fd97aefbf427c Signed-off-by: Tim Rozet <trozet@redhat.com>
-rw-r--r--apex/common/utils.py10
-rw-r--r--apex/deploy.py3
-rw-r--r--apex/tests/test_apex_undercloud.py15
-rw-r--r--apex/undercloud/undercloud.py20
4 files changed, 46 insertions, 2 deletions
diff --git a/apex/common/utils.py b/apex/common/utils.py
index 0328a3b5..b727b11a 100644
--- a/apex/common/utils.py
+++ b/apex/common/utils.py
@@ -13,6 +13,7 @@ import json
import logging
import os
import pprint
+import socket
import subprocess
import tarfile
import time
@@ -210,3 +211,12 @@ def install_ansible():
subprocess.check_call([pkg_mgr, '-y', 'install', 'ansible'])
except subprocess.CalledProcessError:
logging.warning('Unable to install Ansible')
+
+
+def internet_connectivity():
+ try:
+ urllib.request.urlopen('http://opnfv.org', timeout=3)
+ return True
+ except (urllib.request.URLError, socket.timeout):
+ logging.debug('No internet connectivity detected')
+ return False
diff --git a/apex/deploy.py b/apex/deploy.py
index 5171c5cd..1b398b8a 100644
--- a/apex/deploy.py
+++ b/apex/deploy.py
@@ -382,7 +382,8 @@ def main():
args.deploy_dir,
root_pw=root_pw,
external_network=uc_external,
- image_name=os.path.basename(uc_image))
+ image_name=os.path.basename(uc_image),
+ os_version=os_version)
undercloud.start()
# Generate nic templates
diff --git a/apex/tests/test_apex_undercloud.py b/apex/tests/test_apex_undercloud.py
index c821ade5..0df785f9 100644
--- a/apex/tests/test_apex_undercloud.py
+++ b/apex/tests/test_apex_undercloud.py
@@ -197,3 +197,18 @@ class TestUndercloud(unittest.TestCase):
ds = {'global_params': {}}
Undercloud('img_path', 'tplt_path').generate_config(ns, ds)
+
+ @patch.object(Undercloud, '_get_vm', return_value=None)
+ @patch.object(Undercloud, 'create')
+ @patch('apex.undercloud.undercloud.virt_utils')
+ def test_update_delorean(self, mock_vutils, mock_uc_create, mock_get_vm):
+ uc = Undercloud('img_path', 'tmplt_path', external_network=True)
+ uc._update_delorean_repo()
+ download_cmd = (
+ "curl -L -f -o "
+ "/etc/yum.repos.d/deloran.repo "
+ "https://trunk.rdoproject.org/centos7-{}"
+ "/current-tripleo/delorean.repo".format(
+ constants.DEFAULT_OS_VERSION))
+ test_ops = {'--run-command': download_cmd}
+ mock_vutils.virt_customize.assert_called_with(test_ops, uc.volume)
diff --git a/apex/undercloud/undercloud.py b/apex/undercloud/undercloud.py
index d28ed981..4490ed20 100644
--- a/apex/undercloud/undercloud.py
+++ b/apex/undercloud/undercloud.py
@@ -31,8 +31,10 @@ class Undercloud:
"""
def __init__(self, image_path, template_path,
root_pw=None, external_network=False,
- image_name='undercloud.qcow2'):
+ image_name='undercloud.qcow2',
+ os_version=constants.DEFAULT_OS_VERSION):
self.ip = None
+ self.os_version = os_version
self.root_pw = root_pw
self.external_net = external_network
self.volume = os.path.join(constants.LIBVIRT_VOLUME_PATH,
@@ -73,6 +75,7 @@ class Undercloud:
template_dir=self.template_path)
self.setup_volumes()
self.inject_auth()
+ self._update_delorean_repo()
def _set_ip(self):
ip_out = self.vm.interfaceAddresses(
@@ -237,3 +240,18 @@ class Undercloud:
}
return config
+
+ def _update_delorean_repo(self):
+ if utils.internet_connectivity():
+ logging.info('Updating delorean repo on Undercloud')
+ delorean_repo = (
+ "https://trunk.rdoproject.org/centos7-{}"
+ "/current-tripleo/delorean.repo".format(self.os_version))
+ cmd = ("curl -L -f -o "
+ "/etc/yum.repos.d/deloran.repo {}".format(delorean_repo))
+ try:
+ virt_utils.virt_customize({constants.VIRT_RUN_CMD: cmd},
+ self.volume)
+ except Exception:
+ logging.warning("Failed to download and update delorean repo "
+ "for Undercloud")