def add_and_teardown_registry(request): registry_info = get_registry_info() registry_payload = { 'registry': registry_info['service_name'], 'registry_name': 'localhost', 'registry_pass': registry_info['pass'], 'registry_type': 'docker_v2', 'registry_user': registry_info['user'], 'registry_verify': False } _logger.info("Adding Registry. APIConf={}".format( str(request.param.__name__))) add_registry_resp = http_post(['registries'], registry_payload, config=request.param) if add_registry_resp.code != 200: raise RequestFailedError(add_registry_resp.url, add_registry_resp.code, add_registry_resp.body) def remove_registry(): _logger.info("Removing Registry. APIConf={}".format( str(request.param.__name__))) remove_resp = http_del( ['registries', quote(registry_info['service_name'])], config=request.param) if remove_resp.code != 200: raise RequestFailedError( remove_resp.url, remove_resp.code, '' if not hasattr(remove_resp, 'body') else remove_resp.body) request.addfinalizer(remove_registry) return add_registry_resp, request.param
def test_get_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry resp = http_get( ['registries', quote(get_registry_info()['service_name'], '')], config=api_conf) assert resp == APIResponse(200)
def add_and_teardown_registry(request): registry_info = get_registry_info() registry_payload = { "registry": registry_info["service_name"], "registry_name": registry_info["host"].split(":")[0], "registry_pass": registry_info["pass"], "registry_type": "docker_v2", "registry_user": registry_info["user"], "registry_verify": False, } _logger.info("Adding Registry. APIConf={}".format( str(request.param.__name__))) add_registry_resp = http_post(["registries"], registry_payload, config=request.param) if add_registry_resp.code != 200: raise RequestFailedError(add_registry_resp.url, add_registry_resp.code, add_registry_resp.body) def remove_registry(): _logger.info("Removing Registry. APIConf={}".format( str(request.param.__name__))) remove_resp = http_del( ["registries", quote(registry_info["service_name"])], config=request.param) if remove_resp.code != 200: raise RequestFailedError( remove_resp.url, remove_resp.code, "" if not hasattr(remove_resp, "body") else remove_resp.body, ) request.addfinalizer(remove_registry) return add_registry_resp, request.param
def add_image_to_local_registry(docker_client): """ Pull alpine:latest to local environment, and re-tag it for the local docker-registry Note: if the docker registry run by scripts/ci/docker-compose-ci.yaml is not up, this will fail """ registry_info = get_registry_info() _logger.info("Pulling alpine:latest image from remote") docker_client.images.pull("alpine:latest") _logger.info("Re-tagging as the local docker registry's image") local_image = "{}/alpine".format(registry_info["host"]) rc = docker_client.api.tag("alpine:latest", local_image, "latest") if not rc: raise RequestFailedError(rc, "docker_client:tag", None) # Login to the Local Registry (running from scripts/ci/docker-compose-ci.yaml) _logger.info("Ensure we are logged into the local docker registry") docker_client.login( username=registry_info["user"], password=registry_info["pass"], registry=registry_info["host"], ) _logger.info("Push the re-tagged image to the local docker registry") docker_client.images.push(local_image, "latest")
def test_update_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry get_resp = http_get( ['registries', quote(get_registry_info()['service_name'], '')], config=api_conf) assert get_resp == APIResponse(200) # copy payload from existing (password isn't provided, so re-add it) update_payload = copy.copy(get_resp.body[0]) update_payload[ 'registry_name'] = 'updated_registry_name_functional_test' update_payload['registry_pass'] = get_registry_info()['pass'] update_resp = http_put(['registries', 'docker-registry:5000'], payload=update_payload, config=api_conf) assert update_resp == APIResponse(200)
def test_get_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry resp = http_get( ["registries", quote(get_registry_info()["service_name"], "")], config=api_conf, ) assert resp == APIResponse(200)
def test_update_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry get_resp = http_get( ["registries", quote(get_registry_info()["service_name"], "")], config=api_conf, ) assert get_resp == APIResponse(200) # copy payload from existing (password isn't provided, so re-add it) update_payload = copy.copy(get_resp.body[0]) update_payload[ "registry_name"] = "updated_registry_name_functional_test" update_payload["registry_pass"] = get_registry_info()["pass"] update_resp = http_put( ["registries", "docker-registry:5000"], payload=update_payload, config=api_conf, ) assert update_resp == APIResponse(200)
def add_image_to_local_registry(docker_client): """ Pull alpine:latest to local environment, and re-tag it for the local docker-registry Note: if the docker registry run by tests/functional/artifacts/registry/docker-registry-service.yaml is not up, this will fail """ _logger.info("Pulling alpine:latest image from remote") docker_client.images.pull('alpine:latest') _logger.info("Re-tagging as the local docker registry's image") rc = docker_client.api.tag('alpine:latest', 'localhost:5000/alpine', 'latest') if not rc: raise RequestFailedError(rc, 'docker_client:tag', None) # Login to the Local Registry (running from tests/functional/artifacts/registry/docker-registry-service.yaml registry_info = get_registry_info() _logger.info("Ensure we are logged into the local docker registry") docker_client.login(username=registry_info['user'], password=registry_info['pass'], registry=registry_info['host']) _logger.info("Push the re-tagged image to the local docker registry") docker_client.images.push('localhost:5000/alpine', 'latest')