github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/test/integration/daemon-configs.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  export DRIVER=virtualbox
     6  export NAME="bats-$DRIVER-daemon-configs"
     7  export MACHINE_STORAGE_PATH=/tmp/machine-bats-daemon-test-$DRIVER
     8  # Default memsize is 1024MB and disksize is 20000MB
     9  # These values are defined in drivers/virtualbox/virtualbox.go
    10  export DEFAULT_MEMSIZE=1024
    11  export DEFAULT_DISKSIZE=20000
    12  export CUSTOM_MEMSIZE=1536
    13  export CUSTOM_DISKSIZE=10000
    14  export CUSTOM_CPUCOUNT=1
    15  export BAD_URL="http://dev.null:9111/bad.iso"
    16  
    17  function setup() {
    18    # add sleep because vbox; ugh
    19    sleep 1
    20  }
    21  
    22  findDiskSize() {
    23    # SATA-0-0 is usually the boot2disk.iso image
    24    # We assume that SATA 1-0 is root disk VMDK and grab this UUID
    25    # e.g. "SATA-ImageUUID-1-0"="fb5f33a7-e4e3-4cb9-877c-f9415ae2adea"
    26    # TODO(slashk): does this work on Windows ?
    27    run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep SATA-ImageUUID-1-0 | cut -d'=' -f2"
    28    run bash -c "VBoxManage showhdinfo $output | grep "Capacity:" | awk -F' ' '{ print $2 }'"
    29  }
    30  
    31  findMemorySize() {
    32    run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep memory= | cut -d'=' -f2"
    33  }
    34  
    35  findCPUCount() {
    36    run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep cpus= | cut -d'=' -f2"
    37  }
    38  
    39  buildMachineWithOldIsoCheckUpgrade() {
    40    run wget https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso -O $MACHINE_STORAGE_PATH/cache/boot2docker.iso
    41    run machine create -d virtualbox $NAME
    42    run machine upgrade $NAME
    43  }
    44  
    45  @test "$DRIVER: machine should not exist" {
    46    run machine active $NAME
    47    [ "$status" -eq 1  ]
    48  }
    49  
    50  @test "$DRIVER: VM should not exist" {
    51    run VBoxManage showvminfo $NAME
    52    [ "$status" -eq 1  ]
    53  }
    54  
    55  @test "$DRIVER: create" {
    56    run machine create -d $DRIVER $NAME
    57    [ "$status" -eq 0  ]
    58  }
    59  
    60  @test "$DRIVER: active" {
    61    run machine active $NAME
    62    [ "$status" -eq 0  ]
    63  }
    64  
    65  @test "$DRIVER: check default machine memory size" {
    66    findMemorySize
    67    [[ ${output} == "${DEFAULT_MEMSIZE}"  ]]
    68  }
    69  
    70  @test "$DRIVER: check default machine disksize" {
    71    findDiskSize
    72    [[ ${output} == *"$DEFAULT_DISKSIZE"* ]]
    73  }
    74  
    75  @test "$DRIVER: test bridge-ip" {
    76    run machine ssh $NAME sudo /etc/init.d/docker stop
    77    run machine ssh $NAME sudo ifconfig docker0 down
    78    run machine ssh $NAME sudo ip link delete docker0
    79    BIP='--bip=172.168.45.1/24'
    80    set_extra_config $BIP
    81    cat ${TMP_EXTRA_ARGS_FILE} | machine ssh $NAME sudo tee /var/lib/boot2docker/profile
    82    cat ${DAEMON_CFG_FILE} | machine ssh $NAME "sudo tee -a /var/lib/boot2docker/profile"
    83    run machine ssh $NAME sudo /etc/init.d/docker start
    84    run machine ssh $NAME ifconfig docker0
    85    [ "$status" -eq 0  ]
    86    [[ ${lines[1]} =~ "172.168.45.1"  ]]
    87  }
    88  
    89  @test "$DRIVER: run busybox container" {
    90    run machine ssh $NAME sudo cat /var/lib/boot2docker/profile
    91    run docker $(machine config $NAME) run busybox echo hello world
    92    [ "$status" -eq 0  ]
    93  }
    94  
    95  @test "$DRIVER: remove machine" {
    96    run machine rm -f $NAME
    97  }
    98  
    99  # Cleanup of machine store should always be the last 'test'
   100  @test "$DRIVER: cleanup" {
   101    run rm -rf $MACHINE_STORAGE_PATH
   102    [ "$status" -eq 0  ]
   103  }
   104