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

Commit

Permalink
Merge pull request #147 from nasibehteimouri/master
Browse files Browse the repository at this point in the history
Bug "Copy Image Not Working #146" resolved.
  • Loading branch information
apoorvemohan authored Feb 10, 2018
2 parents 5e649c1 + 8839eb7 commit 8a334df
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ims/einstein/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,35 @@ def get_node_ip(self, node_name):

@log
def copy_image(self, img1, dest_project, img2=None):
"""
Create a deep copy of src image
:param img1: Name of src image
:param dest_project: Name of the project where des image will be
created
:param img2: Name of des image
:return: True on successful completion
"""
try:
if not self.is_admin and (self.proj != dest_project):
raise AuthorizationFailedException()
dest_pid = self.__does_project_exist(dest_project)
self.db.image.copy_image(self.proj, img1, dest_pid, img2)
if img2 is not None:
ceph_name = self.__get_ceph_image_name(img2, dest_project)
ceph_name = self.get_ceph_image_name_from_project(img2,
dest_project)
else:
ceph_name = self.__get_ceph_image_name(img1, dest_project)
self.fs.clone(self.__get_ceph_image_name(img1, self.proj),
constants.DEFAULT_SNAPSHOT_NAME, ceph_name)
ceph_name = self.get_ceph_image_name_from_project(img1,
dest_project)
self.fs.clone(self.get_ceph_image_name_from_project(
img1, self.proj),
constants.DEFAULT_SNAPSHOT_NAME,
ceph_name)

self.fs.flatten(ceph_name)
self.fs.snap_image(ceph_name, constants.DEFAULT_SNAPSHOT_NAME)
self.fs.snap_protect(ceph_name, constants.DEFAULT_SNAPSHOT_NAME)

return self.__return_success(True)
except (DBException, FileSystemException) as e:
logger.exception('')
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/einstein/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
NOT_EXIST_IMG_NAME = _cfg.tests.not_exist_img_name
NOT_EXIST_SNAP_NAME = _cfg.tests.not_exist_snap_name

IMG2 = 'img2'


class TestProvision(TestCase):
"""
Expand Down Expand Up @@ -222,3 +224,41 @@ def tearDown(self):
self.db.project.delete_with_name(PROJECT)
self.db.close()
self.good_bmi.shutdown()


class TestCopyImage(TestCase):
"""
Creating a flatten copy of an image
"""
@trace
def setUp(self):
self.db = Database()
self.db.project.insert(PROJECT, NETWORK)

self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
PROJECT)
self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

def runTest(self):
response = self.good_bmi.copy_image(EXIST_IMG_NAME, PROJECT,
IMG2)
self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
images = self.db.image.fetch_images_from_project(PROJECT)
exists_image = False
for image in images:
if IMG2 == image:
exists_image = True
break
self.assertTrue(exists_image)
with ceph.RBD(_cfg.fs,
_cfg.iscsi.password) as fs:
img_id = self.good_bmi.get_ceph_image_name_from_project(
IMG2, PROJECT)
fs.get_image(img_id)

def tearDown(self):
self.good_bmi.remove_image(IMG2)
self.good_bmi.remove_image(EXIST_IMG_NAME)
self.db.project.delete_with_name(PROJECT)
self.db.close()
self.good_bmi.shutdown()

0 comments on commit 8a334df

Please sign in to comment.