Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7998 from mmojzis/templates_fix
Browse files Browse the repository at this point in the history
[NOTEST][RFR] EC2 template fix
  • Loading branch information
mshriver authored Oct 17, 2018
2 parents fccfd57 + a366419 commit 9c0e63b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 6 additions & 12 deletions cfme/utils/template/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from contextlib import closing
from subprocess import check_call, CalledProcessError
from os import path
from threading import Lock

from cached_property import cached_property
from fauxfactory import gen_alphanumeric
from glanceclient import Client
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError
from six.moves.urllib import request

from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.cloud.provider.gce import GCEProvider
Expand Down Expand Up @@ -234,22 +235,15 @@ def deploy_template(self):
@log_wrap("download image locally")
def download_image(self):
# Check if file exists already:
try:
check_call(['ls', self.local_file_path])
except CalledProcessError:
pass
else:
if path.isfile(self.local_file_path):
logger.info('Local image found, skipping download: %s', self.local_file_path)
return True

# Download file to cli-tool-client
try:
check_call(['curl',
'--output',
self.local_file_path,
self.raw_image_url])
except CalledProcessError:
logger.exception('Failed download of image using curl')
request.urlretrieve(self.raw_image_url, self.local_file_path)
except URLError:
logger.exception('Failed download of image using urllib')
return False
else:
return True
Expand Down
9 changes: 4 additions & 5 deletions cfme/utils/template/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from cfme.utils.log import logger
from cfme.utils.template.base import ProviderTemplateUpload, log_wrap
from cfme.utils.wait import wait_for
from wrapanapi.systems.ec2 import EC2Image


class EC2TemplateUpload(ProviderTemplateUpload):
Expand Down Expand Up @@ -40,7 +41,7 @@ def upload_image(self):
file_path=self.file_path,
file_name=self.template_name)
return True
except:
except Exception:
return False

@log_wrap("import image from bucket")
Expand All @@ -58,10 +59,8 @@ def import_image(self):
message='Importing image to EC2')

ami_id = self.mgmt.get_image_id_if_import_completed(import_task_id)
self.mgmt.copy_image(source_region=self.mgmt.api.region.name,
source_image=ami_id,
image_id=self.template_name)
self.mgmt.get_template(ami_id).cleanup()
ami = EC2Image(uuid=ami_id, system=self.mgmt)
ami.set_tag("Name", self.template_name)
return True

except Exception:
Expand Down

0 comments on commit 9c0e63b

Please sign in to comment.