Example #1
0
 def delete_image(self, image: Image):
     if self.data.get_instances_by_image_id(image.id):
         raise ImageWithInstancesError(image)
     if image.id is None:
         raise NonExistingImageError(image)
     self.data.remove_image(image.id)
     self.save()
     image.unbind_meta_repo()
Example #2
0
 def to_obj(self) -> Image:
     image = Image(name=self.name,
                   author=self.author,
                   creation_date=self.creation_date,
                   id=self.id,
                   model_id=self.model_id,
                   params=safe_loads(self.params, Image.Params))
     return self.attach(image)
Example #3
0
 def factory(saved=False):
     nonlocal counter
     counter += 1
     image = Image('Test Image-{}'.format(counter), params={'test': counter}, source=BuildableMock())
     if saved:
         task = task_factory(True)
         task.add_image(image)
     return image
Example #4
0
 def factory(saved=False):
     nonlocal counter
     counter += 1
     image = Image('Test Image-{}'.format(counter), params={'test': counter})
     if saved:
         model = model_factory(True)
         model.add_image(image)
     return image
Example #5
0
 def to_obj(self) -> Image:
     image = Image(name=self.name,
                   author=self.author,
                   creation_date=self.creation_date,
                   id=self.id,
                   task_id=self.task_id,
                   params=safe_loads(self.params, Image.Params),
                   source=safe_loads(self.source, Buildable),
                   environment_id=self.environment_id)
     return self.attach(image)
Example #6
0
def delete_image_ok(ebnt: Ebonite, model: Model):
    task = ebnt.get_or_create_task('Project', 'Task')
    model = ebnt.push_model(model, task)
    image = Image(task_id=task.id, name='Image', source=BuildableMock())
    image = ebnt.meta_repo.create_image(image)

    assert ebnt.meta_repo.get_task_by_id(task.id) is not None
    assert ebnt.meta_repo.get_model_by_id(model.id) is not None
    assert ebnt.meta_repo.get_image_by_id(image.id) is not None
    ebnt.delete_image(image)

    assert ebnt.meta_repo.get_image_by_id(image.id) is None
Example #7
0
    def create_image(self, image: Image) -> Image:
        self._validate_image(image)

        existing_model = self.get_model_by_id(image.model_id)
        if existing_model is None:
            raise NonExistingModelError(image.model_id)

        if self.get_image_by_name(image.name, existing_model) is not None:
            raise ExistingImageError(image)

        image._id = self.data.get_and_increment('next_image_id')
        self.data.add_image(copy.deepcopy(image))
        self.save()
        return image
Example #8
0
    def create_image(self, image: Image) -> Image:
        self._validate_image(image)

        task = self.get_task_by_id(image.task_id)
        if task is None:
            raise NonExistingTaskError(image.task_id)

        if self.get_image_by_name(image.name, task) is not None:
            raise ExistingImageError(image)

        image._id = self.data.get_and_increment('next_image_id')
        self.data.add_image(copy.deepcopy(image))
        self.save()
        return image
Example #9
0
def image_to_delete(ebnt: Ebonite, model, mock_env):
    task = ebnt.get_or_create_task('Project', 'Task')
    ebnt.meta_repo.create_environment(mock_env)
    image = Image('image', BuildableMock(), id=None, task_id=task.id, params=Image.Params())
    image.environment = mock_env
    image.params.name = 'image'
    image.bind_builder(mock_env.params.get_builder())
    image = ebnt.meta_repo.create_image(image)
    yield image
Example #10
0
def test_delete_task_cascade_ok(ebnt: Ebonite, model: Model, mock_env,
                                image: Image, pipeline: Pipeline):
    task = ebnt.get_or_create_task('Project', 'Task')
    model = ebnt.push_model(model, task)
    image.environment = ebnt.meta_repo.create_environment(mock_env)
    task.add_pipeline(pipeline)
    task.add_image(image)
    task = ebnt.meta_repo.get_task_by_id(task.id).bind_as(task)

    assert ebnt.meta_repo.get_task_by_id(task.id) is not None
    assert ebnt.meta_repo.get_model_by_id(model.id) is not None
    assert ebnt.meta_repo.get_pipeline_by_id(pipeline.id) is not None
    assert ebnt.meta_repo.get_image_by_id(image.id) is not None
    ebnt.delete_task(task, cascade=True)

    assert ebnt.meta_repo.get_task_by_id(task.id) is None
    assert ebnt.meta_repo.get_model_by_id(model.id) is None
    assert ebnt.meta_repo.get_pipeline_by_id(pipeline.id) is None
    assert ebnt.meta_repo.get_image_by_id(image.id) is None
Example #11
0
def image():
    return Image('Test Image', BuildableMock())
Example #12
0
def image():
    return Image("Test Image", params=TestParams(123))
Example #13
0
 def delete_image(self, image: Image):
     self._delete_object(self.images, image, NonExistingImageError)
     image.unbind_meta_repo()
Example #14
0
 def delete_image(self, image: Image):
     if image.id is None:
         raise NonExistingImageError(image)
     self.data.remove_image(image.id)
     self.save()
     image.unbind_meta_repo()
Example #15
0
def image():
    return Image("Meta Test Image",
                 params=TestParams(123),
                 source=TestBuildable())