\ /
Backup  Ansible  Automation 

Using Molecule to testing the deployment of a Veritas Netbackup Master Server with DR Process

Introduction

Molecule is a tool used for testing Ansible roles on different kind of testing environments. You can learn more about the main purpose and concepts of Molecule in the following link:

Setting up Molecule for testing Ansible roles with Vagrant and Testinfra

On this post we will learn how to use molecule for automate the testing of Ansible role used for deploy a Veritas Netbackup Master Server and make after this a Disaster Recovery process on the server.

Prerequisites

Molecule installed with all the components that was detailed in the other post.

To continue, we need to clone a fresh copy of the NBU_DRAAS Sorint repo.

Link to repository

How it works

We have two roles on this repo.

  • install_master (Used for installation of NB Master Server)
  • dr_process (Used for make Disaster Recovery process)

Take a look to the main config Molecule file of dr_process role:

---
# roles/dr_process/molecule/default/molecule.yml
dependency:
  name: galaxy
driver:
  name: vagrant
  provider:
    name: virtualbox
platforms:
  - name: backup
    box: lgarcia/centos7
    memory: 4096
    cpu: 2
    interfaces:
      # Uncomment one of this blocks to configure Eth connection on the VM
      #####################################################################
      # Public Network bridging the host NIC####
      ##########################################
      #- network_name: public_network
      #  ip: <<IP>>
      #  bridge: <<INTERFACE>>
      ######################################################################
      # Private Network using virtual host NIC##
      ##########################################
      #- network_name: private_network
      # ip: <<IP>>
      #  name: <<INTERFACE>>
provisioner:
  name: ansible
  options:
    v: True
  inventory:
    hosts:
      all:
        vars:
          nbu_license: KJXZ-9YZW-LOJT-CZCP-3NPN-PJW4-LGO2-LM7M-LMPP-XC
          nbu_smart: /software/veritas_customer_registration_key.json
          nbu_smart_dest: /software/veritas_customer_registration_key.json
          nbu_sw_path: /software
          nbu_unarch_path: /software
          nbu_version: 8.2
          install_master__reinstall: n
          dr_process__catalog_packet: /software/DRPKG/Catalog_1594296652_FULL.drpkg
          dr_process__catalog_file: /software/DRPKG/Catalog_1594296652_FULL
          dr_process__contradr: P@ssw0rd
          dr_process__with_install: n
lint: |
  set -e
  yamllint .
  ansible-lint
scenario:
  test_sequence:
    - dependency
    - syntax
    - lint
    - create
    - prepare
    - converge
    - verify
    - destroy
verifier:
  name: testinfra
  enabled: True
  options:
    v: 1

This file is used for automate the deployment of a VM on our localhost using Vagrant for the automation and VirtualBox as hypervisor to manage the VM. The virtual machine deployed going to have four gigabytes of ram and two cores, a CentOS7 as an OS (Also we can use a RHEL distribution) and finally a network interface adapted to our needs.

Next are defined the provisioner for the VM (Obviously Ansible) and the inventory vars that we need for the role. This is necessary because Molecule has not able to pointing to our inventory file.

Also are defined the tools that are used for make the linting on the repo code. Yamllint for check good practices of YAML code and Ansible-Lint for check the good practises of Ansible.

Finally testinfra is used as a verifier of the environment once the role has been executed on the VM. This tool uses Python scripts to testing.

The test sequence tell to Molecule which are the steps needed when we invoke the "molecule test" command.

Execution

For make the execution of Molecule. The currentdir must be the role directory. We are going to use the dr_process because we are going to specify also the installation of NB Master Server before execution of the DR process.

So only type the following command:

molecule test -s default

This process are going to make the next things in order.

  1. Syntax checking of role code. The execution will stop if any error occurs.
  2. Code linting of the role.
  3. Creation of the Centos7 VM on your VirtualBox.
  4. Execution of prepare.yml playbook. This playbook is executed on the VM to prepare them for the role execution. Without Molecule to execute these tasks it was necessary to do it manually for the testing environment. This tasks copy from our localhost the files needed for the dr process and open firewall ports on the VM for make tests in addition to other things.
