Beispiel #1
0
def download_arista_image():
    """Download arista-cvx-virt-test.qcow2 from a web server.

    The download will happen only if the env var TEST_ARISTA_IMAGE_REMOTE has
    been set, so you don't have to set it if you already have the image
    locally.

    If the env var TEST_ARISTA_IMAGE_LOCAL isn't set, it will be set to
    `/tmp/arista-cvx-virt-test.qcow2`. This is where the image will be
    downloaded to if TEST_ARISTA_IMAGE_REMOTE has been set.
    """
    try:
        os.environ['TEST_ARISTA_IMAGE_LOCAL']
    except KeyError:
        os.environ['TEST_ARISTA_IMAGE_LOCAL'] = ''
    if not os.environ['TEST_ARISTA_IMAGE_LOCAL']:
        os.environ['TEST_ARISTA_IMAGE_LOCAL'] \
            = '/tmp/arista-cvx-virt-test.qcow2'

    try:
        if os.environ['TEST_ARISTA_IMAGE_REMOTE']:
            logging.info('Downloading Arista image from {}'.format(
                os.environ['TEST_ARISTA_IMAGE_REMOTE']))
            openstack_utils.download_image(
                os.environ['TEST_ARISTA_IMAGE_REMOTE'],
                os.environ['TEST_ARISTA_IMAGE_LOCAL'])
    except KeyError:
        # TEST_ARISTA_IMAGE_REMOTE isn't set, which means the image is already
        # available at TEST_ARISTA_IMAGE_LOCAL
        pass

    logging.info('Arista image can be found at {}'.format(
        os.environ['TEST_ARISTA_IMAGE_LOCAL']))
Beispiel #2
0
 def test_download_image(self):
     urllib_opener_mock = mock.MagicMock()
     self.patch_object(openstack_utils, "get_urllib_opener")
     self.get_urllib_opener.return_value = urllib_opener_mock
     self.patch_object(openstack_utils.urllib.request, "install_opener")
     self.patch_object(openstack_utils.urllib.request, "urlretrieve")
     openstack_utils.download_image('http://cirros/c.img', '/tmp/c1.img')
     self.install_opener.assert_called_once_with(urllib_opener_mock)
     self.urlretrieve.assert_called_once_with('http://cirros/c.img',
                                              '/tmp/c1.img')
 def _download_nvidia_package(self):
     package_cache_dir = tempfile.gettempdir()
     package_url = os.environ['TEST_NVIDIA_VGPU_HOST_SW']
     package_name = os.path.basename(urllib.parse.urlparse(
         package_url).path)
     package_local_path = os.path.join(package_cache_dir, package_name)
     if not os.path.exists(package_local_path):
         logging.info('Downloading {} to {} ...'.format(
             package_url, package_local_path))
         openstack_utils.download_image(package_url, package_local_path)
     else:
         logging.info(
             'Cached package found at {} - Skipping download'.format(
                 package_local_path))
     return package_local_path