Verified Commit 27597fd1 authored by Peter Stanko's avatar Peter Stanko
Browse files

Test for images endpoint

parent 631743bf
Loading
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -33,21 +33,26 @@ def submissions_cli_cancel(sid):
    commands.cancel_submission(sid)


@management_cli.command('register', help="Register tenant")
@management_cli.command('register', help="Register worker")
def management_cli_register():
    print(f"Register worker")
    commands.register_worker()


@management_cli.command('status', help="Status")
def management_cli_register():
    print(f"Status:")
    commands.register_worker()
@management_cli.command('status', help="Print worker status")
def submissions_cli_status():
    commands.status()


@management_cli.command('status')
@management_cli.command('clean', help="Clean image cache")
@click.argument('test_files_hash')
def submissions_cli_status(test_files_hash):
    commands.clean_image(test_files_hash)


@management_cli.command('clean-all', help="Clean image cache")
def submissions_cli_status():
    commands.status()
    commands.clean_all_images()


def parse_param(array: List[str]) -> dict:
+7 −0
Original line number Diff line number Diff line
@@ -60,3 +60,10 @@ class CommandsManager(object):

    def register_worker(self):
        return self.mgmt.register_worker()

    def clean_image(self, test_files_hash):
        ManagementService().clean_image(test_files_hash)

    def clean_all_images(self):
        ManagementService().clean_all_images()
+21 −0
Original line number Diff line number Diff line
@@ -17,3 +17,24 @@ class StatusResource(Resource):
        Returns:
        """
        return ManagementService().status


@management_namespace.route('/images')
class ImagesResource(Resource):
    @require_authorization
    def get(self):
        return ManagementService().list_images()


@management_namespace.route('/images/<string:img>/clean')
class ImagesResource(Resource):
    @require_authorization
    def post(self, img):
        return ManagementService().clean_image(img)


@management_namespace.route('/registration')
class RegisterResource(Resource):
    @require_authorization
    def post(self):
        return ManagementService().register_worker()
+16 −0
Original line number Diff line number Diff line
@@ -23,3 +23,19 @@ class ManagementService:
        )
        log.info(f"[MGMT] Register worker {self.context.worker.name}: {params}")
        self.context.rest.workers.update(params, eid=self.context.worker.name)

    def list_images(self):
        return self.context.hashes.list()

    def clean_image(self, test_files_hash: str):
        log.debug(f"[DEL] Delete old image: {test_files_hash}")
        if context.hashes.get(test_files_hash):
            log.info(f"[DEL] Deleting old image: {test_files_hash}")
            context.hashes.remove(test_files_hash)
            context.docker.docker.images.remove(test_files_hash)

    def clean_all_images(self):
        log.debug("[DEL] Deleting all images")
        for image in self.list_images():
            self.clean_image(image)
+12 −2
Original line number Diff line number Diff line
@@ -4,8 +4,18 @@ from mockredis import mock_redis_client
from tests.rest import utils


def assert_response(response, code=200):
    assert response.status_code == code
    assert response.mimetype == 'application/json'


@mock.patch('redis.Redis', mock_redis_client)
def test_status_endpoint_should_be_accessible(client):
    response = utils.make_request(client, f"/management/status")
    assert response.status_code == 200
    assert response.mimetype == 'application/json'
    assert_response(response)


@mock.patch('redis.Redis', mock_redis_client)
def test_(client):
    response = utils.make_request(client, f"/management/images")
    assert_response(response)