Exemplo n.º 1
0
def copy_image_to_web_server(source_file_path, destination):
    """Copies the given image to the http web server.

    This method copies the given image to the http_root location.
    It enables read-write access to the image else the deploy fails
    as the image file at the web_server url is inaccessible.

    :param source_file_path: The absolute path of the image file
                             which needs to be copied to the
                             web server root.
    :param destination: The name of the file that
                        will contain the copied image.
    :raises: ImageUploadFailed exception if copying the source
             file to the web server fails.
    :returns: image url after the source image is uploaded.

    """

    image_url = urljoin(CONF.deploy.http_url, destination)
    image_path = os.path.join(CONF.deploy.http_root, destination)
    try:
        shutil.copyfile(source_file_path, image_path)
    except IOError as exc:
        raise exception.ImageUploadFailed(image_name=destination,
                                          web_server=CONF.deploy.http_url,
                                          reason=exc)
    os.chmod(image_path, 0o644)
    return image_url
Exemplo n.º 2
0
 def test_copy_image_to_web_server_fails(self, copy_mock, chmod_mock):
     CONF.deploy.http_url = "http://x.y.z.a/webserver/"
     CONF.deploy.http_root = "/webserver"
     source = 'tmp_image_file'
     destination = "image-UUID"
     image_path = "/webserver/image-UUID"
     exc = exception.ImageUploadFailed('reason')
     copy_mock.side_effect = exc
     self.assertRaises(exception.ImageUploadFailed,
                       ilo_common.copy_image_to_web_server, source,
                       destination)
     copy_mock.assert_called_once_with(source, image_path)
     self.assertFalse(chmod_mock.called)