| # Set up common components for Swarming hosts in the lab |
| |
| class cast_builder::swarm_host_lab ($user, $group, $home_dir) { |
| |
| # save globals as in-scope class variables |
| $cipd_ref = $cipd_env # lint:ignore:variable_scope |
| |
| $swarm_home_dir = "${home_dir}/swarm_home" |
| $cipd_ensure_puppet = "${home_dir}/cipd_ensure_puppet" |
| $puppet_dir = "${home_dir}/puppet" |
| $puppet_manifest = "${puppet_dir}/cast_builder/files/swarm/lab_nodes/site.pp" |
| $puppet_run_sh = "${home_dir}/swarm_puppet_run.sh" |
| $depot_tools_dir = "${home_dir}/depot_tools" |
| $cipd_key = "${home_dir}/home-cipd-service-account.json" |
| # TODO(b/79684886): better service account key management. |
| $monitoring_key = "${home_dir}/home-ci-controller-staging.json" |
| $monitoring_tool = "${swarm_home_dir}/eurtest_binaries/home_binaries/tools/host_monitor" |
| $email = 'livingroom-releng+alerts+puppet@google.com' |
| $swarming_key = "${home_dir}/luci/swarming-key.json" |
| |
| $packages = [ |
| 'puppet', |
| ] |
| |
| File { |
| ensure => file, |
| owner => $user, |
| group => $group, |
| mode => '0755', |
| } |
| |
| package { $packages: |
| ensure => latest, |
| } |
| |
| file { $monitoring_key: |
| require => File[$home_dir], |
| } -> |
| cast_builder::test_md5 { $monitoring_key: |
| md5 => $::md5_monitoring_key, |
| } -> |
| notify { 'correct_monitoring_key_file': |
| message => "Successfully tested file ${monitoring_key}", |
| } |
| |
| file { $swarming_key: |
| require => File[$home_dir], |
| } -> |
| cast_builder::test_md5 { $swarming_key: |
| md5 => $::md5_swarming_key, |
| } -> |
| notify { 'correct_swarming_key_file': |
| message => "Successfully tested file ${monitoring_key}", |
| } |
| |
| |
| # Install ADB and Fastboot |
| exec { 'download_adb': |
| cwd => $swarm_home_dir, |
| command => "/usr/bin/wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip -O ${swarm_home_dir}/platform-tools-latest-linux.zip", |
| } -> |
| exec { 'extract_adb': |
| cwd => $swarm_home_dir, |
| command => "/usr/bin/unzip -o -q ${swarm_home_dir}/platform-tools-latest-linux.zip -d ${swarm_home_dir}/", |
| } -> |
| file { '/usr/local/sbin/adb': |
| ensure => file, |
| mode => '0755', |
| source => "${swarm_home_dir}/platform-tools/adb", |
| checksum => md5, |
| backup => false |
| } -> |
| file { '/usr/local/sbin/fastboot': |
| ensure => file, |
| mode => '0755', |
| source => "${swarm_home_dir}/platform-tools/fastboot", |
| checksum => md5 |
| } -> |
| file { "${swarm_home_dir}/platform-tools-latest-linux.zip": |
| ensure => absent, |
| } -> |
| file { "${swarm_home_dir}/platform-tools": |
| ensure => absent, |
| recurse => true, |
| purge => true, |
| force => true, |
| } |
| |
| # (TODO:kevinfei) remove deleted cron once change is rolled out 100% |
| file { $puppet_run_sh: |
| ensure => file, |
| content => template('cast_builder/swarm_puppet_run.sh.erb'), |
| } -> |
| file { $cipd_ensure_puppet: |
| content => "home_internal/swarm_puppet ${cipd_ref}", |
| } -> |
| cron { 'cipd_ensure_puppet': |
| ensure => absent, |
| # Ensure we always have a cron that downloads latest puppet scripts before |
| # actually executing them, so that hosts can self-update even if their |
| # current copy of puppet scripts are broken. |
| command => "${depot_tools_dir}/cipd ensure -ensure-file ${cipd_ensure_puppet} -root ${puppet_dir} -service-account-json ${cipd_key} && /usr/bin/apt-get update; /usr/bin/puppet apply --modulepath ${puppet_dir} ${puppet_manifest} --logdest syslog; ${monitoring_tool} --service_account_json ${monitoring_key} --puppet_run_exit_code \$?", |
| minute => '*/30', # every 30 mins |
| require => [ |
| Package['puppet'], |
| ], |
| environment => [ |
| 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', |
| ], |
| } -> |
| cron { 'cipd_ensure_puppet_monitoring': |
| ensure => present, |
| # Ensure we always have a cron that downloads latest puppet scripts before |
| # actually executing them, so that hosts can self-update even if their |
| # current copy of puppet scripts are broken. |
| command => "/bin/bash ${puppet_run_sh}", |
| hour => '*/2', # every 2 hours |
| minute => fqdn_rand(60), |
| require => [ |
| Package['puppet'], |
| ], |
| environment => [ |
| 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', |
| ], |
| } |
| } |