import logging
import os
import pprint
+import socket
import subprocess
import tarfile
import time
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
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
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)
"""
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,
template_dir=self.template_path)
self.setup_volumes()
self.inject_auth()
+ self._update_delorean_repo()
def _set_ip(self):
ip_out = self.vm.interfaceAddresses(
}
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")