-
Notifications
You must be signed in to change notification settings - Fork 90
OADP-2982: Add a sample / example of a VM backup and restore that works with default openshift-virtualization #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19b153d
first pass at todo vm and service / route
weshayutin 8b4479d
tested blockmode b/r
weshayutin 6fe8bb1
add selinux set and relabel for todo service to start
weshayutin b5cc194
add more instructions
weshayutin e057924
add note
weshayutin 6783dff
fix from comments, thanks all!
weshayutin f58280d
ensure the populate data section makes sense
weshayutin f58de54
accidently remove data dict
weshayutin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # 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 | ||
|
|
||
| # Start vm | ||
| `oc create -f namemspace-virttodo.yaml -f virtualmachine-fedora-close-carp.yaml -f service.yaml -f vmroute.yaml` | ||
|
weshayutin marked this conversation as resolved.
|
||
|
|
||
| # 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 | ||
|
|
||
| * alternatively, use the python test.py script to populate data. | ||
| `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` | ||
|
|
||
| # 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 | ||
12 changes: 12 additions & 0 deletions
12
tests/e2e/sample-applications/virt-todo/backup_virttodo.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
4 changes: 4 additions & 0 deletions
4
tests/e2e/sample-applications/virt-todo/namemspace-virttodo.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: virttodo |
8 changes: 8 additions & 0 deletions
8
tests/e2e/sample-applications/virt-todo/restore_virttodo.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: vm-service | ||
| namespace: virttodo | ||
| spec: | ||
| selector: | ||
| special: key | ||
| ports: | ||
| - name: todoport | ||
| port: 8000 | ||
| targetPort: 8000 | ||
| type: NodePort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env python | ||
|
weshayutin marked this conversation as resolved.
|
||
|
|
||
| import argparse | ||
| import json | ||
| import requests | ||
|
|
||
| from datetime import datetime | ||
|
|
||
|
|
||
| def updateToDo(base_url, id, completed): | ||
| """Update data to the todo application | ||
|
|
||
| Args: | ||
| item_dict: dict of todo item | ||
| completed: bool | ||
|
|
||
| Returns: | ||
|
weshayutin marked this conversation as resolved.
|
||
| bool | ||
| """ | ||
| 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(base_url, 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(base_url, completed): | ||
| """Get data from the todo application | ||
|
|
||
| Args: | ||
| completed: bool | ||
|
|
||
| Returns: | ||
| json dict | ||
| """ | ||
| # 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(base_url, item): | ||
| """Delete data from 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(): | ||
| 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(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 __name__ == "__main__": | ||
| main() | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.