Skip to content

Commit

Permalink
test(devtools): more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jul 10, 2020
1 parent 161acc1 commit a9b2fa7
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 27 deletions.
22 changes: 22 additions & 0 deletions kubernetes/aliases/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'config_file' in d.k3s and d.k3s.config_file %}
{%- set sls_binary_clean = tplroot ~ '.k3s.binary.clean' %}
{%- set sls_script_clean = tplroot ~ '.k3s.script.clean' %}
include:
- {{ sls_binary_clean if d.k3s.pkg.use_upstream_binary else sls_script_clean }}
{{ formula }}-k3s-config-clean:
file.absent:
- names:
- {{ d.k3s.config_file }}
- require:
- sls: {{ sls_binary_clean if d.k3s.pkg.use_upstream_binary else sls_script_clean }}
{%- endif %}
33 changes: 33 additions & 0 deletions kubernetes/aliases/file.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'config' in d.k3s and d.k3s.config %}
{%- set sls_binary_install = tplroot ~ '.k3s.binary.install' %}
{%- set sls_package_install = tplroot ~ '.k3s.package.install' %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
include:
- {{ sls_binary_install if d.k3s.pkg.use_upstream_binary else sls_package_install }}
{{ formula }}-k3s-config-file-install-file-managed:
file.managed:
- name: {{ d.k3s.config_file }}
- source: {{ files_switch(['config.yml.jinja'],
lookup='k8s-k3s-config-file-install-file-managed'
)
}}
- mode: 644
- user: {{ d.identity.rootuser }}
- group: {{ d.identity.rootgroup }}
- makedirs: True
- template: jinja
- context:
config: {{ d.k3s.config|json }}
- require:
- sls: {{ sls_binary_install if d.k3s.pkg.use_upstream_binary else sls_package_install }}
{%- endif %}
5 changes: 5 additions & 0 deletions kubernetes/aliases/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file
16 changes: 13 additions & 3 deletions kubernetes/devtools/binary/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{{ formula }}-devtools-stern-binary-clean:
{%- if 'wanted' in d.devtools and d.devtools.wanted %}
{%- for tool in d.devtools.wanted %}
{%- if 'pkg' in d.devtools and tool in d.devtools['pkg'] and d.devtools['pkg'][tool] %}
{%- if 'binary' in d.devtools['pkg'][tool] %}
{{ formula }}-devtools-{{ tool }}-binary-clean:
file.absent:
- names:
- /usr/local/bin/stern
- {{ d.devtools.stern.pkg.binary.name }}/bin/stern
- /usr/local/bin/{{ tool }}
- {{ d.devtools['pkg'][tool]['binary']['name'] }}/bin/{{ tool }}
{% endif %}
{% endif %}
{%- endfor %}
{%- endif %}
42 changes: 29 additions & 13 deletions kubernetes/devtools/binary/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,58 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{{ formula }}-devtools-stern-binary-install:
{%- if 'wanted' in d.devtools and d.devtools.wanted %}
{%- for tool in d.devtools.wanted %}
{%- if 'pkg' in d.devtools and tool in d.devtools['pkg'] and d.devtools['pkg'][tool] %}
{%- if 'archive' in d.devtools['pkg'][tool] %}
{{ formula }}-devtools-{{ tool }}-archive-install:
file.directory:
- name: {{ d.devtools.stern.pkg.binary.name }}/bin
- name: {{ d.devtools[tool]['pkg']['archive']['name'] }}/bin
- user: {{ d.identity.rootuser }}
- group: {{ d.identity.rootgroup }}
- mode: 755
- makedirs: True
- require_in:
- cmd: {{ formula }}-devtools-stern-binary-install
- cmd: {{ formula }}-devtools-{{ tool }}-archive-install
- recurse:
- user
- group
- mode
cmd.run:
- names:
- curl -Lo {{ d.devtools.stern.pkg.binary.name }}/bin/stern {{ d.stern.pkg.binary.source }}
- chmod '0755' {{ d.devtools.stern.pkg.binary.name }}/bin/stern 2>/dev/null
- curl -Lo {{ d.devtools[tool]['pkg']['archive']['name'] }}/bin/[tool] {{ d[tool]['pkg']['archive']['source'] }}
- chmod '0755' {{ d.devtools[tool]['pkg']['archive']['name'] }}/bin/[tool] 2>/dev/null
- retry: {{ d.retry_option|json }}
- user: {{ d.identity.rootuser }}
- group: {{ d.identity.rootgroup }}
{%- if 'source_hash' in d.devtools.stern.pkg.binary and d.stern.pkg.binary.source_hash %}
{%- if 'source_hash' in d.devtools[tool]['pkg']['archive'] and d[tool]['pkg']['archive']['source_hash'] %}
module.run:
- name: file.check_hash
- path: {{ d.devtools.stern.pkg.binary.name }}/bin/stern
- file_hash: {{ d.devtools.stern.pkg.binary.source_hash }}
- path: {{ d.devtools[tool]['pkg']['archive']['name'] }}/bin/{{ tool }}
- file_hash: {{ d.devtools[tool]['pkg']['archive']['source_hash'] }}
- require:
- cmd: {{ formula }}-devtools-stern-binary-install
- cmd: {{ formula }}-devtools-{{ tool }}-archive-install
{%- endif %}
{{ formula }}-devtools-stern-binary-install-symlink:
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.devtools['pkg'][tool]['commands'] %}
{{ formula }}-devtools-{{ tool }}-archive-install-symlink-{{ cmd }}:
file.symlink:
- name: /usr/local/bin/stern
- target: {{ d.devtools.stern.pkg.binary.name }}/bin/stern
- name: /usr/local/bin/{{ cmd }}
- target: {{ d.devtools['pkg'][tool]['archive']['name'] }}/{{ tool }}
- force: True
- require:
- cmd: {{ formula }}-devtools-stern-binary-install
- cmd: {{ formula }}-devtools-{{ tool }}-archive-install
- unless:
- {{ d.linux.altpriority|int > 0 }}
- {{ grains.os_family|lower in ('windows',) }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{%- endfor %}
{%- endif %}
13 changes: 7 additions & 6 deletions kubernetes/devtools/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- if 'wanted' in d.devtools and d.devtools.wanted %}
include:
- .binary
- .binary.clean
{%- if 'wanted' in d.devtools and d.devtools.wanted %}
{%- for tool in d.devtools.wanted %}
{%- if 'pkg' in d.devtools and tool in d.devtools['pkg'] and d.devtools['pkg'][tool] %}
{%- if 'archive' in d.devtools['pkg'][tool] %}
{{ formula }}-devtools-{{ tool }}-archive-clean:
file.absent:
- names:
- {{ d.devtools['pkg'][tool]['archive']['name'] }}
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.devtools['pkg'][tool]['commands'] %}
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.devtools['pkg'][tool]['commands'] %}
- /usr/local/bin/{{ cmd }}
{%- endfor %}
{%- endfor %}
{%- endif %}
{%- endif %}
{% endif %}
{%- endfor %}
{%- endif %}
12 changes: 7 additions & 5 deletions kubernetes/devtools/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{%- if 'wanted' in d.devtools and d.devtools.wanted %}
{%- for tool in d.devtools.wanted %}
{%- if 'pkg' in d.devtools and tool in d.devtools['pkg'] and d.devtools['pkg'][tool] %}
{%- if 'archive' in d.devtools['pkg'][tool] %}
{{ formula }}-devtools-{{ tool }}-archive-install:
file.directory:
Expand Down Expand Up @@ -35,12 +36,12 @@
- recurse:
- user
- group
{%- if tool not in ('audit2rbac',) %} {# tarbombs #}
{%- if tool not in ('audit2rbac',) %} {# tarbombs #}
- options: '--strip-components=1'
{%- endif %}
{%- endif %}
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.devtools['pkg'][tool]['commands'] %}
{%- if d.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS') %}
{%- for cmd in d.devtools['pkg'][tool]['commands'] %}
{{ formula }}-devtools-{{ tool }}-archive-install-symlink-{{ cmd }}:
file.symlink:
Expand All @@ -50,7 +51,8 @@
- require:
- archive: {{ formula }}-devtools-{{ tool }}-archive-install
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions test/integration/default/controls/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,20 @@
describe file('/usr/local/src/kubernetes/shell-operator') do
it { should be_directory }
end
describe file('/usr/local/kubernetes-devtools-stern-1.11.0/') do
it { should be_directory }
end
describe file('/usr/local/bin/stern') do
it { should be_symlink }
it { should be_file }
it { should_not be_directory }
end
describe file('/usr/local/kubernetes-devtools-dive-0.9.2/') do
it { should be_directory }
end
describe file('/usr/local/bin/dive') do
it { should be_symlink }
it { should be_file }
it { should_not be_directory }
end
end
16 changes: 16 additions & 0 deletions test/integration/redhat/controls/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,20 @@
describe file('/usr/local/src/kubernetes/shell-operator') do
it { should be_directory }
end
describe file('/usr/local/kubernetes-devtools-stern-1.11.0/') do
it { should be_directory }
end
describe file('/usr/local/bin/stern') do
it { should be_symlink }
it { should be_file }
it { should_not be_directory }
end
describe file('/usr/local/kubernetes-devtools-dive-0.9.2/') do
it { should be_directory }
end
describe file('/usr/local/bin/dive') do
it { should be_symlink }
it { should be_file }
it { should_not be_directory }
end
end

0 comments on commit a9b2fa7

Please sign in to comment.