Skip to content

Commit

Permalink
Remove binary file from molecule test suite (#298) (#302)
Browse files Browse the repository at this point in the history
[backport/2.2] Remove binary file from molecule test suite

SUMMARY

The binary file used to test k8s_cp is causing larger problems
downstream. There's no reason why the binary file needs to function as
all we care about is that the content of the file has not changed during
the copy process. This can be accomplished by comparing file hashes.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION


Reviewed-by: Abhijeet Kasurde 
Reviewed-by: None 
(cherry picked from commit fa65698)

Reviewed-by: None <None>
  • Loading branch information
gravesm committed Dec 7, 2021
1 parent dc5a1e6 commit bc168a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
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

0 comments on commit bc168a5

Please sign in to comment.