module PDQTest::Docker
Constants
- CONTAINER_PATHS
volume paths are different for windows containers superuser.com/questions/1051520/docker-windows-container-how-to-mount-a-host-folder-as-data-volume-on-windows path for common things inside the container
Also… bind mounting files is impossible on windows in docker right now:
- ERR
- HOST_PATHS
path for common things on the host computer running pdqtest (vm, laptop, etc)
- IMAGES
- OUT
- STATUS
Public Class Methods
_exec_real(container, real_c)
click to toggle source
# File lib/pdqtest/docker.rb, line 72 def self._exec_real(container, real_c) $logger.debug("exec_real: running docker command: #{real_c}") _res = container.exec(real_c, tty: true) # docker returns an array of stuff - convert to hash with labels res = { :OUT => _res[OUT], :ERR => _res[ERR], :STATUS => _res[STATUS], } res end
acceptance_test_images()
click to toggle source
detect the image to use based on metadata.json
# File lib/pdqtest/docker.rb, line 87 def self.acceptance_test_images() supported_images = [] os_hash = Puppet::module_metadata['operatingsystem_support'] || {} # returns a hash that looks like this (if non-empty): # [ # { # "operatingsystem": "RedHat", # "operatingsystemrelease": [ # "6", # "7" # ] # }, # ] # We will map this list of OSs to the simple list of docker images we # supply if os_hash.size == 0 # Always support the default test system if no metadata present supported_images << IMAGES[:DEFAULT] else os_hash.each { |os| case os["operatingsystem"].downcase when "ubuntu" supported_images << IMAGES[:UBUNTU] when "windows" supported_images << IMAGES[:WINDOWS] else supported_images << IMAGES[:DEFAULT] end } end supported_images.uniq end
cleanup_container(container)
click to toggle source
# File lib/pdqtest/docker.rb, line 196 def self.cleanup_container(container) container.stop container.delete(:force => true) end
new_container(image_name, privileged)
click to toggle source
# File lib/pdqtest/docker.rb, line 122 def self.new_container(image_name, privileged) if Util.is_windows ::Docker.url = "tcp://127.0.0.1:2375" # nasty hack for https://github.com/swipely/docker-api/issues/441 ::Docker.send(:remove_const, 'API_VERSION') ::Docker.const_set('API_VERSION', '1.24') end # security options seem required on OSX to allow SYS_ADMIN capability to # work - without this container starts fine with no errors but the CAP is # missing from the inspect output and all systemd commands fail with errors # about dbus security_opt = if (/darwin/ =~ RUBY_PLATFORM) != nil ["seccomp:unconfined"] else [] end if ! Util.is_windows if ! Dir.exists?(HOST_PATHS[Util.host_platform][:yum_cache]) FileUtils.mkdir_p(HOST_PATHS[Util.host_platform][:yum_cache]) end end # # volumes (container -> host) # volumes = supporting_volumes # # binds (host -> container) # binds = Util.volumes2binds(volumes) # # hostconfig->tmpfs (linux) # if Util.is_windows start_body = {} if privileged $logger.error "--privileged has no effect on windows" end else start_body = { 'HostConfig' => { 'Tmpfs': { '/run' => '', '/run/lock' => '', }, CapAdd: [ 'SYS_ADMIN'], Privileged: privileged, } } end # # container # container = ::Docker::Container.create( 'Image' => image_name, 'Volumes' => volumes, 'HostConfig' => { "SecurityOpt" => security_opt, "Binds": binds, }, ) container.start(start_body) container end
supporting_volumes()
click to toggle source
Map the testcase and any OS specific volumes we would always want, eg yum cache, random crap for systemd, etc
# File lib/pdqtest/docker.rb, line 54 def self.supporting_volumes pwd = Dir.pwd platform = Util.host_platform if Util.is_windows # normalise output for windows pwd = pwd.gsub(/\//, '\\') end test_dir = CONTAINER_PATHS[platform][:testcase] volumes = {test_dir => {pwd => 'rw'}} if ! Util.is_windows volumes['/sys/fs/cgroup'] = {'/sys/fs/cgroup' => 'ro'} volumes[CONTAINER_PATHS[platform][:yum_cache]] = {HOST_PATHS[platform][:yum_cache] => 'rw'} end volumes end
test_dir()
click to toggle source
convenience lookup for container testcase dir since its used all over the place fixme! - belongs somewhere else now…
# File lib/pdqtest/docker.rb, line 48 def self.test_dir CONTAINER_PATHS[Util.host_platform][:testcase] end