Remove binary file from molecule test suite (#298) (#302)

[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>
This commit is contained in:
Mike Graves
2021-12-07 03:39:20 -05:00
committed by GitHub
parent dc5a1e6dd1
commit bc168a5727
3 changed files with 45 additions and 27 deletions

View File

@@ -0,0 +1,3 @@
---
bugfixes:
- remove binary file from k8s_cp test suite (https://github.com/ansible-collections/kubernetes.core/pull/298).

View File

@@ -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