summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeng Pan <fpan@redhat.com>2018-02-16 21:27:59 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-02-16 21:27:59 +0000
commita4f70cb1db40eac845c2df17158e77163c887ff1 (patch)
tree829fe4ddf906d429695cb5a5b5cd6d2e0ed595c0
parent5443898e7a1927d8e3cd35e70e3872ed5d9a6d97 (diff)
parent2beef21903d7a36bdac19b3170003043693562dd (diff)
Merge "Fixes stale undercloud delorean repos"
-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 fe25634f..5703e081 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 63f9183a..a70c465a 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(
@@ -240,3 +243,18 @@ class Undercloud:
config['https_proxy'] = ns.get('https_proxy', '')
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")