Skip to content

Commit

Permalink
Add Contributaiong (#431)
Browse files Browse the repository at this point in the history
* Add Contributaiong

* enhance contributaion

* fix readme

* Add comments to sample var files for simplicity

* Minor typo

---------

Co-authored-by: Pradeepsingh Bhati <pradeep.bhati@nutanix.com>
  • Loading branch information
alaa-bish and bhati-pradeep authored Nov 9, 2023
1 parent ec3113e commit 9e688b1
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,56 @@ We glady welcome contributions from the community. From updating the documentati
* [Contributing Guide](CONTRIBUTING.md)
* [Code of Conduct](CODE_OF_CONDUCT.md)

# Testing

## Integration Testing for Nutanix Ansible Modules

To conduct integration tests for a specific Ansible module such as the `ntnx_vms` module, the following step-by-step procedures can be followed:

### Prerequisites
- Ensure you are in the installed collection directory where the module is located. For example:
`/Users/mac.user1/.ansible/collections/ansible_collections/nutanix/ncp`

### Setting up Variables
1. Navigate to the `tests/integration/targets` directory within the collection.

2. Define the necessary variables within the feature-specific var files, such as `tests/integration/targets/prepare_env/vars/main.yml`, `tests/integration/targets/prepare_foundation_env/vars/main.yml`,`tests/integration/targets/prepare_ndb_env/tasks/prepare_env.yml`, etc.

Note: For Karbon and FC tests, use the PC vars exclusively, as these features rely on pc setup. Not all variables are mandatory; define only the required variables for the particular feature to be tested.

3. Run the test setup playbook for the specific feature you intend to test to create entities in setup:
- For PC, NDB, and Foundation tests, execute the relevant commands:
```bash
ansible-playbook prepare_env/tasks/prepare_env.yml
ansible-playbook prepare_ndb_env/tasks/prepare_env.yml
ansible-playbook prepare_foundation_env/tasks/prepare_foundation_env.yml
```

### Running Integration Tests
1. Conduct integration tests for all modules using:
```bash
ansible-integration
```

2. To perform integration tests for a specific module:
```bash
ansible-integration module_test_name
```
Replace `module_test_name` with test directory name under tests/integration/targets.

### Cleanup
1. After completing the integration tests, perform a cleanup specific to the tested feature:
- For PC tests, execute the command:
```bash
ansible-playbook prepare_env/tasks/clean_up.yml
```
- For Foundation tests, execute the command:
```bash
ansible-playbook prepare_foundation_env/tasks/clean_up.yml
```

By following these steps, you can perform comprehensive integration testing for the specified Ansible module and ensure a clean testing environment afterward. Define only the necessary variables for the specific feature you intend to test.

# Examples
## Playbook for IaaS provisioning on Nutanix

Expand Down
145 changes: 145 additions & 0 deletions tests/integration/targets/prepare_env/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
ip: TEST_PC_IP
username: TEST_PC_USERNAME
password: TEST_PC_PASSWORD
validate_certs: TEST_VALIDATE_CERT_FLAG

# for NKE related tests
k8s_version: TEST_K8S_VERSION
host_os: TEST_HOST_OS
nutanix_cluster_password: TEST_CLUSTER_PASSWORD
nutanix_cluster_username: TEST_CLUSTER_USERNAME
cni:
node_cidr_mask_size: "TEST_MASK_CIDR"
service_ipv4_cidr: "TEST_SERVICE_CIDR"
pod_ipv4_cidr: "TEST_POD_CIDR"

# docker registry url for nke tests
url: TEST_REGISTRIES_URL

# cluster reference for several tests
cluster:
name: TEST_CLUSTER_NAME
uuid: TEST_CLUSTER_UUID

# For tests like vms, etc.
network:
dhcp:
name: TEST_VLAN_NAME
uuid: TEST_VLAN_UUID
static:
ip: TEST_STATIC_IP

vm_owner:
name: TEST_OWNER_NAME
uuid: TEST_OWNER_UUID

# can be skipped
todelete: []

# for ntnx_image tests
disk_image:
url: TEST_IMAGE_URL
dest: TEST_DEST_PATH
checksum: TEST_CHECKSUM
centos: "TEST_CENTOS"

# used in test setup for creation of networks and some networking tests
external_nat_subnets:
name: TEST_NAT_NAME
vlan_id: TEST_VLAN_ID
gateway_ip_address: TEST_GATEWAY_IP
network_prefix: TEST_PREFIX
network_ip: TEST_NETWORK_IP
dhcp:
start_address: TEST_START_DHCP
end_address: TEST_END_DHCP
static:
start_address: TEST_START_STATIC
end_address: TEST_END_STATIC

# Details for creating this resources during test setup and same are used related tests
vpc_name: TEST_VPC_NAME
vm_name: TEST_VM_NAME
static_subnet_name: TEST_STATIC_SUBNET
overlay_subnet:
name: TEST_OVERLAY_NAME
network_ip: TEST_OVERLAY_NETWORK_IP
network_prefix: TEST_OVERLAY_PREFIX
gateway_ip: TEST_OVERLAY_GATEWAY_IP
private_ip: TEST_OVERLAY_PRIVATE_IP

# security rule related tests
quarantine_rule_uuid: TEST_QUARANTINE_UUID
categories:
apptiers:
- Default
- sub_app_1

# name of images in setup for vms test
centos: "TEST_CENTOS"
ubuntu: "TEST_UBUNTU"

# virtual switch reference primarily for vms test
virtual_switch:
name: TEST_SWITCH_NAME
uuid: TEST_SWITCH_UUID

# storage reference primarily for vms test
storage_container:
name: TEST_CONTAINER_NAME
uuid: TEST_CONTAINER_UUID

# user and user groups from AD for user and user groups tests
users:
- TEST_USER_UUID_1
- TEST_USER_UUID_2
user_groups:
- TEST_GROUP_UUID

# project reference for vms test
project:
name: TEST_PROJECT_NAME
uuid: TEST_PROJECT_UUID

# list of roles for advanced projects tests
roles:
- "TEST_ROLES_NAME_1"
- "TEST_ROLES_NAME_2"
- "TEST_ROLES_NAME_3"
- "TEST_ROLES_NAME_4"

# account reference for advanced projects related tests
accounts:
- name: "NTNX_LOCAL_AZ"
uuid: "TEST_ACCOUNT_UUID"

# user and user groups for projects tests when new users are to be added
new_user: "TEST_NEW_USER_EMAIL"
new_user_group: "TEST_NEW_USER_GROUP_DN"

# acp tests related vars
acp:
role:
name: "Project Admin"
uuid: TEST_ROLE_UUID
user_uuid: TEST_USER_UUID
user_group_uuid: TEST_GROUP_UUID

# auth details for projects, acps, user and user groups related tests
distinguished_name: "TEST_DISTINGUISHED_NAME"
principal_name: "TEST_PRINCIPAL_NAME"
directory_service_uuid: "TEST_DIRECTORY_UUID"
identity_provider_uuid: "TEST_IDENTITY_UUID"

# vm created during test setup for dr tests
dr_vm_name: TEST_VM_NAME

# dr related tests vars
dr:
primary_az_url: TEST_PRIMARY_URL
recovery_az_url: TEST_RECOVERY_URL
recovery_site_network: "TEST_RECOVERY_NETWORK"
recovery_ip1: TEST_RECOVERY_IP1
recovery_ip2: TEST_RECOVERY_IP2
gateway_ip: TEST_GATEWAY_IP
prefix: TEST_PREFIX
95 changes: 95 additions & 0 deletions tests/integration/targets/prepare_foundation_env/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# foundation host to be ued in tests
foundation_host: "TEST_FOUNDATION_HOST"

# the dir in local machine where test setup will install nos image and pick during image upload tests
source: 'TEST_SOURCE_PATH'

# nos image url for images tests
image_url: "TEST_IMAGE_URL"

# nos package name
nos_package: "TEST_NOS_PACKAGE"

# common details for all nodes used under test
cvm_gateway: "TEST_CVM_GATEWAY"
cvm_netmask: "TEST_CVM_NETMASK"
hypervisor_gateway: "TEST_HYPERVISOR_GATEWAY"
hypervisor_netmask: "TEST_HYPERVISOR_NETMASK"
default_ipmi_user: "TEST_IPMI_USER"

# IBIS_node is just a random name we used for our tests
# this nodes where used for tests related to bare metal, dos and aos installed nodes.
IBIS_node:
block_id: "TEST_BLOCK_ID"
node1:
node_serial: "TEST_NODE_SERIAL_1"
hypervisor_hostname: "TEST_HYPERVISOR_HOSTNAME_1"
cvm_ip: TEST_CVM_IP_1
hypervisor_ip: TEST_HYPERVISOR_IP_1
node_position: "TEST_NODE_POSITION_1"
hypervisor: "TEST_HYPERVISOR_1"
ipmi_password: "TEST_IPMI_PASSWORD_1"
ipmi_ip: TEST_IPMI_IP_1
ipmi_netmask: "TEST_IPMI_NETMASK_1"
ipmi_gateway: TEST_IPMI_GATEWAY_1
node2:
node_serial: "TEST_NODE_SERIAL_2"
hypervisor_hostname: "TEST_HYPERVISOR_HOSTNAME_2"
cvm_ip: TEST_CVM_IP_2
hypervisor_ip: TEST_HYPERVISOR_IP_2
node_position: "TEST_NODE_POSITION_2"
hypervisor: "TEST_HYPERVISOR_2"
ipmi_password: "TEST_IPMI_PASSWORD_2"
ipmi_ip: TEST_IPMI_IP_2
node3:
node_serial: "TEST_NODE_SERIAL_3"
hypervisor_hostname: "TEST_HYPERVISOR_HOSTNAME_3"
cvm_ip: TEST_CVM_IP_3
hypervisor_ip: TEST_HYPERVISOR_IP_3
node_position: "TEST_NODE_POSITION_3"
hypervisor: "TEST_HYPERVISOR_3"
ipmi_password: "TEST_IPMI_PASSWORD_3"
ipmi_ip: TEST_IPMI_IP_3
node4:
node_serial: "TEST_NODE_SERIAL_4"
hypervisor_hostname: "TEST_HYPERVISOR_HOSTNAME_4"
cvm_ip: TEST_CVM_IP_4
hypervisor_ip: TEST_HYPERVISOR_IP_4
node_position: "TEST_NODE_POSITION_4"
hypervisor: "TEST_HYPERVISOR_4"
ipmi_password: "TEST_IPMI_PASSWORD_4"
ipmi_ip: TEST_IPMI_IP_4

# we used this nodes for our sanity tests.
nodes:
current_cvm_vlan_tag: "TEST_CVM_VLAN_TAG"
block_id: "TEST_BLOCK_ID_NODES"
node1:
cvm_ip: TEST_CVM_IP_NODE1
hypervisor: "TEST_HYPERVISOR_NODE1"
hypervisor_ip: TEST_HYPERVISOR_IP_NODE1
node_position: "TEST_NODE_POSITION_NODE1"
hypervisor_hostname: "TEST_HYPERVISOR_HOSTNAME_NODE1"
node_serial: "TEST_NODE_SERIAL_NODE1"
ipmi_password: "TEST_IPMI_PASSWORD_NODE1"
ipmi_ip: TEST_IPMI_IP_NODE1
ipmi_netmask: "TEST_IPMI_NETMASK_NODE1"
ipmi_gateway: TEST_IPMI_GATEWAY_NODE1
ntp_servers:
- "TEST_NTP_SERVER_1"
- "TEST_NTP_SERVER_2"
dns_servers:
- "TEST_DNS_SERVER_1"
- "TEST_DNS_SERVER_2"
backplane_vlan: "TEST_BACKPLANE_VLAN"
backplane_subnet: "TEST_BACKPLANE_SUBNET"
backplane_netmask: "TEST_BACKPLANE_NETMASK"

# this is for bmc ipmi config related tests
bmc:
ipmi_user: "TEST_IPMI_USER_BMC"
ipmi_password: "TEST_IPMI_PASSWORD_BMC"
ipmi_netmask: "TEST_IPMI_NETMASK_BMC"
ipmi_gateway: TEST_IPMI_GATEWAY_BMC
ipmi_mac: "TEST_IPMI_MAC"
ipmi_ip: TEST_IPMI_IP_BMC
Loading

0 comments on commit 9e688b1

Please sign in to comment.