From: Francisco Manuel Garcia Botella Date: Thu, 6 Jun 2024 11:36:28 +0000 (+0200) Subject: regress: Add more k8s tests X-Git-Tag: Release-15.0.3~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dcd09648ab3d41e7bf24e1715d7796ae4cbd1a2;p=thirdparty%2Fbacula.git regress: Add more k8s tests --- diff --git a/regress/scripts/kubernetes/kubernetes-plugin-test-0003-bacula-dir.conf.in b/regress/scripts/kubernetes/kubernetes-plugin-test-0003-bacula-dir.conf.in new file mode 100644 index 000000000..e453d0e24 --- /dev/null +++ b/regress/scripts/kubernetes/kubernetes-plugin-test-0003-bacula-dir.conf.in @@ -0,0 +1,148 @@ +# +# Kubernetes Plugin Bacula Director Configuration file +# Target: Test the feature where avoid pvcs which are in status `Terminating`. +# + +Director { # define myself + Name = @hostname@-dir + DIRPort = @dirport@ # where we listen for UA connections + QueryFile = "@scriptdir@/query.sql" + WorkingDirectory = "@working_dir@" + PidDirectory = "@piddir@" + SubSysDirectory = "@subsysdir@" + Maximum Concurrent Jobs = 1 + Password = "pNvX1WiXnwv2C/F7E52LGvw6rKjbbPvu2kyuPa9pVaL3" # Console password + Messages = Standard +} + +JobDefs { + Name = "BackupJob" + Type = Backup + Pool = Default + Storage = File + Messages = Standard + Priority = 10 + Client=@hostname@-fd + Write Bootstrap = "@working_dir@/%n-%f.bsr" +} + +JobDefs { + Name = "Default" + Type = Backup + Client=@hostname@-fd + Level = Full + Storage = File1 + Messages = Standard + Write Bootstrap = "@working_dir@/%c.bsr" + Pool = Default + SpoolData = yes + Max Run Time = 30min +} + +# List of files to be backed up +FileSet { + Name = "Full Set" + Include { Options { signature=SHA1 } + File =<@tmpdir@/file-list + } +} + +# Client (File Services) to backup +Client { + Name = @hostname@-fd + Address = @hostname@ + FDPort = @fdport@ + Catalog = MyCatalog + Password = "xevrjURYoCHhn26RaJoWbeWXEY/a3VqGKp/37tgWiuHc" # password for FileDaemon + File Retention = 30d # 30 days + Job Retention = 180d # six months + AutoPrune = yes # Prune expired Jobs/Files +} + +# Definiton of file storage device +Storage { + Name = File + Address = @hostname@ # N.B. Use a fully qualified name here + SDPort = @sdport@ + Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9" + Device = FileStorage + Media Type = File +} + +# Definiton of file storage device +Storage { + Name = File1 + Address = @hostname@ # N.B. Use a fully qualified name here + SDPort = @sdport@ + Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9" + Device = FileStorage1 + Media Type = File1 +} + +# Standard Restore template, to be changed by Console program +Job { + Name = "RestoreFiles" + Type = Restore + Client=@hostname@-fd + FileSet="Full Set" + Storage = File1 + Messages = Standard + Pool = Default + Where = @tmpdir@/bacula-restores + Max Run Time = 30min +} + +# Generic catalog service +Catalog { + Name = MyCatalog + @libdbi@ + dbname = @db_name@; user = @db_user@; password = "@db_password@" +} + +# Reasonable message delivery -- send most everything to email address +# and to the console +Messages { + Name = Standard + mailcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: %t %e of %c %l\" %r" + operatorcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: Intervention needed for %j\" %r" +# MailOnError = @job_email@ = all, !terminate +# operator = @job_email@ = mount + console = all + + append = "@working_dir@/log" = all, !skipped + catalog = all, !skipped +} + +Messages { + Name = NoEmail + mailcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: %t %e of %c %l\" %r" + console = all, !skipped, !terminate, !restored + append = "@working_dir@/log" = all, !skipped + catalog = all, !skipped +} + + +# Default pool definition +Pool { + Name = Default + Pool Type = Backup + Recycle = yes # Bacula can automatically recycle Volumes + AutoPrune = yes # Prune expired volumes + Volume Retention = 365d # one year +} + + +### Specific configuration to kubernetes tests + +#### 01 Test - Backup PostgreSQL containers with their data. +FileSet { + Name = "Test-K8S-Set-0003-1" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=standard pvcdata=@PVC_N1_0003_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0003-1" + JobDefs = Default + FileSet = Test-K8S-Set-0003-1 +} \ No newline at end of file diff --git a/regress/scripts/kubernetes/kubernetes-plugin-test-0003.yaml b/regress/scripts/kubernetes/kubernetes-plugin-test-0003.yaml new file mode 100644 index 000000000..ce92a2e71 --- /dev/null +++ b/regress/scripts/kubernetes/kubernetes-plugin-test-0003.yaml @@ -0,0 +1,58 @@ +# testing-ns-0003: Config file to test the backup with postgresql pods + +apiVersion: v1 +kind: Namespace +metadata: + name: testing-ns-0003-1 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: testing-ns-0003-1 + name: test-secret-0003-1 + labels: + app: postgres +data: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0003-1 + namespace: testing-ns-0003-1 + labels: + app: postgres +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: local-path +--- +apiVersion: v1 +kind: Pod +metadata: + namespace: testing-ns-0003-1 + name: test-pod-0003-1 + labels: + app: postgres +spec: + volumes: + - name: pvc-dc7cdd05-a92d-416a-b584-fd7043b5bf68 + persistentVolumeClaim: + claimName: test-pvc-0003-1 + containers: + - name: test-postgres-container + image: 'postgres:14' + imagePullPolicy: IfNotPresent + ports: + - containerPort: 5432 + envFrom: + - configMapRef: + name: test-secret-0003-1 + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: pvc-dc7cdd05-a92d-416a-b584-fd7043b5bf68 \ No newline at end of file diff --git a/regress/scripts/kubernetes/kubernetes-plugin-test-0004-bacula-dir.conf.in b/regress/scripts/kubernetes/kubernetes-plugin-test-0004-bacula-dir.conf.in new file mode 100644 index 000000000..7782c0058 --- /dev/null +++ b/regress/scripts/kubernetes/kubernetes-plugin-test-0004-bacula-dir.conf.in @@ -0,0 +1,305 @@ +# +# Kubernetes Plugin Bacula Director Configuration file +# Target: Test the feature where avoid pvcs which are in status `Terminating`. +# + +Director { # define myself + Name = @hostname@-dir + DIRPort = @dirport@ # where we listen for UA connections + QueryFile = "@scriptdir@/query.sql" + WorkingDirectory = "@working_dir@" + PidDirectory = "@piddir@" + SubSysDirectory = "@subsysdir@" + Maximum Concurrent Jobs = 1 + Password = "pNvX1WiXnwv2C/F7E52LGvw6rKjbbPvu2kyuPa9pVaL3" # Console password + Messages = Standard +} + +JobDefs { + Name = "BackupJob" + Type = Backup + Pool = Default + Storage = File + Messages = Standard + Priority = 10 + Client=@hostname@-fd + Write Bootstrap = "@working_dir@/%n-%f.bsr" +} + +JobDefs { + Name = "Default" + Type = Backup + Client=@hostname@-fd + Level = Full + Storage = File1 + Messages = Standard + Write Bootstrap = "@working_dir@/%c.bsr" + Pool = Default + SpoolData = yes + Max Run Time = 30min +} + +# List of files to be backed up +FileSet { + Name = "Full Set" + Include { Options { signature=SHA1 } + File =<@tmpdir@/file-list + } +} + +# Client (File Services) to backup +Client { + Name = @hostname@-fd + Address = @hostname@ + FDPort = @fdport@ + Catalog = MyCatalog + Password = "xevrjURYoCHhn26RaJoWbeWXEY/a3VqGKp/37tgWiuHc" # password for FileDaemon + File Retention = 30d # 30 days + Job Retention = 180d # six months + AutoPrune = yes # Prune expired Jobs/Files +} + +# Definiton of file storage device +Storage { + Name = File + Address = @hostname@ # N.B. Use a fully qualified name here + SDPort = @sdport@ + Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9" + Device = FileStorage + Media Type = File +} + +# Definiton of file storage device +Storage { + Name = File1 + Address = @hostname@ # N.B. Use a fully qualified name here + SDPort = @sdport@ + Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9" + Device = FileStorage1 + Media Type = File1 +} + +# Standard Restore template, to be changed by Console program +Job { + Name = "RestoreFiles" + Type = Restore + Client=@hostname@-fd + FileSet="Full Set" + Storage = File1 + Messages = Standard + Pool = Default + Where = @tmpdir@/bacula-restores + Max Run Time = 30min +} + +# Generic catalog service +Catalog { + Name = MyCatalog + @libdbi@ + dbname = @db_name@; user = @db_user@; password = "@db_password@" +} + +# Reasonable message delivery -- send most everything to email address +# and to the console +Messages { + Name = Standard + mailcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: %t %e of %c %l\" %r" + operatorcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: Intervention needed for %j\" %r" +# MailOnError = @job_email@ = all, !terminate +# operator = @job_email@ = mount + console = all + + append = "@working_dir@/log" = all, !skipped + catalog = all, !skipped +} + +Messages { + Name = NoEmail + mailcommand = "@sbindir@/bsmtp -h localhost -f \"\(Bacula regression\) %r\" -s \"Regression: %t %e of %c %l\" %r" + console = all, !skipped, !terminate, !restored + append = "@working_dir@/log" = all, !skipped + catalog = all, !skipped +} + + +# Default pool definition +Pool { + Name = Default + Pool Type = Backup + Recycle = yes # Bacula can automatically recycle Volumes + AutoPrune = yes # Prune expired volumes + Volume Retention = 365d # one year +} + + +### Specific configuration to kubernetes tests + +### B01 One compatible pvc with specific backup mode: snapshot +FileSet { + Name = "Test-K8S-Set-0004-1" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_5@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-1" + JobDefs = Default + FileSet = Test-K8S-Set-0004-1 +} + +### B02 Two compatible pvc with specific backup mode: snapshot +FileSet { + Name = "Test-K8S-Set-0004-2" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_5@,@PVC_N1_0004_6@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-2" + JobDefs = Default + FileSet = Test-K8S-Set-0004-2 +} + +### B03 One compatible pvc with specific backup mode: clone +FileSet { + Name = "Test-K8S-Set-0004-3" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=clone pvcdata=@PVC_N1_0004_5@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-3" + JobDefs = Default + FileSet = Test-K8S-Set-0004-3 +} + +### B04 Two compatible pvcs with specific backup mode: clone +FileSet { + Name = "Test-K8S-Set-0004-4" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=clone pvcdata=@PVC_N1_0004_5@,@PVC_N1_0004_6@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-4" + JobDefs = Default + FileSet = Test-K8S-Set-0004-4 +} + +### B05 One pvc with specific backup mode: standard +FileSet { + Name = "Test-K8S-Set-0004-5" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=standard pvcdata=@PVC_N1_0004_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-5" + JobDefs = Default + FileSet = Test-K8S-Set-0004-5 +} + +### B06 Two pvcs with specific backup mode: standard +FileSet { + Name = "Test-K8S-Set-0004-6" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=standard pvcdata=@PVC_N1_0004_1@,@PVC_N1_0004_3@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-6" + JobDefs = Default + FileSet = Test-K8S-Set-0004-6 +} + +### B07 One no-compatible pvc with specific backup mode: snapshot +FileSet { + Name = "Test-K8S-Set-0004-7" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-7" + JobDefs = Default + FileSet = Test-K8S-Set-0004-7 +} + +### B08 One no-compatible pvc with specific backup mode: clone +FileSet { + Name = "Test-K8S-Set-0004-8" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=clone pvcdata=@PVC_N1_0004_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-8" + JobDefs = Default + FileSet = Test-K8S-Set-0004-8 +} + +### B09 Two pvc (one compatible and other not) with specific backup mode: snapshot +FileSet { + Name = "Test-K8S-Set-0004-9" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_5@,@PVC_N1_0004_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-9" + JobDefs = Default + FileSet = Test-K8S-Set-0004-9 +} + +### B10 Two pvc (one no-compatible and other yes) with specific backup mode: snapshot +FileSet { + Name = "Test-K8S-Set-0004-10" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_1@,@PVC_N1_0004_5@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-10" + JobDefs = Default + FileSet = Test-K8S-Set-0004-10 +} + +### B11 Two pvc (one compatible and other not) with specific backup mode: clone +FileSet { + Name = "Test-K8S-Set-0004-11" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=clone pvcdata=@PVC_N1_0004_5@,@PVC_N1_0004_1@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-11" + JobDefs = Default + FileSet = Test-K8S-Set-0004-11 +} + +### B12 Two pvc (one no-compatible and other yes) with specific backup mode: clone + +FileSet { + Name = "Test-K8S-Set-0004-12" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=clone pvcdata=@PVC_N1_0004_1@,@PVC_N1_0004_5@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-12" + JobDefs = Default + FileSet = Test-K8S-Set-0004-12 +} + +### B13 One pod with two attached pvcs +FileSet { + Name = "Test-K8S-Set-0004-13" + Include { Options { signature=SHA1 } + Plugin = "@LPLUG@ backup_mode=snapshot pvcdata=@PVC_N1_0004_7@,@PVC_N1_0004_8@ namespace=@K8S_NAMESPACE_1@" + } +} +Job { + Name = "Test-K8S-0004-13" + JobDefs = Default + FileSet = Test-K8S-Set-0004-13 +} \ No newline at end of file diff --git a/regress/scripts/kubernetes/kubernetes-plugin-test-0004.yaml b/regress/scripts/kubernetes/kubernetes-plugin-test-0004.yaml new file mode 100644 index 000000000..c01aa5617 --- /dev/null +++ b/regress/scripts/kubernetes/kubernetes-plugin-test-0004.yaml @@ -0,0 +1,289 @@ +# testing-ns-0004: Config file to test the backup with postgresql pods + +apiVersion: v1 +kind: Namespace +metadata: + name: testing-ns-0004-1 +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: nfs-client +parameters: + archiveOnDelete: "false" +provisioner: k8s-sigs.io/nfs-subdir-external-provisioner +reclaimPolicy: Delete +volumeBindingMode: Immediate +--- +allowVolumeExpansion: true +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"rook-ceph-block"},"parameters":{"clusterID":"rook-ceph","csi.storage.k8s.io/controller-expand-secret-name":"rook-csi-rbd-provisioner","csi.storage.k8s.io/controller-expand-secret-namespace":"rook-ceph","csi.storage.k8s.io/fstype":"ext4","csi.storage.k8s.io/node-stage-secret-name":"rook-csi-rbd-node","csi.storage.k8s.io/node-stage-secret-namespace":"rook-ceph","csi.storage.k8s.io/provisioner-secret-name":"rook-csi-rbd-provisioner","csi.storage.k8s.io/provisioner-secret-namespace":"rook-ceph","imageFeatures":"layering","imageFormat":"2","pool":"replicapool"},"provisioner":"rook-ceph.rbd.csi.ceph.com","reclaimPolicy":"Delete","volumeBindingMode":"Immediate"} + name: rook-ceph-block +parameters: + clusterID: rook-ceph + csi.storage.k8s.io/controller-expand-secret-name: rook-csi-rbd-provisioner + csi.storage.k8s.io/controller-expand-secret-namespace: rook-ceph + csi.storage.k8s.io/fstype: ext4 + csi.storage.k8s.io/node-stage-secret-name: rook-csi-rbd-node + csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph + csi.storage.k8s.io/provisioner-secret-name: rook-csi-rbd-provisioner + csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph + imageFeatures: layering + imageFormat: "2" + pool: replicapool +provisioner: rook-ceph.rbd.csi.ceph.com +reclaimPolicy: Delete +volumeBindingMode: Immediate +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-1 + namespace: testing-ns-0004-1 +spec: + storageClassName: local-path + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-2 + namespace: testing-ns-0004-1 +spec: + storageClassName: local-path + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-3 + namespace: testing-ns-0004-1 +spec: + storageClassName: nfs-client + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-4 + namespace: testing-ns-0004-1 +spec: + storageClassName: nfs-client + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-5 + namespace: testing-ns-0004-1 +spec: + storageClassName: rook-ceph-block + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-6 + namespace: testing-ns-0004-1 +spec: + storageClassName: rook-ceph-block + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-7 + namespace: testing-ns-0004-1 +spec: + storageClassName: rook-ceph-block + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc-0004-8 + namespace: testing-ns-0004-1 +spec: + storageClassName: rook-ceph-block + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-1 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-1 + persistentVolumeClaim: + claimName: test-pvc-0004-1 + containers: + - name: test-container-0004-2 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-1 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-2 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-2 + persistentVolumeClaim: + claimName: test-pvc-0004-2 + containers: + - name: test-container-0004-2 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-2 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-3 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-3 + persistentVolumeClaim: + claimName: test-pvc-0004-3 + containers: + - name: test-container-0004-3 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-3 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-4 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-4 + persistentVolumeClaim: + claimName: test-pvc-0004-4 + containers: + - name: test-container-0004-4 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-4 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-5 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-5 + persistentVolumeClaim: + claimName: test-pvc-0004-5 + containers: + - name: test-container-0004-5 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-5 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-6 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-6 + persistentVolumeClaim: + claimName: test-pvc-0004-6 + containers: + - name: test-container-0004-6 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-6 +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-pod-0004-7 + namespace: testing-ns-0004-1 +spec: + volumes: + - name: pvc-0004-7 + persistentVolumeClaim: + claimName: test-pvc-0004-7 + - name: pvc-0004-8 + persistentVolumeClaim: + claimName: test-pvc-0004-8 + containers: + - name: test-container-0004-7 + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/pvc" + name: pvc-0004-7 + - mountPath: "/pvc2" + name: pvc-0004-8 \ No newline at end of file diff --git a/regress/scripts/regress-utils.sh b/regress/scripts/regress-utils.sh index a3e46827b..f3d08ff93 100755 --- a/regress/scripts/regress-utils.sh +++ b/regress/scripts/regress-utils.sh @@ -31,7 +31,7 @@ setup_plugin_param() LPLUG=$1 if [ "x$debug" != "x" ] then - LPLUG="$LPLUG debug=1" + LPLUG="$LPLUG debug=$debug" fi export LPLUG } @@ -72,12 +72,12 @@ setup_self_signed_cert() # regress_test_result() { -if [ $1 -ne 0 ] -then - echo "failed" -else - echo "ok" -fi + if [ $1 -ne 0 ] + then + echo "failed" + else + echo "ok" + fi } # diff --git a/regress/tests/kubernetes/k8s-utils.sh b/regress/tests/kubernetes/k8s-utils.sh index 572057771..cf4b02283 100644 --- a/regress/tests/kubernetes/k8s-utils.sh +++ b/regress/tests/kubernetes/k8s-utils.sh @@ -56,4 +56,31 @@ end_set_up_k8s_annotations() { # Remove annotation in pod. ${KUBECTL} annotate pod ${POD_WITH_ANNOTATIONS} ${BACKUP_MODE_ANN}- > /dev/null ${KUBECTL} annotate pod ${POD_WITH_ANNOTATIONS} ${BACKUP_VOL_ANN}- > /dev/null +} + +wait_until_pod_run() { + NAMESPACE=$1 + POD=$2 + i=0 + SPIN=('-' '\\' '|' '/') + printf "\n ... Waiting to pod is running ... \n" + sleep 3 + while true + do + kstat=`${KUBECTL} -n ${NAMESPACE} get pods ${POD} | grep "Running" | wc -l` + if [ $kstat -eq 1 ] + then + break + fi; + w=1 + printf "\b${SPIN[(($i % 4))]}" + if [ $i -eq 60 ] + then + echo "Timeout waiting for pod is running. Cannot continue!" + exit 1 + fi + ((i++)) + sleep 1 + done + sleep 3 } \ No newline at end of file diff --git a/regress/tests/kubernetes/kubernetes-plugin-tests-0001 b/regress/tests/kubernetes/kubernetes-plugin-tests-0001 index e7b006981..5ab71da45 100755 --- a/regress/tests/kubernetes/kubernetes-plugin-tests-0001 +++ b/regress/tests/kubernetes/kubernetes-plugin-tests-0001 @@ -89,10 +89,10 @@ fi if [ ! -z "$KUBE_BACULA_IMAGE" ] then - CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} " + CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} imagepullpolicy=ifNotPresent " fi -export debug=1 +export debug=2 scripts/cleanup scripts/copy-kubernetes-plugin-confs ${TEST_ID} @@ -222,6 +222,11 @@ sed -i -f ${out_sed} ${conf}/bacula-dir.conf printf "\n ... Done ...\n" +## Variables to restore from other jobs +JOB_ID_TO_RESTORE_1=0 +JOB_ID_TO_RESTORE_2=0 + + start_test # We must put the bconsole command in ${cwd}/tmp/bconcmds @@ -349,6 +354,7 @@ btest1 () { # Test 1 TEST=1 OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_1=${JOBID} do_regress_backup_test ${TEST} check_regress_backup_statusT ${TEST} F=$? @@ -396,6 +402,7 @@ btest2 () { # Test 2 TEST=2 OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_2=${JOBID} do_regress_backup_test ${TEST} check_regress_backup_statusT ${TEST} F=$? @@ -538,7 +545,8 @@ btest5 () { # Test 5 TEST=5 OUTPUT_FILE=${tmp}/blog${TEST}.out - kstat=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc ${PVC_N1_0001_1} | grep -v Terminating | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc ${PVC_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}-k8s.out + kstat=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc | grep ${PVC_N1_0001_1} | grep -v Terminating | wc -l` do_regress_backup_test ${TEST} check_regress_backup_statusT ${TEST} F=$? @@ -588,7 +596,7 @@ btest6 () { TEST=6 OUTPUT_FILE=${tmp}/blog${TEST}.out do_regress_backup_test ${TEST} - check_regress_backup_statusW ${TEST} + check_regress_backup_statusT ${TEST} F=$? # Check pvc1 is not backup F_1=0 @@ -601,9 +609,9 @@ btest6 () { fi # Check warning in job log F_2=0 - RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | grep "${PVC_N1_0001_1}" | grep "standard mode" | wc -l` + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | grep "standard mode" | wc -l` RES=1 - RET2='grep "As clone backup is empty" ${OUTPUT_FILE} | grep "${PVC_N1_0001_1}" | grep "standard mode" | wc -l' + RET2=`grep "As clone backup is empty" ${OUTPUT_FILE} | grep "standard mode" | wc -l` printf "%s\n%s\n%s\n" "+++++++++++++++++++" "Results: ${RET}" "Command:${RET2}" if [ $RET -ne $RES ] then @@ -620,24 +628,146 @@ btest6 () { } + +############# +## RTEST 1 ## +############# +rtest1 () { + TEST=1 + if [ "${JOB_ID_TO_RESTORE_1}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0001_1}) and pod (${POD_N1_0001_1})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0001_1}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0001_1}.yaml" + "mark ${PVC_N1_0001_1}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_1} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0001_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + F_1=0 F_2=0 + rets=($RET $RET_1) + fs=("F_1" "F_2") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0001_1} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0001_1} was restored: " $(regress_test_result ${F_2}) + printf "%s\n" "--------" +} + + +############# +## RTEST 2 ## +############# +rtest2 () { + TEST=2 + if [ "${JOB_ID_TO_RESTORE_2}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the ns:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get secrets 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get service 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get configmap 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the namespace:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} delete namespace ${K8S_NAMESPACE_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the namespace (${K8S_NAMESPACE_1})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/" + "mark ${K8S_NAMESPACE_1}" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_2} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0001_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_2} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0001_2} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0001_1} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0001_1} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0001_2} was restored: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + estat=0 -etest1 -etest2 +# etest1 +# etest2 bstat=0 JOBID=1 # This job is the base of all backup jobs names JobName=${JobNameBase}- -btest1 -btest2 -btest3 -btest4 + +# btest1 +# btest2 +# btest3 +# btest4 btest5-pre btest5 btest5-post btest6 +# rtest1 +# rtest2 -stop_bacula +# stop_bacula end_test \ No newline at end of file diff --git a/regress/tests/kubernetes/kubernetes-plugin-tests-0002 b/regress/tests/kubernetes/kubernetes-plugin-tests-0002 index f33b3b45e..f493d2e8f 100755 --- a/regress/tests/kubernetes/kubernetes-plugin-tests-0002 +++ b/regress/tests/kubernetes/kubernetes-plugin-tests-0002 @@ -60,10 +60,10 @@ fi if [ ! -z "$KUBE_BACULA_IMAGE" ] then - CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} " + CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} imagepullpolicy=ifNotPresent " fi -export debug=1 +export debug=2 scripts/cleanup scripts/copy-kubernetes-plugin-confs ${TEST_ID} @@ -178,44 +178,6 @@ END_OF_DATA run_bacula -############# -## ETEST 1 ## -############# -etest1 () { - TEST=1 - OUTPUT_FILE=${tmp}/elog${TEST}.out - JobName=${JobNameBase}-${TEST} - # special case for all objects - do_regress_estimate_test ${TEST} - F_1=0 - RET=`grep "${K8S_NAMESPACE_1}" ${OUTPUT_FILE} | grep "yaml" | wc -l` - # (ns 1) + (configmap 1) + (serviceaccount 1) + (pvc 2) + (pods 2) - RES=5 - echo "RET: $RET RES: $RES" >> ${OUTPUT_FILE} - if [ $RET -le $RES ] - then - F_1=1 - ((estat++)) - fi - - # Check if exists ingress folder - F_2=0 - RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "/ingress/" | wc -l` - RES=1 - if [ $RET -ne $RES ] - then - F_2=1 - ((estat++)) - fi - - printf "%s\n" "--------" - printf "Results estimate test ${TEST}:\n" - printf "%s%s\n" " -> Estimated all objects: " $(regress_test_result ${F_1}) - printf "%s%s\n" " -> Estimated included ingress objects: " $(regress_test_result ${F_2}) - printf "%s\n" "--------" -} - - ############# ## BTEST 1 ## ############# diff --git a/regress/tests/kubernetes/kubernetes-plugin-tests-0003 b/regress/tests/kubernetes/kubernetes-plugin-tests-0003 new file mode 100755 index 000000000..e5ecf5e69 --- /dev/null +++ b/regress/tests/kubernetes/kubernetes-plugin-tests-0003 @@ -0,0 +1,328 @@ +#!/bin/bash +# +# Copyright (C) 2000-2015 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# + +# +# Attempt to backup and restore kubernetes where contains postgresql pods +# +# +# Assumes: +# - You have a working K8S cluster avaialable +# - You can create storage class with any local-storage provider + +# +# The k8s cluster status: + +# $ kubectl apply -f scripts/kubernetes/kubernetes-plugin-test-0003.yaml +# namespace/testing-ns-0003-1 created +# configmap/test-secret-0003-1 created +# persistentvolumeclaim/test-pvc-0003-1 created +# pod/test-pod-0003-1 created +# +# +# +# $ kubectl -n testing-ns-0003-1 get pods -o wide +# NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +# test-pod-0003-1 1/1 Running 0 58m 10.85.2.50 am-u20-k8s-worker03-bck +# +# $ kubectl -n testing-ns-0003-1 get pvc -o wide +# NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE +# test-pvc-0003-1 Bound pvc-cf505dcc-46e9-448f-b403-33c66a4cd91f 1Gi RWO local-path 58m Filesystem + +TEST_ID=0003 +TestName="kubernetes-plugin-test-${TEST_ID}" +JobNameBase="Test-K8S-${TEST_ID}" +FileSetName="Test-K8S-Set-${TEST_ID}-" + +# Variables in tests +K8S_SCRIPT_YAML_FILE="scripts/kubernetes/kubernetes-plugin-test-${TEST_ID}.yaml" +K8S_NAMESPACE_1="testing-ns-0003-1" +K8S_NAMESPACE_2="testing namespace in progress" +PVC_N1_0003_1="test-pvc-0003-1" +# PVC_N1_0003_2="test-pvc-0003-2" +# PVC_N2_0003_3="test-pvc-0003-3" +POD_N1_0003_1="test-pod-0003-1" +# POD_N1_0003_2="test-pod-0003-2" +# POD_N2_0003_3="test-pod-0003-3" +PVC_PATH_IN_POD="/var/lib/postgresql/data" + +POD_N1_0003_1_TABLE="test_table" + +. scripts/functions +. scripts/regress-utils.sh + +. tests/kubernetes/k8s-utils.sh + +printf "\nInit test: ${TestName}\n" + +CONNECTION_ARGS="" +if [ ! -z $KUBE_FD_CERT_FILE ] +then + setup_self_signed_cert $KUBE_FD_CERT_DIR $KUBE_FD_CERT_NAME + CONNECTION_ARGS=" fdkeyfile=$KUBE_FD_KEY_FILE fdcertfile=$KUBE_FD_CERT_FILE " +fi + +if [ ! -z "$KUBE_PROXY_POD_PLUGIN_HOST" ] +then + CONNECTION_ARGS="${CONNECTION_ARGS} pluginhost=${KUBE_PROXY_POD_PLUGIN_HOST} " +fi + +if [ ! -z "$KUBE_BACULA_IMAGE" ] +then + CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} imagepullpolicy=ifNotPresent " +fi + +export debug=2 +scripts/cleanup +scripts/copy-kubernetes-plugin-confs ${TEST_ID} + +printf "\n ... Preparing ...\n" + +# export requires variables +setup_plugin_param "kubernetes:" +if [ "x$KUBECONFIG" != "x" ] +then + export KUBECONFIG + LPLUG="${LPLUG} config='$KUBECONFIG' ${CONNECTION_ARGS}" +fi + +KSTORAGECLASS=`${KUBECTL} get storageclass | grep local | wc -l` +if [ $KSTORAGECLASS -eq 0 ] +then + echo "Do you need a local storage class. It is to simplify the errors!" + exit 1 +fi + +tmp="${tmp}/test-${TEST_ID}" + +mkdir -p ${tmp} + +# check the requirements +KNODES=`${KUBECTL} get nodes | grep Ready | wc -l` +if [ $KNODES -eq 0 ] +then + echo "A working Kubernetes cluster required!" + exit 1 +fi + +# check if K8S_NAMESPACE_1 or K8S_NAMESPACE_2 exist +KPLUGTEST_1=`${KUBECTL} get ns | grep "^${K8S_NAMESPACE_1} " | wc -l` +# KPLUGTEST_2=`${KUBECTL} get ns | grep "^${K8S_NAMESPACE_2} " | wc -l` +if [ $KPLUGTEST_1 -ne 0 ] && [ "x$1" != "xforce" ]; +then + echo "Namespace \"${K8S_NAMESPACE_1}\" exist on cluster and no force option specified!" + exit 1 +fi +# if [ $KPLUGTEST_2 -ne 0 ] && [ "x$1" != "xforce" ]; +# then +# echo "Namespace \"${K8S_NAMESPACE_2}\" exist on cluster and no force option specified!" +# exit 1 +# fi + + +# prepare data +printf "\n ... Apply data ... \n" +reset_k8s_env() { + if [ $KPLUGTEST_1 -ne 0 ] + then + printf "Removing namespaces: ${K8S_NAMESPACE_1} and ${K8S_NAMESPACE_2}\n" + ${KUBECTL} delete ns ${K8S_NAMESPACE_1} 2>&1 > ${tmp}/kube.log + # ${KUBECTL} delete ns ${K8S_NAMESPACE_2} 2>&1 >> ${tmp}/kube.log + printf "Removed namespaces: ${K8S_NAMESPACE_1} and ${K8S_NAMESPACE_2}\n" + fi + ${KUBECTL} apply -f ${K8S_SCRIPT_YAML_FILE} 2>&1 >> ${tmp}/kube.log + + i=0 + SPIN=('-' '\\' '|' '/') + printf "\n ... Waiting to ready ... \n" + while true + do + # TODO: Check also the pods in namespace_2 are running + kstat=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pods -o go-template='{{range .items}}{{.status.phase}}{{"\n"}}{{end}}' | grep -v Running | wc -l` + if [ $kstat -eq 0 ] + then + break + fi; + w=1 + printf "\b${SPIN[(($i % 4))]}" + if [ $i -eq 600 ] + then + echo "Timeout waiting for test data to populate. Cannot continue!" + exit 1 + fi + ((i++)) + sleep 1 + done + sleep 10 # Wait to ready pods + + # Command to create a file inside pvc + printf "\n ... Refill data in pvcs ...\n" + SIZE_MB=10 + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + # Exec command inside pod to create a random file + ${KUBECTL} exec -it $POD_N1_0003_1 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + # Exec command to create table and insert values in database + printf "\n ... Inserting values in database ... \n" + printf "... Command executed ... \n" + echo "${KUBECTL} exec -ti $POD_N1_0003_1 -n ${K8S_NAMESPACE_1} -- env PGPASSWORD=postgres psql -h localhost -U postgres postgres -c \"CREATE TABLE IF NOT EXISTS ${POD_N1_0003_1_TABLE} (id INT, name VARCHAR(255)); INSERT INTO test_table(id,name) VALUES (1, 'value1'), (2, 'value2'), (3, 'value3');\"" + printf "\n" + ${KUBECTL} exec -ti $POD_N1_0003_1 -n ${K8S_NAMESPACE_1} -- env PGPASSWORD=postgres psql -h localhost -U postgres postgres -c "CREATE TABLE IF NOT EXISTS ${POD_N1_0003_1_TABLE} (id INT, name VARCHAR(255)); INSERT INTO test_table(id,name) VALUES (1, 'value1'), (2, 'value2'), (3, 'value3');" +} + +reset_k8s_env + + +# wait a bit to objects to populate. +sleep 3 + + +# get variables +printf "\n ... Get Environment Variables ...\n" +${KUBECTL} get ns -o name > ${tmp}/allns.log +${KUBECTL} get pv -o name > ${tmp}/allpv.log + + +# Prepare bacula dir configuration +printf "\n ... Preparing Bacula-dir configuration ...\n" +export PLUGIN_WORKING=${cwd}/working + +out_sed="${tmp}/sed_tmp" +echo "s%@LPLUG@%${LPLUG}%" > ${out_sed} +echo "s%@K8S_NAMESPACE_1@%${K8S_NAMESPACE_1}%" >> ${out_sed} +echo "s%@K8S_NAMESPACE_2@%${K8S_NAMESPACE_2}%" >> ${out_sed} +echo "s%@PVC_N1_0003_1@%${PVC_N1_0003_1}%" >> ${out_sed} +echo "s%@PVC_N1_0003_2@%${PVC_N1_0003_2}%" >> ${out_sed} +echo "s%@PVC_N2_0003_3@%${PVC_N2_0003_3}%" >> ${out_sed} + +echo "s%@CONNECTION_ARGS@%${CONNECTION_ARGS}%" >> ${out_sed} +echo "s%@BACKUP_PROXY_WITHOUT_PVC@%${BACKUP_PROXY_WITHOUT_PVC}%" >> ${out_sed} +echo "s%@BACKUP_ONLY_PVC@%${BACKUP_ONLY_PVC}%" >> ${out_sed} +printf "\nCommand launched:\n" +echo "sed -i -f ${out_sed} ${conf}/bacula-dir.conf" + +sed -i -f ${out_sed} ${conf}/bacula-dir.conf + +printf "\n ... Done ...\n" + +## Variables to restore from other jobs +JOB_ID_TO_RESTORE_1=0 +JOB_ID_TO_RESTORE_2=0 + + +start_test + +# We must put the bconsole command in ${cwd}/tmp/bconcmds +cat <${tmp}/bconcmds +@output /dev/null +messages +@$out ${tmp}/log.out +label storage=File1 pool=Default volume=TestVolume001 +@setdebug dir level=500 trace=1 +quit +END_OF_DATA + +run_bacula + + +############# +## BTEST 1 ## +############# +btest1 () { + # Test 1 + TEST=1 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_1=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc1 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0003_1}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0003_1}' is backup once: " $(regress_test_result ${F_1}) + printf "%s\n" "--------" +} + + + +############# +## RTEST 1 ## +############# +rtest1 () { + TEST=1 + if [ "${JOB_ID_TO_RESTORE_1}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0003_1}) and pod (${POD_N1_0003_1})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "mark *" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_1} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + sleep 5 + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0003_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0003_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0003_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} exec -ti $POD_N1_0003_1 -n ${K8S_NAMESPACE_1} -- timeout 10 env PGPASSWORD=postgres psql -h localhost -U postgres postgres -c "SELECT * FROM test_table;" 2>&1 > ${tmp}/rlog${TEST}-sql.out + RET_2=`grep "value1" ${tmp}/rlog${TEST}-sql.out | wc -l` + + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0003_1} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0003_1} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The database data of postgres was restored correctly: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + +estat=0 + +bstat=0 +JOBID=1 +# This job is the base of all backup jobs names +JobName=${JobNameBase}- + +btest1 + +rtest1 + +# stop_bacula +end_test \ No newline at end of file diff --git a/regress/tests/kubernetes/kubernetes-plugin-tests-0004 b/regress/tests/kubernetes/kubernetes-plugin-tests-0004 new file mode 100755 index 000000000..95367a0a9 --- /dev/null +++ b/regress/tests/kubernetes/kubernetes-plugin-tests-0004 @@ -0,0 +1,1837 @@ +#!/bin/bash +# +# Copyright (C) 2000-2015 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# + +# +# Attempt to backup and restore using vsnapshots +# +# Assumes: +# - You have a working K8S cluster avaialable +# - You can create storage class with any csi-storage provider +# - The storageclass must be named rook-ceph-block + +# +# The k8s cluster status: + +# $ kubectl apply -f scripts/kubernetes/kubernetes-plugin-test-0004.yaml +# namespace/testing-ns-0004-1 created +# storageclass.storage.k8s.io/local-storage unchanged +# persistentvolumeclaim/test-persistent-volume-claim-0004 created +# pod/test-pod-0004 created + + +# $ kubectl -n testing-ns-0004-1 get pods -o wide +# NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +# test-pod-0004 1/1 Running 0 4m59s 10.85.0.124 am-u20-k8s-worker02-bck + +# $ kubectl -n testing-ns-0004-1 get pvc -o wide +# NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE +# test-persistent-volume-claim-0004 Bound pvc-e4b2c7b7-2679-494c-af61-8e1cac026c4d 1Gi RWO local-path 5m29s Filesystem + +# $ kubectl -n testing-ns-0004-1 get svc -o wide +# No resources found in testing-ns-0004-1 namespace. + +# $ kubectl -n testing-ns-0004-1 get rs -o wide +# No resources found in testing-ns-0004-1 namespace. + +# $ kubectl -n testing-ns-0004-1 get sts -o wide +# No resources found in testing-ns-0004-1 namespace. + +# $ kubectl -n testing-ns-0004-1 get storageclass -o wide +# NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE +# csi-hostpath-sc hostpath.csi.k8s.io Delete Immediate true 16d +# local-path rancher.io/local-path Delete WaitForFirstConsumer false 21d +# local-st-waitforconsumer rancher.io/local-path Delete WaitForFirstConsumer false 25h +# local-storage kubernetes.io/no-provisioner Delete WaitForFirstConsumer false 21d +# nfs-client k8s-sigs.io/nfs-subdir-external-provisioner Delete Immediate false 271d +# rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 257d + + + +# $ kubectl -n testing-ns-0004-1 get volumesnapshotclasses -o wide +# NAME DRIVER DELETIONPOLICY AGE +# csi-rbdplugin-snapclass rook-ceph.rbd.csi.ceph.com Delete 235d + +TEST_ID=0004 +TestName="kubernetes-plugin-test-${TEST_ID}" +JobNameBase="Test-K8S-${TEST_ID}" +FileSetName="Test-K8S-Set-${TEST_ID}-" + +# Variables in tests +K8S_SCRIPT_YAML_FILE="scripts/kubernetes/kubernetes-plugin-test-${TEST_ID}.yaml" +K8S_NAMESPACE_1="testing-ns-0004-1" +PVC_N1_0004_1="test-pvc-0004-1" +PVC_N1_0004_2="test-pvc-0004-2" +PVC_N1_0004_3="test-pvc-0004-3" +PVC_N1_0004_4="test-pvc-0004-4" +PVC_N1_0004_5="test-pvc-0004-5" +PVC_N1_0004_6="test-pvc-0004-6" +PVC_N1_0004_7="test-pvc-0004-7" +PVC_N1_0004_8="test-pvc-0004-8" +POD_N1_0004_1="test-pod-0004-1" +POD_N1_0004_2="test-pod-0004-2" +POD_N1_0004_3="test-pod-0004-3" +POD_N1_0004_4="test-pod-0004-4" +POD_N1_0004_5="test-pod-0004-5" +POD_N1_0004_6="test-pod-0004-6" +POD_N1_0004_7="test-pod-0004-7" +PVC_PATH_IN_POD="/pvc" + +. scripts/functions +. scripts/regress-utils.sh + +. tests/kubernetes/k8s-utils.sh + +printf "\nInit test: ${TestName}\n" + +CONNECTION_ARGS="" +if [ ! -z $KUBE_FD_CERT_FILE ] +then + setup_self_signed_cert $KUBE_FD_CERT_DIR $KUBE_FD_CERT_NAME + CONNECTION_ARGS=" fdkeyfile=$KUBE_FD_KEY_FILE fdcertfile=$KUBE_FD_CERT_FILE " +fi + +if [ ! -z "$KUBE_PROXY_POD_PLUGIN_HOST" ] +then + CONNECTION_ARGS="${CONNECTION_ARGS} pluginhost=${KUBE_PROXY_POD_PLUGIN_HOST} " +fi + +if [ ! -z "$KUBE_BACULA_IMAGE" ] +then + CONNECTION_ARGS="${CONNECTION_ARGS} baculaimage=${KUBE_BACULA_IMAGE} imagepullpolicy=ifNotPresent " +fi + +export debug=2 +scripts/cleanup +scripts/copy-kubernetes-plugin-confs ${TEST_ID} + +printf "\n ... Preparing ...\n" + +# export requires variables +setup_plugin_param "kubernetes:" +if [ "x$KUBECONFIG" != "x" ] +then + export KUBECONFIG + LPLUG="${LPLUG} config='$KUBECONFIG' ${CONNECTION_ARGS}" +fi + +KSTORAGECLASS=`${KUBECTL} get storageclass | grep local | wc -l` +if [ $KSTORAGECLASS -eq 0 ] +then + echo "Do you need a local storage class. It is to simplify the errors!" + exit 1 +fi + +tmp="${tmp}/test-${TEST_ID}" + +mkdir -p ${tmp} + +# check the requirements +KNODES=`${KUBECTL} get nodes | grep Ready | wc -l` +if [ $KNODES -eq 0 ] +then + echo "A working Kubernetes cluster required!" + exit 1 +fi + +# check if K8S_NAMESPACE_1 exist +KPLUGTEST_1=`${KUBECTL} get ns | grep "^${K8S_NAMESPACE_1} " | wc -l` +if [ $KPLUGTEST_1 -ne 0 ] && [ "x$1" != "xforce" ]; +then + echo "Namespace \"${K8S_NAMESPACE_1}\" exist on cluster and no force option specified!" + exit 1 +fi + + +# prepare data +printf "\n ... Apply data ... \n" +reset_k8s_env() { + if [ $KPLUGTEST_1 -ne 0 ] + then + printf "Removing namespaces: ${K8S_NAMESPACE_1}\n" + ${KUBECTL} delete ns ${K8S_NAMESPACE_1} 2>&1 > ${tmp}/kube.log + printf "Removed namespaces: ${K8S_NAMESPACE_1}\n" + fi + ${KUBECTL} apply -f ${K8S_SCRIPT_YAML_FILE} 2>&1 >> ${tmp}/kube.log + + i=0 + SPIN=('-' '\\' '|' '/') + printf "\n ... Waiting to ready ... \n" + while true + do + # TODO: Check also the pods in namespace_2 are running + kstat=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pods -o go-template='{{range .items}}{{.status.phase}}{{"\n"}}{{end}}' | grep -v Running | wc -l` + if [ $kstat -eq 0 ] + then + break + fi; + w=1 + printf "\b${SPIN[(($i % 4))]}" + if [ $i -eq 600 ] + then + echo "Timeout waiting for test data to populate. Cannot continue!" + exit 1 + fi + ((i++)) + sleep 1 + done + sleep 3 + # Command to create a file inside pvc + printf "\n ... Refill data in pvcs ...\n" + SIZE_MB=10 + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + # Exec command inside pod. + ${KUBECTL} exec -it $POD_N1_0004_1 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_2 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_3 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_4 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_5 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_6 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + # Add files inside pod with two pvcs + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_7 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + SIZE_MB=$(( ${SIZE_MB} + 10 )) + DD_CMD="dd if=/dev/urandom of=${PVC_PATH_IN_POD}2/file${SIZE_MB}MB bs=1M count=${SIZE_MB}" + ${KUBECTL} exec -it $POD_N1_0004_7 -n ${K8S_NAMESPACE_1} -- /bin/bash -c "$DD_CMD" + # +} + +reset_k8s_env + + +# wait a bit to objects to populate. +sleep 10 + + +# get variables +printf "\n ... Get Environment Variables ...\n" +${KUBECTL} get ns -o name > ${tmp}/allns.log +${KUBECTL} get pv -o name > ${tmp}/allpv.log + + +# Prepare bacula dir configuration +printf "\n ... Preparing Bacula-dir configuration ...\n" +export PLUGIN_WORKING=${cwd}/working + +out_sed="${tmp}/sed_tmp" +echo "s%@LPLUG@%${LPLUG}%" > ${out_sed} +echo "s%@K8S_NAMESPACE_1@%${K8S_NAMESPACE_1}%" >> ${out_sed} +echo "s%@PVC_N1_0004_1@%${PVC_N1_0004_1}%" >> ${out_sed} +echo "s%@PVC_N1_0004_2@%${PVC_N1_0004_2}%" >> ${out_sed} +echo "s%@PVC_N1_0004_3@%${PVC_N1_0004_3}%" >> ${out_sed} +echo "s%@PVC_N1_0004_4@%${PVC_N1_0004_4}%" >> ${out_sed} +echo "s%@PVC_N1_0004_5@%${PVC_N1_0004_5}%" >> ${out_sed} +echo "s%@PVC_N1_0004_6@%${PVC_N1_0004_6}%" >> ${out_sed} +echo "s%@PVC_N1_0004_7@%${PVC_N1_0004_7}%" >> ${out_sed} +echo "s%@PVC_N1_0004_8@%${PVC_N1_0004_8}%" >> ${out_sed} + +echo "s%@CONNECTION_ARGS@%${CONNECTION_ARGS}%" >> ${out_sed} +echo "s%@BACKUP_PROXY_WITHOUT_PVC@%${BACKUP_PROXY_WITHOUT_PVC}%" >> ${out_sed} +echo "s%@BACKUP_ONLY_PVC@%${BACKUP_ONLY_PVC}%" >> ${out_sed} +printf "\nCommand launched:\n" +echo "sed -i -f ${out_sed} ${conf}/bacula-dir.conf" + +sed -i -f ${out_sed} ${conf}/bacula-dir.conf + +printf "\n ... Done ...\n" + +## Variables to restore from other jobs +JOB_ID_TO_RESTORE_1=0 +JOB_ID_TO_RESTORE_2=0 +JOB_ID_TO_RESTORE_3=0 +JOB_ID_TO_RESTORE_4=0 +JOB_ID_TO_RESTORE_5=0 + +start_test + +# We must put the bconsole command in ${cwd}/tmp/bconcmds +cat <${tmp}/bconcmds +@output /dev/null +messages +@$out ${tmp}/log.out +label storage=File1 pool=Default volume=TestVolume001 +@setdebug dir level=500 trace=1 +quit +END_OF_DATA + +run_bacula + + +############# +## BTEST 1 ## +############# +btest1 () { + # Test 1 + TEST=1 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_1=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_4=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot technology + F_5=0 + RET=`grep "is compatible with volume snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup + F_6=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is compatible with snapshot mode: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with snapshot mode: " $(regress_test_result ${F_6}) + printf "%s\n" "--------" +} + + +############# +## BTEST 2 ## +############# +btest2 () { + # Test 2 + TEST=2 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc6 data is backup + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_6}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot technology + F_6=0 + RET=`grep "is compatible with volume snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot technology + F_7=0 + RET=`grep "is compatible with volume snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_6}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_8=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_9=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_6}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_6}' is backup: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is compatible with snapshot mode: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_6}' is compatible with snapshot mode: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with snapshot mode: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_6}' is backup with snapshot mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + + +############# +## BTEST 3 ## +############# +btest3 () { + # Test 3 + TEST=3 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_2=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check if selected backup mode is clone + F_4=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "clone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_5=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The backup mode selected is clone: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with clone mode: " $(regress_test_result ${F_5}) + printf "%s\n" "--------" +} + + +############# +## BTEST 4 ## +############# +btest4 () { + # Test 4 + TEST=4 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc6 data is backup + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_6}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is clone + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "clone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_6=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_7=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_6}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_6}' is backup: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is clone: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with clone mode: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_6}' is backup with clone mode: " $(regress_test_result ${F_7}) + printf "%s\n" "--------" +} + + +############# +## BTEST 5 ## +############# +btest5 () { + # Test 5 + TEST=5 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_3=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc1 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check if selected backup mode is standard + F_4=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "standard" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected pvc is backup with standard + F_5=0 + RET=`grep "will be backup with standard mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The backup mode selected is standard: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is backup with standard mode: " $(regress_test_result ${F_5}) + printf "%s\n" "--------" +} + + +############# +## BTEST 6 ## +############# +btest6 () { + # Test 6 + TEST=6 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc1 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc3 data is backup + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_3}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is standard + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "standard" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with standard + F_6=0 + RET=`grep "will be backup with standard mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with standard + F_7=0 + RET=`grep "will be backup with standard mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_3}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_3}' is backup: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is standard: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is backup with standard mode: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_3}' is backup with standard mode: " $(regress_test_result ${F_7}) + printf "%s\n" "--------" +} + + +############# +## BTEST 7 ## +############# +btest7 () { + # Test 7 + TEST=7 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_4=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_4=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if is pvc is not compatible with snapshot + F_5=0 + RET=`grep "is not compatible with snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_6=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup(two files): " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode snapshot: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is backup with clone mode: " $(regress_test_result ${F_6}) + printf "%s\n" "--------" +} + + +############# +## BTEST 8 ## +############# +btest8 () { + # Test 8 + TEST=8 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check if selected backup mode is clone + F_4=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "clone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if pvc is not compatible with clone + F_5=0 + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_6=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup(two files): " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The backup mode selected is clone: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode clone: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is backup with clone mode: " $(regress_test_result ${F_6}) + printf "%s\n" "--------" +} + + +############# +## BTEST 9 ## +############# +btest9 () { + # Test 9 + TEST=9 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_6=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_7=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if pvc is not compatible with clone + F_8=0 + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_9=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup (two files): " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' try to backup mode snapshot: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode snapshot and try clone: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode clone: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with snapshot mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + + +############## +## BTEST 10 ## +############## +btest10 () { + # Test 10 + TEST=10 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc1 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_6=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_7=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if pvc is not compatible with clone + F_8=0 + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_9=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup (two files): " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' try to backup mode snapshot: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode snapshot and try clone: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode clone: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with snapshot mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + + +############## +## BTEST 11 ## +############## +btest11 () { + # Test 11 + TEST=11 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc5 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is clone + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "clone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_6=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if pvc is not compatible with clone + F_7=0 + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_8=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_9=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup(two files): " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is clone: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' try to backup mode clone: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode clone: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' will be backup with clone mode: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with clone mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + + +############## +## BTEST 12 ## +############## +btest12 () { + # Test 12 + TEST=12 + OUTPUT_FILE=${tmp}/blog${TEST}.out + do_regress_backup_test ${TEST} + check_regress_backup_statusW ${TEST} + F=$? + # Check pvc1 is backup twice (because detect that clone is empty and retry with standard) + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}.tar" | wc -l` + RES=2 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc5 data is backup + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is clone + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "clone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_6=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_1}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if pvc is not compatible with clone + F_7=0 + RET=`grep "As clone backup is empty" ${OUTPUT_FILE} | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_8=0 + RET=`grep "will be backup with clone mode" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with clone + F_9=0 + RET=`grep "Prepare clone" ${OUTPUT_FILE} | grep "${PVC_N1_0004_5}-baculaclone" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusW: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_1}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_5}' is backup: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is clone: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' try to backup mode clone: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_1}' is not compatible with backup mode clone: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' will be backup with clone mode: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_5}' is backup with clone mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + +############## +## BTEST 13 ## +############## +btest13 () { + # Test 13 + TEST=13 + OUTPUT_FILE=${tmp}/blog${TEST}.out + JOB_ID_TO_RESTORE_5=${JOBID} + do_regress_backup_test ${TEST} + check_regress_backup_statusT ${TEST} + F=$? + # Check pvc7 is backup once + F_1=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_7}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_1=1 + ((bstat++)) + fi + + # Check pvc2 data is not backup + F_2=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.tar" | wc -l` + RES=0 + if [ $RET -ne $RES ] + then + F_2=1 + ((bstat++)) + fi + # Check pvc2 yaml is backup + F_3=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_2}.yaml" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_3=1 + ((bstat++)) + fi + # Check pvc8 is backup once + F_4=0 + RET=`grep "@kubernetes" ${OUTPUT_FILE} | grep "${PVC_N1_0004_8}.tar" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_4=1 + ((bstat++)) + fi + # Check if selected backup mode is snapshot + F_5=0 + RET=`grep "selected default backup mode" ${OUTPUT_FILE} | grep "snapshot" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_5=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot technology + F_6=0 + RET=`grep "is compatible with volume snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_7}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_6=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot technology + F_7=0 + RET=`grep "is compatible with volume snapshot backup" ${OUTPUT_FILE} | grep "${PVC_N1_0004_8}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_7=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_8=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_7}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_8=1 + ((bstat++)) + fi + # Check if selected pvc is backup with snapshot + F_9=0 + RET=`grep "will be backup with snapshot mode" ${OUTPUT_FILE} | grep "bacula-pvcfs-${PVC_N1_0004_8}" | wc -l` + RES=1 + if [ $RET -ne $RES ] + then + F_9=1 + ((bstat++)) + fi + printf "\n%s\n" "--------" + printf "Results backup test ${TEST}:\n" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_7}' is backup: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_2}' will not backup: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc yaml of '${PVC_N1_0004_2}' is backup: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The pvc data of '${PVC_N1_0004_8}' is backup: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The backup mode selected is snapshot: " $(regress_test_result ${F_5}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_7}' is compatible with snapshot mode: " $(regress_test_result ${F_6}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_8}' is compatible with snapshot mode: " $(regress_test_result ${F_7}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_7}' is backup with snapshot mode: " $(regress_test_result ${F_8}) + printf "%s%s\n" " -> The pvc '${PVC_N1_0004_8}' is backup with snapshot mode: " $(regress_test_result ${F_9}) + printf "%s\n" "--------" +} + + +############# +## RTEST 1 ## +############# +rtest1 () { + TEST=1 + if [ "${JOB_ID_TO_RESTORE_1}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0004_5}) and pod (${POD_N1_0004_5})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0004_5}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0004_5}.yaml" + "mark ${PVC_N1_0004_5}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_1} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + wait_until_pod_run ${K8S_NAMESPACE_1} ${POD_N1_0004_5} + + echo "---> Check size of restored file:" 2>&1 >> ${tmp}/rlog${TEST}.out + FILE_SIZE=50 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_5} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_5} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0004_5} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_5} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_5} takes up 50M: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + + + +############# +## RTEST 2 ## +############# +rtest2 () { + TEST=2 + if [ "${JOB_ID_TO_RESTORE_2}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0004_5}) and pod (${POD_N1_0004_5})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0004_5}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0004_5}.yaml" + "mark ${PVC_N1_0004_5}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_2} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_5} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_5} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + wait_until_pod_run ${K8S_NAMESPACE_1} ${POD_N1_0004_5} + + echo "---> Check size of restored file:" 2>&1 >> ${tmp}/rlog${TEST}.out + FILE_SIZE=50 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_5} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_5} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0004_5} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_5} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_5} takes up 50M: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + + +############# +## RTEST 3 ## +############# +rtest3 () { + TEST=3 + if [ "${JOB_ID_TO_RESTORE_3}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0004_1}) and pod (${POD_N1_0004_1})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0004_1}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0004_1}.yaml" + "mark ${PVC_N1_0004_1}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_3} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + wait_until_pod_run ${K8S_NAMESPACE_1} ${POD_N1_0004_1} + + echo "---> Check size of restored file:" 2>&1 >> ${tmp}/rlog${TEST}.out + FILE_SIZE=10 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_1} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_1} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0004_1} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_1} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_1} takes up 10M: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + +############# +## RTEST 4 ## +############# +rtest4 () { + TEST=4 + if [ "${JOB_ID_TO_RESTORE_4}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvc(${PVC_N1_0004_1}) and pod (${POD_N1_0004_1})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0004_1}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0004_1}.yaml" + "mark ${PVC_N1_0004_1}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_4} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_1} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + wait_until_pod_run ${K8S_NAMESPACE_1} ${POD_N1_0004_1} + + echo "---> Check size of restored file:" 2>&1 >> ${tmp}/rlog${TEST}.out + FILE_SIZE=10 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_1} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_1} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + + F_1=0 F_2=0 F_3=0 + rets=($RET $RET_1 $RET_2) + fs=("F_1" "F_2" "F_3") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0004_1} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_1} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_1} takes up 10M: " $(regress_test_result ${F_3}) + printf "%s\n" "--------" +} + + +############# +## RTEST 5 ## +############# +rtest5 () { + TEST=5 + if [ "${JOB_ID_TO_RESTORE_5}" -eq 0 ]; then + printf "%s\n" "--------------" + printf "%s\n" "The job id to restore ${TEST} was not assigned." + printf "%s\n" "--------------" + exit 1 + fi + # Before delete + echo "---> Before delete the pvc:" 2>&1 > ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_8} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleting the pvc and pod:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pod/${POD_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} delete pvc/${PVC_N1_0004_8} 2>&1 >> ${tmp}/rlog${TEST}.out + echo "---> Deleted the pvcs(${PVC_N1_0004_7}, ${PVC_N1_0004_8}) and pod (${POD_N1_0004_7})" 2>&1 >> ${tmp}/rlog${TEST}.out + actions=( + "" # Always starts with empty line. I don't know why is neccesary. + "cd @kubernetes/namespaces/${K8S_NAMESPACE_1}/pods/" + "mark ${POD_N1_0004_7}.yaml" + "cd ../persistentvolumeclaims/" + "mark ${PVC_N1_0004_7}.yaml" + "mark ${PVC_N1_0004_7}.tar" + "mark ${PVC_N1_0004_8}.yaml" + "mark ${PVC_N1_0004_8}.tar" + ) + do_regress_restore_test_jobid ${TEST} ${JOB_ID_TO_RESTORE_5} "/" $actions + check_regress_restore_statusT ${TEST} + F=$? + # check if object restored on kubernetes + + echo "---> After restore the pod and pvc:" 2>&1 >> ${tmp}/rlog${TEST}.out + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + RET=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pod/${POD_N1_0004_7} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_7} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_1=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_7} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + ${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_8} 2>&1 >> ${tmp}/rlog${TEST}.out + RET_2=`${KUBECTL} -n ${K8S_NAMESPACE_1} get pvc/${PVC_N1_0004_8} -o go-template='{{.metadata.name}}{{"\n"}}' 2>/dev/null | wc -l` + + wait_until_pod_run ${K8S_NAMESPACE_1} ${POD_N1_0004_7} + + echo "---> Check size of restored file:" 2>&1 >> ${tmp}/rlog${TEST}.out + FILE_SIZE=70 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_7} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_3=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_7} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + FILE_SIZE=80 + ${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_7} -- du -hls /pvc/file${FILE_SIZE}MB 2>&1 >> ${tmp}/rlog${TEST}.out + RET_4=`${KUBECTL} -n ${K8S_NAMESPACE_1} exec -it ${POD_N1_0004_7} -- du -hls /pvc/file${FILE_SIZE}MB | grep "${FILE_SIZE}M" | wc -l` + F_1=0 F_2=0 F_3=0 F_4=0 F_5=0 + rets=($RET $RET_1 $RET_2 $RET_3 $RET_4) + fs=("F_1" "F_2" "F_3" "F_4" "F_5") + + for i in ${!rets[@]}; do + echo "RET: ${rets[i]}" >> ${tmp}/rlog${TEST}.out + if [ ${rets[i]} -ne 1 ]; then + eval ${fs[i]}=1 + dstat=$((dstat+1)) + fi + done + + printf "\n%s\n" "--------" + printf "Result restore test ${TEST}:" + printf "%s%s\n" " -> StatusT: " $(regress_test_result ${F}) + printf "%s%s\n" " -> The pod ${POD_N1_0004_7} was restored: " $(regress_test_result ${F_1}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_7} was restored: " $(regress_test_result ${F_2}) + printf "%s%s\n" " -> The pvc ${PVC_N1_0004_8} was restored: " $(regress_test_result ${F_3}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_7} takes up 70M: " $(regress_test_result ${F_4}) + printf "%s%s\n" " -> The restored file in ${PVC_N1_0004_8} takes up 80M: " $(regress_test_result ${F_5}) + printf "%s\n" "--------" +} + +estat=0 + +bstat=0 +JOBID=1 +# This job is the base of all backup jobs names +JobName=${JobNameBase}- + +btest1 +btest2 +btest3 +btest4 +btest5 +btest6 +btest7 +btest8 +btest9 +btest10 +btest11 +btest12 +btest13 + +dstat=0 +rtest1 +rtest2 +rtest3 +rtest4 +rtest5 + +# stop_bacula +end_test \ No newline at end of file