Skip to content

Commit

Permalink
First integration test (contributes to IBM-Blockchain#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Stone <[email protected]>
  • Loading branch information
Simon Stone committed Jun 17, 2020
1 parent 5ed5b2f commit fcb8a00
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ dmypy.json
ibm-blockchain_platform-*.tar.gz

# generated documentation
docs/source/modules/*.rst
docs/source/modules/*.rst

# test output
tests/output
15 changes: 15 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ steps:
oc login -u apikey -p $(IBM Cloud API Key)
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Log in to IBM Cloud
- script: |
set -ex
ibmcloud oc cluster get -c $(IBM Cloud OpenShift Cluster ID) --json > cluster.json
export TEST_RUN_ID=$(dd if=/dev/urandom bs=4096 count=1 2>/dev/null | shasum | awk '{print $1}')
export SHORT_TEST_RUN_ID=$(echo ${TEST_RUN_ID} | awk '{print substr($1,1,8)}')
yq -yi '.api_endpoint="$(IBM Blockchain Platform API Endpoint)"' tests/integration/integration_config.yml
yq -yi '.api_authtype="$(IBM Blockchain Platform API Auth Type)"' tests/integration/integration_config.yml
yq -yi '.api_key="$(IBM Blockchain Platform API Key)"' tests/integration/integration_config.yml
yq -yi '.api_secret="$(IBM Blockchain Platform API Secret)"' tests/integration/integration_config.yml
yq -yi '.k8s_namespace="$(IBM Blockchain Platform K8S Namespace)"' tests/integration/integration_config.yml
yq -yi .test_run_id=\"${TEST_RUN_ID}\" tests/integration/integration_config.yml
yq -yi .short_test_run_id=\"${SHORT_TEST_RUN_ID}\" tests/integration/integration_config.yml
ansible-test integration
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Run tests
- script: |
set -ex
VERSION=$(yq -r .version galaxy.yml)
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/integration_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# SPDX-License-Identifier: Apache-2.0
#
---
api_endpoint: https://ibp-console.example.org:32000
api_authtype: basic
api_key: xxxxxxxx
api_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
k8s_namespace: ibp
test_run_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
short_test_run_id: xxxxxxxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# SPDX-License-Identifier: Apache-2.0
#
---
- assert:
that:
- result is success
- "result is {{ 'changed' if expected_change else 'not changed' }}"
- result.certificate_authority.name == ca_name

- uri:
url: "{{ result.certificate_authority.api_url }}/cainfo"
validate_certs: no
until: result.status == 200
retries: 60
delay: 1
register: result

- assert:
that:
- result.json.result.CAChain is defined

- k8s_info:
api_version: ibp.com/v1alpha1
kind: IBPCA
namespace: "{{ k8s_namespace }}"
name: "{{ k8s_name }}"
register: result

- assert:
that:
- result is success
- result.resources
- result.resources[0].spec.configoverride.ca.registry.identities[0].name == expected_enrollment_id
- result.resources[0].spec.configoverride.ca.registry.identities[0].pass == expected_enrollment_secret
- result.resources[0].spec.resources.ca.requests.cpu == expected_cpu
- result.resources[0].spec.resources.ca.requests.memory == expected_memory
- result.resources[0].spec.storage.ca.class == expected_storage_class
- result.resources[0].spec.storage.ca.size == expected_storage_size
103 changes: 103 additions & 0 deletions tests/integration/targets/certificate_authority/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#
# SPDX-License-Identifier: Apache-2.0
#
---
- name: Set test facts
set_fact:
ibp_connection_info: &ibp_connection_info
api_endpoint: "{{ api_endpoint | mandatory }}"
api_authtype: "{{ api_authtype | mandatory }}"
api_key: "{{ api_key | mandatory }}"
api_secret: "{{ api_secret | mandatory }}"
ca_name: "Test CA {{ short_test_run_id }}"
ca_config_override:
ca:
registry:
maxenrollments: -1
identities:
- name: admin
pass: adminpw
type: client
maxenrollments: -1
attrs:
hf.Registrar.Roles: "*"
hf.Registrar.DelegateRoles: "*"
hf.Revoker: true
hf.IntermediateCA: true
hf.GenCRL: true
hf.Registrar.Attributes: "*"
hf.AffiliationMgr: true
k8s_namespace: "{{ k8s_namespace | mandatory }}"
k8s_name: "testca{{ short_test_run_id }}"
wait_timeout: 600

- name: Run tests
block:
- name: Create certificate authority
ibm.blockchain_platform.certificate_authority:
state: present
<<: *ibp_connection_info
name: "{{ ca_name }}"
config_override: "{{ ca_config_override }}"
wait_timeout: "{{ wait_timeout }}"
register: result

- include_tasks: assertions.yml
vars:
expected_change: yes
expected_enrollment_id: admin
expected_enrollment_secret: adminpw
expected_cpu: 100m
expected_memory: 200M
expected_storage_class: default
expected_storage_size: 20Gi

- name: Ensure idempotency
ibm.blockchain_platform.certificate_authority:
state: present
<<: *ibp_connection_info
name: "{{ ca_name }}"
config_override: "{{ ca_config_override }}"
wait_timeout: "{{ wait_timeout }}"
register: result

- include_tasks: assertions.yml
vars:
expected_change: no
expected_enrollment_id: admin
expected_enrollment_secret: adminpw
expected_cpu: 100m
expected_memory: 200M
expected_storage_class: default
expected_storage_size: 20Gi

- name: Change resources
ibm.blockchain_platform.certificate_authority:
state: present
<<: *ibp_connection_info
name: "{{ ca_name }}"
config_override: "{{ ca_config_override }}"
resources:
ca:
requests:
cpu: 200m
memory: 400M
wait_timeout: "{{ wait_timeout }}"
register: result

- include_tasks: assertions.yml
vars:
expected_change: yes
expected_enrollment_id: admin
expected_enrollment_secret: adminpw
expected_cpu: 200m
expected_memory: 400M
expected_storage_class: default
expected_storage_size: 20Gi

always:
- name: Delete certificate authority
ibm.blockchain_platform.certificate_authority:
state: absent
<<: *ibp_connection_info
name: "{{ ca_name }}"

0 comments on commit fcb8a00

Please sign in to comment.