github.com/vmware/govmomi@v0.43.0/govc/test/disk.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load test_helper
     4  
     5  @test "disk.ls" {
     6    vcsim_env
     7  
     8    run govc disk.ls
     9    assert_success
    10  
    11    run govc disk.ls enoent
    12    assert_failure
    13  }
    14  
    15  @test "disk.create" {
    16    vcsim_env
    17  
    18    name=$(new_id)
    19  
    20    run govc disk.create -size 10M "$name"
    21    assert_success
    22    id="${lines[1]}"
    23  
    24    run govc disk.ls "$id"
    25    assert_success
    26  
    27    govc disk.ls -json "$id" | jq .
    28  
    29    vm=DC0_H0_VM0
    30  
    31    run govc disk.attach -vm $vm "$id"
    32    assert_success
    33  
    34    run govc disk.detach -vm $vm "$id"
    35    assert_success
    36  
    37    run govc disk.rm "$id"
    38    assert_success
    39  
    40    run govc disk.rm "$id"
    41    assert_failure
    42  
    43    name=$(new_id)
    44    run govc disk.create -profile enoent "$name"
    45    assert_failure # profile does not exist
    46  
    47    run govc disk.create -profile "vSAN Default Storage Policy" "$name"
    48    assert_success
    49  }
    50  
    51  @test "disk.create -datastore-cluster" {
    52    vcsim_env -pod 1 -ds 3 -cluster 2
    53  
    54    pod=/DC0/datastore/DC0_POD0
    55    id=$(new_id)
    56  
    57    run govc disk.create -datastore-cluster $pod "$id"
    58    assert_failure
    59  
    60    run govc find $pod -type s
    61    assert_success
    62    [ ${#lines[@]} -eq 0 ]
    63  
    64    run govc object.mv /DC0/datastore/LocalDS_{1,2} $pod
    65    assert_success
    66  
    67    run govc find $pod -type s
    68    assert_success
    69    [ ${#lines[@]} -eq 2 ]
    70  
    71    run govc disk.create -datastore-cluster $pod -size 10M "$id"
    72    assert_success
    73  
    74    id=$(new_id)
    75    pool=$GOVC_RESOURCE_POOL
    76    unset GOVC_RESOURCE_POOL
    77    run govc disk.create -datastore-cluster $pod -size 10M "$id"
    78    assert_failure # -pool is required
    79  
    80    run govc disk.create -datastore-cluster $pod -size 10M -pool "$pool" "$id"
    81    assert_success
    82  }
    83  
    84  @test "disk.register" {
    85    vcsim_env
    86  
    87    id=$(new_id)
    88    vmdk="$id/$id.vmdk"
    89  
    90    run govc datastore.mkdir "$id"
    91    assert_success
    92  
    93    # create with VirtualDiskManager
    94    run govc datastore.disk.create -size 10M "$vmdk"
    95    assert_success
    96  
    97    run govc disk.register "$id" "$id"
    98    assert_failure # expect fail for directory
    99  
   100    run govc disk.register "" "$id"
   101    assert_failure # expect fail for empty path
   102  
   103    run govc disk.register "$vmdk" "$id"
   104    assert_success
   105    id="$output"
   106  
   107    run govc disk.ls "$id"
   108    assert_success
   109  
   110    run govc disk.register "$vmdk" "$id"
   111    assert_failure
   112  
   113    run govc disk.rm "$id"
   114    assert_success
   115  
   116    run govc disk.rm "$id"
   117    assert_failure
   118  }
   119  
   120  @test "disk.snapshot" {
   121    vcsim_env
   122  
   123    name=$(new_id)
   124  
   125    run govc disk.create -size 10M "$name"
   126    assert_success
   127    id="${lines[1]}"
   128  
   129    run govc disk.snapshot.ls "$id"
   130    assert_success
   131  
   132    run govc disk.snapshot.create "$id"
   133    assert_success
   134    sid="${lines[1]}"
   135  
   136    govc disk.snapshot.ls "$id" | grep "$sid"
   137  
   138    govc disk.snapshot.ls -json "$id" | jq .
   139  
   140    run govc disk.snapshot.rm "$id" "$sid"
   141    assert_success
   142  
   143    run govc disk.snapshot.rm "$id" "$sid"
   144    assert_failure
   145  
   146    run govc disk.rm "$id"
   147    assert_success
   148  }
   149  
   150  @test "disk.tags" {
   151    vcsim_env
   152  
   153    run govc tags.category.create region
   154    assert_success
   155  
   156    run govc tags.create -c region US-WEST
   157    assert_success
   158  
   159    name=$(new_id)
   160  
   161    run govc disk.create -size 10M "$name"
   162    assert_success
   163    id="${lines[1]}"
   164  
   165    run govc disk.ls "$id"
   166    assert_success
   167  
   168    run govc disk.ls -c region -t US-WEST
   169    assert_success ""
   170  
   171    govc disk.ls -T | grep -v US-WEST
   172  
   173    run govc disk.tags.attach -c region US-WEST "$id"
   174    assert_success
   175  
   176    run govc disk.ls -c region -t US-WEST
   177    assert_success
   178    assert_matches "$id"
   179  
   180    run govc disk.ls -T
   181    assert_success
   182    assert_matches US-WEST
   183  
   184    run govc disk.tags.detach -c region enoent "$id"
   185    assert_failure
   186  
   187    run govc disk.tags.detach -c region US-WEST "$id"
   188    assert_success
   189  
   190    govc disk.ls -T | grep -v US-WEST
   191  }
   192  
   193  @test "disk.reconcile" {
   194    vcsim_env
   195  
   196    name=$(new_id)
   197  
   198    run govc disk.create -size 10M "$name"
   199    assert_success
   200    id="${lines[1]}"
   201  
   202    run govc disk.create -size 10M "$(new_id)"
   203    assert_success
   204  
   205    run govc disk.ls
   206    assert_success
   207  
   208    path=$(govc disk.ls -json "$id" | jq -r .objects[].config.backing.filePath)
   209    run govc datastore.rm "$path"
   210    assert_success
   211  
   212    run govc disk.ls
   213    assert_failure # file backing was removed without using disk.rm, results in NotFound fault
   214  
   215    run govc disk.ls -R
   216    assert_success
   217  }