github.com/vmware/govmomi@v0.37.2/govc/test/snapshot.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  test_vm_snapshot() {
     6    vm=$1
     7    id=$(new_id)
     8  
     9    # No snapshots == no output
    10    run govc snapshot.tree -vm "$vm"
    11    assert_success ""
    12  
    13    run govc snapshot.remove -vm "$vm" '*'
    14    assert_success
    15  
    16    run govc snapshot.revert -vm "$vm"
    17    assert_failure
    18  
    19    run govc snapshot.create -vm "$vm" "$id"
    20    assert_success
    21  
    22    run govc snapshot.revert -vm "$vm" enoent
    23    assert_failure
    24  
    25    run govc snapshot.revert -vm "$vm"
    26    assert_success
    27  
    28    run govc snapshot.remove -vm "$vm" "$id"
    29    assert_success
    30  
    31    run govc snapshot.create -vm "$vm" root
    32    assert_success
    33  
    34    run govc snapshot.tree -C -vm "$vm"
    35    assert_success "root"
    36  
    37    run govc snapshot.create -vm "$vm" child
    38    assert_success
    39  
    40    run govc snapshot.tree -C -vm "$vm"
    41    assert_success "child"
    42  
    43    run govc snapshot.create -vm "$vm" grand
    44    assert_success
    45  
    46    run govc snapshot.create -vm "$vm" child
    47    assert_success
    48  
    49    result=$(govc snapshot.tree -vm "$vm" -f | grep -c root/child/grand/child)
    50    [ "$result" -eq 1 ]
    51  
    52    run govc snapshot.revert -vm "$vm" root
    53    assert_success
    54  
    55    run govc snapshot.create -vm "$vm" child
    56    assert_success
    57  
    58    # 3 snapshots named "child"
    59    result=$(govc snapshot.tree -vm "$vm" | grep -c child)
    60    [ "$result" -eq 3 ]
    61  
    62    run govc snapshot.remove -vm "$vm" child
    63    assert_failure
    64  
    65    # 2 snapshots with path "root/child"
    66    result=$(govc snapshot.tree -vm "$vm" -f | egrep -c 'root/child$')
    67    [ "$result" -eq 2 ]
    68  
    69    run govc snapshot.remove -vm "$vm" root/child
    70    assert_failure
    71  
    72    # path is unique
    73    run govc snapshot.remove -vm "$vm" root/child/grand/child
    74    assert_success
    75  
    76    # set current to grand
    77    run govc snapshot.revert -vm "$vm" grand
    78    assert_success
    79  
    80    vm_id=$(govc find -i vm -name "$vm")
    81    entity=$(govc object.collect -s TaskManager:TaskManager recentTask | awk -F, '{print $NF}' | xargs -I% govc object.collect -s % info.entity)
    82    assert_equal "$vm_id" "$entity"
    83  
    84    # name is unique
    85    run govc snapshot.remove -vm "$vm" grand
    86    assert_success
    87  
    88    result=$(govc snapshot.tree -vm "$vm" -f | grep root/child/grand/child | wc -l)
    89    [ "$result" -eq 0 ]
    90  
    91    # current given to parent of previous current
    92    result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
    93    [ "$result" -eq 1 ]
    94  
    95    id=$(govc snapshot.tree -vm "$vm" -f -i | egrep 'root/child$' | head -n1 | awk '{print $1}' | tr -d '[]')
    96    # moid is unique
    97    run govc snapshot.remove -vm "$vm" "$id"
    98    assert_success
    99  
   100    # now root/child is unique
   101    run govc snapshot.remove -vm "$vm" root/child
   102    assert_success
   103  
   104    run govc snapshot.remove -vm "$vm" root
   105    assert_success
   106  
   107    # current is removed
   108    result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
   109    [ "$result" -eq 0 ]
   110  
   111    # new root
   112    run govc snapshot.create -vm "$vm" 2ndroot
   113    assert_success
   114  
   115    # new snapshot 2ndroot is current
   116    result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
   117    [ "$result" -eq 1 ]
   118  }
   119  
   120  @test "vm.snapshot vcsim" {
   121    vcsim_env
   122  
   123    vm=$(new_empty_vm)
   124  
   125    test_vm_snapshot $vm
   126  }
   127  
   128  @test "vm.snapshot" {
   129    esx_env
   130  
   131    vm=$(new_ttylinux_vm)
   132  
   133    test_vm_snapshot $vm
   134  }