Fixes stale undercloud delorean repos 49/52249/2
authorTim Rozet <trozet@redhat.com>
Fri, 16 Feb 2018 15:45:55 +0000 (10:45 -0500)
committerTim Rozet <trozet@redhat.com>
Fri, 16 Feb 2018 15:59:39 +0000 (10:59 -0500)
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>
apex/common/utils.py
apex/deploy.py
apex/tests/test_apex_undercloud.py
apex/undercloud/undercloud.py

index 0328a3b..b727b11 100644 (file)
@@ -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
index 5171c5c..1b398b8 100644 (file)
@@ -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
index c821ade..0df785f 100644 (file)
@@ -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)
index d28ed98..4490ed2 100644 (file)
@@ -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")