def test_create_disk_snapshot(self): """Test CreateDiskSnapshot """ radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) new_url = "mock0://linux.for.ev.er/test" cloud0 = self.get_cloud_connector_mock("MyMock0") cloud0.create_snapshot = Mock(return_value=(True, new_url)) self.register_cloudconnector("Mock0", cloud0) auth0 = self.getAuth([0], [], [("Mock0", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) InfrastructureList.infrastructure_list[infId].vm_list[ 0].cloud_connector = cloud0 res = IM.CreateDiskSnapshot(infId, 0, 0, "test", True, auth0) self.assertEqual(res, new_url) self.assertEqual(cloud0.create_snapshot.call_count, 1)
def RESTCreateDiskSnapshot(infid=None, vmid=None, disknum=None): try: auth = get_auth_header() except Exception: return return_error(401, "No authentication data provided") try: bottle.response.content_type = "text/plain" if "image_name" in bottle.request.params.keys(): image_name = bottle.request.params.get("image_name") else: return return_error(400, "Parameter image_name required.") if "auto_delete" in bottle.request.params.keys(): str_auto_delete = bottle.request.params.get("auto_delete").lower() if str_auto_delete in ['yes', 'true', '1']: auto_delete = True elif str_auto_delete in ['no', 'false', '0']: auto_delete = False else: return return_error( 400, "Incorrect value in auto_delete parameter") else: auto_delete = False return InfrastructureManager.CreateDiskSnapshot( infid, vmid, int(disknum), image_name, auto_delete, auth) except DeletedInfrastructureException as ex: return return_error(404, "Error creating snapshot: %s" % get_ex_error(ex)) except IncorrectInfrastructureException as ex: return return_error(404, "Error creating snapshot: %s" % get_ex_error(ex)) except UnauthorizedUserException as ex: return return_error(403, "Error creating snapshot: %s" % get_ex_error(ex)) except DeletedVMException as ex: return return_error(404, "Error creating snapshot: %s" % get_ex_error(ex)) except IncorrectVMException as ex: return return_error(404, "Error creating snapshot: %s" % get_ex_error(ex)) except DisabledFunctionException as ex: return return_error(403, "Error Destroying Inf: %s" % get_ex_error(ex)) except Exception as ex: logger.exception("Error creating snapshot") return return_error(400, "Error creating snapshot: %s" % get_ex_error(ex))