From 19b153d57b3c7cded6ed322e9d22de0ad8faaf7b Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Tue, 12 Mar 2024 15:48:14 -0600 Subject: [PATCH 1/8] first pass at todo vm and service / route --- .../virt-todo/service.yaml | 13 ++ .../virtualmachine-fedora-close-herring.yaml | 201 ++++++++++++++++++ .../virt-todo/vmroute.yaml | 14 ++ 3 files changed, 228 insertions(+) create mode 100644 tests/e2e/sample-applications/virt-todo/service.yaml create mode 100644 tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml create mode 100644 tests/e2e/sample-applications/virt-todo/vmroute.yaml diff --git a/tests/e2e/sample-applications/virt-todo/service.yaml b/tests/e2e/sample-applications/virt-todo/service.yaml new file mode 100644 index 00000000000..0360a0829d8 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: vm-service + namespace: openshift-virtualization-os-images +spec: + selector: + special: key + ports: + - name: todoport + port: 8000 + targetPort: 8000 + type: NodePort diff --git a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml new file mode 100644 index 00000000000..f8a046666a1 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml @@ -0,0 +1,201 @@ +apiVersion: kubevirt.io/v1 +kind: VirtualMachine +metadata: + annotations: + kubemacpool.io/transaction-timestamp: '2024-03-12T19:47:37.178653544Z' + vm.kubevirt.io/validations: | + [ + { + "name": "minimal-required-memory", + "path": "jsonpath::.spec.domain.memory.guest", + "rule": "integer", + "message": "This VM requires more memory.", + "min": 1073741824 + } + ] + creationTimestamp: '2024-03-12T19:47:37Z' + generation: 1 + labels: + app: fedora-close-herring + vm.kubevirt.io/template: fedora-server-small + vm.kubevirt.io/template.namespace: openshift + vm.kubevirt.io/template.revision: '1' + vm.kubevirt.io/template.version: v0.26.0 + managedFields: + - apiVersion: kubevirt.io/v1 + fieldsType: FieldsV1 + fieldsV1: + 'f:metadata': + 'f:annotations': + .: {} + 'f:kubemacpool.io/transaction-timestamp': {} + 'f:vm.kubevirt.io/validations': {} + 'f:labels': + .: {} + 'f:app': {} + 'f:vm.kubevirt.io/template': {} + 'f:vm.kubevirt.io/template.namespace': {} + 'f:vm.kubevirt.io/template.revision': {} + 'f:vm.kubevirt.io/template.version': {} + 'f:spec': + .: {} + 'f:dataVolumeTemplates': {} + 'f:running': {} + 'f:template': + .: {} + 'f:metadata': + .: {} + 'f:annotations': + .: {} + 'f:vm.kubevirt.io/flavor': {} + 'f:vm.kubevirt.io/os': {} + 'f:vm.kubevirt.io/workload': {} + 'f:creationTimestamp': {} + 'f:labels': + .: {} + 'f:kubevirt.io/domain': {} + 'f:kubevirt.io/size': {} + 'f:spec': + .: {} + 'f:architecture': {} + 'f:domain': + .: {} + 'f:cpu': + .: {} + 'f:cores': {} + 'f:sockets': {} + 'f:threads': {} + 'f:devices': + .: {} + 'f:disks': {} + 'f:interfaces': {} + 'f:networkInterfaceMultiqueue': {} + 'f:rng': {} + 'f:features': + .: {} + 'f:acpi': {} + 'f:smm': + .: {} + 'f:enabled': {} + 'f:firmware': + .: {} + 'f:bootloader': + .: {} + 'f:efi': {} + 'f:machine': + .: {} + 'f:type': {} + 'f:memory': + .: {} + 'f:guest': {} + 'f:resources': {} + 'f:networks': {} + 'f:terminationGracePeriodSeconds': {} + 'f:volumes': {} + manager: kubectl-create + operation: Update + time: '2024-03-12T19:47:37Z' + name: fedora-close-herring + namespace: openshift-virtualization-os-images + uid: 26d098f2-7b20-42da-90d9-66bec57188f4 +spec: + dataVolumeTemplates: + - apiVersion: cdi.kubevirt.io/v1beta1 + kind: DataVolume + metadata: + creationTimestamp: null + name: fedora-close-herring + spec: + sourceRef: + kind: DataSource + name: fedora + namespace: openshift-virtualization-os-images + storage: + resources: + requests: + storage: 30Gi + running: true + template: + metadata: + annotations: + vm.kubevirt.io/flavor: small + vm.kubevirt.io/os: fedora + vm.kubevirt.io/workload: server + creationTimestamp: null + labels: + kubevirt.io/domain: fedora-close-herring + kubevirt.io/size: small + special: key + spec: + architecture: amd64 + domain: + cpu: + cores: 1 + sockets: 1 + threads: 1 + devices: + disks: + - disk: + bus: virtio + name: rootdisk + - disk: + bus: virtio + name: cloudinitdisk + interfaces: + - macAddress: '02:73:43:00:00:06' + masquerade: {} + model: virtio + name: default + networkInterfaceMultiqueue: true + rng: {} + features: + acpi: {} + smm: + enabled: true + firmware: + bootloader: + efi: {} + machine: + type: pc-q35-rhel9.2.0 + memory: + guest: 2Gi + resources: {} + networks: + - name: default + pod: {} + terminationGracePeriodSeconds: 180 + volumes: + - dataVolume: + name: fedora-close-herring + name: rootdisk + - cloudInitConfigDrive: + userData: |- + #cloud-config + user: fedora + password: dog8code + chpasswd: { expire: False } + user: test + password: dog8code + chpasswd: { expire: False } + packages: + - mariadb-server + - unzip + - wget + runcmd: + - systemctl stop firewalld + - systemctl disable firewalld + - systemctl start mariadb + - systemctl enable mariadb + - mysql -uroot -e "CREATE DATABASE todolist; USE todolist; CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" + - mysql -uroot -e "grant all privileges on todolist.* to test@'localhost' identified by 'test'; FLUSH PRIVILEGES;" + - pushd /home/test/ + - wget https://github.com/weshayutin/todolist-mariadb-go/releases/download/testing1/todolist-linux-amd64.zip + - unzip todolist-linux-amd64.zip + - cp systemd/todolist-mariadb.service /etc/systemd/user + - popd + - systemctl --user daemon-reload + - systemctl --user start todolist-mariadb.service + - systemctl --user enable todolist-mariadb.service + - systemctl --user status todolist-mariadb.service + - systemctl disable cloud-init + name: cloudinitdisk diff --git a/tests/e2e/sample-applications/virt-todo/vmroute.yaml b/tests/e2e/sample-applications/virt-todo/vmroute.yaml new file mode 100644 index 00000000000..cbda33644f5 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/vmroute.yaml @@ -0,0 +1,14 @@ +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: vmroute + namespace: openshift-virtualization-os-images +spec: + #host: vmroute-openshift-virtualization-os-images.apps.cluster-wdh03122024metala.wdh03122024metala.mg.dog8code.com + port: + targetPort: todoport + to: + kind: Service + name: vm-service + weight: 100 + wildcardPolicy: None From 8b4479d502cfac737a3243e3629f710eca62096c Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Wed, 13 Mar 2024 10:56:04 -0600 Subject: [PATCH 2/8] tested blockmode b/r --- tests/e2e/sample-applications/virt-todo/README | 2 ++ .../virt-todo/backup_virttodo.yaml | 12 ++++++++++++ .../virt-todo/restore_virttodo.yaml | 8 ++++++++ .../e2e/sample-applications/virt-todo/service.yaml | 2 +- ....yaml => virtualmachine-fedora-close-carp.yaml} | 14 +++++++------- .../e2e/sample-applications/virt-todo/vmroute.yaml | 2 +- 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 tests/e2e/sample-applications/virt-todo/README create mode 100644 tests/e2e/sample-applications/virt-todo/backup_virttodo.yaml create mode 100644 tests/e2e/sample-applications/virt-todo/restore_virttodo.yaml rename tests/e2e/sample-applications/virt-todo/{virtualmachine-fedora-close-herring.yaml => virtualmachine-fedora-close-carp.yaml} (95%) diff --git a/tests/e2e/sample-applications/virt-todo/README b/tests/e2e/sample-applications/virt-todo/README new file mode 100644 index 00000000000..5a551d00b44 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/README @@ -0,0 +1,2 @@ +# check volumeMode +oc get pvc fedora-close-carp -o yaml -n virttodo | grep volumeMode diff --git a/tests/e2e/sample-applications/virt-todo/backup_virttodo.yaml b/tests/e2e/sample-applications/virt-todo/backup_virttodo.yaml new file mode 100644 index 00000000000..1e33f13c15d --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/backup_virttodo.yaml @@ -0,0 +1,12 @@ +apiVersion: velero.io/v1 +kind: Backup +metadata: + name: virttodo-backup-dm-1 + namespace: openshift-adp +spec: + includedNamespaces: + - virttodo + storageLocation: default + ttl: 720h0m0s + snapshotMoveData: True + defaultVolumesToFsBackup: False diff --git a/tests/e2e/sample-applications/virt-todo/restore_virttodo.yaml b/tests/e2e/sample-applications/virt-todo/restore_virttodo.yaml new file mode 100644 index 00000000000..836743d0fa8 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/restore_virttodo.yaml @@ -0,0 +1,8 @@ +apiVersion: velero.io/v1 +kind: Restore +metadata: + name: virttodo-restore-1 + namespace: openshift-adp +spec: + backupName: virttodo-backup-dm-1 + restorePVs: true diff --git a/tests/e2e/sample-applications/virt-todo/service.yaml b/tests/e2e/sample-applications/virt-todo/service.yaml index 0360a0829d8..0c4696ce352 100644 --- a/tests/e2e/sample-applications/virt-todo/service.yaml +++ b/tests/e2e/sample-applications/virt-todo/service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: vm-service - namespace: openshift-virtualization-os-images + namespace: virttodo spec: selector: special: key diff --git a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml similarity index 95% rename from tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml rename to tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml index f8a046666a1..4b4f6ef0a41 100644 --- a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-herring.yaml +++ b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml @@ -16,7 +16,7 @@ metadata: creationTimestamp: '2024-03-12T19:47:37Z' generation: 1 labels: - app: fedora-close-herring + app: fedora-close-carp vm.kubevirt.io/template: fedora-server-small vm.kubevirt.io/template.namespace: openshift vm.kubevirt.io/template.revision: '1' @@ -95,8 +95,8 @@ metadata: manager: kubectl-create operation: Update time: '2024-03-12T19:47:37Z' - name: fedora-close-herring - namespace: openshift-virtualization-os-images + name: fedora-close-carp + namespace: virttodo uid: 26d098f2-7b20-42da-90d9-66bec57188f4 spec: dataVolumeTemplates: @@ -104,7 +104,7 @@ spec: kind: DataVolume metadata: creationTimestamp: null - name: fedora-close-herring + name: fedora-close-carp spec: sourceRef: kind: DataSource @@ -123,7 +123,7 @@ spec: vm.kubevirt.io/workload: server creationTimestamp: null labels: - kubevirt.io/domain: fedora-close-herring + kubevirt.io/domain: fedora-close-carp kubevirt.io/size: small special: key spec: @@ -142,7 +142,7 @@ spec: bus: virtio name: cloudinitdisk interfaces: - - macAddress: '02:73:43:00:00:06' + - macAddress: '02:73:43:00:00:07' masquerade: {} model: virtio name: default @@ -166,7 +166,7 @@ spec: terminationGracePeriodSeconds: 180 volumes: - dataVolume: - name: fedora-close-herring + name: fedora-close-carp name: rootdisk - cloudInitConfigDrive: userData: |- diff --git a/tests/e2e/sample-applications/virt-todo/vmroute.yaml b/tests/e2e/sample-applications/virt-todo/vmroute.yaml index cbda33644f5..3989f062a78 100644 --- a/tests/e2e/sample-applications/virt-todo/vmroute.yaml +++ b/tests/e2e/sample-applications/virt-todo/vmroute.yaml @@ -2,7 +2,7 @@ apiVersion: route.openshift.io/v1 kind: Route metadata: name: vmroute - namespace: openshift-virtualization-os-images + namespace: virttodo spec: #host: vmroute-openshift-virtualization-os-images.apps.cluster-wdh03122024metala.wdh03122024metala.mg.dog8code.com port: From 6fe8bb1bf87363f5ab7af9ce940e8c235cc427e7 Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Wed, 13 Mar 2024 14:36:57 -0600 Subject: [PATCH 3/8] add selinux set and relabel for todo service to start --- .../virtualmachine-fedora-close-carp.yaml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml index 4b4f6ef0a41..9f3aaf4d782 100644 --- a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml +++ b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml @@ -189,13 +189,16 @@ spec: - mysql -uroot -e "CREATE DATABASE todolist; USE todolist; CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" - mysql -uroot -e "grant all privileges on todolist.* to test@'localhost' identified by 'test'; FLUSH PRIVILEGES;" - pushd /home/test/ - - wget https://github.com/weshayutin/todolist-mariadb-go/releases/download/testing1/todolist-linux-amd64.zip + - wget https://github.com/weshayutin/todolist-mariadb-go/releases/download/testing3/todolist-linux-amd64.zip - unzip todolist-linux-amd64.zip - - cp systemd/todolist-mariadb.service /etc/systemd/user + - chown -R test:test /home/test + - semanage fcontext --add --type bin_t '/home/test/todolist-linux-amd64' + - restorecon -Fv /home/test/todolist-linux-amd64 + - cp systemd/todolist-mariadb.service /etc/systemd/system/ - popd - - systemctl --user daemon-reload - - systemctl --user start todolist-mariadb.service - - systemctl --user enable todolist-mariadb.service - - systemctl --user status todolist-mariadb.service + - systemctl daemon-reload + - systemctl start todolist-mariadb.service + - systemctl enable todolist-mariadb.service + - systemctl status todolist-mariadb.service - systemctl disable cloud-init name: cloudinitdisk From b5cc1949dee483bf333f57f57f40cdf15cce2a66 Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Wed, 13 Mar 2024 15:50:30 -0600 Subject: [PATCH 4/8] add more instructions --- .../e2e/sample-applications/virt-todo/README | 2 - .../sample-applications/virt-todo/README.MD | 37 ++++ .../virt-todo/namemspace-virttodo.yaml | 4 + .../e2e/sample-applications/virt-todo/test.py | 179 ++++++++++++++++++ .../virtualmachine-fedora-close-carp.yaml | 78 -------- 5 files changed, 220 insertions(+), 80 deletions(-) delete mode 100644 tests/e2e/sample-applications/virt-todo/README create mode 100644 tests/e2e/sample-applications/virt-todo/README.MD create mode 100644 tests/e2e/sample-applications/virt-todo/namemspace-virttodo.yaml create mode 100755 tests/e2e/sample-applications/virt-todo/test.py diff --git a/tests/e2e/sample-applications/virt-todo/README b/tests/e2e/sample-applications/virt-todo/README deleted file mode 100644 index 5a551d00b44..00000000000 --- a/tests/e2e/sample-applications/virt-todo/README +++ /dev/null @@ -1,2 +0,0 @@ -# check volumeMode -oc get pvc fedora-close-carp -o yaml -n virttodo | grep volumeMode diff --git a/tests/e2e/sample-applications/virt-todo/README.MD b/tests/e2e/sample-applications/virt-todo/README.MD new file mode 100644 index 00000000000..523acd1b837 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/README.MD @@ -0,0 +1,37 @@ +# To install +setup the openshift-virtualization operator + +# Start vm +`oc create -f namemspace-virttodo.yaml -f virtualmachine-fedora-close-carp.yaml -f service.yaml -f vmroute.yaml` + +# Check volumeMode +`oc get pvc fedora-close-carp -o yaml -n virttodo | grep volumeMode` + +# Wait for the cloud-init scripts to: +* install mariadb +* install and start the todolist app + +* login w/ test/dog8code +`tail -f /var/log/cloud-init-output.log` + +# Add data to the todolist +* get the route +* `oc get route -n virttodo` +* open browser to $route + * add data + +# Build out the test.py +* edit the test.py script, add the route prepended with http:// +`python test.py` + +# Backup vm +`oc create -f backup_virttodo.yaml` + +# Delete everything +`oc delete -f namemspace-virttodo.yaml -f virtualmachine-fedora-close-carp.yaml -f service.yaml -f vmroute.yaml` + +# Restore vm +`oc create -f restore_virttodo.yaml` + +# Check the data +* compare the data you entered prior to the backup with the current data diff --git a/tests/e2e/sample-applications/virt-todo/namemspace-virttodo.yaml b/tests/e2e/sample-applications/virt-todo/namemspace-virttodo.yaml new file mode 100644 index 00000000000..7a24a7a178b --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/namemspace-virttodo.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: virttodo diff --git a/tests/e2e/sample-applications/virt-todo/test.py b/tests/e2e/sample-applications/virt-todo/test.py new file mode 100755 index 00000000000..e6ccf9b2241 --- /dev/null +++ b/tests/e2e/sample-applications/virt-todo/test.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python +from datetime import datetime +import json +import requests + + +#base_url = "http://localhost:8000" +base_url = "http://vmroute-virttodo.apps.cluster-wdh03122024metala.wdh03122024metala.mg.dog8code.com" +# example remote +# base_url = "http://todolist-route-mysql-persistent.apps.cluster-wdh01102024g.wdh01102024g.mg.dog8code.com" + +def updateToDo(id, completed): + """Update data to the todo application + + Args: + item_dict: dict of todo item + completed: bool + + Returns: + {"updated": true/false} + """ + data = { + "id": id, + "completed": completed + } + + # Set the endpoint URL + endpoint = base_url + "/todo/" + str(id) + # Send a POST request with the data and the endpoint URL + response = requests.post(endpoint, data=data) + # Check the status code of the response + if response.status_code == 201 or response.status_code == 200: + print("Task updated successfully!") + return True + else: + print("Error updating task.") + return False + + +def createToDo(description, completed): + """Post data to the todo application + + Args: + description: todo list description + completed: bool + + Returns: + id of todo item in db + """ + data = { + "description": description, + "completed": completed + } + + # Set the endpoint URL + endpoint = base_url + "/todo" + # Send a POST request with the data and the endpoint URL + response = requests.post(endpoint, data=data) + # Check the status code of the response + if response.status_code == 201 or response.status_code == 200: + print("Task created successfully!") + else: + print("Error creating task.") + response_dict = json.loads(response.text)[0] + return response_dict + +def checkToDoLists(completed): + """Post data to the todo application + + Args: + completed: bool + + Returns: + json list + """ + # Set the endpoint URL + if completed: + endpoint = base_url + "/todo-completed" + else: + endpoint = base_url + "/todo-incomplete" + # Send a POST request with the data and the endpoint URL + response = requests.get(endpoint) + # Check the status code of the response + if response.status_code == 201 or response.status_code == 200: + print("Got list of items") + else: + print("Failed to get list of items") + response_dict = json.loads(response.text) + return response_dict + +def deleteToDoItems(item): + """Post data to the todo application + + Args: + item: dict + + Returns: + bool + """ + + endpoint = base_url + "/todo/" + str(item["Id"]) + # Send a POST request with the data and the endpoint URL + response = requests.delete(endpoint) + # Check the status code of the response + if response.status_code == 201 or response.status_code == 200: + print("Deleted item " + str(item["Id"])) + return True + else: + print("Failed to delete item " + str(item["Id"])) + return False + + + +def main(): + date = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') + # create todo items + test1 = createToDo("pytest-1-" + date, False) + test2 = createToDo("pytest-2-" + date, False) + test3 = createToDo("pytest-1-" + date, False) + + # update todo items + success = updateToDo(test1["Id"], True) + success = updateToDo(test2["Id"], True) + + # check todo's + completed = checkToDoLists(True) + incomplete = checkToDoLists(False) + print("COMPLETED ITEMS:") + print(completed) + print("INCOMPLETE ITEMS:") + print(incomplete) + + # test complete or incomplete + found_completed = False + for i in completed: + if test1["Description"] == i["Description"]: + found_completed = True + + found_incomplete = False + for i in incomplete: + if test3["Description"] == i["Description"]: + found_incomplete = True + + if found_completed == False or found_incomplete == False: + print("FAILED complete / incomplete TEST") + else: + print("SUCCESS!") + + # Delete items + deleteToDoItems(test1) + deleteToDoItems(test3) + completed = checkToDoLists(True) + incomplete = checkToDoLists(False) + print("COMPLETED ITEMS:") + print(completed) + print("INCOMPLETE ITEMS:") + print(incomplete) + + # Test deleted items + found_completed = False + for i in completed: + if test1["Description"] == i["Description"]: + found_completed = True + + found_incomplete = False + for i in incomplete: + if test3["Description"] == i["Description"]: + found_incomplete = True + + if found_completed == True or found_incomplete == True: + print("FAILED Delete TEST") + else: + print("SUCCESS!") + + + +if __name__ == "__main__": + main() + diff --git a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml index 9f3aaf4d782..3634a56ee0a 100644 --- a/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml +++ b/tests/e2e/sample-applications/virt-todo/virtualmachine-fedora-close-carp.yaml @@ -2,7 +2,6 @@ kind: VirtualMachine metadata: annotations: - kubemacpool.io/transaction-timestamp: '2024-03-12T19:47:37.178653544Z' vm.kubevirt.io/validations: | [ { @@ -13,91 +12,14 @@ metadata: "min": 1073741824 } ] - creationTimestamp: '2024-03-12T19:47:37Z' - generation: 1 labels: app: fedora-close-carp vm.kubevirt.io/template: fedora-server-small vm.kubevirt.io/template.namespace: openshift vm.kubevirt.io/template.revision: '1' vm.kubevirt.io/template.version: v0.26.0 - managedFields: - - apiVersion: kubevirt.io/v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:annotations': - .: {} - 'f:kubemacpool.io/transaction-timestamp': {} - 'f:vm.kubevirt.io/validations': {} - 'f:labels': - .: {} - 'f:app': {} - 'f:vm.kubevirt.io/template': {} - 'f:vm.kubevirt.io/template.namespace': {} - 'f:vm.kubevirt.io/template.revision': {} - 'f:vm.kubevirt.io/template.version': {} - 'f:spec': - .: {} - 'f:dataVolumeTemplates': {} - 'f:running': {} - 'f:template': - .: {} - 'f:metadata': - .: {} - 'f:annotations': - .: {} - 'f:vm.kubevirt.io/flavor': {} - 'f:vm.kubevirt.io/os': {} - 'f:vm.kubevirt.io/workload': {} - 'f:creationTimestamp': {} - 'f:labels': - .: {} - 'f:kubevirt.io/domain': {} - 'f:kubevirt.io/size': {} - 'f:spec': - .: {} - 'f:architecture': {} - 'f:domain': - .: {} - 'f:cpu': - .: {} - 'f:cores': {} - 'f:sockets': {} - 'f:threads': {} - 'f:devices': - .: {} - 'f:disks': {} - 'f:interfaces': {} - 'f:networkInterfaceMultiqueue': {} - 'f:rng': {} - 'f:features': - .: {} - 'f:acpi': {} - 'f:smm': - .: {} - 'f:enabled': {} - 'f:firmware': - .: {} - 'f:bootloader': - .: {} - 'f:efi': {} - 'f:machine': - .: {} - 'f:type': {} - 'f:memory': - .: {} - 'f:guest': {} - 'f:resources': {} - 'f:networks': {} - 'f:terminationGracePeriodSeconds': {} - 'f:volumes': {} - manager: kubectl-create - operation: Update - time: '2024-03-12T19:47:37Z' name: fedora-close-carp namespace: virttodo - uid: 26d098f2-7b20-42da-90d9-66bec57188f4 spec: dataVolumeTemplates: - apiVersion: cdi.kubevirt.io/v1beta1 From e0579246b6d9f156f31d95e232b499c02d5823ab Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Wed, 13 Mar 2024 15:52:14 -0600 Subject: [PATCH 5/8] add note --- tests/e2e/sample-applications/virt-todo/README.MD | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e/sample-applications/virt-todo/README.MD b/tests/e2e/sample-applications/virt-todo/README.MD index 523acd1b837..1752b39db10 100644 --- a/tests/e2e/sample-applications/virt-todo/README.MD +++ b/tests/e2e/sample-applications/virt-todo/README.MD @@ -1,3 +1,7 @@ +# notes: +Obviously there are improvements to this workflow, however this is meant to +serve as a template or example to fit into other working test frameworks. + # To install setup the openshift-virtualization operator From 6783dff2ee1cbef03923e6d13be76b6cc843cc9f Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Thu, 14 Mar 2024 13:55:37 -0600 Subject: [PATCH 6/8] fix from comments, thanks all! * add cli * fix doc strings --- .../sample-applications/virt-todo/README.MD | 11 +- .../e2e/sample-applications/virt-todo/test.py | 152 +++++++++--------- 2 files changed, 86 insertions(+), 77 deletions(-) diff --git a/tests/e2e/sample-applications/virt-todo/README.MD b/tests/e2e/sample-applications/virt-todo/README.MD index 1752b39db10..92c134e9113 100644 --- a/tests/e2e/sample-applications/virt-todo/README.MD +++ b/tests/e2e/sample-applications/virt-todo/README.MD @@ -26,7 +26,16 @@ setup the openshift-virtualization operator # Build out the test.py * edit the test.py script, add the route prepended with http:// -`python test.py` +`python test.py --base_url=$route` + +* alternatively you can use curl commands, for example: +``` +export date=`date "+%F-%T"` +curl -d "description=curl_todo_1_$date&completed=false" -X POST http://localhost:8000/todo +curl -d "description=curl_todo_2_$date&completed=false" -X POST http://localhost:8000/todo +curl -d "description=curl_todo_3_$date&completed=false" -X POST http://localhost:8000/todo +curl -d "id=1&completed=true" -X POST http://localhost:8000/todo/1 +``` # Backup vm `oc create -f backup_virttodo.yaml` diff --git a/tests/e2e/sample-applications/virt-todo/test.py b/tests/e2e/sample-applications/virt-todo/test.py index e6ccf9b2241..0d386031d67 100755 --- a/tests/e2e/sample-applications/virt-todo/test.py +++ b/tests/e2e/sample-applications/virt-todo/test.py @@ -1,15 +1,13 @@ #!/usr/bin/env python -from datetime import datetime + +import argparse import json import requests +from datetime import datetime -#base_url = "http://localhost:8000" -base_url = "http://vmroute-virttodo.apps.cluster-wdh03122024metala.wdh03122024metala.mg.dog8code.com" -# example remote -# base_url = "http://todolist-route-mysql-persistent.apps.cluster-wdh01102024g.wdh01102024g.mg.dog8code.com" -def updateToDo(id, completed): +def updateToDo(base_url, id, completed): """Update data to the todo application Args: @@ -17,12 +15,8 @@ def updateToDo(id, completed): completed: bool Returns: - {"updated": true/false} + bool """ - data = { - "id": id, - "completed": completed - } # Set the endpoint URL endpoint = base_url + "/todo/" + str(id) @@ -37,7 +31,7 @@ def updateToDo(id, completed): return False -def createToDo(description, completed): +def createToDo(base_url, description, completed): """Post data to the todo application Args: @@ -64,14 +58,14 @@ def createToDo(description, completed): response_dict = json.loads(response.text)[0] return response_dict -def checkToDoLists(completed): - """Post data to the todo application +def checkToDoLists(base_url, completed): + """Get data from the todo application Args: completed: bool Returns: - json list + json dict """ # Set the endpoint URL if completed: @@ -88,8 +82,8 @@ def checkToDoLists(completed): response_dict = json.loads(response.text) return response_dict -def deleteToDoItems(item): - """Post data to the todo application +def deleteToDoItems(base_url, item): + """Delete data from the todo application Args: item: dict @@ -109,68 +103,74 @@ def deleteToDoItems(item): print("Failed to delete item " + str(item["Id"])) return False - - def main(): - date = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') - # create todo items - test1 = createToDo("pytest-1-" + date, False) - test2 = createToDo("pytest-2-" + date, False) - test3 = createToDo("pytest-1-" + date, False) - - # update todo items - success = updateToDo(test1["Id"], True) - success = updateToDo(test2["Id"], True) - - # check todo's - completed = checkToDoLists(True) - incomplete = checkToDoLists(False) - print("COMPLETED ITEMS:") - print(completed) - print("INCOMPLETE ITEMS:") - print(incomplete) - - # test complete or incomplete - found_completed = False - for i in completed: - if test1["Description"] == i["Description"]: - found_completed = True - - found_incomplete = False - for i in incomplete: - if test3["Description"] == i["Description"]: - found_incomplete = True + parser = argparse.ArgumentParser(description='Process some integers.') + parser.add_argument('--base_url', dest='base_url', required=True, + help='The openshift route to the VM') + args = parser.parse_args() + print(args.base_url) + base_url = args.base_url + + + date = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') + # create todo items + test1 = createToDo(base_url, "pytest-1-" + date, False) + test2 = createToDo(base_url, "pytest-2-" + date, False) + test3 = createToDo(base_url, "pytest-1-" + date, False) + + # update todo items + success = updateToDo(base_url, test1["Id"], True) + success = updateToDo(base_url, test2["Id"], True) + + # check todo's + completed = checkToDoLists(base_url, True) + incomplete = checkToDoLists(base_url, False) + print("COMPLETED ITEMS:") + print(completed) + print("INCOMPLETE ITEMS:") + print(incomplete) + + # test complete or incomplete + found_completed = False + for i in completed: + if test1["Description"] == i["Description"]: + found_completed = True + + found_incomplete = False + for i in incomplete: + if test3["Description"] == i["Description"]: + found_incomplete = True - if found_completed == False or found_incomplete == False: - print("FAILED complete / incomplete TEST") - else: - print("SUCCESS!") - - # Delete items - deleteToDoItems(test1) - deleteToDoItems(test3) - completed = checkToDoLists(True) - incomplete = checkToDoLists(False) - print("COMPLETED ITEMS:") - print(completed) - print("INCOMPLETE ITEMS:") - print(incomplete) - - # Test deleted items - found_completed = False - for i in completed: - if test1["Description"] == i["Description"]: - found_completed = True - - found_incomplete = False - for i in incomplete: - if test3["Description"] == i["Description"]: - found_incomplete = True + if found_completed == False or found_incomplete == False: + print("FAILED complete / incomplete TEST") + else: + print("SUCCESS!") + + # Delete items + deleteToDoItems(base_url, test1) + deleteToDoItems(base_url, test3) + completed = checkToDoLists(base_url, True) + incomplete = checkToDoLists(base_url, False) + print("COMPLETED ITEMS:") + print(completed) + print("INCOMPLETE ITEMS:") + print(incomplete) + + # Test deleted items + found_completed = False + for i in completed: + if test1["Description"] == i["Description"]: + found_completed = True + + found_incomplete = False + for i in incomplete: + if test3["Description"] == i["Description"]: + found_incomplete = True - if found_completed == True or found_incomplete == True: - print("FAILED Delete TEST") - else: - print("SUCCESS!") + if found_completed == True or found_incomplete == True: + print("FAILED Delete TEST") + else: + print("SUCCESS!") From f58280d53f32c7171dfd01ae9e749b28b9a2db4c Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Thu, 14 Mar 2024 13:59:09 -0600 Subject: [PATCH 7/8] ensure the populate data section makes sense --- tests/e2e/sample-applications/virt-todo/README.MD | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/e2e/sample-applications/virt-todo/README.MD b/tests/e2e/sample-applications/virt-todo/README.MD index 92c134e9113..f3e1d65586c 100644 --- a/tests/e2e/sample-applications/virt-todo/README.MD +++ b/tests/e2e/sample-applications/virt-todo/README.MD @@ -24,8 +24,7 @@ setup the openshift-virtualization operator * open browser to $route * add data -# Build out the test.py -* edit the test.py script, add the route prepended with http:// +* alternatively, use the python test.py script to populate data. `python test.py --base_url=$route` * alternatively you can use curl commands, for example: From f58de547cc3eebf7c4cc84b6326d57662850e8a9 Mon Sep 17 00:00:00 2001 From: Wesley Hayutin Date: Thu, 14 Mar 2024 14:04:55 -0600 Subject: [PATCH 8/8] accidently remove data dict --- tests/e2e/sample-applications/virt-todo/test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e/sample-applications/virt-todo/test.py b/tests/e2e/sample-applications/virt-todo/test.py index 0d386031d67..9b381e2ed9e 100755 --- a/tests/e2e/sample-applications/virt-todo/test.py +++ b/tests/e2e/sample-applications/virt-todo/test.py @@ -17,6 +17,10 @@ def updateToDo(base_url, id, completed): Returns: bool """ + data = { + "id": id, + "completed": completed + } # Set the endpoint URL endpoint = base_url + "/todo/" + str(id)