File: snapshot.bats

package info (click to toggle)
golang-github-vmware-govmomi 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,848 kB
  • sloc: sh: 2,285; lisp: 1,560; ruby: 948; xml: 139; makefile: 54
file content (129 lines) | stat: -rwxr-xr-x 2,794 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bats

load test_helper

test_vm_snapshot() {
  vm=$1
  id=$(new_id)

  # No snapshots == no output
  run govc snapshot.tree -vm "$vm"
  assert_success ""

  run govc snapshot.remove -vm "$vm" '*'
  assert_success

  run govc snapshot.revert -vm "$vm"
  assert_failure

  run govc snapshot.create -vm "$vm" "$id"
  assert_success

  run govc snapshot.revert -vm "$vm" enoent
  assert_failure

  run govc snapshot.revert -vm "$vm"
  assert_success

  run govc snapshot.remove -vm "$vm" "$id"
  assert_success

  run govc snapshot.create -vm "$vm" root
  assert_success

  run govc snapshot.tree -C -vm "$vm"
  assert_success "root"

  run govc snapshot.create -vm "$vm" child
  assert_success

  run govc snapshot.tree -C -vm "$vm"
  assert_success "child"

  run govc snapshot.create -vm "$vm" grand
  assert_success

  run govc snapshot.create -vm "$vm" child
  assert_success

  result=$(govc snapshot.tree -vm "$vm" -f | grep -c root/child/grand/child)
  [ "$result" -eq 1 ]

  run govc snapshot.revert -vm "$vm" root
  assert_success

  run govc snapshot.create -vm "$vm" child
  assert_success

  # 3 snapshots named "child"
  result=$(govc snapshot.tree -vm "$vm" | grep -c child)
  [ "$result" -eq 3 ]

  run govc snapshot.remove -vm "$vm" child
  assert_failure

  # 2 snapshots with path "root/child"
  result=$(govc snapshot.tree -vm "$vm" -f | egrep -c 'root/child$')
  [ "$result" -eq 2 ]

  run govc snapshot.remove -vm "$vm" root/child
  assert_failure

  # path is unique
  run govc snapshot.remove -vm "$vm" root/child/grand/child
  assert_success

  # set current to grand
  run govc snapshot.revert -vm "$vm" grand

  # name is unique
  run govc snapshot.remove -vm "$vm" grand
  assert_success

  result=$(govc snapshot.tree -vm "$vm" -f | grep root/child/grand/child | wc -l)
  [ "$result" -eq 0 ]

  # current given to parent of previous current
  result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
  [ "$result" -eq 1 ]

  id=$(govc snapshot.tree -vm "$vm" -f -i | egrep 'root/child$' | head -n1 | awk '{print $1}' | tr -d '[]')
  # moid is unique
  run govc snapshot.remove -vm "$vm" "$id"
  assert_success

  # now root/child is unique
  run govc snapshot.remove -vm "$vm" root/child
  assert_success

  run govc snapshot.remove -vm "$vm" root
  assert_success

  # current is removed
  result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
  [ "$result" -eq 0 ]

  # new root
  run govc snapshot.create -vm "$vm" 2ndroot
  assert_success

  # new snapshot 2ndroot is current
  result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
  [ "$result" -eq 1 ]
}

@test "vm.snapshot vcsim" {
  vcsim_env

  vm=$(new_empty_vm)

  test_vm_snapshot $vm
}

@test "vm.snapshot" {
  esx_env

  vm=$(new_ttylinux_vm)

  test_vm_snapshot $vm
}