fix(dispatcher): add missing files for local dispatcher
authorJavier Bértoli <javier@netmanagers.com.ar>
Sat, 17 Oct 2020 00:03:41 +0000 (21:03 -0300)
committerJavier Bértoli <javier@netmanagers.com.ar>
Sat, 17 Oct 2020 00:05:12 +0000 (21:05 -0300)
13 files changed:
arvados/defaults.yaml
arvados/dispatcher/service/file.sls [new file with mode: 0644]
arvados/dispatcher/service/files/default/crunch-dispatch-local-service.tmpl [new file with mode: 0644]
arvados/dispatcher/service/files/default/crunch-run-sh.tmpl [new file with mode: 0644]
arvados/dispatcher/service/init.sls
arvados/dispatcher/service/running.sls
test/integration/dispatcher/README.md [new file with mode: 0644]
test/integration/dispatcher/controls/config_spec.rb [new file with mode: 0644]
test/integration/dispatcher/controls/files_spec.rb [new file with mode: 0644]
test/integration/dispatcher/controls/packages_spec.rb [new file with mode: 0644]
test/integration/dispatcher/controls/services_spec.rb [new file with mode: 0644]
test/integration/dispatcher/inspec.yml [new file with mode: 0644]
test/integration/shell/controls/config_spec.rb

index 38aa764c8dabbe9cdcfa9361469fc268cab5e6c2..31f805e23184b754d15282976cc2d5551889e3c0 100644 (file)
@@ -78,7 +78,7 @@ arvados:
       # arvados-dispatch-cloud
       # crunch-dispatch-slurm
     service:
-      name: ''
+      name: crunch-dispatch-local
       port: ''
   ##### KEEPPROXY
   keepproxy:
