Add artifact collector
This patch adds artifact_collector state to collect artifacts like
logs, installed packages, pillars, grains from nodes
Change-Id: I66dc1e6dba335c875698fe23c518c9d274881b29
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..4d24d42
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,36 @@
+
+Sample Pillars
+==============
+
+Collect artifacts and deploy to artifactory:
+Actifact list:
+ - packages list - collected by default
+ - Salt pillar - collected by default
+ - Salt grains - collected by default
+ - Logs - see example below
+ - Cmd output - see example below
+
+.. code-block:: yaml
+ runtest:
+ artifact_collector:
+ enabled: true
+ artifactory:
+ enabled: true
+ user: some_user_name
+ password: some_password
+ host: artifactory.mcp.mirantis.net
+ port: 443
+ proto: https
+ endpoint: /oscore-local/${_param:cluster_domain}/${_param:infra_config_hostname}
+ artifacts:
+ sys_logs:
+ path: /var/log
+ etc:
+ path: /etc
+ cmds:
+ some_cmd:
+ cmd: ip addr
+ dst: /tmp/ip_addr.txt
+ yet_another_cmd:
+ cmd: ps -ef
+ dst: /tmp/ps.txt
diff --git a/runtest/artifact_collector.sls b/runtest/artifact_collector.sls
new file mode 100644
index 0000000..27a678d
--- /dev/null
+++ b/runtest/artifact_collector.sls
@@ -0,0 +1,52 @@
+{%- from "runtest/map.jinja" import artifact_collector with context %}
+{%- if artifact_collector.get('enabled', False) -%}
+
+{%- for cmd_name, cmd_params in artifact_collector.cmds.iteritems() %}
+{%- set cmd = cmd_params.cmd + " > " + cmd_params.dst %}
+run_{{ cmd_name }}:
+ cmd.run:
+ - name: {{ cmd }}
+
+{%- if artifact_collector.get('artifactory', {}).get('enabled', False) %}
+deploy_{{ cmd_name }}:
+ module.run:
+ - name: artifactory.deploy_artifact
+ - source_file: {{ cmd_params.dst }}
+ - endpoint: {{ artifact_collector.artifactory.endpoint }}
+ - kwargs:
+ user: {{ artifact_collector.artifactory.user }}
+ password: {{ artifact_collector.artifactory.password }}
+ host: {{ artifact_collector.artifactory.host }}
+ proto: {{ artifact_collector.artifactory.get('proto', 'https') }}
+ port: {{ artifact_collector.artifactory.get('port', 443) }}
+{%- endif %}
+
+{%- endfor %}
+
+
+{%- for artifact_name, artifact_params in artifact_collector.artifacts.iteritems() %}
+{%- set zip_file = "/tmp/"+artifact_name+".zip" %}
+
+zip_{{artifact_name}}:
+ module.run:
+ - name: archive.zip
+ - zip_file: {{ zip_file }}
+ - sources: {{ artifact_params.path }}
+
+{%- if artifact_collector.get('artifactory', {}).get('enabled', False) %}
+deploy_{{artifact_name}}:
+ module.run:
+ - name: artifactory.deploy_artifact
+ - source_file: {{ zip_file }}
+ - endpoint: {{ artifact_collector.artifactory.endpoint }}
+ - kwargs:
+ user: {{ artifact_collector.artifactory.user }}
+ password: {{ artifact_collector.artifactory.password }}
+ host: {{ artifact_collector.artifactory.host }}
+ proto: {{ artifact_collector.artifactory.get('proto', 'https') }}
+ port: {{ artifact_collector.artifactory.get('port', 443) }}
+{%- endif %}
+
+{%- endfor %}
+
+{%- endif -%}
diff --git a/runtest/map.jinja b/runtest/map.jinja
index 3d1db39..7360cbc 100644
--- a/runtest/map.jinja
+++ b/runtest/map.jinja
@@ -10,3 +10,23 @@
'cfg_name': 'tempest.conf',
}
}, grain='os', merge=salt['pillar.get']('runtest', {}).get('tempest', {}), base='default') %}
+
+{% set artifact_collector = salt['grains.filter_by']({
+ 'default': {
+ 'cmds': {
+ 'pillar': {
+ 'cmd': 'salt-call pillar.items',
+ 'dst': '/tmp/pillar.txt'
+ },
+ 'grains': {
+ 'cmd': 'salt-call grains.items',
+ 'dst': '/tmp/grains.txt'
+ },
+ 'packages': {
+ 'cmd': 'dpkg -l',
+ 'dst': '/tmp/packages.txt'
+ }
+ }
+ }
+}, grain='os', merge=salt['pillar.get']('runtest', {}).get('artifact_collector', {}), base='default') %}
+