Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove binary file from molecule test suite #298

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/298-remove-binary-file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- remove binary file from k8s_cp test suite (https://github.com/ansible-collections/kubernetes.core/pull/298).
Binary file removed molecule/default/roles/k8scopy/files/hello
Binary file not shown.
69 changes: 42 additions & 27 deletions molecule/default/roles/k8scopy/tasks/test_copy_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,65 @@
kubectl_path: "{{ kubectl_path }}"

# Binary file
- name: Generate random content
set_fact:
hello_arg: "{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=16') }}"

- name: Create temp binary file
tempfile:
state: file
register: binfile

- name: Generate random binary content
command: dd if=/dev/urandom of={{ binfile.path }} bs=1M count=1

- name: Copy executable into Pod
k8s_cp:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: files/hello
local_path: "{{ binfile.path }}"
state: to_pod

- name: Compare executable
kubectl_file_compare:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: "{{ role_path }}/files/hello"
kubectl_path: "{{ kubectl_path }}"
args:
- "{{ hello_arg }}"
- name: Get remote hash
kubernetes.core.k8s_exec:
namespace: "{{ copy_namespace }}"
pod: "{{ pod_with_one_container.name }}"
command: sha256sum -b /tmp/hello.exe
register: remote_hash

- name: Get local hash
command: sha256sum -b {{ binfile.path }}
register: local_hash

- assert:
that:
- remote_hash.stdout.split()[0] == local_hash.stdout.split()[0]

- name: Generate tempfile
tempfile:
state: file
register: binfile

- name: Copy executable from Pod
k8s_cp:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: /tmp/hello
local_path: "{{ binfile.path }}"
state: from_pod

- name: update executable permission
file:
path: /tmp/hello
mode: '0755'
- name: Get remote hash
kubernetes.core.k8s_exec:
namespace: "{{ copy_namespace }}"
pod: "{{ pod_with_one_container.name }}"
command: sha256sum -b /tmp/hello.exe
register: remote_hash

- name: Compare executable
kubectl_file_compare:
namespace: '{{ copy_namespace }}'
pod: '{{ pod_with_one_container.name }}'
remote_path: /tmp/hello.exe
local_path: /tmp/hello
kubectl_path: "{{ kubectl_path }}"
args:
- "{{ hello_arg }}"
- name: Get local hash
command: sha256sum -b {{ binfile.path }}
register: local_hash

- assert:
that:
- remote_hash.stdout.split()[0] == local_hash.stdout.split()[0]

# zip files
- name: copy zip file into remote pod
Expand Down