This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test for maintenance-mode subcommand and removed old testes rel…
…ated to maintenance-mode
- Loading branch information
Jameer Pathan
committed
Jun 20, 2019
1 parent
d3a6a9b
commit c89f7a9
Showing
5 changed files
with
224 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Usage: | ||
foreman-maintain maintenance-mode [OPTIONS] SUBCOMMAND [ARG] ... | ||
Parameters: | ||
SUBCOMMAND subcommand | ||
[ARG] ... subcommand arguments | ||
Subcommands: | ||
start Start maintenance-mode | ||
stop Stop maintenance-mode | ||
status Get maintenance-mode status | ||
is-enabled Get maintenance-mode status code | ||
Options: | ||
-h, --help print help | ||
""" | ||
from testfm.base import Base | ||
|
||
|
||
class MaintenanceMode(Base): | ||
"""Manipulates Foreman-maintain's maintenance-mode command""" | ||
command_base = 'maintenance-mode' | ||
|
||
@classmethod | ||
def start(cls, options=None): | ||
"""foreman-maintain maintenance-mode start [OPTIONS]""" | ||
cls.command_sub = 'start' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def stop(cls, options=None): | ||
"""foreman-maintain maintenance-mode stop [OPTIONS]""" | ||
cls.command_sub = 'stop' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def status(cls, options=None): | ||
"""foreman-maintain maintenance-mode status [OPTIONS]""" | ||
cls.command_sub = 'status' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def is_enabled(cls, options=None): | ||
"""foreman-maintain maintenance-mode is-enabled [OPTIONS]""" | ||
cls.command_sub = 'is-enabled' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
from testfm.maintenance_mode import MaintenanceMode | ||
from testfm.log import logger | ||
import yaml | ||
|
||
|
||
def test_positive_maintenance_mode(setup_sync_plan, ansible_module): | ||
"""Test foreman-maintain maintenance-mode subcommand | ||
:id: 51d76219-d3cc-43c0-9894-7bcb75c163c3 | ||
:setup: | ||
1. foreman-maintain should be installed. | ||
2. active sync-plans | ||
3. set :manage_crond: true in /etc/foreman-maintain/foreman_maintain.yml' | ||
:steps: | ||
1. Verify that maintenance-mode is Off. | ||
2. Start maintenance-mode. | ||
3. Verify that active sync-plans got disabled or not. | ||
4. Verify that FOREMAN_MAINTAIN is mentioned in iptables list. | ||
5. Verify that crond.service is stopped. | ||
6. Validate maintenance-mode status command's output. | ||
7. Validate maintenance-mode is-enabled command's output. | ||
8. Stop maintenance-mode. | ||
9. Verify that disabled sync-plans got re-enabled or not. | ||
10. Verify that FOREMAN_MAINTAIN is not mentioned in iptables list. | ||
11. Verify that crond.service is running. | ||
12. Validate maintenance-mode status command's output. | ||
13. Validate maintenance-mode is-enabled command's output. | ||
:expectedresults: foreman-maintain maintenance-mode start/stop able | ||
to disable/enable sync-plan, stop/start crond.service and is able to add | ||
FOREMAN_MAINTAIN chain rule in iptables. | ||
:CaseImportance: Critical | ||
""" | ||
sync_ids, sat_hostname = setup_sync_plan() | ||
maintenance_mode_off = ['Status of maintenance-mode: Off', 'Iptables chain: absent', | ||
'sync plans: enabled', 'cron jobs: running'] | ||
maintenance_mode_on = ['Status of maintenance-mode: On', 'Iptables chain: present', | ||
'sync plans: disabled', 'cron jobs: not running'] | ||
|
||
# Verify maintenance-mode status | ||
setup = ansible_module.command(MaintenanceMode.status()) | ||
for result in setup.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
# Verify maintenance-mode is-enabled | ||
setup = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in setup.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 1 | ||
assert 'Maintenance mode is Off' in result['stdout'] | ||
|
||
# Verify maintenance-mode start | ||
contacted = ansible_module.command(MaintenanceMode.start()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert result["rc"] == 0 | ||
assert "Total {} sync plans are now disabled.".format(len(sync_ids)) in result['stdout'] | ||
ansible_module.fetch( | ||
src="/var/lib/foreman-maintain/data.yml", | ||
dest="./" | ||
) | ||
with open('./{0}/var/lib/foreman-maintain/data.yml'.format(sat_hostname)) as f: | ||
data_yml = yaml.safe_load(f) | ||
assert len(sync_ids) == len(data_yml[':default'][':sync_plans'][':disabled']) | ||
assert sorted(sync_ids) == sorted(data_yml[':default'][':sync_plans'][':disabled']) | ||
check_iptables = ansible_module.command("iptables -L") | ||
for rules in check_iptables.values(): | ||
logger.info(rules['stdout']) | ||
assert "FOREMAN_MAINTAIN" in rules['stdout'] # Assert FOREMAN_MAINTAIN is listed iptables | ||
# Assert crond.service is stopped | ||
contacted = ansible_module.service_facts() | ||
assert 'stopped' in contacted.values()[0]['ansible_facts']['services']['crond.service']['state'] | ||
# Verify maintenance-mode status | ||
contacted = ansible_module.command(MaintenanceMode.status()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
for i in maintenance_mode_on: | ||
assert i in result['stdout'] | ||
# Verify maintenance-mode is-enabled | ||
contacted = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
assert 'Maintenance mode is On' in result['stdout'] | ||
|
||
# Verify maintenance-mode stop | ||
contacted = ansible_module.command(MaintenanceMode.stop()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert result["rc"] == 0 | ||
assert "FAIL" not in result['stdout'] | ||
assert "Total {} sync plans are now enabled.".format(len(sync_ids)) in result['stdout'] | ||
ansible_module.fetch( | ||
src="/var/lib/foreman-maintain/data.yml", | ||
dest="./" | ||
) | ||
with open('./{0}/var/lib/foreman-maintain/data.yml'.format(sat_hostname)) as f: | ||
data_yml = yaml.safe_load(f) | ||
assert len(sync_ids) == len(data_yml[':default'][':sync_plans'][':enabled']) | ||
assert sorted(sync_ids) == sorted(data_yml[':default'][':sync_plans'][':enabled']) | ||
check_iptables = ansible_module.command("iptables -L") | ||
for rules in check_iptables.values(): | ||
logger.info(rules['stdout']) | ||
assert "FOREMAN_MAINTAIN" not in rules['stdout'] # Assert FOREMAN_MAINTAIN not listed in iptables | ||
# Assert crond.service is running | ||
contacted = ansible_module.service_facts() | ||
assert 'running' in contacted.values()[0]['ansible_facts']['services']['crond.service']['state'] | ||
# Verify maintenance-mode status | ||
contacted = ansible_module.command(MaintenanceMode.status()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
for i in maintenance_mode_off: | ||
assert i in result['stdout'] | ||
# Verify maintenance-mode is-enabled | ||
contacted = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 1 | ||
assert 'Maintenance mode is Off' in result['stdout'] |