github.com/vmware/govmomi@v0.37.2/govc/test/datastore_file_manager_test.sh (about)

     1  #!/bin/bash -e
     2  
     3  # This test is not run via bats
     4  
     5  # See also: datastore.bats@test "datastore.disk"
     6  
     7  export GOVC_TEST_URL=$GOVC_URL
     8  
     9  . "$(dirname "$0")"/test_helper.bash
    10  
    11  echo -n "checking datastore type..."
    12  type=$(govc object.collect -s "datastore/$GOVC_DATASTORE" summary.type)
    13  echo "$type"
    14  
    15  if [ "$type" = "vsan" ] ; then
    16    echo -n "checking for orphan objects..."
    17    objs=($(govc datastore.vsan.dom.ls -o))
    18    echo "${#objs[@]}"
    19  
    20    if [ "${#objs[@]}" -ne "0" ] ; then
    21      govc datastore.vsan.dom.rm "${objs[@]}"
    22    fi
    23  fi
    24  
    25  dir=govc-test-dfm
    26  
    27  echo "uploading plain file..."
    28  cal | govc datastore.upload - $dir/cal.txt
    29  echo "removing plain file..."
    30  govc datastore.rm $dir/cal.txt
    31  
    32  scratch=$dir/govc-test-scratch/govc-test-scratch.vmdk
    33  
    34  govc datastore.mkdir -p "$(dirname $scratch)"
    35  
    36  echo "creating disk $scratch..."
    37  govc datastore.disk.create -size 1M $scratch
    38  
    39  id=$(new_id)
    40  
    41  echo "creating $id VM with disk linked to $scratch..."
    42  govc vm.create -on=false -link -disk $scratch "$id"
    43  info=$(govc device.info -vm "$id" disk-*)
    44  echo "$info"
    45  
    46  disk="$(grep Name: <<<"$info" | awk '{print $2}')"
    47  vmdk="$id/$id.vmdk"
    48  
    49  echo "removing $disk device but keeping the .vmdk backing file..."
    50  govc device.remove -vm "$id" -keep "$disk"
    51  
    52  echo -n "checking delta disk ddb.deletable..."
    53  govc datastore.download "$vmdk" - | grep -q -v ddb.deletable
    54  echo "yes"
    55  
    56  echo -n "checking scratch disk ddb.deletable..."
    57  govc datastore.download "$scratch" - | grep ddb.deletable | grep -q false
    58  echo "no"
    59  
    60  echo "removing $vmdk"
    61  govc datastore.rm "$vmdk"
    62  
    63  echo -n "checking that rm $scratch fails..."
    64  govc datastore.rm "$scratch" 2>/dev/null || echo "yes"
    65  
    66  echo -n "checking that rm -f $scratch deletes..."
    67  govc datastore.rm -f "$scratch" && echo "yes"
    68  
    69  echo "removing disk Directory via FileManager..."
    70  govc datastore.mkdir -p "$(dirname $scratch)"
    71  govc datastore.disk.create -size 1M $scratch
    72  govc datastore.rm "$(dirname $scratch)"
    73  
    74  echo -n "checking for remaining files..."
    75  govc datastore.ls -p -R $dir
    76  
    77  teardown
    78  
    79  status=0
    80  
    81  if [ "$type" = "vsan" ] ; then
    82    echo -n "checking for leaked objects..."
    83    objs=($(govc datastore.vsan.dom.ls -l -o | awk '{print $3}'))
    84    echo "${#objs[@]}"
    85  
    86    if [ "${#objs[@]}" -ne "0" ] ; then
    87      printf "%s\n" "${objs[@]}"
    88      status=1
    89    else
    90      # this is expected to leak on vSAN currently
    91      echo -n "checking if FileManager.Delete still leaks..."
    92      govc datastore.mkdir -p "$(dirname $scratch)"
    93      govc datastore.disk.create -size 1M $scratch
    94      # '-t=false' forces use of FileManager instead of VirtualDiskManager
    95      govc datastore.rm -t=false $scratch
    96      govc datastore.rm $dir
    97  
    98      govc datastore.vsan.dom.ls -o | xargs -r govc datastore.vsan.dom.rm -v
    99    fi
   100  fi
   101  
   102  exit $status