forked from devfile/integration-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_deploy_cmd.py
124 lines (96 loc) · 5.88 KB
/
test_deploy_cmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sys
import tempfile
from utils.config import *
from utils.util import *
@pytest.mark.usefixtures("use_test_registry")
class TestDeployCmd:
CONTEXT = "test-context"
tmp_project_name = None
@classmethod
def setup_class(cls):
# Runs once per class
cls.tmp_project_name = create_test_project()
@classmethod
def teardown_class(cls):
'''Runs at end of class'''
subprocess.run(["odo", "project", "delete", cls.tmp_project_name, "-f", "-w"])
def test_deploy(self):
print("Test case : should run odo deploy by using a devfile.yaml containing a deploy command")
with tempfile.TemporaryDirectory() as tmp_workspace:
os.chdir(tmp_workspace)
# example devfile path
source_devfile_path = os.path.join(os.path.dirname(__file__),
'../examples/source/devfiles/nodejs/devfile-deploy.yaml')
copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT)
os.environ['PODMAN_CMD'] = "echo"
# building and pushing image to registry
result = subprocess.run(["odo", "deploy", "--context", self.CONTEXT],
capture_output=True, text=True, check=True)
assert contains(result.stdout, "build -t quay.io/unknown-account/myimage -f "
+ os.path.abspath(os.path.join(self.CONTEXT, "Dockerfile"))
+ " "
+ os.path.abspath(self.CONTEXT))
assert contains(result.stdout, "push quay.io/unknown-account/myimage")
# deploying a deployment with the built image
# MacOS: reuse the existing kubectl inside minikube
result = subprocess.run(["minikube", "kubectl", "--", "get", "deployment", "my-component", "-n", "intg-test-project",
"-o", "jsonpath='{.spec.template.spec.containers[0].image}'"],
capture_output=True, text=True, check=True)
assert contains(result.stdout, "quay.io/unknown-account/myimage")
def test_deploy_image_component(self):
print("Test case : should run odo deploy by using a devfile.yaml containing an Image component with a build context")
with tempfile.TemporaryDirectory() as tmp_workspace:
os.chdir(tmp_workspace)
# example devfile path
source_devfile_path = os.path.join(os.path.dirname(__file__),
'../examples/source/devfiles/nodejs/devfile-outerloop-project_source-in-docker-build-context.yaml')
copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT)
os.environ['PODMAN_CMD'] = "echo"
# building and pushing image to registry
result = subprocess.run(["odo", "deploy", "--context", self.CONTEXT],
capture_output=True, text=True, check=True)
assert contains(result.stdout, "build -t localhost:5000/devfile-nodejs-deploy:0.1.0 -f "
+ os.path.abspath(os.path.join(self.CONTEXT, "Dockerfile")))
assert contains(result.stdout, "push localhost:5000/devfile-nodejs-deploy:0.1.0")
assert contains(result.stdout, "Deploying Kubernetes Deployment: devfile-nodejs-deploy")
assert contains(result.stdout, "Deploying Kubernetes Service: devfile-nodejs-deploy")
# deploying a deployment with the built image
# MacOS: reuse the existing kubectl inside minikube
# result = subprocess.run(["minikube", "kubectl", "--", "get", "deployment", "my-component", "-n", "intg-test-project",
# "-o", "jsonpath='{.spec.template.spec.containers[0].image}'"],
# capture_output=True, text=True, check=True)
# assert contains(result.stdout, "quay.io/unknown-account/myimage")
# Supporting multiple deploy commands are not supported yet
# issue: https://github.com/redhat-developer/odo/issues/5454
# @pytest.mark.skip(reason=None)
# def test_two_deploy_commands(self):
#
# print("Test case : should run odo deploy by using a devfile.yaml containing a deploy command")
#
# with tempfile.TemporaryDirectory() as tmp_workspace:
# os.chdir(tmp_workspace)
#
# # example devfile path
# source_devfile_path = os.path.join(os.path.dirname(__file__),
# '../examples/source/devfiles/nodejs/devfile-with-two-deploy-commands.yaml')
#
# copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT)
#
# os.environ['PODMAN_CMD'] = "echo"
#
# # building and pushing image to registry
# result = subprocess.run(["odo", "deploy", "--context", self.CONTEXT],
# capture_output=True, text=True, check=True)
#
# assert contains(result.stdout, "build -t quay.io/unknown-account/myimage -f "
# + os.path.abspath(os.path.join(self.CONTEXT, "Dockerfile"))
# + " "
# + os.path.abspath(self.CONTEXT))
# assert contains(result.stdout, "push quay.io/unknown-account/myimage")
#
# # deploying a deployment with the built image
# # MacOS: reuse the existing kubectl inside minikube
# result = subprocess.run(["minikube", "kubectl", "--", "get", "deployment", "my-component", "-n", "intg-test-project",
# "-o", "jsonpath='{.spec.template.spec.containers[0].image}'"],
# capture_output=True, text=True, check=True)
# assert contains(result.stdout, "quay.io/unknown-account/myimage")