Acumos Adapter updates to support v3 schema
[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 # Copyright (c) 2021 highstreet technologies GmbH. All rights reserved.
6 # =============================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END======================================================
19
20 from testing_helpers import get_json_fixture, get_fixture_path
21 from aoconversion import docker_gen, scanner
22 import test_fed
23
24 TEST_META = get_json_fixture("models/example-model/metadata.json")
25
26
27 def test_generate_dockerfile():
28     assert (
29         docker_gen._generate_dockerfile(TEST_META, "example-model", '', '', '')
30         == """
31     FROM python:3.6.8
32
33     ENV MODELNAME example-model
34     RUN mkdir /app
35     WORKDIR /app
36
37     ADD ./example-model /app/example-model
38     ADD ./requirements.txt /app
39     ENV http_proxy=
40     ENV https_proxy=
41     ENV HTTP_PROXY=
42     ENV HTTPS_PROXY=
43     ENV no_proxy=
44     ENV NO_PROXY=
45     RUN pip install -r /app/requirements.txt && \
46         pip install acumos_dcae_model_runner && \
47         pip install pyyaml
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')