Enable Adapter to work behind proxy
[dcaegen2/platform.git] / adapter / acumos / tests / test_docker.py
1 # ============LICENSE_START====================================================
2 # org.onap.dcae
3 # =============================================================================
4 # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 # =============================================================================
6 # Copyright (c) 2021 highstreet technologies GmbH. All rights reserved.
7 # =============================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END======================================================
20
21 from testing_helpers import get_json_fixture, get_fixture_path
22 from aoconversion import docker_gen, scanner
23 import test_fed
24
25 TEST_META = get_json_fixture("models/example-model/metadata.json")
26
27
28 def test_generate_dockerfile():
29     assert (
30         docker_gen._generate_dockerfile(TEST_META, "example-model", '', '', '')
31         == """
32     FROM python:3.6.8
33
34     ENV MODELNAME example-model
35     RUN mkdir /app
36     WORKDIR /app
37
38     ADD ./example-model /app/example-model
39     ADD ./requirements.txt /app
40     ENV http_proxy=
41     ENV https_proxy=
42     ENV HTTP_PROXY=
43     ENV HTTPS_PROXY=
44     ENV no_proxy=
45     ENV NO_PROXY=
46     RUN pip install -r /app/requirements.txt && \
47         pip install acumos_dcae_model_runner
48
49     ENV DCAEPORT=10000
50     EXPOSE $DCAEPORT
51
52     ENTRYPOINT ["acumos_dcae_model_runner"]
53     CMD ["/app/example-model"]
54     """
55     )
56
57
58 def test_build_and_push_docker(monkeypatch):
59     model_repo_path = get_fixture_path('models')
60     config = scanner.Config(dcaeurl='http://dcaeurl', dcaeuser='dcaeuser', onboardingurl='https://onboarding', onboardinguser='obuser', onboardingpass='obpass', acumosurl='https://acumos', certfile=None, dockerregistry='dockerregistry', dockeruser='registryuser', dockerpass='registrypassword', http_proxy='', https_proxy='', no_proxy='', tmpdir=model_repo_path)
61     monkeypatch.setattr(docker_gen, 'APIClient', test_fed._mockdocker.APIClient)
62     assert(docker_gen.build_and_push_docker(config, 'example-model', model_version="latest") == 'dockerregistry/example-model:latest')