| # Setup for swarm bots in Gotham CI. |
| # Enumerates the connected Gothams, and bootstraps a Swarming bot for each. |
| # Uses Systemd to restart bots in case they or the host crashes. |
| |
| class cast_builder::swarm_bot_gotham ($user, $group, $home_dir) { |
| |
| $cipd_key = "${home_dir}/home-cipd-service-account.json" |
| $gsutil_dir = "${home_dir}/gsutil" |
| $gsutil_boto = "${home_dir}/.boto" |
| $fragglerock_key = "${home_dir}/fragglerock_service_key.json" |
| $swarm_home_dir = "${home_dir}/swarm_home" |
| $depot_tools_dir = "${home_dir}/depot_tools" |
| $swarm_bots_home = "${swarm_home_dir}/bots" |
| $venv = "${swarm_home_dir}/swarm_env" |
| $prefix = 'swarming_bot--' |
| |
| $packages = [ |
| 'libudev-dev', |
| 'libusb-1.0.0-dev', |
| 'virtualenv', |
| ] |
| |
| package { $packages: |
| ensure => latest, |
| } |
| |
| file { '/etc/udev/rules.d/99-nxpusb.rules': |
| ensure => file, |
| owner => $user, |
| group => $group, |
| mode => '0644', |
| content => ' |
| # Give non-superusers access to connected NXP boards |
| |
| # SDP protocol |
| KERNEL=="hidraw*", ATTRS{idVendor}=="1fc9", MODE="0666" |
| ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1fc9", MODE="666" |
| ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", MODE="666" |
| |
| # Flashloader |
| KERNEL=="hidraw*", ATTRS{idVendor}=="15a2", MODE="0666"' |
| } |
| |
| file { '/etc/udev/rules.d/70-caraway.rules': |
| ensure => file, |
| owner => $user, |
| group => $group, |
| mode => '0644', |
| content => ' |
| # 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB) |
| # This grants rw to plugdev so that the usb device is accessible to tools (e.g. |
| # openocd) without sudo. |
| SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="374b", MODE="0664", GROUP="plugdev", SYMLINK+="stlink-latest", SYMLINK+="stlink%n", RUN+="/usr/bin/touch /tmp/A" |
| |
| # 0483:df11 STMicroelectronics STM Device in DFU Mode |
| # This grants rw to plugdev so that the usb device is accessible to tools (e.g. dfuse.py) without sudo. |
| SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="df11", MODE="0664", GROUP="plugdev" |
| |
| # 18d1:* Google Inc. |
| # Prevents modem-manager from probing for a modem on any serial ports with |
| # idVendor == Google, and grants rw to plugdev so that the usb device is |
| # accessible to tools without sudo. |
| SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ENV{ID_MM_DEVICE_IGNORE}="1", MODE="0664", GROUP="plugdev" |
| |
| # If you need to be more specific than just using idVendor == Google, i.e. you are also using |
| # separate rules for other Google devices, you can comment out the rule directly above this |
| # and uncomment the following rule, filling in the appropriate value for idProduct. Note the |
| # use of the plural "ATTRS" to match parents of the device being added. |
| # SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTRS{idProduct}=="", ENV{ID_MM_DEVICE_IGNORE}="1", MODE="0664", GROUP="plugdev"' |
| } |
| |
| # usb_devices is a Facter fact enumerating the connected Gothams. |
| # This is invoked at runtime and defined in lib/facter/devices.rb. |
| $::usb_devices.each |String $serial_port| { |
| $bot_id = sha1($serial_port)[0,6] |
| |
| file { [ "${swarm_bots_home}/${bot_id}/", |
| "${swarm_bots_home}/${bot_id}/bot_root/", ]: |
| ensure => directory, |
| owner => $user, |
| group => $group, |
| mode => '0755', |
| } -> |
| file { "${swarm_bots_home}/${bot_id}/bot_dimensions.json": |
| ensure => file, |
| owner => $user, |
| group => $group, |
| mode => '0644', |
| content => "{ \"gotham_serial_port\" : [\"${serial_port}\"] }", |
| } -> |
| # Note that bots routinely clear the directory in which they were started. |
| # Any file or directory other than swarming_bot.zip will be deleted. |
| file { "${swarm_bots_home}/${bot_id}/bot_root/swarming_bot.zip": |
| ensure => file, |
| owner => $user, |
| group => $group, |
| mode => '0755', |
| |
| # TODO(dustingadal) This is curled here by the host bootstrap script. |
| # It shouldn't be placed in the bot-specific directory bots/1/ |
| # See: //eureka_internal/test/lab_system/setup_swarm_host.sh |
| source => "file:${swarm_bots_home}/1/swarming_bot.zip", |
| } -> |
| # This will restart the bot if it or the host goes down. |
| file { "/etc/systemd/system/${prefix}${bot_id}.service": |
| ensure => file, |
| owner => 'root', |
| group => 'root', |
| mode => '0644', |
| content => template('cast_builder/swarm_bot.systemd.erb'), |
| } -> |
| service { "${prefix}${bot_id}": |
| ensure => running, |
| enable => true, |
| provider => 'systemd', |
| before => Exec['restart_systemd'], |
| } |
| } |
| |
| # The services previously registered are run as systemd restarts. |
| exec { 'restart_systemd': |
| command => '/bin/systemctl daemon-reload', |
| } |
| } |