---
# roles/dr_process/molecule/default/prepare.yml
- name: Prepare instance for role execution
  hosts: all
  become: True
  vars:
    dr_process__nbu_basic_path: /BASIC
    dr_process__nbu_backup_src_path: /software/backup_image.tar
    dr_process__nbu_backup_dest_path: /BASIC/backup_image.tar
    dr_process__backup_files:
      - "backup_1594296620_C1_F1.1594296620.img"
      - "backup_1594296620_C1_F1.1594296620.info"
      - "backup_1594296620_C1_HDR.1594296620.img"
      - "backup_1594296620_C1_HDR.1594296620.info"
      - "backup_1594296652_C1_F1.1594296652.img"
      - "backup_1594296652_C1_F1.1594296652.info"
      - "backup_1594296652_C1_HDR.1594296652.img"
      - "backup_1594296652_C1_HDR.1594296652.info"
      - "backup_1594296652_C1_TIR.1594296652.img"
      - "backup_1594296652_C1_TIR.1594296652.info"
  tasks:
  - name: dr_process | molecule | prepare.yml | Create NBU bin path
    file:
      path: "{{ nbu_unarch_path }}"
      state: directory
      owner: root
      group: root
  - name: dr_process | molecule | prepare.yml | Copy Veritas Registration Key to NBU bin path
    copy:
      src: "{{ nbu_smart }}"
      dest: "{{ nbu_smart_dest }}"
      owner: root
      group: root
  - name: dr_process | molecule | prepare.yml | Create BASIC path
    file:
      path: "{{ dr_process__nbu_basic_path }}"
      state: directory
      owner: root
      group: root
  - name: dr_process | molecule | prepare.yml | Copy backup_image.tar to BASIC path on VM
    copy:
      src: "{{ dr_process__nbu_backup_src_path }}"
      dest: "{{ dr_process__nbu_backup_dest_path }}"
  - name: dr_process | molecule | prepare.yml | Extract backup_image.tar in BASIC path
    unarchive:
      src: "{{ dr_process__nbu_backup_dest_path }}"
      dest: "{{ dr_process__nbu_basic_path }}"
      remote_src: True
  - name: dr_process | molecule | prepare.yml | Copy files from backup to correct location
    copy:
      src: "{{ dr_process__nbu_basic_path }}/MSDP/DR/{{ item }}"
      dest: "{{ dr_process__nbu_basic_path }}"
      remote_src: True
    loop: "{{ dr_process__backup_files }}"

  - name: dr_process | molecule | prepare.yml | Install expect package # noqa 403
    yum:
      name: expect
      state: latest
  - name: dr_process | molecule | prepare.yml | Open HTTPS service on firewall-cmd
    firewalld:
      service: https
      permanent: True
      state: enabled
      zone: public
  - name: dr_process | molecule | prepare.yml | Reload firewall-cmd service
    service:
      name: firewalld
      state: reloaded
  1. The next step execute the converge.yml playbook. This playbook is so simple. Only have a include statement of the roles that we need to test on the VM. So this playbook will execute the steps to install the master server and make after the dr_process in this order. You can check the roles code on the repo.
---
# roles/dr_process/molecule/default/converge.yml
- name: Converge
  hosts: all
  become: True
  tasks:
    - name: "Include install_master"
      include_role:
        name: "install_master"
    - name: "Include dr_process"
      include_role:
        name: "dr_process"
  1. After the execution of the roles is time to make some tests to verify if all the things are fine with the role execution on the VM. For this purpose we developed a Python script to check some things like NB processes, users, groups, sockets and packages. If all it's fine Testinfra show a message which say that 100% of tests are passed succesfully.
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest
import testinfra.utils.ansible_runner

def test_nbu_packages_are_installed(host):
    pkgs_list = ["VRTSnbpck","VRTSnbjava","VRTSnetbp","VRTSpbx","VRTSnbjre","VRTSpddea","VRTSnbcfg","VRTSnbclt","VRTSpddes"]
    for package in pkgs_list:
        nbu_packages = host.package(package)
        assert nbu_packages.is_installed
def test_nbu_processes_are_running(host):
    proc_nbu_list = ["vnetd","bpclntcmd","nbaudit","bpcd","nbdisco","nbevtmgr","nbemm","nbrb","bprd","bpdbm","bpcompatd","nbjm","bpjobd","nbpem","nbstserv","nbrmms","nbproxy","nbsl","nbim","nbvault","nbsvcmon","bpdbm","nbatd"]
    proc_nbu_running = str([host.process.filter()])
    for proc in proc_nbu_list:
        assert proc in proc_nbu_running
def test_nbu_user_nbwebsvc_exists(host):
    nbu_user = host.user("nbwebsvc")
    assert nbu_user.exists
def test_nbu_group_nbwebgrp_exists(host):
    nbu_group = host.group("nbwebgrp")
    assert nbu_group.exists
def test_nbu_ports_are_listenting(host):
    ports_list = ["1556","13724","443"]
    for port in ports_list:
        port_check = host.socket("tcp://0.0.0.0:"+port)
        assert port_check.is_listening
  1. The final step is the destruction of the VM. We don't need to define it in this case. Molecule do it automatically. Also if something goes bad during the execution of the test sequence Molecule automatically will broke the sequence and destroy the VM for the next time execution.

Summary

As we can see Molecule have a lot of possibilities to testing and we only need to execute a simple command for doing the testing process. But it not finish here, Molecule support integration with platforms like Docker, Azure, AWS, etc.... for the deployment of testing environments.

You can check now how to deploy a testing environment on Azure Cloud platform with free account for testing the Netbackup Master Server and Disaster Recovery process on the following link:

Using Molecule to testing the deployment of a Veritas Netbackup Master Server with DR Process on Azure Cloud

comments powered by Disqus