-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
101 lines (74 loc) · 3.39 KB
/
test.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
#!/usr/bin/python3
#// Author: Thomas Grothe, [email protected]
#// 2024/2/22
import pytest
import podpatcher as pp
import json
#test cases
#would probably be good to verify that files in the pod are the same as ones provided from user
#program-file: podpatcher.py
# test case for each function
# range of possible args (arg domain)
# set of args of interest mapped to expected outputs
#
#system verification
'''
verify that cluster is in working order
- kubectl cmd works
- some pods are running
- we can restart pods
- podman cmd works
- we can build and push images
- test a patch
- produce system state/config files containing all the pods, depls, etc.
'''
def test_setup():
f_depls = open('depls.cfg', 'w') #save all the pods
f_pods = open('pods.cfg', 'w') #save all the deployments
f_imgs = open('images.cfg', 'w') #save all the podman images that exist on this host
res = str(pp.runcmd('kubectl'))
assert 'Command not found' not in res
res = pp.runcmd('kubectl get pod -o json')
jo = json.loads(res)
assert len(jo['items']) > 0
for pod in jo['items']:
assert pod['kind'] == 'Pod'
f_pods.write(f"{pod['metadata']['name']},{pod['status']['phase']}\n")
res = pp.runcmd('kubectl get deployment -o json')
jo = json.loads(res)
for dpl in jo['items']:
assert dpl['kind'] == 'Deployment'
f_depls.write(f"{dpl['metadata']['name']}\n")
res = str(pp.runcmd('podman'))
assert 'Command not found' not in res
res = pp.runcmd('podman image list --format json')
#TODO take a look at checkSystem.py
def test_patch_non_existent_deployment():
# Test that patching a non-existent deployment returns an error message
def test_patch_one_deployment_no_files():
# Test that patching one deployment with no provided files returns an error message
def test_patch_one_deployment_non_existent_tag():
# Test that patching one deployment with a non-existent tag returns an error message
def test_patch_one_deployment_some_files():
# Test that patching one deployment with some files applies the patch and returns a success message
def test_patch_multiple_deployments_no_files():
# Test that patching multiple deployments with no provided files returns an error message
def test_patch_multiple_deployments_some_files():
# Test that patching multiple deployments with some files applies the patch and returns a success message
def test_set_tags_non_existent_tag():
# Test that setting tags for one or multiple deployments with a non-existent tag returns an error message
def test_set_tags_existent_tag():
# Test that setting tags for one or multiple deployments with an existing tag returns the k8s result
#program-file: httpsrv.py
#attempt to patch a non-existent deployment ==> do nothing, return error msg
#attempt to patch one deployment, or multiple deployments
# with no provided files ==> do nothing, return error msg
# based on a non-existent tag ==> do nothing, return error msg
# with some files ==> apply patch and return correct msg
# build to a tag that already exists ==> do nothing, return error msg
#attempt to set tags of one or multiple deployments
# tag doesn't exist ==> return error msg
# tag exists ==> set and return k8s result
#verify sqlite db is made and correct data is written/read to/from it
#program: doPatch.py
#program: setTags.py