diff --git a/arvados/dispatcher/service/file.sls b/arvados/dispatcher/service/file.sls
new file mode 100644 (file)
index 0000000..df75286
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+# vim: ft=sls
+
+{#- Get the `tplroot` from `tpldir` #}
+{%- set tplroot = tpldir.split('/')[0] %}
+{%- set sls_config_file = tplroot ~ '.config.file' %}
+{%- from tplroot ~ "/map.jinja" import arvados with context %}
+{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
+
+include:
+  - ..package
+  - {{ sls_config_file }}
+  - .running
+
+{%- if arvados.dispatcher.pkg.name == 'crunch-dispatch-local' %}
+arvados-dispatcher-service-file-file-managed-crunch-run-sh:
+  file.managed:
+    - name: /usr/local/bin/crunch-run.sh
+    - source: {{ files_switch(['crunch-run-sh.tmpl'],
+                              lookup='arvados-dispatcher-service-file-file-managed-crunch-run-sh',
+                              use_subpath=True
+                 )
+              }}
+    - mode: '0755'
+    - user: root
+    - group: root
+    - makedirs: True
+    - template: jinja
+    - context:
+        arvados: {{ arvados | json }}
+    - require:
+      - pkg: arvados-dispatcher-package-install-pkg-installed
+
+arvados-dispatcher-service-file-file-managed-crunch-dispatch-local-service:
+  file.managed:
+    - name: /etc/systemd/system/crunch-dispatch-local.service
+    - source: {{ files_switch(['crunch-dispatch-local-service.tmpl'],
+                              lookup='arvados-dispatcher-service-file-file-managed-crunch-dispatch-local-service',
+                              use_subpath=True
+                 )
+              }}
+    - mode: '0644'
+    - user: root
+    - group: root
+    - makedirs: True
+    - template: jinja
+    - context:
+        arvados: {{ arvados | json }}
+    - require:
+      - file: arvados-dispatcher-service-file-file-managed-crunch-run-sh
+      - pkg: arvados-dispatcher-package-install-pkg-installed
+  cmd.run:
+    - name: systemctl daemon-reload
+    - require_in:
+      - service: arvados-dispatcher-service-running-service-running
+    - require:
+      - file: arvados-dispatcher-service-file-file-managed-crunch-dispatch-local-service
+{%- endif %}
diff --git a/arvados/dispatcher/service/files/default/crunch-dispatch-local-service.tmpl b/arvados/dispatcher/service/files/default/crunch-dispatch-local-service.tmpl
new file mode 100644 (file)
index 0000000..f0cda3e
--- /dev/null
@@ -0,0 +1,30 @@
+########################################################################
+# File managed by Salt at <{{ source }}>.
+# Your changes will be overwritten.
+########################################################################
+[Unit]
+Description=Arvados Crunch Dispatcher for LOCAL service
+Documentation=https://doc.arvados.org/
+After=network.target
+
+# systemd==229 (ubuntu:xenial) obeys StartLimitInterval in the [Unit] section
+StartLimitInterval=0
+
+# systemd>=230 (debian:9) obeys StartLimitIntervalSec in the [Unit] section
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+EnvironmentFile=-/etc/arvados/environment
+ExecStart=/usr/bin/crunch-dispatch-local -poll-interval=1 -crunch-run-command=/usr/local/bin/crunch-run.sh
+# Set a reasonable default for the open file limit
+LimitNOFILE=65536
+Restart=always
+RestartSec=1
+LimitNOFILE=1000000
+
+# systemd<=219 (centos:7, debian:8, ubuntu:trusty) obeys StartLimitInterval in the [Service] section
+StartLimitInterval=0
+
+[Install]
+WantedBy=multi-user.target
diff --git a/arvados/dispatcher/service/files/default/crunch-run-sh.tmpl b/arvados/dispatcher/service/files/default/crunch-run-sh.tmpl
new file mode 100644 (file)
index 0000000..5c15293
--- /dev/null
@@ -0,0 +1,6 @@
+########################################################################
+# File managed by Salt at <{{ source }}>.
+# Your changes will be overwritten.
+########################################################################
+#!/bin/sh
+exec /usr/bin/crunch-run -container-enable-networking=default -container-network-mode=host $@
index 6fe4d1a35478cf86b6a213b873cb0226ae7deae5..e913c0a4c2e57bad78679c098d6c6766e85d6811 100644 (file)
@@ -2,4 +2,5 @@
 # vim: ft=sls
 
 include:
+  - .file
   - .running
index cda4e1a9ba4d00ffdbd67068eff92aafab3bbfab..bed21c6b98495d21835b926452b8cf57b4854a2b 100644 (file)
@@ -5,10 +5,11 @@
 {%- set tplroot = tpldir.split('/')[0] %}
 {%- set sls_config_file = tplroot ~ '.config.file' %}
 {%- from tplroot ~ "/map.jinja" import arvados with context %}
+{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
 
-{%- if arvados.dispatcher.pkg.name != 'crunch-dispatch-local' %}
 include:
   - ..package
+  - .file
   - {{ sls_config_file }}
 
 arvados-dispatcher-service-running-service-running:
@@ -19,5 +20,3 @@ arvados-dispatcher-service-running-service-running:
       - sls: {{ sls_config_file }}
     - require:
       - pkg: arvados-dispatcher-package-install-pkg-installed
-    - only_if: test "{{ arvados.dispatcher.pkg.name }}" != "crunch-dispatch-local"
-{%- endif %}
diff --git a/test/integration/dispatcher/README.md b/test/integration/dispatcher/README.md
new file mode 100644 (file)
index 0000000..4c295db
--- /dev/null
@@ -0,0 +1,50 @@
+# InSpec Profile: `dispatcher`
+
+This shows the implementation of the `dispatcher` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
+
+## Verify a profile
+
+InSpec ships with built-in features to verify a profile structure.
+
+```bash
+$ inspec check dispatcher
+Summary
+-------
+Location: dispatcher
+Profile: profile
+Controls: 4
+Timestamp: 2019-06-24T23:09:01+00:00
+Valid: true
+
+Errors
+------
+
+Warnings
+--------
+```
+
+## Execute a profile
+
+To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
+
+```bash
+$ inspec exec dispatcher
+..
+
+Finished in 0.0025 seconds (files took 0.12449 seconds to load)
+8 examples, 0 failures
+```
+
+## Execute a specific control from a profile
+
+To run one control from the profile use `inspec exec /path/to/profile --controls name`.
+
+```bash
+$ inspec exec dispatcher --controls package
+.
+
+Finished in 0.0025 seconds (files took 0.12449 seconds to load)
+1 examples, 0 failures
+```
+
+See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
diff --git a/test/integration/dispatcher/controls/config_spec.rb b/test/integration/dispatcher/controls/config_spec.rb
new file mode 100644 (file)
index 0000000..bbc54f8
--- /dev/null
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+dispatcher_stanza = <<-DISPATCHER_STANZA
+      DispatchCloud:
+        InternalURLs:
+          http://fixme.example.net:9006: {}
+DISPATCHER_STANZA
+
+control 'arvados configuration' do
+  title 'should match desired dispatcher lines'
+
+  describe file('/etc/arvados/config.yml') do
+    it { should be_file }
+    it { should be_owned_by 'root' }
+    # We're testing it in the API instance, so group will be nginx's
+    it { should be_grouped_into 'www-data' }
+    its('mode') { should cmp '0640' }
+    its('content') do
+      should include(
+        'File managed by Salt at <salt://arvados/files/default/config.tmpl.jinja>.'
+      )
+    end
+    its('content') { should include(dispatcher_stanza) }
+  end
+end
diff --git a/test/integration/dispatcher/controls/files_spec.rb b/test/integration/dispatcher/controls/files_spec.rb
new file mode 100644 (file)
index 0000000..17945a0
--- /dev/null
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+control 'arvados dispatcher service' do
+  impact 0.5
+  title 'files should exist'
+
+  describe file('/usr/local/bin/crunch-run.sh') do
+    it { should be_file }
+    it { should be_owned_by 'root' }
+    it { should be_grouped_into 'root' }
+    its('mode') { should cmp '0755' }
+    its('content') do
+      should include(
+        # rubocop:disable Metrics/LineLength
+        'File managed by Salt at <salt://arvados/dispatcher/service/files/default/crunch-run-sh.tmpl>.'
+        # rubocop:enable Metrics/LineLength
+      )
+    end
+  end
+  describe file('/etc/systemd/system/crunch-dispatch-local.service') do
+    it { should be_file }
+    it { should be_owned_by 'root' }
+    it { should be_grouped_into 'root' }
+    its('mode') { should cmp '0644' }
+    its('content') do
+      should include(
+        # rubocop:disable Metrics/LineLength
+        'File managed by Salt at <salt://arvados/dispatcher/service/files/default/crunch-dispatch-local-service.tmpl>.'
+        # rubocop:enable Metrics/LineLength
+      )
+    end
+  end
+end
diff --git a/test/integration/dispatcher/controls/packages_spec.rb b/test/integration/dispatcher/controls/packages_spec.rb
new file mode 100644 (file)
index 0000000..03f3e6b
--- /dev/null
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+control 'arvados dispatcher package' do
+  title 'should be installed'
+
+  describe package('crunch-dispatch-local') do
+    it { should be_installed }
+  end
+end
diff --git a/test/integration/dispatcher/controls/services_spec.rb b/test/integration/dispatcher/controls/services_spec.rb
new file mode 100644 (file)
index 0000000..465746e
--- /dev/null
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+control 'arvados dispatcher service' do
+  impact 0.5
+  title 'should be running and enabled'
+
+  describe service('crunch-dispatch-local') do
+    it { should be_enabled }
+    it { should be_running }
+  end
+end
diff --git a/test/integration/dispatcher/inspec.yml b/test/integration/dispatcher/inspec.yml
new file mode 100644 (file)
index 0000000..4a0fcb1
--- /dev/null
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+# vim: ft=yaml
+---
+name: dispatcher
+title: arvados formula dispatcher submodule
+maintainer: SaltStack Formulas
+license: Apache-2.0
+summary: Verify that the arvados formula dispatcher is setup and configured correctly
+supports:
+  - platform-name: debian
+  - platform-name: ubuntu
+  - platform-name: centos
index 9fa65b7af63d9084985647f0841d13451c4e690e..13bfa2482bf7b444e4a888d6972a1b35ae7b80f0 100644 (file)
@@ -20,9 +20,9 @@ control 'shellinabox configuration' do
     its('mode') { should cmp '0644' }
     its('content') do
       should include(
-        # rubocop:disable Metrics/LineLength
+        # rubocop:disable Layout/LineLength
         'File managed by Salt at <salt://arvados/shell/config/files/default/shell-shellinabox.tmpl.jinja>.'
-        # rubocop:enable Metrics/LineLength
+        # rubocop:enable Layout/LineLength
       )
     end
     its('content') { should include(siab_stanza) }
@@ -39,9 +39,9 @@ control 'libpam-arvados configuration' do
     its('mode') { should cmp '0644' }
     its('content') do
       should include(
-        # rubocop:disable Metrics/LineLength
+        # rubocop:disable Layout/LineLength
         'File managed by Salt at <salt://arvados/shell/config/files/default/shell-libpam-arvados.tmpl.jinja>.'
-        # rubocop:enable Metrics/LineLength
+        # rubocop:enable Layout/LineLength
       )
     end
     its('content') { should include(libpam_stanza) }